OpenQAOA Braket API Reference

AWS Braket Cloud Devices

class openqaoa_braket.backends.devices.DeviceAWS(device_name, s3_bucket_name=None, aws_region=None, folder_name='openqaoa')[source]

Contains the required information and methods needed to access QPUs hosted on AWS Braket.


When connection to AWS is established, this attribute contains a list of device names which can be used to access the selected device by reinitialising the Access Object with the name of the available device as input to the device_name parameter.




The maximum number of qubits available for the selected backend. Only available if check_connection method is executed and a connection to the qpu and provider is established.




This method should allow a user to easily check if the credentials provided to access the remote QPU is valid.


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:


property connectivity: List[List[int]]

obtain the device connectivity as a list of qubit pairs

Return type:


Amazon Braket Cloud Backend

class openqaoa_braket.backends.qaoa_braket_qpu.QAOAAWSQPUBackend(qaoa_descriptor, device, n_shots, prepend_state, append_state, init_hadamard, cvar_alpha, disable_qubit_rewiring=False, initial_qubit_mapping=None)[source]

A QAOA simulator as well as for real QPU using Amazon Braket as backend

  • device (DeviceAWS) – An object of the class DeviceAWS which contains the credentials for accessing the QPU via cloud and the name of the device.

  • qaoa_descriptor (QAOADescriptor) – An object of the class QAOADescriptor which contains information on circuit construction and depth of the circuit.

  • n_shots (int) – The number of shots to be taken for each circuit.

  • prepend_state (QuantumCircuit) – The state prepended to the circuit.

  • append_state (QuantumCircuit) – 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 alpha for the CVaR method.

  • disable_qubit_rewiring (bool) – A boolean that determines whether qubit routing on the provider’s end is used. This is False by default. Not all providers provide this feature.


Assigns the angle values of the variational parameters to the circuit gates specified as a list of gates in the abstract_circuit.


params (QAOAVariationalBaseParams) – The variational parameters(angles) to be assigned to the circuit gates

Return type:



Computes the energy of a given bitstring with respect to the cost Hamiltonian.


bitstring (Union[List[int],str]) – A list of integers 0 and 1 of length n_qubits representing a configuration.


The energy of a given bitstring with respect to the cost Hamiltonian.

Return type:



A method to convert the entire QAOA QuantumCircuit object into a OpenQASM string

Return type:


property exact_solution

Computes exactly the minimum energy of the cost function and its corresponding configuration of variables using standard numpy module.


(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]


Call the execute function on the circuit to compute the expectation value of the Quantum Circuit w.r.t cost operator


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=None)[source]

Execute the circuit and obtain the counts

  • params (QAOAVariationalBaseParams) – The QAOA parameters - an object of one of the parameter classes, containing variable parameters.

  • n_shots (int) – The number of times to run the circuit. If None, n_shots is set to the default: self.n_shots.

Return type:



A dictionary with the bitstring as the key and the number of counts as its value.

log_with_backend(metric_name, value, iteration_number)[source]

If using AWS Jobs, these values will be logged.

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.

  • input_gate_list (List[GateMap]) – The GateMap list including rotation gates

  • params (QAOAVariationalBaseParams) – The variational parameters(angles) to be assigned to the circuit gates


angles_list – The list of angles in the order of gates in the GateMap list

Return type:


property parametric_qaoa_circuit: braket.circuits.Circuit

Creates a parametric QAOA circuit, given the qubit pairs, single qubits with biases, and a set of circuit angles. Note that this function does not actually run the circuit.


The final QAOA circuit to be executed on the QPU.


params (QAOAVariationalBaseParams) –


qaoa_circuit – The final QAOA circuit constructed using the angles from variational params.

Return type:



Reset self.circuit after performing a computation