cutqc2.library.QAOA package

Submodules

cutqc2.library.QAOA.hw_efficient_ansatz module

class cutqc2.library.QAOA.hw_efficient_ansatz.HWEA(width, depth, parameters='optimal', seed=None, barriers=False, measure=False, regname=None)[source]

Bases: object

Class to implement a hardware efficient ansatz for the QAOA algorithm. Based on the community detection circuit implemented by Francois-Marie Le Régent. This ansatz uses the entangler+rotation block structure like that described in the paper by Nikolaj Moll et al. (http://iopscience.iop.org/article/10.1088/2058-9565/aab822)

A HW efficient ansatz circuit can be generated with an instance of this class by calling its gen_circuit() method.

nq

number of qubits

Type:

int

d

number of layers to apply. Where a layer = rotation block + entangler block This is also the same as the “P” value often referenced for QAOA.

Type:

int

parameters

optional string which changes the rotation angles in the rotation block [optimal, random, seeded]

Type:

str

seed

a number to seed the number generator with

Type:

int

barriers

should barriers be included in the generated circuit

Type:

bool

measure

should a classical register & measurement be added to the circuit

Type:

bool

regname

optional string to name the quantum and classical registers. This allows for the easy concatenation of multiple QuantumCircuits.

Type:

str

qr

Qiskit QuantumRegister holding all of the quantum bits

Type:

QuantumRegister

cr

Qiskit ClassicalRegister holding all of the classical bits

Type:

ClassicalRegister

circ

Qiskit QuantumCircuit that represents the hardware-efficient ansatz

Type:

QuantumCircuit

gen_circuit()[source]

Create a circuit for the QAOA RyRz ansatz

This methods generates a circuit with repeated layers of an entangler block sandwiched between parameterized rotation columns

Returns:

  • QuantumCircuit – QuantumCircuit of size nb_qubits with no ClassicalRegister and no measurements

  • QiskitError – Prints the error in the circuit

get_noiseless_theta()[source]

Set the parameters to the optimal value which solves the community detection problem.

This method returns a vector of length (1 + d)*2nq The first gate on the first qubit is a pi/2 rotation (Hadamard) After the entangler block, the first half of the qubits (round down for odd n_qubits) receive a pi rotation (X gate)

Parameters:

nb_qubits (int) – Number of qubits in the circuit

Returns:

vector of length 2*nq * (1+d)

Return type:

list

get_random_theta()[source]

Module contents