utility
QuICT.qcda.synthesis.unitary_decomposition.utility ¶
Barrier
module-attribute
¶
CCRz
module-attribute
¶
Double-Qubit Controlled Rz Gate, CCRz Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
CCX
module-attribute
¶
Double-Qubit Controlled X Gate, CCX Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
CCZ
module-attribute
¶
Double-Qubit Controlled Z Gate, CCZ Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
CH
module-attribute
¶
Controlled H Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
CRy
module-attribute
¶
Controlled Ry Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
CRz
module-attribute
¶
Controlled Rz Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
CSwap
module-attribute
¶
Controlled Swap Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
CU1
module-attribute
¶
Controlled U1 Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
CU3
module-attribute
¶
Controlled U3 Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
CX
module-attribute
¶
Controlled X Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
CY
module-attribute
¶
Controlled Y Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
CZ
module-attribute
¶
Controlled Z Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
ECR
module-attribute
¶
ECR Quantum Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
FSim
module-attribute
¶
Fermions Simulation Quantum Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
GPhase
module-attribute
¶
Global Phase Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
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]
Hy
module-attribute
¶
ID
module-attribute
¶
Measure
module-attribute
¶
MeasureX
module-attribute
¶
MeasureY
module-attribute
¶
Phase
module-attribute
¶
Single-Qubit Rotation Gate about Z axis.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
RCCX
module-attribute
¶
Simplified Double-Qubit Controlled X Gate, or Margolus gate
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
Reset
module-attribute
¶
Rx
module-attribute
¶
Single-Qubit Rotation Gate, which apply an \(\lambda\) rotation about X axis.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
Rxx
module-attribute
¶
Double-Qubits X \(\otimes\) X Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
Ry
module-attribute
¶
Single-Qubit Rotation Gate, which apply an \(\lambda\) rotation about Y axis. [Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
Ryy
module-attribute
¶
Double-Qubits Y \(\otimes\) Y Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
Rz
module-attribute
¶
Single-Qubit Rotation Gate, which apply an \(\lambda\) rotation about Z axis.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
Rzx
module-attribute
¶
Double-Qubits Z \(\otimes\) X Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
Rzz
module-attribute
¶
Double-Qubits Z \(\otimes\) Z Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
S
module-attribute
¶
SW
module-attribute
¶
Single-Qubit Sqrt-W Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
SX
module-attribute
¶
SX_dagger
module-attribute
¶
SY
module-attribute
¶
SY_dagger
module-attribute
¶
S_dagger
module-attribute
¶
Swap
module-attribute
¶
Swap Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
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]
T_dagger
module-attribute
¶
Single-Qubit T Dagger Gate, which produce a -pi/4 phase.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
U1
module-attribute
¶
Single-Qubit Rotation Gate, which apply an \(\lambda\) rotation about Z axis.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
U2
module-attribute
¶
Single-Qubit Rotation Gate about X and Z axis.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
U3
module-attribute
¶
Single-Qubit Rotation Gate with three Euler Angles.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
X
module-attribute
¶
Y
module-attribute
¶
Z
module-attribute
¶
iSwap
module-attribute
¶
iSwap Gate, a double-qubit XX + YY Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
iSwap_dagger
module-attribute
¶
iSwap Dagger Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
sqiSwap
module-attribute
¶
Swap Gate.
[Matrix Representation]
[How to apply]
[Graph Representation]
[QASM Representation]
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
Circuit ¶
Circuit(wires, name: str = None, topology: Layout = None, ancilla_qubits: List[int] = None, precision: bool = 'double')
Bases: CircuitBased
Implement a Quantum Circuit. Circuit is the core part of the framework.
Parameters:
-
wires(Union[Qureg, int]) –the number of qubits for the circuit.
-
name(str, default:None) –the name of the circuit.
-
topology(Layout, default:None) –The topology of the circuit. If it is empty, it will be seemed as fully connected.
-
ancilla_qubits(list<int>, default:None) –The indexes of ancilla qubits for current circuit.
Source code in QuICT/core/circuit/circuit.py
ancilla_qubits
property
writable
¶
Return the list of ancilla qubits indexes.
__call__ ¶
assigned a smaller qureg for this circuit
Parameters:
-
indexes(object) –the indexes passed in, it can have follow form: 1) int 2) list
3) Qubit 4) Qureg
Returns:
-
Qureg–the qureg correspond to the indexes
Raises:
-
TypeError–the type of indexes is error.
Source code in QuICT/core/circuit/circuit.py
__del__ ¶
__getitem__ ¶
to fit the slice operator, overloaded this function.
get a smaller qureg/qubit from this circuit
Parameters:
-
item(int / slice) –slice passed in.
Return
Qubit/Qureg: the result or slice
Source code in QuICT/core/circuit/circuit.py
__or__ ¶
Deal the operator '|', Use the syntax "circuit/CompositeGate | circuit" to add a Quantum Circuit into the other one.
Note that if not assigned the target qubits, it will depending on the Qureg to match the Quantum Circuit.
For the Qureg which not in the target Quantum Circuit, they will be treated as new extra qubits add into the target Quantum Circuit.
Example
circuit_a = Circuit(3) \ circuit_a | circuit([1, 3, 4]) Add a 3-qubits Quantum Circuit into "circuit" with qubit index [1, 3, 4]
Parameters:
-
targets(Circuit) –the targets Quantum Circuit acts on.
Raise
TypeError: the type of targets is wrong
Source code in QuICT/core/circuit/circuit.py
add_qubit ¶
add the extra qubits in circuit.
Parameters:
-
qubits(Union[Qureg, Qubit, int]) –The new qubits, if it is int, means the number of new qubits.
-
is_ancillae_qubit(bool) –whether the given qubits is ancillae, default to False.
Source code in QuICT/core/circuit/circuit.py
append ¶
Add a Quantum Gate or Operator into current circuit.
Parameters:
Source code in QuICT/core/circuit/circuit.py
depth ¶
extend ¶
Add a CompositeGate/Circuit to the circuit.
Parameters:
-
gates(Union[BasicGate, CompositeGate]) –the compositegate or circuit to be added to the circuit
Source code in QuICT/core/circuit/circuit.py
get_DAG_circuit ¶
Translate a quantum circuit to a directed acyclic graph via quantum gates dependencies (The commutation of quantum gates).
The nodes in the graph represented the quantum gates, and the edges means the two quantum gates is non-commutation. In other words, a directed edge between node A with quantum gate GA and node B with quantum gate GB, the quantum gate GA does not commute with GB.
The nodes in the graph have the following attributes: 'name', 'gate', 'cargs', 'targs', 'qargs', 'successors', 'predecessors'.
Reference:
[1] Iten, R., Moyard, R., Metger, T., Sutter, D. and Woerner, S., 2020.
Exact and practical pattern matching for quantum circuit optimization.
arXiv:1909.05270 <https://arxiv.org/abs/1909.05270>_
Returns:
-
DAGCircuit(DAGCircuit) –A directed acyclic graph represent current quantum circuit
Source code in QuICT/core/circuit/circuit.py
inverse ¶
the inverse of all Quantum Gates in current Circuit.
Returns:
-
Circuit(Circuit) –the Quantum Circuit with the inverse of the gateSet
Source code in QuICT/core/circuit/circuit.py
matrix ¶
Generate the circuit's unitary matrix which compose by all quantum gates' matrix in current circuit.
Parameters:
-
device(str, default:'CPU') –The device type for generate circuit's matrix, one of [CPU, GPU]. Defaults to "CPU".
-
expand_gate(bool, default:True) –whether or not expand each gate to the full system size when calculating circuit's matrix. Default to
True.
Return
ndarray: The combined unitary matrix of current Quantum Circuit.
Source code in QuICT/core/circuit/circuit.py
peel ¶
Partially flatten the composite gates inside current circuit.
Parameters:
-
level(int, default:-1) –maximum level to flatten the composite gates.
level = -1means the composite gates will be fully flattened.
Returns:
-
Circuit–a partially flattened circuit.
Source code in QuICT/core/circuit/circuit.py
random_append ¶
random_append(rand_size: int = 10, typelist: list = None, random_params: bool = False, probabilities: list = None, seed: int = None)
add some random gate to the circuit, not include Unitary, Permutation and Permutation_FX Gate.
Parameters:
-
rand_size(int, default:10) –the number of the gate added to the circuit.
-
typelist(list<GateType>, default:None) –the type of gate, default contains. Rx, Ry, Rz, Cx, Cy, Cz, CRz, Ch, Rxx, Ryy, Rzz and FSim
-
random_params(bool, default:False) –whether using random parameters for all quantum gates with parameters.
-
probabilities(list, default:None) –The probability of append for each gates.
-
seed(int, default:None) –The random seed for fixed Quantum Circuit.
Source code in QuICT/core/circuit/circuit.py
reset_qubits ¶
Reset all qubits in current Quantum Circuit, clean the measured result for each qubit.
split ¶
Split the Circuit by qubits or depth.
Parameters:
-
qubits(List, default:None) –The qubit indexes for one of split CompositeGate.
-
depth(Union[int, List], default:None) –The split depth for current CompositeGate, support split by different
Source code in QuICT/core/circuit/circuit.py
sub_circuit ¶
sub_circuit(start: int = 0, max_size: int = -1, qubit_limit: Union[int, List[int], Qureg] = [], gate_limit: List[GateType] = [])
Get a sub-part circuit from the current Quantum Circuit with target GateSet and Qureg limitation.
Parameters:
-
start(int, default:0) –the start gate's index, default 0.
-
max_size(int, default:-1) –max size of the sub circuit, default -1 without limit.
-
qubit_limit(int/list<int>/Qubit/Qureg, default:[]) –the required qubits' indexes, if [], accept all qubits. default to be [].
-
gate_limit(List[GateType], default:[]) –list of required gate's type, if [], accept all quantum gate. default to be [].
Return
Circuit: the sub circuit
Source code in QuICT/core/circuit/circuit.py
supremacy_append ¶
Add a supremacy circuit to the circuit
Parameters:
-
repeat(int, default:1) –the number of two-qubit gates' sequence
-
pattern(str, default:'ABCDCDAB') –indicate the two-qubit gates' sequence
-
random_parameters(bool, default:False) –whether using random parameters for FSim Gate, or not.
Source code in QuICT/core/circuit/circuit.py
to_compositegate ¶
ComplexGateBuilder ¶
The class of all build_gate functions for BasicGate.
build_gate
classmethod
¶
Gate Decomposition, divided the current gate with a set of small gates
Parameters:
-
gate_type(GateType) –The type of Quantum Gate.
-
parg(list) –The parameters of Quantum Gate.
-
gate_matrix(_type_, default:None) –The matrix of Quantum Gate, only use for CU3. Defaults to None.
Returns:
-
List–List of gate_info(gate_type, qubit_index, parameters)
Source code in QuICT/core/gate/utils/gate_matrix.py
CompositeGate ¶
CompositeGate(name: str = None, gates: List[BasicGate, CompositeGate] = None, precision: str = 'double')
Bases: CircuitBased
Implement a group of gate
Parameters:
-
name(str, default:None) –the name of the composite gate. Defaults to None.
-
gates(List[BasicGate, CompositeGate], default:None) –gates within this composite gate. Defaults to None.
Source code in QuICT/core/gate/composite_gate.py
__and__ ¶
assign indexes for the composite gates
Parameters:
-
targets([int / list[int]]) –qubit describe
Source code in QuICT/core/gate/composite_gate.py
__getitem__ ¶
get gates from this composite gate
Parameters:
-
item(int / slice) –slice passed in.
Return
[BasicGates]: the gates
__or__ ¶
deal the operator '|'
Use the syntax "CompositeGate | circuit", "CompositeGate | CompositeGate" to add the gate of gateSet into the circuit
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 the following form, 1) Circuit 2) CompositeGate
Raise: TypeError: the type of other is wrong
Source code in QuICT/core/gate/composite_gate.py
__xor__ ¶
deal the operator '^'
Use the syntax "gateSet ^ circuit", "gateSet ^ gateSet" to add the gate of gateSet's inverse into the circuit
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 the following form, 1) Circuit 2) CompositeGate
Raise: TypeError: the type of other is wrong
Source code in QuICT/core/gate/composite_gate.py
append ¶
Add a quantum gate to current CompositeGate.
Parameters:
-
gate(BasicGate) –The quantum gate need to append
Source code in QuICT/core/gate/composite_gate.py
clean ¶
copy ¶
depth ¶
exp2 ¶
Get a Composite that applys current Composite gate 2^n times
Parameters:
-
n(int) –The exponent.
Returns:
-
CompositeGate(CompositeGate) –a gate that apply the original gate 2^n times.
Source code in QuICT/core/gate/composite_gate.py
extend ¶
Add a CompositeGate to current CompositeGate.
Parameters:
-
gates(CompositeGate) –The given CompositeGate
Source code in QuICT/core/gate/composite_gate.py
inverse ¶
the inverse of CompositeGate
Returns:
-
CompositeGate(CompositeGate) –the inverse of the gateSet
Source code in QuICT/core/gate/composite_gate.py
matrix ¶
matrix of these gates
Parameters:
-
device(str, default:'CPU') –The device type for generate circuit's matrix, one of [CPU, GPU]. Defaults to "CPU".
-
local(bool, default:False) –whether consider only about the occupied qubits or not
-
expand_gate(bool, default:True) –whether or not expand each gate to the full system size when calculating circuit's matrix. Default to
True.
Returns:
-
ndarray–np.ndarray: the matrix of the gates
Source code in QuICT/core/gate/composite_gate.py
peel ¶
Partially flatten the composite gates inside current composite.
Parameters:
-
level(int, default:-1) –maximum level to flatten the composite gates.
lelve = -1means the composite gates will be fully flattened.
Returns:
-
CompositeGate(CompositeGate) –a partially flattened composite gate.
Source code in QuICT/core/gate/composite_gate.py
set_ancilla ¶
Set ancilla qubits' indices.
Parameters:
-
ancilla_qubits(List[int]) –list of indices indicating the ancilla qubits.
Source code in QuICT/core/gate/composite_gate.py
split ¶
Split the CompositeGate by qubits or depth.
Parameters:
-
qubits(List, default:None) –The qubit indexes for one of split CompositeGate.
-
depth(Union[int, List], default:None) –The split depth for current CompositeGate, support split by different
Source code in QuICT/core/gate/composite_gate.py
width ¶
DiagonalGate ¶
Bases: object
Diagonal gate
Reference
https://arxiv.org/abs/2108.06150
Parameters:
-
target(int) –number of target qubits
-
aux(int, default:0) –number of auxiliary qubits
-
opt(bool, default:True) –optimizer switch, enabled by default
-
keep_phase(bool, default:True) –global phase switch
Source code in QuICT/core/gate/diagonal_gate.py
S_x
classmethod
¶
Implement the Appendix H, also the construction of sets \(S_x\).
Parameters:
-
x(int) –the number from \(0\) to \(2^n-1\)
-
n(int) –the length of these binary strings
return
str: an array \(S_x = [x \otimes e_1,x \otimes e_2,...,x \otimes e_n]\)
Source code in QuICT/core/gate/diagonal_gate.py
__call__ ¶
Parameters:
-
theta(List[float]) –list of (2 ** target) angles of rotation in the diagonal gate
Returns:
-
CompositeGate(CompositeGate) –diagonal gate
Source code in QuICT/core/gate/diagonal_gate.py
alpha_s
classmethod
¶
Solve Equation 6 \(\sum_s \alpha_s <s, x> = \theta(x)\)
Parameters:
-
theta(List[float]) –phase angles of the diagonal gate
-
s(int) –key of the solution component
-
n(int) –number of qubits in the diagonal gate
Returns:
-
float(float) –\(\alpha_s\) in Equation 6
Source code in QuICT/core/gate/diagonal_gate.py
binary_addition
classmethod
¶
Implement the function: \(x \otimes y = (x1 \otimes y1, x2 \otimes y2, · · · , xn \otimes yn)^T\)
Parameters:
-
binary_string1(str) –binary string like x
-
binary_string2(str) –binary string like y
-
n(int) –the length of the binary strings
return
str: a string with bitwise binary addition
Source code in QuICT/core/gate/diagonal_gate.py
binary_inner_prod
staticmethod
¶
Calculate the binary inner product of s_bin and x_bin, where s_bin and x_bin are binary representation of s and x respectively of width n
Parameters:
-
s(int) –s in
-
x(int) –x in
-
width(int) –the width of s_bin and x_bin
Returns:
-
int(int) –the binary inner product of s and x
Source code in QuICT/core/gate/diagonal_gate.py
construct_T
classmethod
¶
Realize the construction of a two-dimensional string array T, each row of the array constitutes a matrix with diagonal elements of 1.
Parameters:
-
n(int) –size of the prefixes c
Returns:
-
Tuple[List[List[str]], int]–Tuple[List[List[str]], int]: 2-dimension T string array, with the number of rows: ell
Source code in QuICT/core/gate/diagonal_gate.py
disjoint_families_F
classmethod
¶
Implement the Eq(15),disjoint families F_1,...,F_ell
Parameters:
-
r_c(int) –size of the prefixes c
-
r_t(int) –size of the suffix t
Returns:
-
List[Set[str]]–List[Set[str]]: 2-dimension (r_c + r_t)-bit string array, also the linear independent set F with ell rows and not fixed columns
Source code in QuICT/core/gate/diagonal_gate.py
int_to_binary
classmethod
¶
Parameters:
-
num(int) –the number from 0 to 2^n-1
-
n(int) –the length of the binary strings
return
str: numeric num converted binary string
Source code in QuICT/core/gate/diagonal_gate.py
ket_fjk
classmethod
¶
Implement the part of unitary U1 for every j: \(|0\rangle -> |<s(j, k), x>\rangle\) by adding the CNOT gates
Parameters:
-
j(int) –j is the label of n-bit strings s(j,k)
-
k(int) –k is the label of n-bit strings s(j,k)
-
n(int) –length of 0-1 string to be partitioned
-
t(int) –length of the shared prefix of each row
-
target_num(int) –the target label connecting the CNOT gate
Returns:
-
CompositeGate(CompositeGate) –\(|0\rangle -> |<s(j, k), x>\rangle\)
Source code in QuICT/core/gate/diagonal_gate.py
linear_fjk
classmethod
¶
Implement the linear functions \(f_{jk}(x) = <s(j, k), x>\)
Parameters:
-
j(int) –j is the label of n-bit strings s(j, k)
-
k(int) –k is the label of n-bit strings s(j, k)
-
n(int) –length of 0-1 string to be partitioned
-
t(int) –length of the shared prefix of each row
-
x(int) –the independent variables of the function \(f_{jk}\)
Returns:
-
int(int) –\(f_{jk}(x)\)
Source code in QuICT/core/gate/diagonal_gate.py
linearly_independent_sets_T
classmethod
¶
Implement the Appendix H, also the construction of sets T.
Parameters:
-
n(int) –the size of each sublist T^(i),i = 1,2,...,ell
return
Tuple[List[List[str]], int]: 2-dimension n-bit string array, also the linear independent set T with ell rows and n columns and the number of T, ell.
Source code in QuICT/core/gate/diagonal_gate.py
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 | |
lucal_gray_code
staticmethod
¶
Generate the (k, n)-Gray code defined in and following Lemma 7
Parameters:
-
k(int) –start the circular modification from the k-th binary code
-
n(int) –the length of binary code, that is, the length of Gray code would be 2^n
Returns:
-
List[str]–List[str]: the (k, n)-Gray code
Source code in QuICT/core/gate/diagonal_gate.py
no_aux_qubit ¶
Parameters:
-
n(int) –number of qubits in the diagonal gate
-
theta(List[float]) –list of (2 ** target) angles of rotation in the diagonal gate
Returns:
-
CompositeGate(CompositeGate) –diagonal gate without auxiliary qubit
Source code in QuICT/core/gate/diagonal_gate.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
partitioned_gray_code
classmethod
¶
Lemma 15 by the construction in Appendix E
Parameters:
-
n(int) –length of 0-1 string to be partitioned
-
t(int) –length of the shared prefix of each row
Returns:
-
List[List[str]]–List[List[str]]: partitioned gray code
Source code in QuICT/core/gate/diagonal_gate.py
phase_shift
classmethod
¶
Implement the phase shift \(|x\rangle -> \exp(i \theta(x)) |x\rangle\) by solving Equation 6 \(\sum_s \alpha_s <s, x> = \theta(x)\)
Parameters:
-
theta(List[float]) –phase angles of the diagonal gate
-
seq(Iterable, default:None) –sequence of s application, numerical order if not assigned
-
aux(int, default:None) –key of auxiliary qubit (if exists)
Returns:
-
CompositeGate(CompositeGate) –CompositeGate of the diagonal gate
Source code in QuICT/core/gate/diagonal_gate.py
phase_shift_s
classmethod
¶
Implement the phase shift for a certain s defined in Equation 5 as Figure 8 \(|x\rangle -> \exp(i \alpha_s <s, x>) |x\rangle\)
Parameters:
-
s(int) –whose binary representation stands for the 0-1 string s
-
n(int) –the number of qubits in \(|x\rangle\)
-
alpha(float) –\(\alpha_s\) in the equation
-
aux(int, default:None) –key of auxiliary qubit (if exists)
-
j(int, default:None) –if no auxiliary qubit, the j-th smallest element in s_idx would be the target qubit
Returns:
-
CompositeGate(CompositeGate) –CompositeGate for Equation 5 as Figure 8
Source code in QuICT/core/gate/diagonal_gate.py
with_aux_qubit ¶
Parameters:
-
theta(List[float]) –list of (2 ** target) angles of rotation in the diagonal gate
Returns:
-
CompositeGate(CompositeGate) –diagonal gate with auxiliary qubit at the end of qubits
Source code in QuICT/core/gate/diagonal_gate.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | |
GateAppendError ¶
Bases: QuICTException
BasicGate append error.
Source code in QuICT/tools/exception/core/gate_exception.py
GateMatrixError ¶
Bases: QuICTException
BasicGate matrix error.
Source code in QuICT/tools/exception/core/gate_exception.py
GateMatrixGenerator ¶
Generator the Quantum Gates' Matrix.
based_matrix ¶
Return the no-parameter Quantum Gates' matrix.
Parameters:
-
gate_type(GateType) –The type of Quantum Gate
-
precision(complex) –The precision of Quantum Gate
Returns:
-
–
np.ndarray: The Quantum Gate's matrix
Source code in QuICT/core/gate/utils/gate_matrix.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
get_matrix ¶
Return the given BasicGate's matrix.
Parameters:
-
gate(BasicGate) –The Quantum Gate
-
precision(str, default:None) –The precision of Quantum Gate. Defaults to None.
-
is_get_target(bool, default:False) –Whether return the completed BasicGate's matrix, or only return the target
Returns:
-
ndarray–np.ndarray: The Quantum Gates' matrix.
Source code in QuICT/core/gate/utils/gate_matrix.py
grad_for_param ¶
Return the Parameterized Quantum Gates' gradient matrices.
Parameters:
-
gate_type(GateType) –The type of Quantum Gate.
-
gate_pargs(List) –The Quantum Gate's parameters.
-
symbol_pargs(dict) –The Quantum Gate's symbol parameters.
-
precision(str) –The precision of Quantum Gate, one of [double, single]
Returns:
-
list–Parameterized Quantum Gates' gradient matrices.
Source code in QuICT/core/gate/utils/gate_matrix.py
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 | |
matrix_with_param ¶
matrix_with_param(gate_type: GateType, gate_pargs: list, symbol_gate: bool, symbol_pargs: dict, precision: complex)
Return the Quantum Gates' matrix, which has parameters.
Parameters:
-
gate_type(GateType) –The type of Quantum Gate.
-
gate_pargs(List) –The Quantum Gate's parameters.
-
symbol_gate(bool) –Whether the Quantum Gate is a symbol gate.
-
symbol_pargs(dict) –The Quantum Gate's symbol parameters.
-
precision(complex) –The precision of Quantum Gate.
Returns:
-
–
np.ndarray: The Quantum Gate's matrix.
Source code in QuICT/core/gate/utils/gate_matrix.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | |
GateParametersAssignedError ¶
Bases: QuICTException
Gate's Parameter Error.
Source code in QuICT/tools/exception/core/gate_exception.py
GateQubitAssignedError ¶
Bases: QuICTException
Gate's qubit assign Error.
Source code in QuICT/tools/exception/core/gate_exception.py
Hamiltonian ¶
The Hamiltonian class.
Note
Coefficients are required. And each Pauli Gate should act on different qubit.
Some examples are like this:
[[0.4, 'Y0', 'X1', 'Z2', 'I5'], [0.6]][[1, 'X0', 'I5'], [-3, 'Y3'], [0.01, 'Z5', 'Y0']]
Parameters:
-
pauli_terms(list) –A list of pauli terms in the Hamiltonian.
-
coefficients(list) –A list of coefficients of each pauli term in the Hamiltonian.
Examples:
>>> from QuICT.algorithm.quantum_machine_learning.utils import Hamiltonian
>>> ham = Hamiltonian([["Y0", "X1"], []], [0.4, 0.6])
>>> ham
[0.6]
[0.4, 'Y0', 'X1']
>>> ham_matrix = ham.get_hamilton_matrix(2)
>>> ham_matrix
[[0.6+0.j 0. +0.j 0. +0.j 0. -0.4j]
[0. +0.j 0.6+0.j 0. -0.4j 0. +0.j ]
[0. +0.j 0. +0.4j 0.6+0.j 0. +0.j ]
[0. +0.4j 0. +0.j 0. +0.j 0.6+0.j ]]
Instantiate the Hamiltonian class instance with pauli terms and coefficients.
Source code in QuICT/core/hamiltonian/hamiltonian.py
coefficients
property
¶
The coefficient of each term in the Hamiltonian, i.e. [0.4, 0.6].
pauli_str
property
¶
The pauli string of the Hamiltonian, i.e. [[0.4, 'Y0', 'X1'], [0.6]].
__add__ ¶
Concatenate two Pauli Strings.
Source code in QuICT/core/hamiltonian/hamiltonian.py
__eq__ ¶
Determine whether two Hamiltonians are the same.
Source code in QuICT/core/hamiltonian/hamiltonian.py
__getitem__ ¶
Get slice according to the indexes.
Source code in QuICT/core/hamiltonian/hamiltonian.py
__mul__ ¶
Number multiplication operation for coefficients or multiplication between Hamiltonians.
Source code in QuICT/core/hamiltonian/hamiltonian.py
__repr__ ¶
Return a sorted pauli string of the Hamiltonian.
Source code in QuICT/core/hamiltonian/hamiltonian.py
__sub__ ¶
Concatenate two Pauli strings after the coefficients of the subtrahend term become the opposite.
construct_hamilton_circuit ¶
Construct a circuit form of the Hamiltonian.
Parameters:
-
n_qubits(int) –The number of qubits.
Returns:
-
–
list
: A list of circuits corresponding to the Hamiltonian.
Source code in QuICT/core/hamiltonian/hamiltonian.py
from_pauli_str
classmethod
¶
Instantiate the Hamiltonian class instance with a Pauli string.
Parameters:
-
pauli_str(list) –A list of Hamiltonian information.
Source code in QuICT/core/hamiltonian/hamiltonian.py
get_hamilton_matrix ¶
Construct a matrix form of the Hamiltonian.
Parameters:
-
n_qubits(int) –The number of qubits.
Returns:
-
–
np.array: The Hamiltonian matrix.
Source code in QuICT/core/hamiltonian/hamiltonian.py
InverseGate ¶
The class of all Inverse functions for Quantum Gate.
get_inverse_gate
classmethod
¶
Get Inverse Quantum Gate Information.
Parameters:
-
gate_type(GateType) –The type of Quantum Gate.
-
pargs(list) –The parameters of Quantum Gate.
Returns:
-
tuple(tuple) –The inverse gate info.
Source code in QuICT/core/gate/utils/gate_matrix.py
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
Layout ¶
Layout(qubit_number: int, name: str = 'unknown', layout_type: LayoutType = LayoutType.normal, unreachable_nodes: list = None, layout_width: int = -1)
Implement a topology in a physical device
Parameters:
-
qubit_number(int)–the number of qubits
-
name(string)–the name of the topology
Source code in QuICT/core/layout/layout.py
directionalized
property
¶
Return a copy of current layout with all undirected edges replaced with 2 reversed directional edges.
add_edge ¶
add an edge in the layout
Parameters:
-
u(int)–Edge endpoint u
-
v(int)–Edge endpoint v
-
directional(bool)–Whether the edge is directional
-
error_rate(float)–Error rate, default 1.0
Source code in QuICT/core/layout/layout.py
build_layout_by_double_gate_fidelity ¶
build layout by double_gate_fidelity form virtual quantum machine.
Source code in QuICT/core/layout/layout.py
check_edge ¶
Check whether layout contain u->v
Parameters:
-
u(int)–the edge endpoint u
-
v(int)–the edge endpoint v
Return: bool: whether layout contain u->v
Source code in QuICT/core/layout/layout.py
draw ¶
Visualization of the topology structure.
Parameters:
-
mode(str, default:None) –The mode of topology, should be one of [random, grid, linear, circuit, rhombus]; default to be grid.
Source code in QuICT/core/layout/layout.py
get_sublayout_edges ¶
Get list of edges with target qubits from current Layout.
Parameters:
-
qubits(list) –The target qubits
Returns:
-
list(List[LayoutEdge]) –The list of LayoutEdge
Source code in QuICT/core/layout/layout.py
grid_layout
staticmethod
¶
grid_layout(qubit_number: int, width: int = None, unreachable_nodes: list = [], directional: bool = DIRECTIONAL_DEFAULT, error_rate: list = None)
Get Grid Structure Topology.
Parameters:
-
qubit_number(int)–the number of qubits
-
width(int, default:None) –The width of grid layout. Defaults to None.
-
unreachable_nodes(list, default:[]) –The nodes which are not work. Defaults to [].
-
directional(bool, default:DIRECTIONAL_DEFAULT) –Whether the edge is directional. Defaults to DIRECTIONAL_DEFAULT.
-
error_rate(list, default:None) –Error rate for each edge, default 1.0. Defaults to []. WARNING: The error rate is for each valid edges from top to bottom, left to right. Please make sure you know exactly every edges' position and rate.
Returns:
-
Layout–The layout with grid topology
Source code in QuICT/core/layout/layout.py
linear_layout
staticmethod
¶
Return the layout with linearly topology.
Parameters:
-
qubit_number(int)–the number of qubits
-
directional(_type_, default:DIRECTIONAL_DEFAULT) –Whether the edge is directional. Defaults to DIRECTIONAL_DEFAULT.
-
error_rate(list, default:None) –Error rate for each edges, default 1.0. Defaults to [].
Returns:
-
Layout–The layout with linearly topology
Source code in QuICT/core/layout/layout.py
load_file
classmethod
¶
Load layout from file. Args: file_path(str): Path of layout file. Return: Layout: Layout parsed from file.
Source code in QuICT/core/layout/layout.py
out_edges ¶
edges begin from begin_point
Parameters:
-
begin_point(int)–the index of begin node
Return
list
Source code in QuICT/core/layout/layout.py
remove_edge ¶
remove an edge in the layout
Parameters:
-
u(int)–Edge endpoint u
-
v(int)–Edge endpoint v
-
directional(bool)–Whether the edge is directional
Source code in QuICT/core/layout/layout.py
rhombus_layout
staticmethod
¶
rhombus_layout(qubit_number: int, width: int = None, unreachable_nodes: list = [], directional: bool = DIRECTIONAL_DEFAULT, error_rate: list = None, shape: int = 0)
Get Rhombus Structure Topology.
Parameters:
-
qubit_number(int)–the number of qubits
-
width(int, default:None) –The width of grid layout. Defaults to None.
-
unreachable_nodes(list, default:[]) –The nodes which are not work. Defaults to [].
-
directional(bool, default:DIRECTIONAL_DEFAULT) –Whether the edge is directional. Defaults to DIRECTIONAL_DEFAULT.
-
error_rate(list, default:None) –Error rate for each edge, default 1.0. Defaults to []. WARNING: The error rate is arranged in order of valid edges, from top to bottom, left to right. Please make sure you know exactly every edges' position and rate.
-
shape(int, default:0) –The shape of rhombus; if 0, it will be close shape first; otherwise it will be open shape. default to close shape.
Returns:
-
Layout–The layout with rhombus topology
Source code in QuICT/core/layout/layout.py
set_double_gate_fidelity ¶
Set the coupling strength between qubits
Parameters:
-
double_gate_fidelity(List[Tuple(idx, idx, float)]) –The strength of the interaction between two qubits in a quantum computing system.
Source code in QuICT/core/layout/layout.py
sub_layout ¶
Get partial layout. Only working for undirected layout.
Parameters:
-
qubits_number(list) –The qubit indexes for sub-layout
Returns:
-
Layout(Layout) –The sub-layout
Source code in QuICT/core/layout/layout.py
to_json ¶
Serialize current layout into json string.
Source code in QuICT/core/layout/layout.py
valid_circuit ¶
Validate the given Circuit/CompositeGate is valid with current Layout.
Parameters:
-
circuit(Union[Circuit, CompositeGate]) –The given Circuit/CompositeGate
Returns:
-
bool(bool) –Whether is valid for current layout.
Source code in QuICT/core/layout/layout.py
write_file ¶
Write layout into file.
Parameters:
-
directory(str)–Directory to store layout file in, default "./"
LayoutEdge ¶
Implement a physical connection between physical qubits
Attributes:
-
u(int)–Node u of edge
-
v(int)–Node v of edge
-
directional(bool)–Whether the layout is directional
-
error_rate(float)–Error_rate between u and v, default 1.0
Source code in QuICT/core/layout/layout.py
MatrixType ¶
Bases: Enum
Different Type of quantum gates' matrix
-
normal: based type of matrix
Single Qubit:
\[ \begin{bmatrix} v_{00} & v_{01} \\ v_{10} & v_{11} \\ \end{bmatrix} \]Bi-Qubits (1 control + 1 target):
\[ \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & v_{00} & v_{01} \\ 0 & 0 & v_{10} & v_{11} \\ \end{bmatrix} \] -
diagonal: diagonal matrix
Single Qubit:
\[ \begin{bmatrix} v_{00} & 0 \\ 0 & v_{11} \\ \end{bmatrix} \]Bi-Qubits (1 control + 1 target):
\[ \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & v_{00} & 0 \\ 0 & 0 & 0 & v_{11} \\ \end{bmatrix} \]Bi-Qubits (2 targets):
\[ \begin{bmatrix} v_{00} & 0 & 0 & 0 \\ 0 & v_{11} & 0 & 0 \\ 0 & 0 & v_{22} & 0 \\ 0 & 0 & 0 & v_{33} \\ \end{bmatrix} \]Tri-Qubits (2 controls + 1 target):
\[ \begin{bmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & v_{00} & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & v_{11} \\ \end{bmatrix} \] -
control: control diagonal matrix
Single Qubit:
\[ \begin{bmatrix} 1 & 0 \\ 0 & v_{00} \\ \end{bmatrix} \]Bi-Qubits (1 control + 1 target):
\[ \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & v_{00} \\ \end{bmatrix} \] -
swap: swap quantum gates' matrix
Single Qubit:
\[ \begin{bmatrix} 0 & 1 \\ 1 & 0 \\ \end{bmatrix} \]Bi-Qubits (2 targets):
\[ \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix} \]Tri-Qubits (1 controls + 2 targets):
\[ \begin{bmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ \end{bmatrix} \] -
reverse; reverse matrix
Single Qubit:
\[ \begin{bmatrix} 0 & v_{01} \\ v_{10} & 0 \\ \end{bmatrix} \]Bi-Qubits (1 control + 1 target):
\[ \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & v_{01} \\ 0 & 0 & v_{10} & 0 \\ \end{bmatrix} \]Tri-Qubits (2 controls + 1 target):
\[ \begin{bmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & v_{01} \\ 0 & 0 & 0 & 0 & 0 & 0 & v_{10} & 0 \\ \end{bmatrix} \] -
special: no matrix Gate, such as \(Measure, Reset, Barrier, Perm\)
-
diag_diag: 2-qubits diagonal matrix [TODO: Remove in open_test]
Bi-Qubits (2 targets):
\[ \begin{bmatrix} v_{00} & 0 & 0 & 0 \\ 0 & v_{11} & 0 & 0 \\ 0 & 0 & v_{22} & 0 \\ 0 & 0 & 0 & v_{33} \\ \end{bmatrix} \] -
ctrl_normal: control-normal mixed quantum gate's matrix Bi-Qubits (2 targets):
\[ \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & v_{00} & v_{01} & 0 \\ 0 & v_{10} & v_{11} & 0 \\ 0 & 0 & 0 & v_{33} \\ \end{bmatrix} \] -
normal-normal: normal-normal mixed quantum gate's matrix Bi-Qubits (2 targets):
\[ \begin{bmatrix} v_{00} & 0 & 0 & v_{03} \\ 0 & v_{11} & v_{12} & 0 \\ 0 & v_{21} & v_{22} & 0 \\ v_{30} & 0 & 0 & v_{33} \\ \end{bmatrix} \] -
diagonal-normal: diagonal-normal mixed quantum gate's matrix Bi-Qubits (2 targets):
\[ \begin{bmatrix} v_{00} & v_{01} & 0 & 0 \\ v_{10} & v_{11} & 0 & 0 \\ 0 & 0 & v_{22} & v_{23} \\ 0 & 0 & v_{32} & v_{33} \\ \end{bmatrix} \]
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
MultiControlToffoli ¶
Bases: object
Divided by the usages of auxiliary qubits, here are 4 implementations of multi-control Toffoli gates.
Detailed description of each synthesis algorithm could be found in the backend.
Parameters:
-
aux_usage(str, default:'no_aux') –4 different usages of auxiliary qubits could be chosen, as listed 'no_aux': No auxiliary qubits are used
'one_clean_aux': 1 clean auxiliary qubit is used
'one_dirty_aux': 1 dirty auxiliary qubit is used
'half_dirty_aux': more than half of all qubits are used as auxiliary qubits, which could be dirty
Source code in QuICT/core/gate/multicontrol_toffoli.py
__call__ ¶
By default, the qubit arrangement would be control qubits, target qubit, auxiliary qubits (if exists)
Parameters:
-
control(int) –the number of control qubits
-
aux(int, default:0) –only works when 'half_dirty_aux' is chosen, the number of auxiliary qubits
Returns:
-
CompositeGate(CompositeGate) –the mct gates
Source code in QuICT/core/gate/multicontrol_toffoli.py
Parameter ¶
Used to represent trainable parameters of parameterized quantum gates or parameterized quantum circuits.
Note
Only supports number multiplication operation.
Parameters:
-
symbol(str) –The symbol.
Examples:
>>> from QuICT.core.circuit import Circuit
>>> from QuICT.core.gate import *
>>> cir = Circuit(3)
>>> H | cir
>>> Rx("x") | cir(0)
>>> Rx(Parameter("x") * 0.3) | cir(2)
>>> Rzz("y") | cir([0, 1])
>>> cir.draw("command")
┌───┐ ┌───────┐
q_0: |0>┤ h ├─┤ rx(x) ├───■──────
├───┤ └───────┘ │ZZ(y)
q_1: |0>┤ h ├─────────────■──────
├───┤┌──────────┐
q_2: |0>┤ h ├┤ rx(0.3x) ├────────
└───┘└──────────┘
Initialize a Parameter instance.
Source code in QuICT/core/utils/parameter.py
dx
property
¶
The derivative of the parameter on the symbol.
Returns:
-
float(float) –The derivative.
expr
property
¶
The expression of the parameter.
Returns:
-
str(str) –The expression of the parameter.
multiplier
property
¶
The multiplier of the symbol.
Returns:
-
float(float) –The multiplier.
__lt__ ¶
Determine whether the current parameter is smaller than another parameter.
Parameters:
-
other(Parameter) –Another parameter.
Returns:
-
bool–If True, the current parameter is smaller than another parameter.
Source code in QuICT/core/utils/parameter.py
__mul__ ¶
Multiply a number.
Parameters:
-
other(Number) –The multiplier.
Returns:
-
Parameter–The new parameter after number multiplication operation.
Source code in QuICT/core/utils/parameter.py
__rmul__ ¶
Multiply a number.
Parameters:
-
other(Number) –The multiplier.
Returns:
-
Parameter–The new parameter after number multiplication operation.
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
QASMError ¶
Qubit ¶
Qubit(fidelity: Union[float, tuple] = 1.0, preparation_fidelity: float = 1.0, gate_fidelity: Union[float, dict] = 1.0, T1: float = 0.0, T2: float = 0.0, work_frequency: float = 0.0, readout_frequency: float = 0.0, gate_duration: float = 0.0)
Bases: object
Implement a Quantum bit
Qubit is the basic unit of Quantum Compute.
Parameters:
-
fidelity(Union[float, tuple], default:1.0) –The qubit's measured fidelity, where the fidelity of a quantum qubit is the overlap between the ideal theoretical operation and the actual experimental operation. if it is list, it represent the measured fidelity for state 0 and state 1.
-
preparation_fidelity(float, default:1.0) –The qubit's state preparation fidelity refers to the degree of accuracy with which a quantum bit (qubit) can be prepared in a specific state.
-
gate_fidelity(Union[float, dict], default:1.0) –The fidelity for applying single-qubit quantum gate in this qubit. e.g. {GateType.h: 0.993, GateType.x: 0.989}
-
T1((float, μs), default:0.0) –The longitudinal coherence time, which refers to the time it takes for the qubit to decay back to its ground state from an excited state. Default to None.
-
T2((float, μs), default:0.0) –the transverse coherence time, which refers to the time it takes for the qubit to lose its coherence when subjected to unwanted phase or amplitude fluctuations. Default to None.
-
work_frequency(Union[float, list], default:0.0) –The working frequency in current Qubit.
-
readout_frequency(Union[float, list], default:0.0) –The frequency when measured qubit in current Qubit.
-
gate_duration(Union[float, list], default:0.0) –The amount of time that a Quantum Gate operators on a Qubit.
Source code in QuICT/core/qubit/qubit.py
__bool__ ¶
int value of the qubit(measure result)
Returns:
-
bool–measure result
__int__ ¶
int value of the qubit(measure result)
Returns:
-
int–measure result
Source code in QuICT/core/qubit/qubit.py
__str__ ¶
string describe of the qubit
Returns:
-
str–a simple describe
Source code in QuICT/core/qubit/qubit.py
Qureg ¶
Bases: list
Implement a Quantum Register
Qureg is a list of Qubits, which is a subClass of list.
initial a qureg with qubit(s)
Parameters:
-
qubits(Union[int, Qubit, Qureg], default:None) –the qubits which make up the qureg, it can have below form, 1) int 2) qubit 3) [qubits/quregs]
Source code in QuICT/core/qubit/qubit.py
__add__ ¶
get a combined qureg with this qureg and other qureg
Parameters:
-
other(Qureg)–qureg to be added.
Return
Qureg: the result or slice
__call__ ¶
get a smaller qureg from this qureg
Parameters:
-
indexes(object) –the indexes passed in, it can have follow form: 1) int 2) list
Returns: Qubit[s]: the qureg correspond to the indexes
Source code in QuICT/core/qubit/qubit.py
__eq__ ¶
check two qureg is same or not. Iff all qubits in two qureg are same will return True; otherwise, return False.
Parameters:
-
other(Qureg)–qureg to be checked.
Source code in QuICT/core/qubit/qubit.py
__getitem__ ¶
to fit the slice operator, overloaded this function.
get a smaller qureg/qubit from this qureg
Parameters:
-
item(int/slice)–slice passed in.
Return
Qubit/Qureg: the result or slice
Source code in QuICT/core/qubit/qubit.py
__iadd__ ¶
get a combined qureg with this qureg and other qureg
Parameters:
-
other(Qureg)–qureg to be added.
Return
Qureg: the result or slice
Source code in QuICT/core/qubit/qubit.py
__int__ ¶
the value of the register
Return the value of the register if all qubits have been measured. Note that the compute mode is BigEndian.
Returns:
-
int–the value of the register
Raises:
-
Exception–some qubit has not be measured
Source code in QuICT/core/qubit/qubit.py
__str__ ¶
the string of the value of the register
Returns:
-
str–the value of the qureg
index ¶
Return the index of given qubits.
Parameters:
Returns:
-
Union[int, list]–Union[int, list]: The index of given qubits in current qureg.
Source code in QuICT/core/qubit/qubit.py
reset_qubits ¶
set_fidelity ¶
Set the fidelity for each qubits
Parameters:
-
fidelity(list) –The list of fidelity for each qubits, should equal to len(qureg).
Source code in QuICT/core/qubit/qubit.py
set_gate_fidelity ¶
Set the Single-Qubit Gate Fidelity for each qubits
Parameters:
-
gate_fidelity(list) –The list of gate fidelity for each qubits, should equal to len(qureg).
Source code in QuICT/core/qubit/qubit.py
set_preparation_fidelity ¶
Set the QSP fidelity for each qubits
Parameters:
-
fidelity(list) –The list of fidelity for each qubits, should equal to len(qureg).
Source code in QuICT/core/qubit/qubit.py
set_t1_time ¶
Set the T1 coherence time for each qubit
Parameters:
-
t1_time(list) –The T1 time for each qubit
Source code in QuICT/core/qubit/qubit.py
set_t2_time ¶
Set the T2 coherence time for each qubit
Parameters:
-
t2_time(list) –The T2 time for each qubit
Source code in QuICT/core/qubit/qubit.py
TypeError ¶
Bases: QuICTException
Type Error in Core Module, including Layout, Fidelity, Qureg, ...
Source code in QuICT/tools/exception/core/core_exception.py
UniformlyControlGate ¶
Bases: object
Uniformly Ry, Rz or one-qubit Unitary gate
Detailed description of each synthesis algorithm could be found in the backend.
Parameters:
-
target_gate(GateType, default:unitary) –type of target gate, could be Ry, Rz or Unitary
Source code in QuICT/core/gate/uniformly_control_gate.py
__call__ ¶
Parameters:
-
arg_list(list) –a list of angles for Ry and Rz or a list of 2*2 unitaries for Unitary
Returns:
-
CompositeGate(CompositeGate) –uniformly control target gate
Source code in QuICT/core/gate/uniformly_control_gate.py
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
diagonal_ury_gate ¶
Parameters:
-
qubit_num(int) –the number of qubits in the circuit
-
alpha(list) –the list of rotation angles
-
ancilla(int, default:0) –the number of ancillary qubits
-
opt(bool, default:False) –the switch of cnot optimizer
-
include_phase_gate(bool, default:False) –the switch of phase holder
Returns:
-
–
Tuple[CompositeGate, list]:
-
–
gates are the diagonal equivalent of URy gates;
-
–
qubit[:dg.width()] is the position of all qubits
Source code in QuICT/qcda/synthesis/unitary_decomposition/utility.py
diagonal_urz_gate ¶
Parameters:
-
qubit_num(int) –the number of qubits in the circuit
-
alpha(list) –the list of rotation angles
-
ancilla(int, default:0) –the number of ancillary qubits
-
opt(bool, default:False) –the switch of cnot optimizer
-
include_phase_gate(bool, default:False) –the switch of phase holder
Returns:
-
–
Tuple[CompositeGate, list]:
-
–
gates are the diagonal equivalent of URz gates;
-
–
qubit[:dg.width()] is the position of all qubits
Source code in QuICT/qcda/synthesis/unitary_decomposition/utility.py
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
matrix_product_to_circuit ¶
matrix_product_to_circuit(gate_matrix: ndarray, gate_args: Union[int, list], qubits: int, device: str = 'CPU')
Expand gate matrix with the number of qubits
Parameters:
-
gate_matrix(ndarray) –The gate's matrix.
-
gate_args(Union[int, list]) –The gate's qubit indexes.
-
qubits(int) –The qubits' number
-
device(str,(optional) –Generate matrix in GPU or not. Default to CPU.
Returns:
-
–
np.array: the expanded gate's 2-D matrix
Source code in QuICT/core/utils/utils.py
quantum_shannon_decompose ¶
Decompose a block diagonal even-size unitary matrix. block_diag(u1,u2) == block_diag(v, v) @ block_diag(d, d_dagger) @ block_diag(w, w)
Parameters:
-
u1(ndarray) –upper-left block
-
u2(ndarray) –right-bottom block
Returns:
-
Tuple[ndarray, ndarray, ndarray]–Tuple[np.ndarray,np.ndarray,np.ndarray]