Base Backends and Device
BaseDevice
- class openqaoa.backends.devices_core.DeviceBase[source]
An object that contains the relevant information required to access certain backends. Other Access Objects have to inherit from this object.
- abstract check_connection()[source]
This method should allow a user to easily check if the credentials provided to access the remote QPU is valid.
- Returns:
True if a connection can be established. If False, the error should be logged and printable. (Not creating an exception here is good for extendibility. i.e. able to try multiple providers without exiting the program.)
- Return type:
BaseBackends
- class openqaoa.backends.basebackend.VQABaseBackend(prepend_state, append_state)[source]
This is the Abstract Base Class over which other classes will be built. Since, this is an Abstract Base class, in order to prevent its initialisation the class methods –
__init__
and__cal__
will be decorated as abstractmethods.The Child classes MUST implement and override these abstract methods in their implementation specific to their needs.
Note
In addition one can also implement other methods which are not necessitated by the
VQABaseBackend
Base Class- Parameters:
prepend_state (Union[QuantumCircuitBase, List[complex], np.ndarray]) – The initial state to start the quantum circuit in the backend.
append_state (Union[QuantumCircuitBase, np.ndarray]) – The final state to append to the quantum circuit in the backend.
- abstract property exact_solution
Use linear algebra to compute the exact solution of the problem Hamiltonian classically.
- class openqaoa.backends.basebackend.QAOABaseBackend(qaoa_descriptor, prepend_state, append_state, init_hadamard, cvar_alpha)[source]
This class inherits from the VQABaseBackend and needs to be backend agnostic to QAOA implementations on different devices and their respective SDKs.
- Parameters:
qaoa_descriptor (QAOADescriptor) – This object handles the information to design the QAOA circuit ansatz
prepend_state (Union[QuantumCircuitBase, List[complex]]) – Warm Starting the QAOA problem with some initial state other than the regular $|+ rangle ^{otimes n}$
append_state (Union[QuantumCircuitBase, List[complex]]) – Appending a user-defined circuit/state to the end of the QAOA routine
init_hadamard (bool) – Initialises the QAOA circuit with a hadamard when
True
cvar_alpha (float) –
- assign_angles(params)[source]
Assigns the angle values of the variational parameters to the circuit gates specified as a list of gates in the
abstract_circuit
.- Parameters:
params (QAOAVariationalBaseParams) – The variational parameters(angles) to be assigned to the circuit gates
- Return type:
- bitstring_energy(bitstring)[source]
Computes the energy of a given bitstring with respect to the cost Hamiltonian.
- Parameters:
bitstring (Union[List[int],str]) – A list of integers 0 and 1 of length n_qubits representing a configuration.
- Returns:
The energy of a given bitstring with respect to the cost Hamiltonian.
- Return type:
- abstract circuit_to_qasm()[source]
Implement a method to construct a QASM string from the current state of the QuantumCircuit for the backends
- property exact_solution
Computes exactly the minimum energy of the cost function and its corresponding configuration of variables using standard numpy module.
- Returns:
(energy, config) –
The minimum eigenvalue of the cost Hamiltonian,
The minimum energy eigenvector as a binary array configuration: qubit-0 as the first element in the sequence
- Return type:
Tuple[float, list]
- expectation(**kwargs)
Call the execute function on the circuit to compute the expectation value of the Quantum Circuit w.r.t cost operator
- expectation_w_uncertainty(**kwargs)
Call the execute function on the circuit to compute the expectation value of the Quantum Circuit w.r.t cost operator along with its uncertainty
- abstract get_counts(params, n_shots=None)[source]
This method will be implemented in the child classes according to the type of backend used.
- Parameters:
params (QAOAVariationalBaseParams) – The QAOA parameters - an object of one of the parameter classes, containing variable parameters.
n_shots (int) – The number of shots to be used for the measurement. If None, the backend default.
- Return type:
- obtain_angles_for_pauli_list(input_gate_list, params)[source]
This method uses the pauli gate list information to obtain the pauli angles from the VariationalBaseParams object. The floats in the list are in the order of the input GateMaps list.
- Parameters:
input_gate_list (List[GateMap]) – The GateMap list including rotation gates
params (QAOAVariationalBaseParams) – The variational parameters(angles) to be assigned to the circuit gates
- Returns:
angles_list – The list of angles in the order of gates in the GateMap list
- Return type:
List[float]
- abstract qaoa_circuit(params)[source]
Construct the QAOA circuit and append the parameter values to obtain the final circuit ready for execution on the device.
- Parameters:
params (QAOAVariationalBaseParams) – The QAOA parameters as a 1D array (derived from an object of one of the parameter classes, containing hyperparameters and variable parameters).
- Returns:
quantum_circuit – A Quantum Circuit object of type created by the respective backend service
- Return type:
QuantumCircuitBase
- class openqaoa.backends.basebackend.QAOABaseBackendStatevector(qaoa_descriptor, prepend_state, append_state, init_hadamard, cvar_alpha)[source]
Base backend class for a statevector simulator backend
- assign_angles(params)
Assigns the angle values of the variational parameters to the circuit gates specified as a list of gates in the
abstract_circuit
.- Parameters:
params (QAOAVariationalBaseParams) – The variational parameters(angles) to be assigned to the circuit gates
- Return type:
- bitstring_energy(bitstring)
Computes the energy of a given bitstring with respect to the cost Hamiltonian.
- Parameters:
bitstring (Union[List[int],str]) – A list of integers 0 and 1 of length n_qubits representing a configuration.
- Returns:
The energy of a given bitstring with respect to the cost Hamiltonian.
- Return type:
- abstract circuit_to_qasm()
Implement a method to construct a QASM string from the current state of the QuantumCircuit for the backends
- property exact_solution
Computes exactly the minimum energy of the cost function and its corresponding configuration of variables using standard numpy module.
- Returns:
(energy, config) –
The minimum eigenvalue of the cost Hamiltonian,
The minimum energy eigenvector as a binary array configuration: qubit-0 as the first element in the sequence
- Return type:
Tuple[float, list]
- expectation(**kwargs)
Call the execute function on the circuit to compute the expectation value of the Quantum Circuit w.r.t cost operator
- expectation_w_uncertainty(**kwargs)
Call the execute function on the circuit to compute the expectation value of the Quantum Circuit w.r.t cost operator along with its uncertainty
- get_counts(params, n_shots)[source]
Measurement outcome vs frequency information from a circuit execution represented as a python dictionary
- Parameters:
params (VariationalBaseParams) – The QAOA parameters as a 1D array (derived from an object of one of the parameter classes, containing hyperparameters and variable parameters).
n_shots (int) – The number of measurement shots required; specified as integer
- Returns:
A dictionary of measurement outcomes vs frequency sampled from a statevector
- Return type:
- obtain_angles_for_pauli_list(input_gate_list, params)
This method uses the pauli gate list information to obtain the pauli angles from the VariationalBaseParams object. The floats in the list are in the order of the input GateMaps list.
- Parameters:
input_gate_list (List[GateMap]) – The GateMap list including rotation gates
params (QAOAVariationalBaseParams) – The variational parameters(angles) to be assigned to the circuit gates
- Returns:
angles_list – The list of angles in the order of gates in the GateMap list
- Return type:
List[float]
- probability_dict(params)[source]
Get the counts style probability dictionary with all basis states and their corresponding probabilities. Constructed using the complete statevector
- Parameters:
params (QAOAVariationalBaseParams) – The QAOA parameters as a 1D array (derived from an object of one of the parameter classes, containing hyperparameters and variable parameters).
- Returns:
A dictionary of all basis states and their corresponding probabilities.
- Return type:
- abstract qaoa_circuit(params)
Construct the QAOA circuit and append the parameter values to obtain the final circuit ready for execution on the device.
- Parameters:
params (QAOAVariationalBaseParams) – The QAOA parameters as a 1D array (derived from an object of one of the parameter classes, containing hyperparameters and variable parameters).
- Returns:
quantum_circuit – A Quantum Circuit object of type created by the respective backend service
- Return type:
QuantumCircuitBase
- abstract reset_circuit()
Reset the circuit attribute
- sample_from_wavefunction(params, n_samples)[source]
Get the shot-based measurement results from the statevector. The return object is a list of shot-results.
- Parameters:
params (QAOAVariationalBaseParams) – The QAOA parameters as a 1D array (derived from an object of one of the parameter classes, containing hyperparameters and variable parameters).
n_samples (int) – The number of measurement samples required; specified as integer
- Returns:
A list of measurement outcomes sampled from a statevector
- Return type:
np.ndarray
- abstract wavefunction(params)[source]
Get the wavefunction of the state produced by the QAOA circuit.
- Parameters:
params (QAOAVariationalBaseParams) – The QAOA parameters - an object of one of the parameter classes, containing the variational parameters (angles).
- Returns:
A list of the wavefunction amplitudes.
- Return type:
List[complex]
- class openqaoa.backends.basebackend.QAOABaseBackendShotBased(qaoa_descriptor, n_shots, prepend_state, append_state, init_hadamard, cvar_alpha)[source]
Implementation of Backend object specific to shot-based simulators and QPUs
- assign_angles(params)
Assigns the angle values of the variational parameters to the circuit gates specified as a list of gates in the
abstract_circuit
.- Parameters:
params (QAOAVariationalBaseParams) – The variational parameters(angles) to be assigned to the circuit gates
- Return type:
- bitstring_energy(bitstring)
Computes the energy of a given bitstring with respect to the cost Hamiltonian.
- Parameters:
bitstring (Union[List[int],str]) – A list of integers 0 and 1 of length n_qubits representing a configuration.
- Returns:
The energy of a given bitstring with respect to the cost Hamiltonian.
- Return type:
- abstract circuit_to_qasm()
Implement a method to construct a QASM string from the current state of the QuantumCircuit for the backends
- property exact_solution
Computes exactly the minimum energy of the cost function and its corresponding configuration of variables using standard numpy module.
- Returns:
(energy, config) –
The minimum eigenvalue of the cost Hamiltonian,
The minimum energy eigenvector as a binary array configuration: qubit-0 as the first element in the sequence
- Return type:
Tuple[float, list]
- expectation(**kwargs)
Call the execute function on the circuit to compute the expectation value of the Quantum Circuit w.r.t cost operator
- expectation_w_uncertainty(**kwargs)
Call the execute function on the circuit to compute the expectation value of the Quantum Circuit w.r.t cost operator along with its uncertainty
- abstract get_counts(params, n_shots=None)[source]
Measurement outcome vs frequency information from a circuit execution represented as a python dictionary
- Parameters:
params (QAOAVariationalBaseParams) – The QAOA parameters as a 1D array (derived from an object of one of the parameter classes, containing hyperparameters and variable parameters).
n_shots (int) – The number of shots to be used for the measurement. If None, the backend default.
- Returns:
A dictionary of measurement outcomes vs frequency sampled from a statevector
- Return type:
- obtain_angles_for_pauli_list(input_gate_list, params)
This method uses the pauli gate list information to obtain the pauli angles from the VariationalBaseParams object. The floats in the list are in the order of the input GateMaps list.
- Parameters:
input_gate_list (List[GateMap]) – The GateMap list including rotation gates
params (QAOAVariationalBaseParams) – The variational parameters(angles) to be assigned to the circuit gates
- Returns:
angles_list – The list of angles in the order of gates in the GateMap list
- Return type:
List[float]
- abstract qaoa_circuit(params)
Construct the QAOA circuit and append the parameter values to obtain the final circuit ready for execution on the device.
- Parameters:
params (QAOAVariationalBaseParams) – The QAOA parameters as a 1D array (derived from an object of one of the parameter classes, containing hyperparameters and variable parameters).
- Returns:
quantum_circuit – A Quantum Circuit object of type created by the respective backend service
- Return type:
QuantumCircuitBase
- abstract reset_circuit()
Reset the circuit attribute
Local Backend and Devices — Simulators
Local Device
- class openqaoa.backends.devices_core.DeviceLocal(device_name)[source]
This class is a placeholder for all locally accessible devices.
- check_connection()[source]
This method should allow a user to easily check if the credentials provided to access the remote QPU is valid.
- Returns:
True if a connection can be established. If False, the error should be logged and printable. (Not creating an exception here is good for extendibility. i.e. able to try multiple providers without exiting the program.)
- Return type:
Vectorized
- class openqaoa.backends.qaoa_vectorized.QAOAvectorizedBackendSimulator(qaoa_descriptor, prepend_state, append_state, init_hadamard, cvar_alpha=1)[source]
A simulator class for quantum circuits, oriented to QAOA, and more generally unitaries generated by Hamiltonians which consists of sums of Pauli strings. Works by translating the actions of single and two-Pauli rotation gates into permutations of wavefunction coefficients, obtained by slicing the (2, 2, …, 2)-shaped wavefunction.
Procedure:
Decompose rotation matrices into sum of identity and Pauli matrices with Euler’s formula.
- Compute the action of the Pauli matrices
Pauli X matrix : Flip coefficients with 0 at i-th qubit with coefficients with 1 at i-th qubit
Pauli Y matrx : Multiply 1j to everything. Flip coefficients with 0 at i-th qubit with coefficients with 1 at i-th qubit, and multiply -1 to coefficients with 0 at i-th qubit.
Pauli Z matrix : multiply -1 to coefficients with 0 at i-th qubit.
Obtain final wavefunction by summing up \(\sin(\theta/2)* \textit{original wavefunction} - 1j*\cos(\theta/2)*\textit{processed wavefunction}\).
Qubit labelling begins from the right, so that the right-most qubit has label 0, and the left-most has label n_qubits-1.
- Parameters:
qaoa_descriptor (QAOADescriptor) – An object of the class
QAOADescriptor
which contains information on circuit construction and depth of the circuit.prepend_state (np.array) – The initial state of the circuit (before Hadamards). An array of shape \((2^{n_qubits},)\) or (2, 2, …, 2). Defaults to
[1,0,...,0]
ifNone
.append_state (np.array) – A unitary matrix of shape \((2^{self.n_qubits}, 2^{self.n_qubits})\), to be multiplied to the output state.
init_hadamard (bool) – Whether to apply Hadamard gates to the beginning of the QAOA part of the circuit.
cvar_alpha (float) – Conditional Value-at-Risk (CVaR) - a measure that takes into account only the tail of the probability distribution arising from the circut’s count dictionary. Must be between 0 and 1. Check https://arxiv.org/abs/1907.04769 for further details.
- apply_hadamard(qubit_1)[source]
Applies the Hadamard gate on
qubit_1
in a vectorized way. Only used wheninit_hadamard
is true.- Parameters:
qubit_1 (
int
) – First qubit index to apply gate.- Returns:
None
- apply_rx(qubit_1, rotation_angle)[source]
Applies the RX($theta$ =
rotation_angle
) gate onqubit_1
in a vectorized way.Definition of RX($theta$):
\[\begin{split}RX(\theta) = \exp\left(-i \frac{\theta}{2} X\right) = \begin{pmatrix} \cos{\frac{\theta}{2}} & -i\sin{\frac{\theta}{2}} \\ -i\sin{\frac{\theta}{2}} & \cos{\frac{\theta}{2}} \end{pmatrix}\end{split}\]
- apply_rxx(qubit_1, qubit_2, rotation_angle)[source]
Applies the RXX($theta$ =
rotation_angle
) gate onqubit_1
andqubit_2
in a vectorized way.Definition of RXX($theta$):
\[\begin{split}R_{XX}(\theta) = \exp\left(-i \frac{\theta}{2} X{\otimes}X\right) = \begin{pmatrix} \cos\left(\frac{\theta}{2}\right) & 0 & 0 & -i\sin\left(\frac{\theta}{2}\right) \\ 0 & \cos\left(\frac{\theta}{2}\right) & -i\sin\left(\frac{\theta}{2}\right) & 0 \\ 0 & -i\sin\left(\frac{\theta}{2}\right) & \cos\left(\frac{\theta}{2}\right) & 0 \\ -i\sin\left(\frac{\theta}{2}\right) & 0 & 0 & \cos\left(\frac{\theta}{2}\right) \end{pmatrix}\end{split}\]
- apply_rxy(qubit_1, qubit_2, rotation_angle)[source]
Applies the RXY($ heta$ =
rotation_angle
) gate onqubit_1
andqubit_2
in a vectorized way.
- apply_ry(qubit_1, rotation_angle)[source]
Applies the RY($theta$ =
rotation_angle
) gate onqubit_1
in a vectorized way.Definition of RY($theta$):
\[\begin{split}RY(\theta) = \exp\left(-i \frac{\theta}{2} Y\right) = \begin{pmatrix} \cos{\frac{\theta}{2}} & -\sin{\frac{\theta}{2}} \\ \sin{\frac{\theta}{2}} & \cos{\frac{\theta}{2}} \end{pmatrix}\end{split}\]
- apply_ryy(qubit_1, qubit_2, rotation_angle)[source]
Applies the RYY($theta$ =
rotation_angle
) gate onqubit_1
andqubit_2
in a vectorized way.Definition of RYY($theta$):
\[\begin{split}R_{YY}(\theta) = \exp\left(-i \frac{\theta}{2} X{\otimes}X\right) = \begin{pmatrix} \cos\left(\frac{\theta}{2}\right) & 0 & 0 & -i\sin\left(\frac{\theta}{2}\right) \\ 0 & \cos\left(\frac{\theta}{2}\right) & -i\sin\left(\frac{\theta}{2}\right) & 0 \\ 0 & -i\sin\left(\frac{\theta}{2}\right) & \cos\left(\frac{\theta}{2}\right) & 0 \\ -i\sin\left(\frac{\theta}{2}\right) & 0 & 0 & \cos\left(\frac{\theta}{2}\right) \end{pmatrix}\end{split}\]
- apply_ryz(qubit_1, qubit_2, rotation_angle)[source]
Applies the RYZ($ heta$ =
rotation_angle
) gate onqubit_1
andqubit_2
in a vectorized way.
- apply_rz(qubit_1, rotation_angle)[source]
Applies the RZ($theta$ =
rotation_angle
) gate onqubit_1
in a vectorized way.Definition of RZ($theta$):
\[\begin{split}RZ(\theta) = \exp\left(-i \frac{\theta}{2} Z\right) = \begin{pmatrix} e^{-i\frac{\theta}{2}} & 0 \\ 0 & e^{i \frac{\theta}{2}} \end{pmatrix}\end{split}\]
- apply_rzx(qubit_1, qubit_2, rotation_angle)[source]
Applies the RZX($ heta$ =
rotation_angle
) gate onqubit_1
andqubit_2
in a vectorized way.
- apply_rzz(qubit_1, qubit_2, rotation_angle)[source]
Applies the RZZ($theta$ =
rotation_angle
) gate onqubit_1
andqubit_2
in a vectorized way.Definition of RZZ($theta$):
\[\begin{split}RZZ(\theta) = \exp\left(-i \frac{\theta}{2} Z{\otimes}Z\right) = \begin{pmatrix} e^{-i \frac{\theta}{2}} & 0 & 0 & 0 \\ 0 & e^{i \frac{\theta}{2}} & 0 & 0 \\ 0 & 0 & e^{i \frac{\theta}{2}} & 0 \\ 0 & 0 & 0 & e^{-i \frac{\theta}{2}} \end{pmatrix}\end{split}\]
- apply_x(qubit_1)[source]
Applies the X gate on
qubit_1
in a vectorized way.- Parameters:
qubit_1 (
int
) – Qubit index to apply gate.- Returns:
None
- assign_angles(params)
Assigns the angle values of the variational parameters to the circuit gates specified as a list of gates in the
abstract_circuit
.- Parameters:
params (QAOAVariationalBaseParams) – The variational parameters(angles) to be assigned to the circuit gates
- Return type:
- bitstring_energy(bitstring)
Computes the energy of a given bitstring with respect to the cost Hamiltonian.
- Parameters:
bitstring (Union[List[int],str]) – A list of integers 0 and 1 of length n_qubits representing a configuration.
- Returns:
The energy of a given bitstring with respect to the cost Hamiltonian.
- Return type:
- circuit_to_qasm()[source]
A method to convert the entire QAOA
QuantumCircuit
object into a OpenQASM string
- property exact_solution
Computes exactly the minimum energy of the cost function and its corresponding configuration of variables using standard numpy module.
- Returns:
(energy, config) –
The minimum eigenvalue of the cost Hamiltonian,
The minimum energy eigenvector as a binary array configuration: qubit-0 as the first element in the sequence
- Return type:
Tuple[float, list]
- expectation(**kwargs)
Call the execute function on the circuit to compute the expectation value of the Quantum Circuit w.r.t cost operator
- expectation_w_uncertainty(**kwargs)
Call the execute function on the circuit to compute the expectation value of the Quantum Circuit w.r.t cost operator along with its uncertainty
- get_counts(params, n_shots)
Measurement outcome vs frequency information from a circuit execution represented as a python dictionary
- Parameters:
params (VariationalBaseParams) – The QAOA parameters as a 1D array (derived from an object of one of the parameter classes, containing hyperparameters and variable parameters).
n_shots (int) – The number of measurement shots required; specified as integer
- Returns:
A dictionary of measurement outcomes vs frequency sampled from a statevector
- Return type:
- obtain_angles_for_pauli_list(input_gate_list, params)
This method uses the pauli gate list information to obtain the pauli angles from the VariationalBaseParams object. The floats in the list are in the order of the input GateMaps list.
- Parameters:
input_gate_list (List[GateMap]) – The GateMap list including rotation gates
params (QAOAVariationalBaseParams) – The variational parameters(angles) to be assigned to the circuit gates
- Returns:
angles_list – The list of angles in the order of gates in the GateMap list
- Return type:
List[float]
- probability_dict(params)
Get the counts style probability dictionary with all basis states and their corresponding probabilities. Constructed using the complete statevector
- Parameters:
params (QAOAVariationalBaseParams) – The QAOA parameters as a 1D array (derived from an object of one of the parameter classes, containing hyperparameters and variable parameters).
- Returns:
A dictionary of all basis states and their corresponding probabilities.
- Return type:
- qaoa_circuit(params)[source]
Executes the entire QAOA circuit, with angles specified within
params
. Steps: 1) Creates a (2,…,2) dimensional matrix that represents a 2**n dimensional wavefunction 2) Modify it according to theprepend_state
option. 3) Modify it according toinit_hadamard
option. 4) Modify it according to list of gates inparams
. 5) Modify it accoding toappend_state
option.- Parameters:
params (
Type
[QAOAVariationalBaseParams
]) –QAOAVariationalBaseParams
object that contains rotation angles and gates to be applied.- Returns:
None
- sample_from_wavefunction(params, n_samples)
Get the shot-based measurement results from the statevector. The return object is a list of shot-results.
- Parameters:
params (QAOAVariationalBaseParams) – The QAOA parameters as a 1D array (derived from an object of one of the parameter classes, containing hyperparameters and variable parameters).
n_samples (int) – The number of measurement samples required; specified as integer
- Returns:
A list of measurement outcomes sampled from a statevector
- Return type:
np.ndarray
Analytical Simulator
- class openqaoa.backends.qaoa_analytical_sim.QAOABackendAnalyticalSimulator(qaoa_descriptor, prepend_state=None, append_state=None, init_hadamard=True, cvar_alpha=1)[source]
A simulator class, specific for QAOA with a single layer, p=1, starting with a layer of Hadamards and using the X mixer. Works by calculating the expectation value of the given quantum circuit (specificied with beta and gamma angles) from the analytical formula derived in arXiv:2011.13420v2.
- Parameters:
qaoa_descriptor (QAOADescriptor) – An object of the class
QAOADescriptor
which contains information on circuit construction and depth of the circuit. Note that it only works for p=1 and the X Mixer.
- assign_angles()[source]
Assigns the angle values of the variational parameters to the circuit gates specified as a list of gates in the
abstract_circuit
.- Parameters:
params (QAOAVariationalBaseParams) – The variational parameters(angles) to be assigned to the circuit gates
- bitstring_energy(bitstring)
Computes the energy of a given bitstring with respect to the cost Hamiltonian.
- Parameters:
bitstring (Union[List[int],str]) – A list of integers 0 and 1 of length n_qubits representing a configuration.
- Returns:
The energy of a given bitstring with respect to the cost Hamiltonian.
- Return type:
- circuit_to_qasm()[source]
Implement a method to construct a QASM string from the current state of the QuantumCircuit for the backends
- property exact_solution
Computes exactly the minimum energy of the cost function and its corresponding configuration of variables using standard numpy module.
- Returns:
(energy, config) –
The minimum eigenvalue of the cost Hamiltonian,
The minimum energy eigenvector as a binary array configuration: qubit-0 as the first element in the sequence
- Return type:
Tuple[float, list]
- expectation(**kwargs)
Call the execute function on the circuit to compute the expectation value of the Quantum Circuit w.r.t cost operator
- expectation_w_uncertainty(params)[source]
Call the execute function on the circuit to compute the expectation value of the Quantum Circuit w.r.t cost operator along with its uncertainty
- get_counts()[source]
This method will be implemented in the child classes according to the type of backend used.
- Parameters:
params (QAOAVariationalBaseParams) – The QAOA parameters - an object of one of the parameter classes, containing variable parameters.
n_shots (int) – The number of shots to be used for the measurement. If None, the backend default.
- obtain_angles_for_pauli_list()[source]
This method uses the pauli gate list information to obtain the pauli angles from the VariationalBaseParams object. The floats in the list are in the order of the input GateMaps list.
- Parameters:
input_gate_list (List[GateMap]) – The GateMap list including rotation gates
params (QAOAVariationalBaseParams) – The variational parameters(angles) to be assigned to the circuit gates
- Returns:
angles_list – The list of angles in the order of gates in the GateMap list
- Return type:
List[float]
- qaoa_circuit()[source]
Construct the QAOA circuit and append the parameter values to obtain the final circuit ready for execution on the device.
- Parameters:
params (QAOAVariationalBaseParams) – The QAOA parameters as a 1D array (derived from an object of one of the parameter classes, containing hyperparameters and variable parameters).
- Returns:
quantum_circuit – A Quantum Circuit object of type created by the respective backend service
- Return type:
QuantumCircuitBase
Backend selector method
- openqaoa.backends.qaoa_backend.device_to_backend_mapper(device)[source]
Return the correct QAOABaseBackend object corresponding to the requested device
- Return type:
- openqaoa.backends.qaoa_backend.get_qaoa_backend(qaoa_descriptor, device, prepend_state=None, append_state=None, init_hadamard=True, cvar_alpha=1, **kwargs)[source]
A wrapper function to return a QAOA backend object.
- Parameters:
qaoa_descriptor (QAOADescriptor) – An object of the class
QAOADescriptor
which contains information on circuit construction along with depth of the circuit.device (DeviceBase) – The device to be used: Specified as an object of the class DeviceBase.
prepend_state (Union[QuantumCircuitBase,np.ndarray(complex)]) – The state prepended to the circuit.
append_state (Union[QuantumCircuitBase,np.ndarray(complex)]) – The state appended to the circuit.
init_hadamard (bool) – Whether to apply a Hadamard gate to the beginning of the QAOA part of the circuit.
cvar_alpha (float) – The value of the CVaR parameter.
kwargs –
backend. (Additional keyword arguments for the) –
- initial_qubit_mapping: list
A list of physical qubits to be used for the QAOA circuit.
- n_shots: int
The number of shots to be used for the shot-based computation.
- Returns:
The corresponding backend object.
- Return type:
QAOABaseBackend