LocalDrawer
QuICT.tools.drawer.local_drawer ¶
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
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
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
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 ¶
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
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