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.

available_qpus

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.

Type:

list

n_qubits

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.

Type:

int

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:

bool

property connectivity: List[List[int]]

obtain the device connectivity as a list of qubit pairs

Return type:

List[List[int]]

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

Parameters:
  • 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.

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:

None

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:

float

circuit_to_qasm(params)[source]

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

Return type:

str

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

Execute the circuit and obtain the counts

Parameters:
  • 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:

dict

Returns:

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:

None

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]

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.

qaoa_circuit(params)[source]

The final QAOA circuit to be executed on the QPU.

Parameters:

params (QAOAVariationalBaseParams) –

Returns:

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

Return type:

Circuit

reset_circuit()[source]

Reset self.circuit after performing a computation