BasicGate
QuICT.core.gate.BasicGate ¶
BasicGate(controls: int, targets: int, params: int, type_: GateType, matrix_type: MatrixType = MatrixType.normal, pargs: list = [], precision: str = 'double', is_original_gate: bool = False)
Bases: object
the abstract SuperClass of all basic quantum gate
All basic quantum gate described in the framework have some common attributes and some common functions which defined in this class
Attributes:
-
type(GateType,(read only) –gate's type described by GateType
-
matrix_type(MatrixType,(read only) –gate matrix's type described by MatrixType
-
precision(str)(read only) –The gate's precision, one of [double, single]
-
qasm_name(str,(read only) –gate's name in the OpenQASM 2.0
-
matrix(np.array)(read only) –the unitary matrix of the quantum gate act on qubits
-
target_matrix(np.array)(read only) –the unitary matrix of the quantum gate act on targets
-
targets(int)(read only) –the number of the target bits of the gate
-
targs(list<int>)(read only) –the list of the index of target bits in the circuit
-
targ(int,(read only) –the first object of targs
-
controls(int)(read only) –the number of the control bits of the gate
-
cargs(list<int>)(read only) –the list of the index of control bits in the circuit
-
carg(int,(read only) –the first object of cargs
-
params(list)(read only) –the number of the parameter of the gate
-
pargs(list)(read only) –the list of the parameter
-
parg(read(only) –the first object of pargs
Parameters:
-
controls(int) –The number of control qubits
-
targets(int) –The number of target qubits
-
params(int) –The number of gate's parameters
-
type_(GateType) –The gate's type
-
matrix_type(MatrixType, default:normal) –The gate matrix's type. Defaults to MatrixType.normal.
-
pargs(list, default:[]) –The gate's parameters. Defaults to [].
-
precision(str, default:'double') –The gate's precison, one of [double, single]. Defaults to "double".
-
is_original_gate(bool, default:False) –Whether is the initial quantum gate, such as H. Defaults to False.
Source code in QuICT/core/gate/gate.py
__and__ ¶
deal the operator '&'
Use the syntax "gate & int" or "gate & list
Some Examples are like this: X & 1 CX & [0, 1]
Note that the order of qubits is that control bits first and target bits followed.
Parameters:
-
targets–the targets the gate acts on, it can have following form, 1) int 2) list
Raise
TypeError: the type of targets is wrong
Source code in QuICT/core/gate/gate.py
__call__ ¶
give parameters for the gate, and give parameters by "()", and parameters should be one of int/float/complex
Some Examples are like this:
Rz(np.pi / 2) U3(np.pi / 2, 0, 0)
Important: There is no parameters for some quantum gate.
Returns:
-
BasicGate–the gate after filled by parameters
Source code in QuICT/core/gate/gate.py
__or__ ¶
deal the operator '|'
Use the syntax "gate | circuit" or "gate | Composite Gate" to add the gate into the circuit or composite gate Some Examples are like this:
X | circuit CX | circuit([0, 1]) Measure | CompositeGate
Note that the order of qubits is that control bits first and target bits followed.
Parameters:
-
targets–the targets the gate acts on, it can have following form, 1) Circuit 2) CompositeGate
Raise
TypeError: the type of other is wrong
Source code in QuICT/core/gate/gate.py
build_gate ¶
Gate Decomposition, which divided the current gate with a set of small gates.
Source code in QuICT/core/gate/gate.py
commutative ¶
decide whether gate is commutative with another gate
note when the gate is special gates like Unitary, Permutation, Measure and so on, return False.
Parameters:
-
goal(BasicGate)–the target gate
-
eps(float)–the precision of comparision
Return
bool: True if commutative
Source code in QuICT/core/gate/gate.py
copy ¶
return a copy of this gate
Returns:
-
gate(BasicGate) –a copy of this gate
Source code in QuICT/core/gate/gate.py
expand ¶
expand self matrix into the circuit's unitary linear space. If input qubits is integer, please make sure the indexes of current gate is within [0, qubits).
Parameters:
-
qubits(Union[int, list]) –the total number of qubits of the target circuit or the indexes of expand qubits.
Source code in QuICT/core/gate/gate.py
init_pargs ¶
Initialize the trainable parameters of the gate.
Parameters:
-
symbols(list) –The symbols that needs to be assigned values.
-
values(Union[list, ndarray]) –The values to be assigned.
Source code in QuICT/core/gate/gate.py
inverse ¶
the inverse of the quantum gate, if there is no inverse gate, return itself.
Return
BasicGate: the inverse of the gate
Source code in QuICT/core/gate/gate.py
is_clifford ¶
judge whether gate's matrix is a Clifford gate
Returns:
-
bool(bool) –True if gate's matrix is a Clifford gate
is_control_single ¶
judge whether gate has one control bit and one target bit
Returns:
-
bool(bool) –True if it is has one control bit and one target bit
is_diagonal ¶
judge whether gate's matrix is diagonal
Returns:
-
bool(bool) –True if gate's matrix is diagonal
is_identity ¶
judge whether gate's matrix is identity matrix
Returns:
-
bool(bool) –True if gate's matrix is identity
is_pauli ¶
judge whether gate's matrix is a Pauli gate
Returns:
-
bool(bool) –True if gate's matrix is a Pauli gate
is_single ¶
judge whether gate is a one qubit gate(excluding special gate like measure, reset, custom and so on)
Returns:
-
bool(bool) –True if it is a one qubit gate
is_special ¶
judge whether gate's is special gate, which is one of [Measure, Reset, Barrier, Perm, ...]
Returns:
-
bool(bool) –True if gate's matrix is special
permit_element ¶
judge whether the type of a parameter is int/float/complex
for a quantum gate, the parameter should be int/float/complex
Parameters:
-
element–the element to be judged
Returns:
-
bool–True if the type of element is int/float/complex
Source code in QuICT/core/gate/gate.py
qasm ¶
generator OpenQASM string for the gate
Return
string: the OpenQASM 2.0 describe of the gate
Source code in QuICT/core/gate/gate.py
QuICT.core.gate.Unitary ¶
Unitary(matrix: Union[list, ndarray], matrix_type: MatrixType = None, name: str = None, is_kraus: bool = False)
Bases: BasicGate
The class about the Unitary Quantum Gate
Parameters:
-
matrix(Union[list, ndarray]) –The unitary matrix.
-
matrix_type(MatrixType, default:None) –The matrix's type. Defaults to None.
-
name(str, default:None) –The unitary gate's name
Source code in QuICT/core/gate/gate.py
validate_matrix_type
staticmethod
¶
Check the matrix's type about given unitary matrix
Parameters:
-
matrix(ndarry) –The given unitary matrix
Returns:
-
MatrixType(MatrixType) –The matrix type
Source code in QuICT/core/gate/gate.py
QuICT.core.gate.Perm ¶
Bases: BasicGate
Parameters:
-
n(int) –the number of target qubits
-
params(list[int]) –the list of index, and the index represent which should be 1.
Returns:
-
PermGate–the Perm Gate.
Source code in QuICT/core/gate/gate.py
QuICT.core.gate.MultiControlGate ¶
Bases: BasicGate
The multi-control qubits quantum gate.
Parameters:
-
controls(int) –The number of control qubits
-
gate_type(GateType) –The based quantum gate
-
precision(str, default:'double') –The precison for quantum gate. Defaults to "double".
-
params(list, default:[]) –The parameters for based quantum gate. Defaults to [].
Source code in QuICT/core/gate/gate.py
inverse ¶
the inverse of the quantum gate, if there is no inverse gate, return itself.
Return
BasicGate: the inverse of the gate
Source code in QuICT/core/gate/gate.py
QuICT.core.gate.Kraus ¶
Bases: BasicGate
Source code in QuICT/core/gate/gate.py
expand ¶
expand self matrix into the circuit's unitary linear space. If input qubits is integer, please make sure the indexes of current gate is within [0, qubits).
Parameters:
-
qubits(Union[int, list]) –the total number of qubits of the target circuit or the indexes of expand qubits.
Source code in QuICT/core/gate/gate.py
QuICT.core.gate.gate_builder ¶
gate_builder(gate_type, precision: str = 'double', params: list = [], random_params: bool = False) -> BasicGate
Build the target Quantum Gate.
Parameters:
-
gate_type(GateType) –The gate's type.
-
precision(str, default:'double') –The gate's precision. Defaults to "double".
-
params(list, default:[]) –The gate's parameters. Defaults to [].
-
random_params(bool, default:False) –Whether using random parameters. Defaults to False.
Returns:
-
BasicGate(BasicGate) –The class of target quantum gate
Source code in QuICT/core/gate/gate.py
QuICT.core.gate.H
module-attribute
¶
Single-Qubit Hadamard Gate, which apply a pi rotation about the X and Z axis.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.Hy
module-attribute
¶
QuICT.core.gate.S
module-attribute
¶
QuICT.core.gate.S_dagger
module-attribute
¶
QuICT.core.gate.X
module-attribute
¶
QuICT.core.gate.Y
module-attribute
¶
QuICT.core.gate.Z
module-attribute
¶
QuICT.core.gate.SX
module-attribute
¶
QuICT.core.gate.SX_dagger
module-attribute
¶
QuICT.core.gate.SY
module-attribute
¶
QuICT.core.gate.SY_dagger
module-attribute
¶
QuICT.core.gate.SW
module-attribute
¶
Single-Qubit Sqrt-W Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.ID
module-attribute
¶
QuICT.core.gate.U1
module-attribute
¶
Single-Qubit Rotation Gate, which apply an \(\lambda\) rotation about Z axis.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.U2
module-attribute
¶
Single-Qubit Rotation Gate about X and Z axis.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.U3
module-attribute
¶
Single-Qubit Rotation Gate with three Euler Angles.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.Rx
module-attribute
¶
Single-Qubit Rotation Gate, which apply an \(\lambda\) rotation about X axis.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.Ry
module-attribute
¶
Single-Qubit Rotation Gate, which apply an \(\lambda\) rotation about Y axis. [Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.Rz
module-attribute
¶
Single-Qubit Rotation Gate, which apply an \(\lambda\) rotation about Z axis.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.T
module-attribute
¶
Single-Qubit T Gate, which produce a \(\frac{pi}{4}\) phase. Its matrix equals \(Rz(\frac{pi}{4})\).
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.T_dagger
module-attribute
¶
Single-Qubit T Dagger Gate, which produce a -pi/4 phase.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.Phase
module-attribute
¶
Single-Qubit Rotation Gate about Z axis.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.GPhase
module-attribute
¶
Global Phase Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.XY2P
module-attribute
¶
QuICT.core.gate.XY2M
module-attribute
¶
QuICT.core.gate.CZ
module-attribute
¶
Controlled Z Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.CX
module-attribute
¶
Controlled X Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.CY
module-attribute
¶
Controlled Y Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.CH
module-attribute
¶
Controlled H Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.CRy
module-attribute
¶
Controlled Ry Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.CRz
module-attribute
¶
Controlled Rz Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.CU1
module-attribute
¶
Controlled U1 Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.CU3
module-attribute
¶
Controlled U3 Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.FSim
module-attribute
¶
Fermions Simulation Quantum Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.ECR
module-attribute
¶
ECR Quantum Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.Rxx
module-attribute
¶
Double-Qubits X \(\otimes\) X Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.Ryy
module-attribute
¶
Double-Qubits Y \(\otimes\) Y Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.Rzz
module-attribute
¶
Double-Qubits Z \(\otimes\) Z Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.Rzx
module-attribute
¶
Double-Qubits Z \(\otimes\) X Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.Measure
module-attribute
¶
QuICT.core.gate.MeasureX
module-attribute
¶
QuICT.core.gate.MeasureY
module-attribute
¶
QuICT.core.gate.Reset
module-attribute
¶
QuICT.core.gate.Barrier
module-attribute
¶
QuICT.core.gate.Swap
module-attribute
¶
Swap Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.iSwap
module-attribute
¶
iSwap Gate, a double-qubit XX + YY Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.iSwap_dagger
module-attribute
¶
iSwap Dagger Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.sqiSwap
module-attribute
¶
Swap Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.CCX
module-attribute
¶
Double-Qubit Controlled X Gate, CCX Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.CCZ
module-attribute
¶
Double-Qubit Controlled Z Gate, CCZ Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.CCRz
module-attribute
¶
Double-Qubit Controlled Rz Gate, CCRz Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.CSwap
module-attribute
¶
Controlled Swap Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
QuICT.core.gate.RCCX
module-attribute
¶
Simplified Double-Qubit Controlled X Gate, or Margolus gate
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]