Utility Functions¶
The utility functions provides a set of scripts and objects aiming at facilitating the implementation of more structured algorithms and for testing purposes. In the current release, the utility functions are substantially comprised of a function for generating quanum circuits and by two Fermi-Hubbard toy model functions.
Random Circuit Generator¶
This function generates a quantum circuit with a specified number of qubits and gates, applying random gates sampled frm a user-specified basis set. This function is an useful tool for genereting test circuits, for experimenting the effect of random circuit in quantum computational pipeline and for the generation of initial states in quantum optimization algorithms.
Let’s see how to use the function with a basic example.
Note
The function is exported from qarp.utils.
The following arguments are accepted as part of the API:
num_gates(int): Number of gates in the circuit. Must be a positive integer.num_qubits(int): The number of qubits in the circuit. Must be a positive integer.gate_set: List ofqarpx.GateTypevalues to sample from.
The function returns a built SimpleBlock.
from qarp.utils import generate_random_circuit
import qarpx as qx
gate_set = [qx.GateType.Rz, qx.GateType.Ry, qx.GateType.Rx]
num_gates = 6
num_qubits = 4
my_block = generate_random_circuit(num_gates, num_qubits, gate_set)
The gate set may contain rotation operators, single-qubit no-parameter gates, two-qubit gates,
and controlled rotations. Note that, if a seed is desired, it can be set in the
qarp.config.seed variable.
You can visualise the block using our in-house visualisation tool:
from qarp.plotting import plot
plot(my_block)
Fermi-Hubbard toy models¶
The module qarp.utils contains two functions for constructing a Fermi-Hubbard Hamiltonian with a Trotterized
UCC Singles and Doubles (UCCSD) block. UCCSD is a parametrized ansatz, widely used in chemistry and electronic
simulation, built from single and double fermionic excitation operators. More details about the ansatz are provided
in the block documentation.
The functions FH_ham_and_wf and FH_ham_and_wf_singles_and_doubles both take the following arguments:
n (int): Number of sites. For each site there are two single particle states
t (float): Kinetic or hopping energy between sites.
U (float): Interaction energy
Each constructs a Fermi-Hubbard chain Hamiltonian and then, performing a Jordan-Wigner transformation, maps it to
Pauli matrices. Further, it constructs a UCCSD block on the half-filled reference state.
FH_ham_and_wf always uses generalised excitations and prepares the reference with a
MappedONVStateBlock; FH_ham_and_wf_singles_and_doubles prepares it with a
ComputationalBasisStateBlock and takes generalised (bool, default True) to choose. Further details are
provided in the operators documentation.
Let’s see an example usage.
from qarp.utils import FH_ham_and_wf, FH_ham_and_wf_singles_and_doubles
U=2.13 #interaction energy
t=1 #hopping
n=2 #number of sites
FH_ham, uccsd_wfn = FH_ham_and_wf(n, t, U) # Hamiltonian and generalised UCCSD wfn
FH_ham, uccsd_wfn = FH_ham_and_wf_singles_and_doubles(n, t, U, generalised=False)