cunqa.circuit.CunqaCircuit

class cunqa.circuit.CunqaCircuit(num_qubits, num_clbits=None, id=None)

Bases: object

Class to define a quantum circuit for the cunqa api.

Supported gates

{all_gates!r}

Methods

c_if

Method for implementing a gate contiioned to a classical measurement.

ccx

Class method to apply ccx gate to the given qubits.

ccy

Class method to apply ccy gate to the given qubits.

ccz

Class method to apply ccz gate to the given qubits.

cp

Class method to apply cp gate to the given qubits.

crx

Class method to apply crx gate to the given qubits.

cry

Class method to apply cry gate to the given qubits.

crz

Class method to apply crz gate to the given qubits.

cswap

Class method to apply cswap gate to the given qubits.

csx

Class method to apply csx gate to the given qubits.

cu

Class method to apply cu gate to the given qubits.

cu1

Class method to apply cu1 gate to the given qubits.

cu3

Class method to apply cu3 gate to the given qubits.

cx

Class method to apply cx gate to the given qubits.

cy

Class method to apply cy gate to the given qubits.

cz

Class method to apply cz gate to the given qubits.

ecr

Class method to apply ecr gate to the given qubits.

h

Class method to apply h gate to the given qubit.

id

Class method to apply id gate to the given qubit.

measure

Class method to add a measurement of a qubit or a list of qubits and to register that measurement in the given classical bits.

measure_all

Class to apply a global measurement of all of the qubits of the circuit.

p

Class method to apply p gate to the given qubit.

r

Class method to apply r gate to the given qubit.

recv_gate

Class method to apply a distributed instruction as a gate condioned by a non local classical measurement from a different circuit and applied locally.

rx

Class method to apply rx gate to the given qubit.

rxx

Class method to apply rxx gate to the given qubits.

ry

Class method to apply ry gate to the given qubit.

ryy

Class method to apply ryy gate to the given qubits.

rz

Class method to apply rz gate to the given qubit.

rzx

Class method to apply rzx gate to the given qubits.

rzz

Class method to apply rzz gate to the given qubits.

s

Class method to apply s gate to the given qubit.

sdg

Class method to apply sdg gate to the given qubit.

send_gate

Class method to apply a distributed instruction as a gate condioned by a local classical measurement and applied in a different circuit.

swap

Class method to apply swap gate to the given qubits.

sx

Class method to apply sx gate to the given qubit.

sxdg

Class method to apply sxdg gate to the given qubit.

t

Class method to apply t gate to the given qubit.

tdg

Class method to apply tdg gate to the given qubit.

u

Class method to apply u gate to the given qubit.

u1

Class method to apply u1 gate to the given qubit.

u2

Class method to apply u2 gate to the given qubit.

u3

Class method to apply u3 gate to the given qubit.

unitary

Class method to apply a unitary gate created from an unitary matrix provided.

x

Class method to apply x gate to the given qubit.

y

Class method to apply y gate to the given qubit.

z

Class method to apply z gate to the given qubit.

Attributes

num_clbits

num_qubits

c_if(gate, control_qubit, target_qubit, param=None, matrix=None)

Method for implementing a gate contiioned to a classical measurement. The control qubit provided is measured, if it’s 1 the gate provided is applied to the given qubits.

For parametric gates, only one-parameter gates are supported, therefore only one parameter must be passed.

Args:

gate (str): gate to be applied. Has to be supported by CunqaCircuit.

control (int): control qubit whose classical measurement will control the execution of the gate.

target (list[int], int): list of qubits or qubit to which the gate is intended to be applied.

param (float or int): parameter for the case parametric gate is provided.

ccx(*qubits)

Class method to apply ccx gate to the given qubits.

Args:

*qubits (int): qubits in which the gate is applied, first two will be control qubits and the following one will be target qubit.

ccy(*qubits)

Class method to apply ccy gate to the given qubits.

Args:

*qubits (int): qubits in which the gate is applied, first two will be control qubits and the following one will be target qubit.

ccz(*qubits)

Class method to apply ccz gate to the given qubits.

Args:

*qubits (int): qubits in which the gate is applied, first two will be control qubits and the following one will be target qubit.

cp(param, *qubits)

Class method to apply cp gate to the given qubits.

Args:

qubits (list[int, int]): qubits in which the gate is applied, first one will be the control qubit and second one the target qubit.

param (float or int): parameter for the parametric gate.

crx(param, *qubits)

Class method to apply crx gate to the given qubits.

Args:

qubits (list[int, int]): qubits in which the gate is applied, first one will be the control qubit and second one the target qubit.

param (float or int): parameter for the parametric gate.

cry(param, *qubits)

Class method to apply cry gate to the given qubits.

Args:

qubits (list[int, int]): qubits in which the gate is applied, first one will be the control qubit and second one the target qubit.

param (float or int): parameter for the parametric gate.

crz(param, *qubits)

Class method to apply crz gate to the given qubits.

Args:

qubits (list[int, int]): qubits in which the gate is applied, first one will be the control qubit and second one the target qubit.

param (float or int): parameter for the parametric gate.

cswap(*qubits)

Class method to apply cswap gate to the given qubits.

Args:

*qubits (int): qubits in which the gate is applied, first two will be control qubits and the following one will be target qubit.

csx(*qubits)

Class method to apply csx gate to the given qubits.

Args:

*qubits (int): qubits in which the gate is applied, first one will be control qubit and second one target qubit.

cu(theta, phi, lam, gamma, *qubits)

Class method to apply cu gate to the given qubits.

Args:

theta (float): angle. phi (float): angle. lam (float): angle. gamma (float): angle. *qubits (list[int, int]): qubits in which the gate is applied, first one will be the control qubit and second one the target qubit.

cu1(param, *qubits)

Class method to apply cu1 gate to the given qubits.

Args:

qubits (list[int, int]): qubits in which the gate is applied, first one will be the control qubit and second one the target qubit.

param (float or int): parameter for the parametric gate.

cu3(theta, phi, lam, *qubits)

Class method to apply cu3 gate to the given qubits.

Args:

theta (float): angle. phi (float): angle. lam (float): angle. *qubits (list[int, int]): qubits in which the gate is applied, first one will be the control qubit and second one the target qubit.

cx(*qubits)

Class method to apply cx gate to the given qubits.

Args:

*qubits (int): qubits in which the gate is applied, first one will be control qubit and second one target qubit.

cy(*qubits)

Class method to apply cy gate to the given qubits.

Args:

*qubits (int): qubits in which the gate is applied, first one will be control qubit and second one target qubit.

cz(*qubits)

Class method to apply cz gate to the given qubits.

Args:

*qubits (int): qubits in which the gate is applied, first one will be control qubit and second one target qubit.

ecr(*qubits)

Class method to apply ecr gate to the given qubits.

Args:

*qubits (int): qubits in which the gate is applied.

h(qubit)

Class method to apply h gate to the given qubit.

Args:

qubit (int): qubit in which the gate is applied.

id(qubit)

Class method to apply id gate to the given qubit.

Args:

qubit (int): qubit in which the gate is applied.

measure(qubits, clbits)

Class method to add a measurement of a qubit or a list of qubits and to register that measurement in the given classical bits.

Args:

qubits (list[int] or int): qubits to measure.

clbits (list[int] or int): clasical bits where the measurement will be registered.

measure_all()

Class to apply a global measurement of all of the qubits of the circuit. An additional classcial register will be added and labeled as “measure”.

p(param, qubit)

Class method to apply p gate to the given qubit.

Args:

qubit (int): qubit in which the gate is applied.

param (float or int): parameter for the parametric gate.

r(theta, phi, qubit)

Class method to apply r gate to the given qubit.

Args:

theta (float): angle. phi (float): angle. qubit (int): qubit in which the gate is applied.

recv_gate(gate, param, control_qubit=None, control_circuit=None, target_qubit=None)

Class method to apply a distributed instruction as a gate condioned by a non local classical measurement from a different circuit and applied locally.

Args:

gate (str): gate to be applied. Has to be supported by CunqaCircuit.

param (float or int): parameter in case the gate provided is parametric.

control_qubit (int): control qubit from self.

target_circuit (str, <class ‘cunqa.circuit.CunqaCircuit’>): id of the circuit to which we will send the gate or the circuit itself.

target_qubit (int): qubit where the gate will be conditionally applied.

rx(param, qubit)

Class method to apply rx gate to the given qubit.

Args:

qubit (int): qubit in which the gate is applied.

param (float or int): parameter for the parametric gate.

rxx(param, *qubits)

Class method to apply rxx gate to the given qubits.

Args:

qubits (list[int, int]): qubits in which the gate is applied.

param (float or int): parameter for the parametric gate.

ry(param, qubit)

Class method to apply ry gate to the given qubit.

Args:

qubit (int): qubit in which the gate is applied.

param (float or int): parameter for the parametric gate.

ryy(param, *qubits)

Class method to apply ryy gate to the given qubits.

Args:

qubits (list[int, int]): qubits in which the gate is applied.

param (float or int): parameter for the parametric gate.

rz(param, qubit)

Class method to apply rz gate to the given qubit.

Args:

qubit (int): qubit in which the gate is applied.

param (float or int): parameter for the parametric gate.

rzx(param, *qubits)

Class method to apply rzx gate to the given qubits.

Args:

qubits (list[int, int]): qubits in which the gate is applied.

param (float or int): parameter for the parametric gate.

rzz(param, *qubits)

Class method to apply rzz gate to the given qubits.

Args:

qubits (list[int, int]): qubits in which the gate is applied.

param (float or int): parameter for the parametric gate.

s(qubit)

Class method to apply s gate to the given qubit.

Args:

qubit (int): qubit in which the gate is applied.

sdg(qubit)

Class method to apply sdg gate to the given qubit.

Args:

qubit (int): qubit in which the gate is applied.

send_gate(gate, param, control_qubit=None, target_qubit=None, target_circuit=None)

Class method to apply a distributed instruction as a gate condioned by a local classical measurement and applied in a different circuit.

Args:

gate (str): gate to be applied. Has to be supported by CunqaCircuit.

control_qubit (int): control qubit from self.

target_circuit (str, <class ‘cunqa.circuit.CunqaCircuit’>): id of the circuit to which we will send the gate or the circuit itself.

target_qubit (int): qubit where the gate will be conditionally applied.

param (float or int): parameter in case the gate provided is parametric.

swap(*qubits)

Class method to apply swap gate to the given qubits.

Args:

*qubits (int): qubits in which the gate is applied.

sx(qubit)

Class method to apply sx gate to the given qubit.

Args:

qubit (int): qubit in which the gate is applied.

sxdg(qubit)

Class method to apply sxdg gate to the given qubit.

Args:

qubit (int): qubit in which the gate is applied.

t(qubit)

Class method to apply t gate to the given qubit.

Args:

qubit (int): qubit in which the gate is applied.

tdg(qubit)

Class method to apply tdg gate to the given qubit.

Args:

qubit (int): qubit in which the gate is applied.

u(theta, phi, lam, qubit)

Class method to apply u gate to the given qubit.

Args:

theta (float): angle. phi (float): angle. lam (float): angle. qubit (int): qubit in which the gate is applied.

u1(param, qubit)

Class method to apply u1 gate to the given qubit.

Args:

qubit (int): qubit in which the gate is applied.

param (float or int): parameter for the parametric gate.

u2(theta, phi, qubit)

Class method to apply u2 gate to the given qubit.

Args:

theta (float): angle. phi (float): angle. qubit (int): qubit in which the gate is applied.

u3(theta, phi, lam, qubit)

Class method to apply u3 gate to the given qubit.

Args:

theta (float): angle. phi (float): angle. lam (float): angle. qubit (int): qubit in which the gate is applied.

unitary(matrix, *qubits)

Class method to apply a unitary gate created from an unitary matrix provided.

Args:

matrix (list or <class ‘numpy.ndarray’>): unitary operator in matrix form to be applied to the given qubits.

*qubits (int): qubits to which the unitary operator will be applied.

x(qubit)

Class method to apply x gate to the given qubit.

Args:

qubit (int): qubit in which the gate is applied.

y(qubit)

Class method to apply y gate to the given qubit.

Args:

qubit (int): qubit in which the gate is applied.

z(qubit)

Class method to apply z gate to the given qubit.

Args:

qubit (int): qubit in which the gate is applied.