cunqa.circuit
This module defines CunqaCircuit. Many circuit design models already
exist, the best-known being Qiskit’s QuantumCircuit. The motivation behind the design of
CunqaCircuit does not stem from identifying problems in existing models, but from the lack of
communication directives, which are so vital in CUNQA as a DQC platform. In this way,
CunqaCircuit class allows users to describe quantum circuits that
include not only local quantum operations, but also classical and quantum communication directives
between distributed circuits. A CunqaCircuit can, therefore,
represent both computation and communication in DQC scenarios.
- class CunqaCircuit(num_qubits, num_clbits=None, id=None)
Quantum circuit abstraction for the CUNQA API. This class allows the design of quantum circuits to be executed in the vQPUs. Upon initialization, the circuit is defined by its number of qubits and, optionally, its number of classical bits and a user-defined identifier. If no identifier is provided, a unique one is generated automatically. The circuit identifier is later used to reference the circuit in communication-related instructions.
Once created, instructions can be appended to the circuit using the provided methods, including single- and multi-qubit gates, measurements, classically controlled operations, and remote communication primitives.
Supported operations Group
Category
Operations
Unitary operations
Single-qubit gates with no parameters
id,x,y,z,h,s,sdg,sx,sxdg,sy,sydg,sz,szdg,t,tdg,p0,p1,v,vdg,kSingle-qubit gates with one parameter
Single-qubit gates with two parameters
Single-qubit gates with three parameters
Single-qubit gates with four parameters
Two-qubit gates with no parameters
swap,iswap,fusedswap,cx,cy,cz,ch,csx,csxdg,csy,csz,cs,csdg,ecr,ct,dcxTwo-qubit gates with one parameter
Two-qubit gates with two parameters
Two-qubit gates with three parameters
Two-qubit gates with four parameters
Three-qubit gates with no parameters
Multicontrol gates with no parameters
mcx,mcy,mcz,mcsxMulticontrol gates with one parameter
mcu1,mcp,mcphase,mcrx,mcry,mcrzMulticontrol gates with two parameters
mcu2,mcrMulticontrol gates with three parameters
mcu3Multicontrol gates with four parameters
mcuSpecial gates
unitary,randomunitary,diagonal,multiplexer,multipauli,multipaulirotation,sparsematrix,amplitudedampingnoise,bitflipnoise,dephasingnoise,depolarizingnoise,independentxznoise,twoqubitdepolarizingnoiseLocal non-unitary operations
Local non-unitary operations
Remote operations
Classical communication
Quantum communication
Attributes
- id : str
Returns circuit id.
- info : dict
Information of the instance attributes, given in a dictionary.
- num_qubits : int
Number of qubits of the circuit.
- num_clbits : int
Number of classical bits of the circuit.
- instructions: list[dict]
Set of operations applied to the circuit.
- is_dynamic: bool
Whether the circuit has local non-unitary operations.
- quantum_regs: dict
Dictionary of quantum registers as
{"name": [assigned qubits]}.
- classical_regs: dict
Dictionary of classical registers of the circuit as
{"name": [assigned clbits]}.
- sending_to: set[str]
Set of circuit ids to which the current circuit is sending measurement outcomes or qubits.
Operations
Classical communication directives
Quantum communication directives
Non-unitary operations
Unitary operations
- Parameters:
num_qubits (int)
num_clbits (Optional[int])
id (Optional[str])
Transformations
Besides all quantum operations and communication directives, it is common for users to want to combine two circuits or, conversely, to create several circuits from a single one. This module exists to enable this capability, defining the following functions.
- vsplit()
TODO: Vertical split of a quantum circuit.
- hsplit(circuit, qubits_or_sections)
Horizontal split of a quantum circuit.
This function splits a circuit into a given number of subcircuits. This number is determined by the qubits_or_sections argument. If it is a list, then it specifies the number of qubits each subcircuit will have; however, if it is an int, it specifies the number of subcircuits to be created (each having the same number of qubits, except for one in case the split is not exact, which will take the remainder as its number of qubits).
If a controlled gate is divided an expose quantum directive will be used in order to maintain the global state intact.
This operation is the inverse of the
union.- Parameters:
circuit (CunqaCircuit) – circuit to be splited.
qubits_or_sections (list[int], int) – if is a list, qubits in which to split, if an int, number of subcircuits that result of the split.
- Return type:
list[CunqaCircuit]
- union(circuits)
Union of circuits (addition of qubits).
This function joins the qubits of several
CunqaCircuitobjects. These circuits may be connected via communication directives which will be replaced as follows:expose. The gates applied remotely simply switch to local operations.qrecvandqsend. Switch to be aswapoperation between local qubits.sendandrecv. They provoke a special copy operation among classical registers called copy. For now, this operation is not available in the public API ofCunqaCircuit.
This operation is the inverse of the
hsplit.- Parameters:
circuits (list[CunqaCircuit]) – circuits to join.
- Return type:
- add(circuits)
This function concatenates the instructions of two circuits.
It appends the gates from a list of circuits into a final resulting circuit. The order of the list passed as an argument is important, since the instructions will be appended in that same order.
In this operation, if two circuits in the list contain communication directives between them, an exception will be raised to prevent potential deadlocks and undefined or incorrectly specified behavior.
This operation is the inverse of the
vsplit.- Parameters:
circuits (list[CunqaCircuit])
- Return type: