quairkit.database¶
The library of data generation functions.
- quairkit.database.ising_hamiltonian(edges, vertices)¶
Compute the Ising Hamiltonian.
\[\begin{align} H_{Ising}= \sum_{(u,v) \in E(u>v)}\gamma_{uv}Z_u Z_v + \sum_{k \in V}\beta_k X_k \end{align}\]Examples
import torch from quairkit.database.hamiltonian import ising_hamiltonian edges = torch.tensor([[0, 1, 0.5], [1, 0, 0.2], [0.5, 0.2, 0]]) vertices = torch.tensor([0.3, 0.4, 0.1]) hamiltonian = ising_hamiltonian(edges, vertices) print(f'The Ising_Hamiltonian is \n {hamiltonian}')
The Ising_Hamiltonian is 1.0 Z0, Z1 0.5 Z0, Z2 0.20000000298023224 Z1, Z2 0.30000001192092896 X0 0.4000000059604645 X1 0.10000000149011612 X2
- quairkit.database.xy_hamiltonian(edges)¶
Compute the XY Hamiltonian.
\[\begin{align} H_{XY}= \sum_{(u,v) \in E(u>v)}(\alpha_{uv}X_u X_v + \beta_{uv}Y_u Y_v) \end{align}\]- Parameters:¶
- edges : Tensor¶
A tensor E shape=[2, V, V], where E[0][u][v] is alpha_{uv} and E[1][u][v] is beta_{uv}.
- Returns:¶
Hamiltonian representation of the XY Hamiltonian.
- Return type:¶
Examples
import torch from quairkit.database.hamiltonian import xy_hamiltonian edges = torch.tensor([ [ [0, 0.7, 0], [0.7, 0, 0.2], [0, 0.2, 0] ], [ [0, 0.5, 0], [0.5, 0, 0.3], [0, 0.3, 0] ] ]) H_XY = xy_hamiltonian(edges) print(f'The XY Hamiltonian is:\n{H_XY}')
The XY Hamiltonian is: 0.699999988079071 X0, X1 0.5 Y0, Y1 0.20000000298023224 X1, X2 0.30000001192092896 Y1, Y2
- quairkit.database.heisenberg_hamiltonian(edges)¶
Compute the Heisenberg Hamiltonian.
\[\begin{align} H_{Heisenberg}= \sum_{(u,v) \in E(u>v)}(\alpha_{uv}X_u X_v + \beta_{uv}Y_u Y_v + \gamma_{uv}Z_u Z_v) \end{align}\]- Parameters:¶
- edges : Tensor¶
A tensor E shape=[3, V, V], where E[0][u][v] is alpha_{uv}, E[1][u][v] is beta_{uv}, and E[2][u][v] is gamma_{uv}.
- Returns:¶
Hamiltonian representation of the Heisenberg Hamiltonian.
- Return type:¶
Examples
import torch from quairkit.database.hamiltonian import heisenberg_hamiltonian edges = torch.tensor([ [ [0, 0.5, 0], [0.5, 0, 0.2], [0, 0.2, 0] ], [ [0, 0.3, 0], [0.3, 0, 0.4], [0, 0.4, 0] ], [ [0, 0.7, 0], [0.7, 0, 0.1], [0, 0.1, 0] ] ]) H_Heisenberg = heisenberg_hamiltonian(edges) print(f'The Heisenberg Hamiltonian is:\n{H_Heisenberg}')
The Heisenberg Hamiltonian is: 0.5 X0, X1 0.30000001192092896 Y0, Y1 0.699999988079071 Z0, Z1 0.20000000298023224 X1, X2 0.4000000059604645 Y1, Y2 0.10000000149011612 Z1, Z2
- quairkit.database.phase(dim)¶
Generate phase operator for qudit
Examples
dim = 2 phase_operator = phase(dim) print(f'The phase_operator is:\n{phase_operator}')
The phase_operator is: tensor([[ 1.+0.0000e+00j, 0.+0.0000e+00j], [ 0.+0.0000e+00j, -1.+1.2246e-16j]])
- quairkit.database.shift(dim)¶
Generate shift operator for qudit
Examples
dim = 2 shift_operator = shift(dim) print(f'The shift_operator is:\n{shift_operator}')
The shift_operator is: tensor([[0.+0.j, 1.+0.j], [1.+0.j, 0.+0.j]])
-
quairkit.database.grover_matrix(oracle, dtype=
None
)¶ Construct the Grover operator based on
oracle
.- Parameters:¶
- oracle : ndarray | Tensor¶
the input oracle \(A\) to be rotated.
- Returns:¶
Grover operator in form
\[G = A (2 |0^n \rangle\langle 0^n| - I^n) A^\dagger \cdot (I - 2|1 \rangle\langle 1|) \otimes I^{n-1}\]- Return type:¶
ndarray | Tensor
Examples
oracle = torch.tensor([[0, 1], [1, 0]], dtype=torch.cfloat) grover_op = grover_matrix(oracle) print(f'The grover_matrix is:\n{grover_op}')
The grover_matrix is: tensor([[-1.+0.j, 0.+0.j], [ 0.+0.j, -1.+0.j]])
- quairkit.database.qft_matrix(num_qubits)¶
Construct the quantum Fourier transpose (QFT) gate.
- Parameters:¶
- num_qubits : int¶
number of qubits \(n\) st. \(N = 2^n\).
- Returns:¶
A matrix in the form
\[\begin{split}QFT = \frac{1}{\sqrt{N}} \begin{bmatrix} 1 & 1 & \cdots & 1 \\ 1 & \omega_N & \cdots & \omega_N^{N-1} \\ \vdots & \vdots & \ddots & \vdots \\ 1 & \omega_N^{N-1} & \cdots & \omega_N^{(N-1)^2} \end{bmatrix}, \quad \omega_N = \exp\left(\frac{2\pi i}{N}\right).\end{split}\]- Return type:¶
Tensor
Examples
num_qubits = 1 qft_gate = qft_matrix(num_qubits) print(f'The QFT gate is:\n{qft_gate}')
The QFT gate is: tensor([[ 0.7071+0.0000e+00j, 0.7071+0.0000e+00j], [ 0.7071+0.0000e+00j, -0.7071+8.6596e-17j]])
- quairkit.database.h()¶
Generate the matrix of the Hadamard gate.
\[\begin{split}H = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix}\end{split}\]Examples
H = h() print(f'The Hadamard gate is:\n{H}')
The Hadamard gate is: tensor([[ 0.7071+0.j, 0.7071+0.j], [ 0.7071+0.j, -0.7071+0.j]])
- quairkit.database.s()¶
Generate the matrix of the S gate.
\[\begin{split}S = \begin{bmatrix} 1 & 0 \\ 0 & i \end{bmatrix}\end{split}\]Examples
S = s() print(f'The S gate is:\n{S}')
The S gate is: tensor([[1.+0.j, 0.+0.j], [0.+0.j, 0.+1.j]])
- quairkit.database.sdg()¶
Generate the matrix of the Sdg (S-dagger) gate.
\[\begin{split}S^\dagger = \begin{bmatrix} 1 & 0 \\ 0 & -i \end{bmatrix}\end{split}\]Examples
Sdg = sdg() print(f'The dagger of S gate is:\n{Sdg}')
The dagger of S gate is: tensor([[1.+0.j, 0.+0.j], [0.+0.j, -0.-1.j]])
- quairkit.database.t()¶
Generate the matrix of the T gate.
\[\begin{split}T = \begin{bmatrix} 1 & 0 \\ 0 & e^{i\pi/4} \end{bmatrix}\end{split}\]Examples
T = t() print(f'The T gate is:\n{T}')
The T gate is: tensor([[1.0000+0.0000j, 0.0000+0.0000j], [0.0000+0.0000j, 0.7071+0.7071j]])
- quairkit.database.tdg()¶
Generate the matrix of the Tdg (T-dagger) gate.
\[\begin{split}T^\dagger = \begin{bmatrix} 1 & 0 \\ 0 & e^{-i\pi/4} \end{bmatrix}\end{split}\]Examples
Tdg = tdg() print(f'The dagger of T gate is:\n{Tdg}')
The dagger of T gate is: tensor([[1.0000+0.0000j, 0.0000+0.0000j], [0.0000+0.0000j, 0.7071-0.7071j]])
-
quairkit.database.eye(dim=
2
)¶ Generate the identity matrix.
\[\begin{split}I = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}\end{split}\]- Parameters:¶
- dim : int¶
the dimension of the identity matrix (default is 2 for a qubit).
- Returns:¶
The identity matrix.
- Return type:¶
Tensor
Examples
I = eye() print(f'The Identity Matrix is:\n{I}')
The Identity Matrix is: tensor([[1.+0.j, 0.+0.j], [0.+0.j, 1.+0.j]])
- quairkit.database.x()¶
Generate the Pauli X matrix.
\[\begin{split}X = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}\end{split}\]Examples
X = x() print(f'The Pauli X Matrix is:\n{X}')
The Pauli X Matrix is: tensor([[0.+0.j, 1.+0.j], [1.+0.j, 0.+0.j]])
- quairkit.database.y()¶
Generate the Pauli Y matrix.
\[\begin{split}Y = \begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix}\end{split}\]Examples
Y = y() print(f'The Pauli Y Matrix is:\n{Y}')
The Pauli Y Matrix is: tensor([[0.+0.j, -0.-1.j], [0.+1.j, 0.+0.j]])
- quairkit.database.z()¶
Generate the Pauli Z matrix.
\[\begin{split}Z = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}\end{split}\]Examples
Z = z() print(f'The Pauli Z Matrix is:\n{Z}')
The Pauli Z Matrix is: tensor([[ 1.+0.j, 0.+0.j], [ 0.+0.j, -1.+0.j]])
- quairkit.database.p(theta)¶
Generate the P gate matrix.
\[\begin{split}P(\theta) = \begin{bmatrix} 1 & 0 \\ 0 & e^{i\theta} \end{bmatrix}\end{split}\]- Parameters:¶
- theta : ndarray | Tensor | Iterable[float] | float¶
the (batched) parameter, with shape [1].
- Returns:¶
The matrix of the P gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([torch.pi / 4]) p_matrix = p(theta) print(f'The P Gate is:\n{p_matrix}')
The P Gate is: tensor([[1.0000+0.0000j, 0.0000+0.0000j], [0.0000+0.0000j, 0.7071+0.7071j]])
- quairkit.database.rx(theta)¶
Generate the RX gate matrix.
\[\begin{split}R_X(\theta) = \begin{bmatrix} \cos\frac{\theta}{2} & -i\sin\frac{\theta}{2} \\ -i\sin\frac{\theta}{2} & \cos\frac{\theta}{2} \end{bmatrix}\end{split}\]- Parameters:¶
- theta : ndarray | Tensor | Iterable[float] | float¶
the (batched) parameter, with shape [1].
- Returns:¶
The matrix of the RX gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([torch.pi / 4]) R_x = rx(theta) print(f'The R_x Gate is:\n{R_x}')
The R_x Gate is: tensor([[0.9239+0.0000j, 0.0000-0.3827j], [0.0000-0.3827j, 0.9239+0.0000j]])
- quairkit.database.ry(theta)¶
Generate the RY gate matrix.
\[\begin{split}R_Y(\theta) = \begin{bmatrix} \cos\frac{\theta}{2} & -\sin\frac{\theta}{2} \\ \sin\frac{\theta}{2} & \cos\frac{\theta}{2} \end{bmatrix}\end{split}\]- Parameters:¶
- theta : ndarray | Tensor | Iterable[float] | float¶
the (batched) parameter, with shape [1].
- Returns:¶
The matrix of the RY gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([torch.pi / 4]) R_y = ry(theta) print(f'The R_y Gate is:\n{R_y}')
The R_y Gate is: tensor([[ 0.9239+0.j, -0.3827+0.j], [ 0.3827+0.j, 0.9239+0.j]])
- quairkit.database.rz(theta)¶
Generate the RZ gate matrix.
\[\begin{split}R_Z(\theta) = \begin{bmatrix} e^{-i\theta/2} & 0 \\ 0 & e^{i\theta/2} \end{bmatrix}\end{split}\]- Parameters:¶
- theta : ndarray | Tensor | Iterable[float] | float¶
the (batched) parameter, with shape [1].
- Returns:¶
The matrix of the RZ gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([torch.pi / 4]) R_z = rz(theta) print(f'The R_z Gate is:\n{R_z}')
The R_z Gate is: tensor([[0.9239-0.3827j, 0.0000+0.0000j], [0.0000+0.0000j, 0.9239+0.3827j]])
- quairkit.database.u3(theta)¶
Generate the U3 gate matrix.
\[\begin{split}U_3(\theta, \phi, \lambda) = \begin{bmatrix} \cos\frac{\theta}{2} & -e^{i\lambda}\sin\frac{\theta}{2} \\ e^{i\phi}\sin\frac{\theta}{2} & e^{i(\phi+\lambda)}\cos\frac{\theta}{2} \end{bmatrix}\end{split}\]- Parameters:¶
- theta : ndarray | Tensor | Iterable[float]¶
the (batched) parameters, with shape [3, 1].
- Returns:¶
The matrix of the U3 gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([[torch.pi / 4], [torch.pi / 3], [torch.pi / 6]]) u3_matrix = u3(theta) print(f'The U3 Gate is:\n{u3_matrix}')
The U3 Gate is: tensor([[ 9.2388e-01+0.0000j, -3.3141e-01-0.1913j], [ 1.9134e-01+0.3314j, -4.0384e-08+0.9239j]])
- quairkit.database.cnot()¶
Generate the CNOT gate matrix.
\[\begin{split}CNOT = |0\rangle \langle 0| \otimes I + |1\rangle \langle 1| \otimes X = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{bmatrix}\end{split}\]Examples
CNOT = cnot() print(f'The CNOT Gate is:\n{CNOT}')
The CNOT Gate is: tensor([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j], [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j]])
- quairkit.database.cy()¶
Generate the CY gate matrix.
\[\begin{split}CY = |0\rangle\langle0| \otimes I + |1\rangle\langle1| \otimes Y = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & -i \\ 0 & 0 & i & 0 \end{bmatrix}\end{split}\]Examples
CY = cy() print(f'The CY Gate is:\n{CY}')
The CY Gate is: tensor([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, -0.-1.j], [0.+0.j, 0.+0.j, 0.+1.j, 0.+0.j]])
- quairkit.database.cz()¶
Generate the CZ gate matrix.
\[\begin{split}CZ = |0\rangle\langle0| \otimes I + |1\rangle\langle1| \otimes Z = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & -1 \end{bmatrix}\end{split}\]Examples
CZ = cz() print(f'The CZ Gate is:\n{CZ}')
The CZ Gate is: tensor([[ 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [ 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j], [ 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j], [ 0.+0.j, 0.+0.j, 0.+0.j, -1.+0.j]])
- quairkit.database.swap()¶
Generate the SWAP gate matrix.
\[\begin{split}SWAP = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}\end{split}\]Examples
SWAP = swap() print(f'The SWAP Gate is:\n{SWAP}')
The SWAP Gate is: tensor([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j], [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j]])
- quairkit.database.cp(theta)¶
Generate the CP gate matrix.
\[\begin{split}CP(\theta) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & e^{i\theta} \end{bmatrix}\end{split}\]- Parameters:¶
- theta : ndarray | Tensor | Iterable[float] | float¶
the (batched) parameter, with shape [1].
- Returns:¶
The matrix of the CP gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([torch.pi / 4]) CP = cp(theta) print(f'The CP Gate is:\n{CP}')
The CP Gate is: tensor([[1.0000+0.0000j, 0.0000+0.0000j, 0.0000+0.0000j, 0.0000+0.0000j], [0.0000+0.0000j, 1.0000+0.0000j, 0.0000+0.0000j, 0.0000+0.0000j], [0.0000+0.0000j, 0.0000+0.0000j, 1.0000+0.0000j, 0.0000+0.0000j], [0.0000+0.0000j, 0.0000+0.0000j, 0.0000+0.0000j, 0.7071+0.7071j]])
- quairkit.database.crx(theta)¶
Generate the CR_X gate matrix.
\[\begin{split}CR_X = |0\rangle\langle0| \otimes I + |1\rangle\langle1| \otimes R_X = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & \cos\frac{\theta}{2} & -i\sin\frac{\theta}{2} \\ 0 & 0 & -i\sin\frac{\theta}{2} & \cos\frac{\theta}{2} \end{bmatrix}\end{split}\]- Parameters:¶
- theta : ndarray | Tensor | Iterable[float] | float¶
the (batched) parameter, with shape [1].
- Returns:¶
The matrix of the CR_X gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([torch.pi / 4]) CR_X = crx(theta) print(f'The CR_X Gate is:\n{CR_X}')
The CR_X Gate is: tensor([[1.0000+0.0000j, 0.+0.0000j, 0.+0.0000j, 0.+0.0000j], [0.+0.0000j, 1.0000+0.0000j, 0.+0.0000j, 0.+0.0000j], [0.+0.0000j, 0.+0.0000j, 0.9239+0.0000j, 0.+-0.3827j], [0.+0.0000j, 0.+0.0000j, 0.+-0.3827j, 0.9239+0.0000j]])
- quairkit.database.cry(theta)¶
Generate the CR_Y gate matrix.
\[\begin{split}CR_Y = |0\rangle\langle0| \otimes I + |1\rangle\langle1| \otimes R_Y = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & \cos\frac{\theta}{2} & -\sin\frac{\theta}{2} \\ 0 & 0 & \sin\frac{\theta}{2} & \cos\frac{\theta}{2} \end{bmatrix}\end{split}\]- Parameters:¶
- theta : ndarray | Tensor | Iterable[float] | float¶
the (batched) parameter, with shape [1].
- Returns:¶
The matrix of the CR_Y gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([torch.pi / 4]) CR_Y = cry(theta) print(f'The CR_Y Gate is:\n{CR_Y}')
The CR_Y Gate is: tensor([[1.0000+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 1.0000+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.9239+0.j, -0.3827+0.j], [0.+0.j, 0.+0.j, 0.3827+0.j, 0.9239+0.j]])
- quairkit.database.crz(theta)¶
Generate the CR_Z gate matrix.
\[\begin{split}CR_Z = |0\rangle\langle0| \otimes I + |1\rangle\langle1| \otimes R_Z = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & e^{-i\theta/2} & 0 \\ 0 & 0 & 0 & e^{i\theta/2} \end{bmatrix}\end{split}\]- Parameters:¶
- theta : ndarray | Tensor | Iterable[float] | float¶
the (batched) parameter, with shape [1].
- Returns:¶
The matrix of the CR_Z gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([torch.pi / 4]) CR_Z = crz(theta) print(f'The CR_Z Gate is:\n{CR_Z}')
The CR_Z Gate is: tensor([[1.0000+0.0000j, 0.+0.0000j, 0.+0.0000j, 0.+0.0000j], [0.+0.0000j, 1.0000+0.0000j, 0.+0.0000j, 0.+0.0000j], [0.+0.0000j, 0.+0.0000j, 0.9239-0.3827j, 0.+0.0000j], [0.+0.0000j, 0.+0.0000j, 0.+0.0000j, 0.9239+0.3827j]])
- quairkit.database.cu(theta)¶
Generate the CU gate matrix.
\[\begin{split}CU = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & e^{i\gamma}\cos\frac{\theta}{2} & -e^{i(\lambda+\gamma)}\sin\frac{\theta}{2} \\ 0 & 0 & e^{i(\phi+\gamma)}\sin\frac{\theta}{2} & e^{i(\phi+\lambda+\gamma)}\cos\frac{\theta}{2} \end{bmatrix}\end{split}\]- Parameters:¶
- theta : ndarray | Tensor | Iterable[float]¶
the (batched) parameters, with shape [4, 1].
- Returns:¶
The matrix of the CU gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([[torch.pi / 4], [torch.pi / 3], [torch.pi / 6], [torch.pi / 6]]) CU = cu(theta) print(f'The CU Gate is:\n{CU}')
The CU Gate is: tensor([[1.0000e+00+0.0000j, 0.0000e+00+0.0000j, 0.0000e+00+0.0000j, 0.0000e+00+0.0000j], [0.0000e+00+0.0000j, 1.0000e+00+0.0000j, 0.0000e+00+0.0000j, 0.0000e+00+0.0000j], [0.0000e+00+0.0000j, 0.0000e+00+0.0000j, 8.0010e-01+0.4619j, -1.9134e-01-0.3314j], [0.0000e+00+0.0000j, 0.0000e+00+0.0000j, -1.6728e-08+0.3827j, -4.6194e-01+0.8001j]])
- quairkit.database.rxx(theta)¶
Generate the RXX gate matrix.
\[\begin{split}R_{XX}(\theta) = \begin{bmatrix} \cos\frac{\theta}{2} & 0 & 0 & -i\sin\frac{\theta}{2} \\ 0 & \cos\frac{\theta}{2} & -i\sin\frac{\theta}{2} & 0 \\ 0 & -i\sin\frac{\theta}{2} & \cos\frac{\theta}{2} & 0 \\ -i\sin\frac{\theta}{2} & 0 & 0 & \cos\frac{\theta}{2} \end{bmatrix}\end{split}\]- Parameters:¶
- theta : ndarray | Tensor | Iterable[float] | float¶
the (batched) parameter, with shape [1].
- Returns:¶
The matrix of the RXX gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([torch.pi / 4]) R_XX = rxx(theta) print(f'The R_XX Gate is:\n{R_XX}')
The R_XX Gate is: tensor([[0.9239+0.0000j, 0.0000+0.0000j, 0.0000+0.0000j, 0.0000-0.3827j], [0.0000+0.0000j, 0.9239+0.0000j, 0.0000-0.3827j, 0.0000+0.0000j], [0.0000+0.0000j, 0.0000-0.3827j, 0.9239+0.0000j, 0.0000+0.0000j], [0.0000-0.3827j, 0.0000+0.0000j, 0.0000+0.0000j, 0.9239+0.0000j]])
- quairkit.database.ryy(theta)¶
Generate the RYY gate matrix.
\[\begin{split}R_{YY}(\theta) = \begin{bmatrix} \cos\frac{\theta}{2} & 0 & 0 & i\sin\frac{\theta}{2} \\ 0 & \cos\frac{\theta}{2} & -i\sin\frac{\theta}{2} & 0 \\ 0 & -i\sin\frac{\theta}{2} & \cos\frac{\theta}{2} & 0 \\ i\sin\frac{\theta}{2} & 0 & 0 & \cos\frac{\theta}{2} \end{bmatrix}\end{split}\]- Parameters:¶
- theta : ndarray | Tensor | Iterable[float] | float¶
the (batched) parameter, with shape [1].
- Returns:¶
The matrix of the RYY gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([torch.pi / 4]) R_YY = ryy(theta) print(f'The R_YY Gate is:\n{R_YY}')
The R_YY Gate is: tensor([[0.9239+0.0000j, 0.0000+0.0000j, 0.0000+0.0000j, 0.0000+0.3827j], [0.0000+0.0000j, 0.9239+0.0000j, 0.0000-0.3827j, 0.0000+0.0000j], [0.0000+0.0000j, 0.0000-0.3827j, 0.9239+0.0000j, 0.0000+0.0000j], [0.0000+0.3827j, 0.0000+0.0000j, 0.0000+0.0000j, 0.9239+0.0000j]])
- quairkit.database.rzz(theta)¶
Generate the RZZ gate matrix.
\[\begin{split}R_{ZZ}(\theta) = \begin{bmatrix} e^{-i\theta/2} & 0 & 0 & 0 \\ 0 & e^{i\theta/2} & 0 & 0 \\ 0 & 0 & e^{i\theta/2} & 0 \\ 0 & 0 & 0 & e^{-i\theta/2} \end{bmatrix}\end{split}\]- Parameters:¶
- theta : ndarray | Tensor | Iterable[float] | float¶
the (batched) parameter, with shape [1].
- Returns:¶
The matrix of the RZZ gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([torch.pi / 4]) R_ZZ = rzz(theta) print(f'The R_ZZ Gate is:\n{R_ZZ}')
The R_ZZ Gate is: tensor([[0.9239-0.3827j, 0.0000+0.0000j, 0.0000+0.0000j, 0.0000+0.0000j], [0.0000+0.0000j, 0.9239+0.3827j, 0.0000+0.0000j, 0.0000+0.0000j], [0.0000+0.0000j, 0.0000+0.0000j, 0.9239+0.3827j, 0.0000+0.0000j], [0.0000+0.0000j, 0.0000+0.0000j, 0.0000+0.0000j, 0.9239-0.3827j]])
- quairkit.database.ms()¶
Generate the MS gate matrix.
\[\begin{split}MS = R_{XX}\left(-\frac{\pi}{2}\right) = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 0 & 0 & i \\ 0 & 1 & i & 0 \\ 0 & i & 1 & 0 \\ i & 0 & 0 & 1 \end{bmatrix}\end{split}\]Examples
MS = ms() print(f'The MS Gate is:\n{MS}')
The MS Gate is: tensor([[0.7071+0.0000j, 0.0000+0.0000j, 0.0000+0.0000j, 0.0000+0.7071j], [0.0000+0.0000j, 0.7071+0.0000j, 0.0000+0.7071j, 0.0000+0.0000j], [0.0000+0.0000j, 0.0000+0.7071j, 0.7071+0.0000j, 0.0000+0.0000j], [0.0000+0.7071j, 0.0000+0.0000j, 0.0000+0.0000j, 0.7071+0.0000j]])
- quairkit.database.cswap()¶
Generate the CSWAP gate matrix.
\[\begin{split}CSWAP = \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 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \end{bmatrix}\end{split}\]Examples
CSWAP = cswap() print(f'The CSWAP Gate is:\n{CSWAP}')
The CSWAP Gate is: tensor([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j]])
- quairkit.database.toffoli()¶
Generate the Toffoli gate matrix.
\[\begin{split}Toffoli = \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 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \end{bmatrix}\end{split}\]Examples
Toffoli = toffoli() print(f'The Toffoli Gate is:\n{Toffoli}')
The Toffoli Gate is: tensor([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j]])
- quairkit.database.ccx()¶
Generate the Toffoli gate matrix.
\[\begin{split}Toffoli = \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 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \end{bmatrix}\end{split}\]Examples
Toffoli = toffoli() print(f'The Toffoli Gate is:\n{Toffoli}')
The Toffoli Gate is: tensor([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j]])
- quairkit.database.universal2(theta)¶
Generate the universal two-qubit gate matrix.
- Parameters:¶
- theta : ndarray | Tensor | Iterable[float]¶
the (batched) parameter with shape [15].
- Returns:¶
The matrix of the universal two-qubit gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([ 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5]) Universal2 = universal2(theta) print(f'The matrix of universal two qubits gate is:\n{Universal2}')
The matrix of universal two qubits gate is: tensor([[-0.2858-0.0270j, 0.4003+0.3090j, -0.6062+0.0791j, 0.5359+0.0323j], [-0.0894-0.1008j, -0.5804+0.0194j, 0.3156+0.1677j, 0.7090-0.1194j], [-0.8151-0.2697j, 0.2345-0.1841j, 0.3835-0.1154j, -0.0720+0.0918j], [-0.2431+0.3212j, -0.1714+0.5374j, 0.1140+0.5703j, -0.2703+0.3289j]])
- quairkit.database.universal3(theta)¶
Generate the universal three-qubit gate matrix.
- Parameters:¶
- theta : ndarray | Tensor | Iterable[float]¶
the (batched) parameter with shape [81].
- Returns:¶
The matrix of the universal three-qubit gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([ 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, 5.0, 5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6.0, 6.1, 6.2, 6.3, 6.4, 6.5, 6.6, 6.7, 6.8, 6.9, 7.0, 7.1, 7.2, 7.3, 7.4, 7.5, 7.6, 7.7, 7.8, 7.9, 8.0, 8.1]) Universal3 = universal3(theta) print(f'The matrix of universal three qubits gate is:\n{Universal3}')
The matrix of universal three qubits gate is: tensor([[-0.0675-0.0941j, -0.4602+0.0332j, 0.2635+0.0044j, 0.0825+0.3465j, -0.0874-0.3635j, -0.1177-0.4195j, -0.2735+0.3619j, -0.1760-0.1052j], [ 0.0486+0.0651j, -0.1123+0.0494j, 0.1903+0.0057j, -0.2080+0.2926j, -0.2099+0.0630j, -0.1406+0.5173j, -0.1431-0.3538j, -0.5460-0.1847j], [ 0.0827-0.0303j, 0.1155+0.1111j, 0.5391-0.0701j, -0.4229-0.2655j, -0.1546+0.1943j, -0.0455+0.1744j, -0.3242+0.3539j, 0.3118-0.0041j], [-0.1222+0.3984j, 0.1647-0.1817j, 0.3294-0.1486j, -0.0293-0.1503j, 0.0100-0.6481j, 0.2424+0.1575j, 0.2485+0.0232j, -0.1053+0.1873j], [-0.4309-0.0791j, -0.2071-0.0482j, -0.4331+0.0866j, -0.5454-0.1778j, -0.1401-0.0230j, 0.0170+0.0299j, 0.0078+0.2231j, -0.2324+0.3369j], [ 0.0330+0.3056j, 0.2612+0.6464j, -0.2138-0.1748j, -0.2322-0.0598j, 0.1387-0.1573j, 0.0914-0.2963j, -0.2712-0.1351j, -0.1272-0.1940j], [ 0.0449-0.3844j, 0.1135+0.2846j, -0.0251+0.3854j, 0.0442-0.0149j, -0.3671-0.1774j, 0.5158+0.1148j, 0.2151+0.1433j, -0.0188-0.3040j], [-0.4124-0.4385j, 0.2306+0.0894j, 0.0104-0.2180j, -0.0180+0.2869j, -0.1030-0.2991j, -0.1473+0.0931j, -0.1686-0.3451j, 0.3825+0.1480j]])
- quairkit.database.universal_qudit(theta, dimension)¶
Generate a universal gate matrix for qudits using a generalized Gell-Mann basis.
Examples
dimension = 2 theta = torch.linspace(0.1, 2.5, dimension**2 - 1) u_qudit_matrix = universal_qudit(theta, dimension) print(f'The matrix of 2-dimensional unitary gate is:\n{u_qudit_matrix}')
The matrix of 2-dimensional unitary gate is: tensor([[-0.9486+0.2806j, 0.1459+0.0112j], [-0.1459+0.0112j, -0.9486-0.2806j]])
- quairkit.database.Uf(f, n)¶
Construct the unitary matrix used in Simon’s algorithm.
- Parameters:¶
- Returns:¶
A 2n-qubit unitary matrix satisfying
\[U|x, y\rangle = |x, y \oplus f(x)\rangle\]- Return type:¶
Tensor
Examples
def f(x: int) -> int: return x unitary_matrix = Uf(f, 1) print(f'Unitary matrix is:\n{unitary_matrix}')
Unitary matrix is: tensor([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j], [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j]])
- quairkit.database.Of(f, n)¶
Construct the oracle unitary matrix for an unstructured search problem.
- Parameters:¶
- Returns:¶
An n-qubit unitary matrix satisfying
\[U|x\rangle = (-1)^{f(x)}|x\rangle\]- Return type:¶
Tensor
Examples
def f(x: int) -> int: return x unitary_matrix = Of(f, 1) print(f'Unitary matrix is:\n{unitary_matrix}')
Unitary matrix is: tensor([[ 1.+0.j, 0.+0.j], [ 0.+0.j, -1.+0.j]])
-
quairkit.database.permutation_matrix(perm, system_dim=
2
)¶ Construct a unitary matrix representing a permutation operation on a quantum system.
- Parameters:¶
- perm : List[int]¶
A list representing the permutation of subsystems. For example, [1, 0, 2] swaps the first two subsystems.
- system_dim : int | List[int]¶
The dimension of each subsystem. - If an integer, all subsystems are assumed to have the same dimension. - If a list, it specifies the dimension of each subsystem individually.
- Returns:¶
A unitary matrix representing the permutation in the Hilbert space.
Examples
perm = [1, 0] U_perm = permutation_matrix(perm, system_dim=2) print(f'The permutation matrix is:\n{U_perm}')
The permutation matrix is: tensor([[0.+0.j, 1.+0.j], [1.+0.j, 0.+0.j]])
- quairkit.database.phase_gate(dim)¶
Generate phase operator for qudit
Examples
dim = 2 phase_operator = phase(dim) print(f'The phase_operator is:\n{phase_operator}')
The phase_operator is: tensor([[ 1.+0.0000e+00j, 0.+0.0000e+00j], [ 0.+0.0000e+00j, -1.+1.2246e-16j]])
- quairkit.database.shift_gate(dim)¶
Generate shift operator for qudit
Examples
dim = 2 shift_operator = shift(dim) print(f'The shift_operator is:\n{shift_operator}')
The shift_operator is: tensor([[0.+0.j, 1.+0.j], [1.+0.j, 0.+0.j]])
- quairkit.database.h_gate()¶
Generate the matrix of the Hadamard gate.
\[\begin{split}H = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix}\end{split}\]Examples
H = h() print(f'The Hadamard gate is:\n{H}')
The Hadamard gate is: tensor([[ 0.7071+0.j, 0.7071+0.j], [ 0.7071+0.j, -0.7071+0.j]])
- quairkit.database.s_gate()¶
Generate the matrix of the S gate.
\[\begin{split}S = \begin{bmatrix} 1 & 0 \\ 0 & i \end{bmatrix}\end{split}\]Examples
S = s() print(f'The S gate is:\n{S}')
The S gate is: tensor([[1.+0.j, 0.+0.j], [0.+0.j, 0.+1.j]])
- quairkit.database.sdg_gate()¶
Generate the matrix of the Sdg (S-dagger) gate.
\[\begin{split}S^\dagger = \begin{bmatrix} 1 & 0 \\ 0 & -i \end{bmatrix}\end{split}\]Examples
Sdg = sdg() print(f'The dagger of S gate is:\n{Sdg}')
The dagger of S gate is: tensor([[1.+0.j, 0.+0.j], [0.+0.j, -0.-1.j]])
- quairkit.database.t_gate()¶
Generate the matrix of the T gate.
\[\begin{split}T = \begin{bmatrix} 1 & 0 \\ 0 & e^{i\pi/4} \end{bmatrix}\end{split}\]Examples
T = t() print(f'The T gate is:\n{T}')
The T gate is: tensor([[1.0000+0.0000j, 0.0000+0.0000j], [0.0000+0.0000j, 0.7071+0.7071j]])
- quairkit.database.tdg_gate()¶
Generate the matrix of the Tdg (T-dagger) gate.
\[\begin{split}T^\dagger = \begin{bmatrix} 1 & 0 \\ 0 & e^{-i\pi/4} \end{bmatrix}\end{split}\]Examples
Tdg = tdg() print(f'The dagger of T gate is:\n{Tdg}')
The dagger of T gate is: tensor([[1.0000+0.0000j, 0.0000+0.0000j], [0.0000+0.0000j, 0.7071-0.7071j]])
-
quairkit.database.eye_gate(dim=
2
)¶ Generate the identity matrix.
\[\begin{split}I = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}\end{split}\]- Parameters:¶
- dim : int¶
the dimension of the identity matrix (default is 2 for a qubit).
- Returns:¶
The identity matrix.
- Return type:¶
Tensor
Examples
I = eye() print(f'The Identity Matrix is:\n{I}')
The Identity Matrix is: tensor([[1.+0.j, 0.+0.j], [0.+0.j, 1.+0.j]])
- quairkit.database.x_gate()¶
Generate the Pauli X matrix.
\[\begin{split}X = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}\end{split}\]Examples
X = x() print(f'The Pauli X Matrix is:\n{X}')
The Pauli X Matrix is: tensor([[0.+0.j, 1.+0.j], [1.+0.j, 0.+0.j]])
- quairkit.database.y_gate()¶
Generate the Pauli Y matrix.
\[\begin{split}Y = \begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix}\end{split}\]Examples
Y = y() print(f'The Pauli Y Matrix is:\n{Y}')
The Pauli Y Matrix is: tensor([[0.+0.j, -0.-1.j], [0.+1.j, 0.+0.j]])
- quairkit.database.z_gate()¶
Generate the Pauli Z matrix.
\[\begin{split}Z = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}\end{split}\]Examples
Z = z() print(f'The Pauli Z Matrix is:\n{Z}')
The Pauli Z Matrix is: tensor([[ 1.+0.j, 0.+0.j], [ 0.+0.j, -1.+0.j]])
- quairkit.database.p_gate(theta)¶
Generate the P gate matrix.
\[\begin{split}P(\theta) = \begin{bmatrix} 1 & 0 \\ 0 & e^{i\theta} \end{bmatrix}\end{split}\]- Parameters:¶
- theta : ndarray | Tensor | Iterable[float] | float¶
the (batched) parameter, with shape [1].
- Returns:¶
The matrix of the P gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([torch.pi / 4]) p_matrix = p(theta) print(f'The P Gate is:\n{p_matrix}')
The P Gate is: tensor([[1.0000+0.0000j, 0.0000+0.0000j], [0.0000+0.0000j, 0.7071+0.7071j]])
- quairkit.database.rx_gate(theta)¶
Generate the RX gate matrix.
\[\begin{split}R_X(\theta) = \begin{bmatrix} \cos\frac{\theta}{2} & -i\sin\frac{\theta}{2} \\ -i\sin\frac{\theta}{2} & \cos\frac{\theta}{2} \end{bmatrix}\end{split}\]- Parameters:¶
- theta : ndarray | Tensor | Iterable[float] | float¶
the (batched) parameter, with shape [1].
- Returns:¶
The matrix of the RX gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([torch.pi / 4]) R_x = rx(theta) print(f'The R_x Gate is:\n{R_x}')
The R_x Gate is: tensor([[0.9239+0.0000j, 0.0000-0.3827j], [0.0000-0.3827j, 0.9239+0.0000j]])
- quairkit.database.ry_gate(theta)¶
Generate the RY gate matrix.
\[\begin{split}R_Y(\theta) = \begin{bmatrix} \cos\frac{\theta}{2} & -\sin\frac{\theta}{2} \\ \sin\frac{\theta}{2} & \cos\frac{\theta}{2} \end{bmatrix}\end{split}\]- Parameters:¶
- theta : ndarray | Tensor | Iterable[float] | float¶
the (batched) parameter, with shape [1].
- Returns:¶
The matrix of the RY gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([torch.pi / 4]) R_y = ry(theta) print(f'The R_y Gate is:\n{R_y}')
The R_y Gate is: tensor([[ 0.9239+0.j, -0.3827+0.j], [ 0.3827+0.j, 0.9239+0.j]])
- quairkit.database.rz_gate(theta)¶
Generate the RZ gate matrix.
\[\begin{split}R_Z(\theta) = \begin{bmatrix} e^{-i\theta/2} & 0 \\ 0 & e^{i\theta/2} \end{bmatrix}\end{split}\]- Parameters:¶
- theta : ndarray | Tensor | Iterable[float] | float¶
the (batched) parameter, with shape [1].
- Returns:¶
The matrix of the RZ gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([torch.pi / 4]) R_z = rz(theta) print(f'The R_z Gate is:\n{R_z}')
The R_z Gate is: tensor([[0.9239-0.3827j, 0.0000+0.0000j], [0.0000+0.0000j, 0.9239+0.3827j]])
- quairkit.database.u3_gate(theta)¶
Generate the U3 gate matrix.
\[\begin{split}U_3(\theta, \phi, \lambda) = \begin{bmatrix} \cos\frac{\theta}{2} & -e^{i\lambda}\sin\frac{\theta}{2} \\ e^{i\phi}\sin\frac{\theta}{2} & e^{i(\phi+\lambda)}\cos\frac{\theta}{2} \end{bmatrix}\end{split}\]- Parameters:¶
- theta : ndarray | Tensor | Iterable[float]¶
the (batched) parameters, with shape [3, 1].
- Returns:¶
The matrix of the U3 gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([[torch.pi / 4], [torch.pi / 3], [torch.pi / 6]]) u3_matrix = u3(theta) print(f'The U3 Gate is:\n{u3_matrix}')
The U3 Gate is: tensor([[ 9.2388e-01+0.0000j, -3.3141e-01-0.1913j], [ 1.9134e-01+0.3314j, -4.0384e-08+0.9239j]])
- quairkit.database.cnot_gate()¶
Generate the CNOT gate matrix.
\[\begin{split}CNOT = |0\rangle \langle 0| \otimes I + |1\rangle \langle 1| \otimes X = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{bmatrix}\end{split}\]Examples
CNOT = cnot() print(f'The CNOT Gate is:\n{CNOT}')
The CNOT Gate is: tensor([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j], [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j]])
- quairkit.database.cy_gate()¶
Generate the CY gate matrix.
\[\begin{split}CY = |0\rangle\langle0| \otimes I + |1\rangle\langle1| \otimes Y = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & -i \\ 0 & 0 & i & 0 \end{bmatrix}\end{split}\]Examples
CY = cy() print(f'The CY Gate is:\n{CY}')
The CY Gate is: tensor([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, -0.-1.j], [0.+0.j, 0.+0.j, 0.+1.j, 0.+0.j]])
- quairkit.database.cz_gate()¶
Generate the CZ gate matrix.
\[\begin{split}CZ = |0\rangle\langle0| \otimes I + |1\rangle\langle1| \otimes Z = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & -1 \end{bmatrix}\end{split}\]Examples
CZ = cz() print(f'The CZ Gate is:\n{CZ}')
The CZ Gate is: tensor([[ 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [ 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j], [ 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j], [ 0.+0.j, 0.+0.j, 0.+0.j, -1.+0.j]])
- quairkit.database.swap_gate()¶
Generate the SWAP gate matrix.
\[\begin{split}SWAP = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}\end{split}\]Examples
SWAP = swap() print(f'The SWAP Gate is:\n{SWAP}')
The SWAP Gate is: tensor([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j], [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j]])
- quairkit.database.cp_gate(theta)¶
Generate the CP gate matrix.
\[\begin{split}CP(\theta) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & e^{i\theta} \end{bmatrix}\end{split}\]- Parameters:¶
- theta : ndarray | Tensor | Iterable[float] | float¶
the (batched) parameter, with shape [1].
- Returns:¶
The matrix of the CP gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([torch.pi / 4]) CP = cp(theta) print(f'The CP Gate is:\n{CP}')
The CP Gate is: tensor([[1.0000+0.0000j, 0.0000+0.0000j, 0.0000+0.0000j, 0.0000+0.0000j], [0.0000+0.0000j, 1.0000+0.0000j, 0.0000+0.0000j, 0.0000+0.0000j], [0.0000+0.0000j, 0.0000+0.0000j, 1.0000+0.0000j, 0.0000+0.0000j], [0.0000+0.0000j, 0.0000+0.0000j, 0.0000+0.0000j, 0.7071+0.7071j]])
- quairkit.database.crx_gate(theta)¶
Generate the CR_X gate matrix.
\[\begin{split}CR_X = |0\rangle\langle0| \otimes I + |1\rangle\langle1| \otimes R_X = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & \cos\frac{\theta}{2} & -i\sin\frac{\theta}{2} \\ 0 & 0 & -i\sin\frac{\theta}{2} & \cos\frac{\theta}{2} \end{bmatrix}\end{split}\]- Parameters:¶
- theta : ndarray | Tensor | Iterable[float] | float¶
the (batched) parameter, with shape [1].
- Returns:¶
The matrix of the CR_X gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([torch.pi / 4]) CR_X = crx(theta) print(f'The CR_X Gate is:\n{CR_X}')
The CR_X Gate is: tensor([[1.0000+0.0000j, 0.+0.0000j, 0.+0.0000j, 0.+0.0000j], [0.+0.0000j, 1.0000+0.0000j, 0.+0.0000j, 0.+0.0000j], [0.+0.0000j, 0.+0.0000j, 0.9239+0.0000j, 0.+-0.3827j], [0.+0.0000j, 0.+0.0000j, 0.+-0.3827j, 0.9239+0.0000j]])
- quairkit.database.cry_gate(theta)¶
Generate the CR_Y gate matrix.
\[\begin{split}CR_Y = |0\rangle\langle0| \otimes I + |1\rangle\langle1| \otimes R_Y = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & \cos\frac{\theta}{2} & -\sin\frac{\theta}{2} \\ 0 & 0 & \sin\frac{\theta}{2} & \cos\frac{\theta}{2} \end{bmatrix}\end{split}\]- Parameters:¶
- theta : ndarray | Tensor | Iterable[float] | float¶
the (batched) parameter, with shape [1].
- Returns:¶
The matrix of the CR_Y gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([torch.pi / 4]) CR_Y = cry(theta) print(f'The CR_Y Gate is:\n{CR_Y}')
The CR_Y Gate is: tensor([[1.0000+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 1.0000+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.9239+0.j, -0.3827+0.j], [0.+0.j, 0.+0.j, 0.3827+0.j, 0.9239+0.j]])
- quairkit.database.crz_gate(theta)¶
Generate the CR_Z gate matrix.
\[\begin{split}CR_Z = |0\rangle\langle0| \otimes I + |1\rangle\langle1| \otimes R_Z = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & e^{-i\theta/2} & 0 \\ 0 & 0 & 0 & e^{i\theta/2} \end{bmatrix}\end{split}\]- Parameters:¶
- theta : ndarray | Tensor | Iterable[float] | float¶
the (batched) parameter, with shape [1].
- Returns:¶
The matrix of the CR_Z gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([torch.pi / 4]) CR_Z = crz(theta) print(f'The CR_Z Gate is:\n{CR_Z}')
The CR_Z Gate is: tensor([[1.0000+0.0000j, 0.+0.0000j, 0.+0.0000j, 0.+0.0000j], [0.+0.0000j, 1.0000+0.0000j, 0.+0.0000j, 0.+0.0000j], [0.+0.0000j, 0.+0.0000j, 0.9239-0.3827j, 0.+0.0000j], [0.+0.0000j, 0.+0.0000j, 0.+0.0000j, 0.9239+0.3827j]])
- quairkit.database.cu_gate(theta)¶
Generate the CU gate matrix.
\[\begin{split}CU = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & e^{i\gamma}\cos\frac{\theta}{2} & -e^{i(\lambda+\gamma)}\sin\frac{\theta}{2} \\ 0 & 0 & e^{i(\phi+\gamma)}\sin\frac{\theta}{2} & e^{i(\phi+\lambda+\gamma)}\cos\frac{\theta}{2} \end{bmatrix}\end{split}\]- Parameters:¶
- theta : ndarray | Tensor | Iterable[float]¶
the (batched) parameters, with shape [4, 1].
- Returns:¶
The matrix of the CU gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([[torch.pi / 4], [torch.pi / 3], [torch.pi / 6], [torch.pi / 6]]) CU = cu(theta) print(f'The CU Gate is:\n{CU}')
The CU Gate is: tensor([[1.0000e+00+0.0000j, 0.0000e+00+0.0000j, 0.0000e+00+0.0000j, 0.0000e+00+0.0000j], [0.0000e+00+0.0000j, 1.0000e+00+0.0000j, 0.0000e+00+0.0000j, 0.0000e+00+0.0000j], [0.0000e+00+0.0000j, 0.0000e+00+0.0000j, 8.0010e-01+0.4619j, -1.9134e-01-0.3314j], [0.0000e+00+0.0000j, 0.0000e+00+0.0000j, -1.6728e-08+0.3827j, -4.6194e-01+0.8001j]])
- quairkit.database.rxx_gate(theta)¶
Generate the RXX gate matrix.
\[\begin{split}R_{XX}(\theta) = \begin{bmatrix} \cos\frac{\theta}{2} & 0 & 0 & -i\sin\frac{\theta}{2} \\ 0 & \cos\frac{\theta}{2} & -i\sin\frac{\theta}{2} & 0 \\ 0 & -i\sin\frac{\theta}{2} & \cos\frac{\theta}{2} & 0 \\ -i\sin\frac{\theta}{2} & 0 & 0 & \cos\frac{\theta}{2} \end{bmatrix}\end{split}\]- Parameters:¶
- theta : ndarray | Tensor | Iterable[float] | float¶
the (batched) parameter, with shape [1].
- Returns:¶
The matrix of the RXX gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([torch.pi / 4]) R_XX = rxx(theta) print(f'The R_XX Gate is:\n{R_XX}')
The R_XX Gate is: tensor([[0.9239+0.0000j, 0.0000+0.0000j, 0.0000+0.0000j, 0.0000-0.3827j], [0.0000+0.0000j, 0.9239+0.0000j, 0.0000-0.3827j, 0.0000+0.0000j], [0.0000+0.0000j, 0.0000-0.3827j, 0.9239+0.0000j, 0.0000+0.0000j], [0.0000-0.3827j, 0.0000+0.0000j, 0.0000+0.0000j, 0.9239+0.0000j]])
- quairkit.database.ryy_gate(theta)¶
Generate the RYY gate matrix.
\[\begin{split}R_{YY}(\theta) = \begin{bmatrix} \cos\frac{\theta}{2} & 0 & 0 & i\sin\frac{\theta}{2} \\ 0 & \cos\frac{\theta}{2} & -i\sin\frac{\theta}{2} & 0 \\ 0 & -i\sin\frac{\theta}{2} & \cos\frac{\theta}{2} & 0 \\ i\sin\frac{\theta}{2} & 0 & 0 & \cos\frac{\theta}{2} \end{bmatrix}\end{split}\]- Parameters:¶
- theta : ndarray | Tensor | Iterable[float] | float¶
the (batched) parameter, with shape [1].
- Returns:¶
The matrix of the RYY gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([torch.pi / 4]) R_YY = ryy(theta) print(f'The R_YY Gate is:\n{R_YY}')
The R_YY Gate is: tensor([[0.9239+0.0000j, 0.0000+0.0000j, 0.0000+0.0000j, 0.0000+0.3827j], [0.0000+0.0000j, 0.9239+0.0000j, 0.0000-0.3827j, 0.0000+0.0000j], [0.0000+0.0000j, 0.0000-0.3827j, 0.9239+0.0000j, 0.0000+0.0000j], [0.0000+0.3827j, 0.0000+0.0000j, 0.0000+0.0000j, 0.9239+0.0000j]])
- quairkit.database.rzz_gate(theta)¶
Generate the RZZ gate matrix.
\[\begin{split}R_{ZZ}(\theta) = \begin{bmatrix} e^{-i\theta/2} & 0 & 0 & 0 \\ 0 & e^{i\theta/2} & 0 & 0 \\ 0 & 0 & e^{i\theta/2} & 0 \\ 0 & 0 & 0 & e^{-i\theta/2} \end{bmatrix}\end{split}\]- Parameters:¶
- theta : ndarray | Tensor | Iterable[float] | float¶
the (batched) parameter, with shape [1].
- Returns:¶
The matrix of the RZZ gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([torch.pi / 4]) R_ZZ = rzz(theta) print(f'The R_ZZ Gate is:\n{R_ZZ}')
The R_ZZ Gate is: tensor([[0.9239-0.3827j, 0.0000+0.0000j, 0.0000+0.0000j, 0.0000+0.0000j], [0.0000+0.0000j, 0.9239+0.3827j, 0.0000+0.0000j, 0.0000+0.0000j], [0.0000+0.0000j, 0.0000+0.0000j, 0.9239+0.3827j, 0.0000+0.0000j], [0.0000+0.0000j, 0.0000+0.0000j, 0.0000+0.0000j, 0.9239-0.3827j]])
- quairkit.database.ms_gate()¶
Generate the MS gate matrix.
\[\begin{split}MS = R_{XX}\left(-\frac{\pi}{2}\right) = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 0 & 0 & i \\ 0 & 1 & i & 0 \\ 0 & i & 1 & 0 \\ i & 0 & 0 & 1 \end{bmatrix}\end{split}\]Examples
MS = ms() print(f'The MS Gate is:\n{MS}')
The MS Gate is: tensor([[0.7071+0.0000j, 0.0000+0.0000j, 0.0000+0.0000j, 0.0000+0.7071j], [0.0000+0.0000j, 0.7071+0.0000j, 0.0000+0.7071j, 0.0000+0.0000j], [0.0000+0.0000j, 0.0000+0.7071j, 0.7071+0.0000j, 0.0000+0.0000j], [0.0000+0.7071j, 0.0000+0.0000j, 0.0000+0.0000j, 0.7071+0.0000j]])
- quairkit.database.cswap_gate()¶
Generate the CSWAP gate matrix.
\[\begin{split}CSWAP = \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 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \end{bmatrix}\end{split}\]Examples
CSWAP = cswap() print(f'The CSWAP Gate is:\n{CSWAP}')
The CSWAP Gate is: tensor([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j]])
- quairkit.database.toffoli_gate()¶
Generate the Toffoli gate matrix.
\[\begin{split}Toffoli = \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 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \end{bmatrix}\end{split}\]Examples
Toffoli = toffoli() print(f'The Toffoli Gate is:\n{Toffoli}')
The Toffoli Gate is: tensor([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j]])
- quairkit.database.ccx_gate()¶
Generate the Toffoli gate matrix.
\[\begin{split}Toffoli = \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 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \end{bmatrix}\end{split}\]Examples
Toffoli = toffoli() print(f'The Toffoli Gate is:\n{Toffoli}')
The Toffoli Gate is: tensor([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j]])
- quairkit.database.universal2_gate(theta)¶
Generate the universal two-qubit gate matrix.
- Parameters:¶
- theta : ndarray | Tensor | Iterable[float]¶
the (batched) parameter with shape [15].
- Returns:¶
The matrix of the universal two-qubit gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([ 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5]) Universal2 = universal2(theta) print(f'The matrix of universal two qubits gate is:\n{Universal2}')
The matrix of universal two qubits gate is: tensor([[-0.2858-0.0270j, 0.4003+0.3090j, -0.6062+0.0791j, 0.5359+0.0323j], [-0.0894-0.1008j, -0.5804+0.0194j, 0.3156+0.1677j, 0.7090-0.1194j], [-0.8151-0.2697j, 0.2345-0.1841j, 0.3835-0.1154j, -0.0720+0.0918j], [-0.2431+0.3212j, -0.1714+0.5374j, 0.1140+0.5703j, -0.2703+0.3289j]])
- quairkit.database.universal3_gate(theta)¶
Generate the universal three-qubit gate matrix.
- Parameters:¶
- theta : ndarray | Tensor | Iterable[float]¶
the (batched) parameter with shape [81].
- Returns:¶
The matrix of the universal three-qubit gate.
- Return type:¶
ndarray | Tensor
Examples
theta = torch.tensor([ 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, 5.0, 5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6.0, 6.1, 6.2, 6.3, 6.4, 6.5, 6.6, 6.7, 6.8, 6.9, 7.0, 7.1, 7.2, 7.3, 7.4, 7.5, 7.6, 7.7, 7.8, 7.9, 8.0, 8.1]) Universal3 = universal3(theta) print(f'The matrix of universal three qubits gate is:\n{Universal3}')
The matrix of universal three qubits gate is: tensor([[-0.0675-0.0941j, -0.4602+0.0332j, 0.2635+0.0044j, 0.0825+0.3465j, -0.0874-0.3635j, -0.1177-0.4195j, -0.2735+0.3619j, -0.1760-0.1052j], [ 0.0486+0.0651j, -0.1123+0.0494j, 0.1903+0.0057j, -0.2080+0.2926j, -0.2099+0.0630j, -0.1406+0.5173j, -0.1431-0.3538j, -0.5460-0.1847j], [ 0.0827-0.0303j, 0.1155+0.1111j, 0.5391-0.0701j, -0.4229-0.2655j, -0.1546+0.1943j, -0.0455+0.1744j, -0.3242+0.3539j, 0.3118-0.0041j], [-0.1222+0.3984j, 0.1647-0.1817j, 0.3294-0.1486j, -0.0293-0.1503j, 0.0100-0.6481j, 0.2424+0.1575j, 0.2485+0.0232j, -0.1053+0.1873j], [-0.4309-0.0791j, -0.2071-0.0482j, -0.4331+0.0866j, -0.5454-0.1778j, -0.1401-0.0230j, 0.0170+0.0299j, 0.0078+0.2231j, -0.2324+0.3369j], [ 0.0330+0.3056j, 0.2612+0.6464j, -0.2138-0.1748j, -0.2322-0.0598j, 0.1387-0.1573j, 0.0914-0.2963j, -0.2712-0.1351j, -0.1272-0.1940j], [ 0.0449-0.3844j, 0.1135+0.2846j, -0.0251+0.3854j, 0.0442-0.0149j, -0.3671-0.1774j, 0.5158+0.1148j, 0.2151+0.1433j, -0.0188-0.3040j], [-0.4124-0.4385j, 0.2306+0.0894j, 0.0104-0.2180j, -0.0180+0.2869j, -0.1030-0.2991j, -0.1473+0.0931j, -0.1686-0.3451j, 0.3825+0.1480j]])
- quairkit.database.Uf_gate(f, n)¶
Construct the unitary matrix used in Simon’s algorithm.
- Parameters:¶
- Returns:¶
A 2n-qubit unitary matrix satisfying
\[U|x, y\rangle = |x, y \oplus f(x)\rangle\]- Return type:¶
Tensor
Examples
def f(x: int) -> int: return x unitary_matrix = Uf(f, 1) print(f'Unitary matrix is:\n{unitary_matrix}')
Unitary matrix is: tensor([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j], [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j]])
- quairkit.database.Of_gate(f, n)¶
Construct the oracle unitary matrix for an unstructured search problem.
- Parameters:¶
- Returns:¶
An n-qubit unitary matrix satisfying
\[U|x\rangle = (-1)^{f(x)}|x\rangle\]- Return type:¶
Tensor
Examples
def f(x: int) -> int: return x unitary_matrix = Of(f, 1) print(f'Unitary matrix is:\n{unitary_matrix}')
Unitary matrix is: tensor([[ 1.+0.j, 0.+0.j], [ 0.+0.j, -1.+0.j]])
-
quairkit.database.random_pauli_str_generator(num_qubits, terms=
3
)¶ Generate a random observable in list form.
An observable \(O=0.3X\otimes I\otimes I+0.5Y\otimes I\otimes Z\)’s list form is
[[0.3, 'x0'], [0.5, 'y0,z2']]
. Such an observable is generated byrandom_pauli_str_generator(3, terms=2)
.Examples
observable = random_pauli_str_generator(num_qubits=2, terms=2) print(f'The Hamiltonian of randomly generated observable is:\n{observable}')
The Hamiltonian of randomly generated observable is: [[-0.6019637631250563, 'y0'], [0.12777564473712655, 'x0,z1']]
-
quairkit.database.random_state(num_systems, rank=
None
, is_real=False
, size=1
, system_dim=2
)¶ Generate a random quantum state.
- Parameters:¶
- num_systems : int¶
The number of qubits contained in the quantum state.
- rank : int | None¶
The rank of the density matrix. Defaults to
None
(full rank).- is_real : bool | None¶
If the quantum state only contains real numbers. Defaults to
False
.- size : List[int] | int | None¶
Batch size. Defaults to 1.
- system_dim : List[int] | int¶
Dimension of systems. Can be a list of system dimensions or an int representing the dimension of all systems. Defaults to the qubit case.
- Raises:¶
NotImplementedError – If the backend is wrong or not implemented.
- Returns:¶
The generated quantum state.
- Return type:¶
StateSimulator
Examples
state = random_state(num_systems=1, size=1) print(f'The generated quantum state is:\n{state}') state = random_state(num_systems=1, rank=1) print(f'The generated quantum state is:\n{state}') state = random_state(num_systems=2, system_dim=[1, 2]) print(f'The generated quantum state is:\n{state}') state = random_state(num_systems=3, size=[2, 1], system_dim=[1, 2, 1]) print(f'The generated quantum state is:\n{state}')
The generated quantum state is: --------------------------------------------------- Backend: state_vector System dimension: [2] System sequence: [0] [-0.33+0.72j -0.28+0.55j] --------------------------------------------------- The generated quantum state is: --------------------------------------------------- Backend: state_vector System dimension: [2] System sequence: [0] [ 0.83-0.31j -0.45+0.16j] --------------------------------------------------- The generated quantum state is: --------------------------------------------------- Backend: density_matrix System dimension: [1, 2] System sequence: [0, 1] [[ 0.63+0.j -0.12-0.13j] [-0.12+0.13j 0.37-0.j ]] --------------------------------------------------- The generated quantum state is: --------------------------------------------------- Backend: density_matrix System dimension: [1, 2, 1] System sequence: [0, 1, 2] Batch size: [2, 1] # 0: [[0.43+0.j 0.24-0.37j], [0.24+0.37j 0.57-0.j ]] # 1: [[ 0.88+0.j -0.29-0.11j], [-0.29+0.11j 0.12-0.j ]] ---------------------------------------------------
-
quairkit.database.random_hamiltonian_generator(num_qubits, terms=
3
)¶ Generate a random Hamiltonian.
Examples
Hamiltonian = random_hamiltonian_generator(3, 2) print(f'The randomly generated Hamiltonian is:\n{Hamiltonian}')
The randomly generated Hamiltonian is: 0.11801365595625102 Z0, X2 0.9059897222160238 X0, Z1, Z2
- quairkit.database.random_hermitian(num_qubits)¶
Randomly generate a normalized \(2^n \times 2^n\) Hermitian matrix.
- Parameters:¶
- num_qubits : int¶
Number of qubits \(n\).
- Returns:¶
A \(2^n \times 2^n\) Hermitian matrix.
- Return type:¶
Tensor
Examples
Hermitian = random_hermitian(1) print(f'The randomly generated Hermitian matrix is:\n{Hermitian}')
The randomly generated Hermitian matrix is: tensor([[0.1038+0.0000j, 0.4251+0.2414j], [0.4251-0.2414j, 0.7333+0.0000j]])
-
quairkit.database.random_projector(num_systems, size=
1
, system_dim=2
)¶ Randomly generate a \(d \times d\) orthogonal projector.
Examples
Orthogonal_projector = random_orthogonal_projection(1) print(f'The randomly generated Orthogonal_projector is:\n{Orthogonal_projector}')
The randomly generated Orthogonal_projector is: tensor([[0.9704+1.1123e-10j, 0.1692+7.7007e-03j], [0.1692-7.7008e-03j, 0.0296-1.1123e-10j]])
-
quairkit.database.random_orthogonal_projection(num_systems, size=
1
, system_dim=2
)¶ Randomly generate a \(d \times d\) orthogonal projector.
Examples
Orthogonal_projector = random_orthogonal_projection(1) print(f'The randomly generated Orthogonal_projector is:\n{Orthogonal_projector}')
The randomly generated Orthogonal_projector is: tensor([[0.9704+1.1123e-10j, 0.1692+7.7007e-03j], [0.1692-7.7008e-03j, 0.0296-1.1123e-10j]])
- quairkit.database.random_density_matrix(num_qubits)¶
Randomly generate an num_qubits-qubit state in density matrix form.
- Parameters:¶
- num_qubits : int¶
Number of qubits \(n\).
- Returns:¶
A \(2^n \times 2^n\) density matrix.
- Return type:¶
Tensor
Examples
Density_matrix = random_density_matrix(1) print(f'The randomly generated density matrix is:\n{Density_matrix}')
The randomly generated density matrix is: tensor([[0.3380+0.0000j, 0.4579+0.1185j], [0.4579-0.1185j, 0.6620+0.0000j]])
-
quairkit.database.random_unitary(num_systems, size=
1
, system_dim=2
)¶ Randomly generate a \(d \times d\) unitary.
Examples
unitary_matrix_1 = random_unitary(num_systems=1, system_dim=2) print(f'The randomly generated unitary_matrix_1 is:\n{unitary_matrix_1}') unitary_matrix_2 = random_unitary(num_systems=2, system_dim=[1, 2]) print(f'The randomly generated unitary_matrix_2 is:\n{unitary_matrix_2}') unitary_matrix_3 = random_unitary(num_systems=1, size=[1,2]) print(f'The randomly generated unitary_matrix_3 is:\n{unitary_matrix_3}')
The randomly generated unitary_matrix_1 is: tensor([[-0.5288+0.5296j, -0.5277-0.4019j], [-0.5321-0.3959j, -0.3627+0.6546j]]) The randomly generated unitary_matrix_2 is: tensor([[0.6996-0.1504j, 0.3414+0.6095j], [0.4954-0.4925j, -0.6315-0.3364j]]) The randomly generated unitary_matrix_3 is: tensor([[[[0.3240+0.1404j, 0.4166-0.8377j], [0.6068+0.7121j, -0.2804+0.2146j]], [[-0.2620-0.0886j, -0.3587+0.8916j], [0.5196-0.8084j, 0.2238+0.1624j]]]])
- quairkit.database.random_unitary_hermitian(num_qubits)¶
Randomly generate a \(2^n \times 2^n\) Hermitian unitary.
- Parameters:¶
- num_qubits : int¶
Number of qubits \(n\).
- Returns:¶
A \(2^n \times 2^n\) Hermitian unitary matrix.
- Return type:¶
Tensor
Examples
Unitary_hermitian = random_unitary_hermitian(1) print(f'The randomly generated hermitian unitary is:\n{Unitary_hermitian}')
The randomly generated hermitian unitary is: tensor([[0.2298+2.2018e-09j, -0.8408+4.9013e-01j], [-0.8408-4.9013e-01j, -0.2298-2.2018e-09j]])
-
quairkit.database.random_unitary_with_hermitian_block(num_qubits, is_unitary=
False
)¶ Randomly generate a unitary \(2^n \times 2^n\) matrix that is a block encoding of a \(2^{n/2} \times 2^{n/2}\) Hermitian matrix.
- Parameters:¶
- Returns:¶
A \(2^n \times 2^n\) unitary matrix whose upper-left block is Hermitian.
- Return type:¶
Tensor
Examples
unitary_matrix_1 = random_unitary_with_hermitian_block(num_qubits=2, is_unitary=False) print(f'The randomly generated unitary matrix 1 with hermitian block is:\n{unitary_matrix_1}') unitary_matrix_2 = random_unitary_with_hermitian_block(num_qubits=2, is_unitary=True) print(f'The randomly generated unitary matrix 2 with hermitian block is:\n{unitary_matrix_2}')
The randomly generated unitary matrix 1 with hermitian block is: tensor([[ 5.7873e-01+0.0000j, 2.2460e-01+0.2711j, -1.5514e-08+0.5646j, 3.6316e-01-0.3009j], [ 2.2460e-01-0.2711j, 7.0578e-01+0.0000j, -3.6316e-01-0.3009j, -2.2489e-08+0.3944j], [-1.5514e-08+0.5646j, 3.6316e-01-0.3009j, 5.7873e-01+0.0000j, 2.2460e-01+0.2711j], [-3.6316e-01-0.3009j, -2.2489e-08+0.3944j, 2.2460e-01-0.2711j, 7.0578e-01+0.0000j]]) The randomly generated unitary matrix 2 with hermitian block is: tensor([[-1.8185e-01-1.6847e-09j, 3.0894e-01+3.4855e-01j, 2.2516e-09+8.6603e-01j, -1.4451e-09-9.3500e-11j], [ 3.0894e-01-3.4855e-01j, 1.8185e-01+1.6847e-09j, 1.7456e-09-9.3500e-11j, 2.4038e-09+8.6603e-01j], [ 2.2516e-09+8.6603e-01j, -1.4451e-09-9.3500e-11j, -1.8185e-01-1.6847e-09j, 3.0894e-01+3.4855e-01j], [ 1.7456e-09-9.3500e-11j, 2.4038e-09+8.6603e-01j, 3.0894e-01-3.4855e-01j, 1.8185e-01+1.6847e-09j]])
-
quairkit.database.random_lcu(num_systems, num_ctrl_systems=
1
, system_dim=2
)¶ Randomly generate a unitary that can creates a linear combination of random unitaries. The number of unitaries is at least 2, and at most the dimension of the total control system.
- quairkit.database.haar_orthogonal(dim)¶
Randomly generate an orthogonal matrix following Haar measure, referenced by arXiv:math-ph/0609050v2.
- Parameters:¶
- dim : int¶
Dimension of the orthogonal matrix.
- Returns:¶
A \(d \times d\) orthogonal matrix.
- Return type:¶
Tensor
Examples
Haar_orthogonal = haar_orthogonal(2) print(f'The randomly generated orthogonal matrix is:\n{Haar_orthogonal}')
The randomly generated orthogonal matrix is: tensor([[-0.6859+0.j, 0.7277+0.j], [ 0.7277+0.j, 0.6859+0.j]])
- quairkit.database.haar_unitary(dim)¶
Randomly generate a unitary following Haar measure, referenced by arXiv:math-ph/0609050v2.
- Parameters:¶
- dim : int¶
Dimension of the unitary.
- Returns:¶
A \(d \times d\) unitary.
- Return type:¶
Tensor
Examples
Haar_unitary = haar_unitary(2) print(f'The randomly generated unitary is:\n{Haar_unitary}')
The randomly generated unitary is: tensor([[ 0.2800+0.6235j, 0.7298+0.0160j], [-0.7289-0.0396j, 0.3267-0.6003j]])
-
quairkit.database.haar_state_vector(dim, is_real=
False
)¶ Randomly generate a state vector following Haar measure.
Examples
Haar_state_vector = haar_state_vector(3, is_real=True) print(f'The randomly generated state vector is:\n{Haar_state_vector}')
The randomly generated state vector is: tensor([[0.9908+0.j], [-0.1356+0.j]])
-
quairkit.database.haar_density_operator(dim, rank, is_real=
False
)¶ Randomly generate a density matrix following Haar measure.
Examples
rho1 = haar_density_operator(dim=2, rank=2) print(f'The randomly generated density matrix 1 is:\n{rho1}') rho2 = haar_density_operator(dim=2, rank=1, is_real=True) print(f'The randomly generated density matrix 2 is:\n{rho2}')
The randomly generated density matrix 1 is: tensor([[0.8296+1.1215e-18j, -0.0430+3.5193e-01j], [-0.0430-3.5193e-01j, 0.1704-1.1215e-18j]]) The randomly generated density matrix 2 is: tensor([[0.6113+0.j, -0.4875+0.j], [-0.4875+0.j, 0.3887+0.j]])
-
quairkit.database.random_channel(num_systems, rank=
None
, target='kraus'
, size=1
, system_dim=2
)¶ Generate a random channel from its Stinespring representation.
- Parameters:¶
- num_systems : int¶
Number of systems.
- rank : int¶
Rank of this channel. If None, it is randomly sampled from \([1, d]\).
- target : str¶
Target representation; should be
'choi'
,'kraus'
or'stinespring'
.- size : int | None¶
Batch size. Defaults to 1.
- system_dim : List[int] | int¶
Dimension of systems. Can be a list of system dimensions or an int representing the dimension of all systems. Defaults to the qubit case.
- Returns:¶
The target representation of a random channel.
- Return type:¶
Tensor
Examples
channel_kraus = random_channel(num_systems=1, target="kraus", system_dim=2) print(f'The randomly generated kraus channel is:\n{channel_kraus}') channel_choi = random_channel(num_systems=1, target="choi", system_dim=2) print(f'The randomly generated choi channel is:\n{channel_choi}') channel_stinespring = random_channel(num_systems=1, target="stinespring", size=1, rank=1) print(f'The randomly generated stinespring channel is:\n{channel_stinespring}') batch_channels = random_channel(num_systems=2, size=2, target="kraus", system_dim=[1,2], rank=2) print(f'The randomly generated kraus channel is:\n{batch_channels}')
The randomly generated kraus channel is: tensor([[[ 0.2361+0.7497j, 0.0224+0.6178j], [ 0.5942-0.1706j, -0.7860+0.0085j]]]) The randomly generated choi channel is: tensor([[ 0.5136+0.0000j, -0.4784-0.1446j, -0.2850-0.4106j, -0.1583-0.4886j], [-0.4784+0.1446j, 0.4864+0.0000j, 0.3811+0.3023j, 0.2850+0.4106j], [-0.2850+0.4106j, 0.3811-0.3023j, 0.4864+0.0000j, 0.4784+0.1446j], [-0.1583+0.4886j, 0.2850-0.4106j, 0.4784-0.1446j, 0.5136+0.0000j]]) The randomly generated stinespring channel is: tensor([[ 0.1652+0.5347j, 0.6310+0.5372j], [ 0.4751+0.6790j, -0.5167-0.2150j]]) The randomly generated kraus channel is: tensor([[[[-0.3189-0.6385j, -0.1873+0.1634j], [ 0.2218+0.0440j, -0.6294+0.0947j]], [[-0.0072+0.0749j, -0.0790+0.6740j], [-0.5121-0.4142j, -0.0357-0.2671j]]], [[[-0.1163-0.1931j, 0.2001-0.5852j], [-0.5174+0.5253j, 0.1128-0.2459j]], [[-0.1362+0.3280j, -0.2677+0.5444j], [ 0.4328-0.3033j, -0.3862-0.1646j]]]])
- quairkit.database.random_clifford(num_qubits)¶
Generate a random Clifford unitary.
- Parameters:¶
- num_qubits : int¶
The number of qubits (n).
- Returns:¶
The matrix form of a random Clifford unitary.
- Return type:¶
Tensor
- Reference:
Sergey Bravyi and Dmitri Maslov, Hadamard-free circuits expose the structure of the Clifford group. IEEE Transactions on Information Theory 67(7), 4546-4563 (2021).
Examples
num_qubits = 1 clifford_matrix = random_clifford(num_qubits) print(f'The randomly generated Clifford unitary is:\n{clifford_matrix}')
The randomly generated Clifford unitary is: tensor([[ 0.7071+0.0000j, -0.7071+0.0000j], [ 0.0000+0.7071j, 0.0000+0.7071j]])
- quairkit.database.bit_flip_kraus(prob)¶
Kraus representation of a bit flip channel with form
\[E_0 = \sqrt{1-p} I, E_1 = \sqrt{p} X.\]- Parameters:¶
- prob : ndarray | Tensor | Iterable[float] | float¶
probability \(p\).
- Returns:¶
a list of Kraus operators
- Return type:¶
List[ndarray | Tensor]
Examples
prob = torch.tensor([0.5]) kraus_operators = bit_flip_kraus(prob) print(f'The Kraus operators are:\n{kraus_operators}')
The Kraus operators are: tensor([[[0.7071+0.j, 0.0000+0.j], [0.0000+0.j, 0.7071+0.j]], [[0.0000+0.j, 0.7071+0.j], [0.7071+0.j, 0.0000+0.j]]], dtype=torch.complex128)
- quairkit.database.phase_flip_kraus(prob)¶
Kraus representation of a phase flip channel with form
\[E_0 = \sqrt{1-p} I, E_1 = \sqrt{p} Z.\]- Parameters:¶
- prob : ndarray | Tensor | Iterable[float] | float¶
probability \(p\).
- Returns:¶
a list of Kraus operators
- Return type:¶
List[ndarray | Tensor]
Examples
prob = torch.tensor([0.1]) kraus_operators = phase_flip_kraus(prob) print(f'The Kraus operators are:\n{kraus_operators}')
The Kraus operators are: tensor([[[ 0.9487+0.j, 0.0000+0.j], [ 0.0000+0.j, 0.9487+0.j]], [[ 0.3162+0.j, 0.0000+0.j], [ 0.0000+0.j, -0.3162+0.j]]], dtype=torch.complex128)
- quairkit.database.bit_phase_flip_kraus(prob)¶
Kraus representation of a bit-phase flip channel with form
\[E_0 = \sqrt{1-p} I, E_1 = \sqrt{p} Y.\]- Parameters:¶
- prob : ndarray | Tensor | Iterable[float] | float¶
probability \(p\).
- Returns:¶
a list of Kraus operators
- Return type:¶
List[ndarray | Tensor]
Examples
prob = torch.tensor([0.1]) kraus_operators = bit_phase_flip_kraus(prob) print(f'The Kraus operators are:\n{kraus_operators}')
The Kraus operators are: tensor([[[0.9487+0.0000j, 0.0000+0.0000j], [0.0000+0.0000j, 0.9487+0.0000j]], [[0.0000+0.0000j, 0.0000-0.3162j], [0.0000+0.3162j, 0.0000+0.0000j]]], dtype=torch.complex128)
- quairkit.database.amplitude_damping_kraus(gamma)¶
Kraus representation of an amplitude damping channel with form
\[\begin{split}E_0 = \begin{bmatrix} 1 & 0 \\ 0 & \sqrt{1-\gamma} \end{bmatrix}, E_1 = \begin{bmatrix} 0 & \sqrt{\gamma} \\ 0 & 0 \end{bmatrix}.\end{split}\]- Parameters:¶
- gamma : ndarray | Tensor | Iterable[float] | float¶
coefficient \(\gamma\).
- Returns:¶
a list of Kraus operators
- Return type:¶
List[ndarray | Tensor]
Examples
gamma = torch.tensor(0.2) kraus_operators = amplitude_damping_kraus(gamma) print(f'The Kraus operators are:\n{kraus_operators}')
The Kraus operators are: tensor([[[1.0000+0.j, 0.0000+0.j], [0.0000+0.j, 0.8944+0.j]], [[0.0000+0.j, 0.4472+0.j], [0.0000+0.j, 0.0000+0.j]]], dtype=torch.complex128)
- quairkit.database.generalized_amplitude_damping_kraus(gamma, prob)¶
Kraus representation of a generalized amplitude damping channel with form
\[\begin{split}E_0 = \sqrt{p} \begin{bmatrix} 1 & 0 \\ 0 & \sqrt{1-\gamma} \end{bmatrix}, E_1 = \sqrt{p} \begin{bmatrix} 0 & \sqrt{\gamma} \\ 0 & 0 \end{bmatrix},\\ E_2 = \sqrt{1-p} \begin{bmatrix} \sqrt{1-\gamma} & 0 \\ 0 & 1 \end{bmatrix}, E_3 = \sqrt{1-p} \begin{bmatrix} 0 & 0 \\ \sqrt{\gamma} & 0 \end{bmatrix}.\end{split}\]Examples
gamma = torch.tensor(0.2) prob = torch.tensor(0.1) kraus_operators = generalized_amplitude_damping_kraus(gamma, prob) print(f'The Kraus operators are:\n{kraus_operators}')
The Kraus operators are: tensor([[[0.3162+0.j, 0.0000+0.j], [0.0000+0.j, 0.2828+0.j]], [[0.0000+0.j, 0.1414+0.j], [0.0000+0.j, 0.0000+0.j]], [[0.8485+0.j, 0.0000+0.j], [0.0000+0.j, 0.9487+0.j]], [[0.0000+0.j, 0.0000+0.j], [0.4243+0.j, 0.0000+0.j]]], dtype=torch.complex128)
- quairkit.database.phase_damping_kraus(gamma)¶
Kraus representation of a phase damping channel with form
\[\begin{split}E_0 = \begin{bmatrix} 1 & 0 \\ 0 & \sqrt{1-\gamma} \end{bmatrix}, E_1 = \begin{bmatrix} 0 & 0 \\ 0 & \sqrt{\gamma} \end{bmatrix}.\end{split}\]- Parameters:¶
- gamma : ndarray | Tensor | Iterable[float] | float¶
coefficient \(\gamma\).
- Returns:¶
a list of Kraus operators
- Return type:¶
List[ndarray | Tensor]
Examples
gamma = torch.tensor(0.2) kraus_operators = phase_damping_kraus(gamma) print(f'The Kraus operators are:\n{kraus_operators}')
The Kraus operators are: tensor([[[1.0000+0.j, 0.0000+0.j], [0.0000+0.j, 0.8944+0.j]], [[0.0000+0.j, 0.0000+0.j], [0.0000+0.j, 0.4472+0.j]]], dtype=torch.complex128)
- quairkit.database.depolarizing_kraus(prob)¶
Kraus representation of a depolarizing channel with form
\[E_0 = \sqrt{1-\frac{3p}{4}} I, E_1 = \sqrt{\frac{p}{4}} X, E_2 = \sqrt{\frac{p}{4}} Y, E_3 = \sqrt{\frac{p}{4}} Z.\]- Parameters:¶
- prob : ndarray | Tensor | Iterable[float] | float¶
probability \(p\).
- Returns:¶
a list of Kraus operators
- Return type:¶
List[ndarray | Tensor]
Examples
prob = torch.tensor(0.1) kraus_operators = depolarizing_kraus(prob) print(f'The Kraus operators are:\n{kraus_operators}')
The Kraus operators are: tensor([[[ 0.9618+0.0000j, 0.0000+0.0000j], [ 0.0000+0.0000j, 0.9618+0.0000j]], [[ 0.0000+0.0000j, 0.1581+0.0000j], [ 0.1581+0.0000j, 0.0000+0.0000j]], [[ 0.0000+0.0000j, 0.0000-0.1581j], [ 0.0000+0.1581j, 0.0000+0.0000j]], [[ 0.1581+0.0000j, 0.0000+0.0000j], [ 0.0000+0.0000j, -0.1581+0.0000j]]], dtype=torch.complex128)
- quairkit.database.generalized_depolarizing_kraus(prob, num_qubits)¶
Kraus representation of a generalized depolarizing channel with form
\[E_0 = \sqrt{1-\frac{(D-1)p}{D}} I, \text{ where } D = 4^n, E_k = \sqrt{\frac{p}{D}} \sigma_k, \text{ for } 0 < k < D.\]Examples
prob = torch.tensor(0.1) num_qubits = 1 kraus_operators = generalized_depolarizing_kraus(prob, num_qubits) print(f'The Kraus operators are:\n{kraus_operators}')
The Kraus operators are: tensor([[[ 1.3601+0.0000j, 0.0000+0.0000j], [ 0.0000+0.0000j, 1.3601+0.0000j]], [[ 0.0000+0.0000j, 0.2236+0.0000j], [ 0.2236+0.0000j, 0.0000+0.0000j]], [[ 0.0000+0.0000j, 0.0000-0.2236j], [ 0.0000+0.2236j, 0.0000+0.0000j]], [[ 0.2236+0.0000j, 0.0000+0.0000j], [ 0.0000+0.0000j, -0.2236+0.0000j]]])
- quairkit.database.pauli_kraus(prob)¶
Kraus representation of a pauli channel
- Parameters:¶
- prob : ndarray | Tensor | Iterable[float] | float¶
a list of three probabilities corresponding to X, Y, Z gate \(p\).
- Returns:¶
a list of Kraus operators
- Return type:¶
List[ndarray | Tensor]
Examples
prob_list = torch.tensor([0.1, 0.2, 0.3]) kraus_operators = pauli_kraus(prob_list) print(f'The Kraus operators are:\n{kraus_operators}')
The Kraus operators are: tensor([[[ 0.6325+0.0000j, 0.0000+0.0000j], [ 0.0000+0.0000j, 0.6325+0.0000j]], [[ 0.0000+0.0000j, 0.3162+0.0000j], [ 0.3162+0.0000j, 0.0000+0.0000j]], [[ 0.0000+0.0000j, 0.0000-0.4472j], [ 0.0000+0.4472j, 0.0000+0.0000j]], [[ 0.5477+0.0000j, 0.0000+0.0000j], [ 0.0000+0.0000j, -0.5477+0.0000j]]], dtype=torch.complex128)
- quairkit.database.reset_kraus(prob)¶
Kraus representation of a reset channel with form
\[\begin{split}E_0 = \begin{bmatrix} \sqrt{p} & 0 \\ 0 & 0 \end{bmatrix}, E_1 = \begin{bmatrix} 0 & \sqrt{p} \\ 0 & 0 \end{bmatrix},\\ E_2 = \begin{bmatrix} 0 & 0 \\ \sqrt{q} & 0 \end{bmatrix}, E_3 = \begin{bmatrix} 0 & 0 \\ 0 & \sqrt{q} \end{bmatrix},\\ E_4 = \sqrt{1-p-q} I.\end{split}\]- Parameters:¶
- prob : ndarray | Tensor | Iterable[float] | float¶
list of two probabilities of resetting to state \(|0\rangle\) and \(|1\rangle\).
- Returns:¶
a list of Kraus operators
- Return type:¶
List[ndarray | Tensor]
Examples
prob_list = torch.tensor([0.1, 0.2]) kraus_operators = reset_kraus(prob_list) print(f'The Kraus operators are:\n{kraus_operators}')
The Kraus operators are: tensor([[[0.3162+0.j, 0.0000+0.j], [0.0000+0.j, 0.0000+0.j]], [[0.0000+0.j, 0.3162+0.j], [0.0000+0.j, 0.0000+0.j]], [[0.0000+0.j, 0.0000+0.j], [0.4472+0.j, 0.0000+0.j]], [[0.0000+0.j, 0.0000+0.j], [0.0000+0.j, 0.4472+0.j]], [[0.8367+0.j, 0.0000+0.j], [0.0000+0.j, 0.8367+0.j]]], dtype=torch.complex128)
- quairkit.database.thermal_relaxation_kraus(const_t, exec_time)¶
Kraus representation of a thermal relaxation channel
Examples
const_t = torch.tensor([50, 30]) exec_time = torch.tensor([100]) kraus_operators = thermal_relaxation_kraus(const_t, exec_time) print(f'The Kraus operators are:\n{kraus_operators}')
The Kraus operators are: tensor([[[ 0.9987+0.j, 0.0000+0.j], [ 0.0000+0.j, 0.9987+0.j]], [[ 0.0258+0.j, 0.0000+0.j], [ 0.0000+0.j, -0.0258+0.j]], [[ 0.0447+0.j, 0.0000+0.j], [ 0.0000+0.j, 0.0000+0.j]], [[ 0.0000+0.j, 0.0447+0.j], [ 0.0000+0.j, 0.0000+0.j]]], dtype=torch.complex128)
- quairkit.database.replacement_choi(sigma)¶
Choi representation of a replacement channel
- Parameters:¶
- sigma : ndarray | Tensor | StateSimulator | StateOperator¶
output state of this channel.
- Returns:¶
a Choi operator.
- Return type:¶
ndarray | Tensor
Examples
sigma = torch.tensor([[0.8, 0.0], [0.0, 0.2]]) choi_operator = replacement_choi(sigma) print(f'The Choi operator is :\n{choi_operator}')
The Choi operator is : tensor([[0.8000+0.j, 0.0000+0.j, 0.0000+0.j, 0.0000+0.j], [0.0000+0.j, 0.2000+0.j, 0.0000+0.j, 0.0000+0.j], [0.0000+0.j, 0.0000+0.j, 0.8000+0.j, 0.0000+0.j], [0.0000+0.j, 0.0000+0.j, 0.0000+0.j, 0.2000+0.j]], dtype=torch.complex128)
- quairkit.database.pauli_basis(num_qubits)¶
Generate a Pauli basis.
- Parameters:¶
- num_qubits : int¶
the number of qubits \(n\).
- Returns:¶
The Pauli basis of \(\mathbb{C}^{2^n \times 2^n}\), where each tensor is accessible along the first dimension.
- Return type:¶
Tensor
Examples
num_qubits = 1 basis = pauli_basis(num_qubits) print(f'The Pauli basis is:\n{basis}')
The Pauli basis is: tensor([[[ 0.7071+0.0000j, 0.0000+0.0000j], [ 0.0000+0.0000j, 0.7071+0.0000j]], [[ 0.0000+0.0000j, 0.7071+0.0000j], [ 0.7071+0.0000j, 0.0000+0.0000j]], [[ 0.0000+0.0000j, 0.0000-0.7071j], [ 0.0000+0.7071j, 0.0000+0.0000j]], [[ 0.7071+0.0000j, 0.0000+0.0000j], [ 0.0000+0.0000j, -0.7071+0.0000j]]])
- quairkit.database.pauli_group(num_qubits)¶
Generate a Pauli group i.e., an unnormalized Pauli basis.
- Parameters:¶
- num_qubits : int¶
the number of qubits \(n\).
- Returns:¶
The Pauli group of \(\mathbb{C}^{2^n \times 2^n}\), where each tensor is accessible along the first dimension.
- Return type:¶
Tensor
Examples
num_qubits = 1 group = pauli_group(num_qubits) print(f'The Pauli group is:\n{group}')
The Pauli group is: tensor([[[ 1.0000+0.0000j, 0.0000+0.0000j], [ 0.0000+0.0000j, 1.0000+0.0000j]], [[ 0.0000+0.0000j, 1.0000+0.0000j], [ 1.0000+0.0000j, 0.0000+0.0000j]], [[ 0.0000+0.0000j, 0.0000-1.0000j], [ 0.0000+1.0000j, 0.0000+0.0000j]], [[ 1.0000+0.0000j, 0.0000+0.0000j], [ 0.0000+0.0000j, -1.0000+0.0000j]]])
- quairkit.database.pauli_str_basis(pauli_str)¶
Get the state basis with respect to the Pauli string.
- Parameters:¶
- pauli_str : str | List[str]¶
the string composed of ‘i’, ‘x’, ‘y’ and ‘z’ only.
- Returns:¶
The state basis of the observable given by the Pauli string.
- Return type:¶
StateSimulator
Examples
pauli_str = ['x', 'z'] state_basis = pauli_str_basis(pauli_str) print(f'The state basis of the observable is:\n{state_basis}')
The state basis of the observable is: --------------------------------------------------- Backend: state_vector System dimension: [2] System sequence: [0] Batch size: [2, 2] # 0: [0.71+0.j 0.71+0.j] # 1: [ 0.71+0.j -0.71+0.j] # 2: [1.+0.j 0.+0.j] # 3: [0.+0.j 1.+0.j] ---------------------------------------------------
- quairkit.database.pauli_str_povm(pauli_str)¶
Get the povm with respect to the Pauli string.
- Parameters:¶
- pauli_str : str | List[str]¶
the string composed of ‘i’, ‘x’, ‘y’ and ‘z’ only.
- Returns:¶
The POVM of the observable given by the Pauli string.
- Return type:¶
Tensor
Examples
pauli_str = ['x', 'y'] POVM = pauli_str_povm(pauli_str) print(f'The POVM of the observable is:\n{POVM}')
The POVM of the observable is: tensor([[[[ 0.5000+0.0000j, 0.5000+0.0000j], [ 0.5000+0.0000j, 0.5000+0.0000j]], [[ 0.5000+0.0000j, -0.5000+0.0000j], [-0.5000+0.0000j, 0.5000+0.0000j]]], [[[ 0.5000+0.0000j, 0.0000-0.5000j], [ 0.0000+0.5000j, 0.5000+0.0000j]], [[ 0.5000+0.0000j, 0.0000+0.5000j], [ 0.0000-0.5000j, 0.5000+0.0000j]]]])
- quairkit.database.qft_basis(num_qubits)¶
Compute the eigenvectors (eigenbasis) of the Quantum Fourier Transform (QFT) matrix.
- Parameters:¶
- num_qubits : int¶
Number of qubits \(n\) such that \(N = 2^n\).
- Returns:¶
A tensor where the first index gives the eigenvector of the QFT matrix.
- Return type:¶
StateSimulator
Examples
num_qubits = 2 qft_state = qft_basis(num_qubits) print(f'The eigenvectors of the QFT matrix is:\n{qft_state}')
The eigenvectors of the QFT matrix is: --------------------------------------------------- Backend: state_vector System dimension: [2] System sequence: [0] Batch size: [2] # 0: [0.92+0.j 0.38+0.j] # 1: [-0.38-0.j 0.92+0.j] ---------------------------------------------------
-
quairkit.database.std_basis(num_systems=
None
, system_dim=2
)¶ Generate all standard basis states for a given number of qubits.
- Parameters:¶
- Returns:¶
A tensor where the first index gives the computational vector.
- Return type:¶
StateSimulator
Examples
num_systems = 2 system_dim = [1, 2] basis = std_basis(num_systems, system_dim) print(f'The standard basis states are:\n{basis}')
The standard basis states are: --------------------------------------------------- Backend: state_vector System dimension: [1, 2] System sequence: [0, 1] Batch size: [2] # 0: [1.+0.j 0.+0.j] # 1: [0.+0.j 1.+0.j] ---------------------------------------------------
- quairkit.database.bell_basis()¶
Generate the Bell basis for a 2-qubit system, with each basis state accessible along the first dimension of a tensor.
- Returns:¶
A tensor of shape (4, 4, 1), representing the four Bell basis states.
- Return type:¶
StateSimulator
Examples
basis = bell_basis() print(f'The Bell basis for a 2-qubit system are:\n{basis}')
The Bell basis for a 2-qubit system are: --------------------------------------------------- Backend: state_vector System dimension: [2, 2] System sequence: [0, 1] Batch size: [4] # 0: [0.71+0.j 0. +0.j 0. +0.j 0.71+0.j] # 1: [ 0.71+0.j 0. +0.j 0. +0.j -0.71+0.j] # 2: [0. +0.j 0.71+0.j 0.71+0.j 0. +0.j] # 3: [ 0. +0.j 0.71+0.j -0.71+0.j 0. +0.j] ---------------------------------------------------
- quairkit.database.heisenberg_weyl(dim)¶
Generate Heisenberg-Weyl operator for qudit. The Heisenberg-Weyl operators are defined as \(T(a,b) = e^{-(d+1) \pi i a b/ d}Z^a X^b\).
- Parameters:¶
- dim : int¶
dimension of qudit
- Returns:¶
Heisenberg-Weyl operator for qudit.
- Return type:¶
Tensor
Examples
dim = 2 operator = heisenberg_weyl(dim) print(f'The Heisenberg-Weyl operator for qudit is:\n{operator}')
The Heisenberg-Weyl operator for qudit is: tensor([[[ 1.0000e+00+0.0000e+00j, 0.0000e+00+0.0000e+00j], [ 0.0000e+00+0.0000e+00j, 1.0000e+00+0.0000e+00j]], [[ 1.0000e+00+0.0000e+00j, 0.0000e+00+0.0000e+00j], [ 0.0000e+00+0.0000e+00j, -1.0000e+00+1.2246e-16j]], [[ 0.0000e+00+0.0000e+00j, 1.0000e+00+0.0000e+00j], [ 1.0000e+00+0.0000e+00j, 0.0000e+00+0.0000e+00j]], [[-0.0000e+00+0.0000e+00j, -1.8370e-16+1.0000e+00j], [ 6.1232e-17-1.0000e+00j, -0.0000e+00+0.0000e+00j]]])
- quairkit.database.phase_space_point(dim)¶
Generate phase space point operator for qudit.
- Parameters:¶
- dim : int¶
dimension of qudit
- Returns:¶
Phase space point operator for qudit.
- Return type:¶
Tensor
Examples
dim = 2 operator = phase_space_point(dim) print(f'The phase space point operator for qudit is:\n{operator}')
The phase space point operator for qudit is: tensor([[[ 1.0000+0.0000e+00j, 0.5000+5.0000e-01j], [ 0.5000-5.0000e-01j, 0.0000+6.1232e-17j]], [[ 1.0000+0.0000e+00j, -0.5000-5.0000e-01j], [-0.5000+5.0000e-01j, 0.0000+6.1232e-17j]], [[ 0.0000+6.1232e-17j, 0.5000-5.0000e-01j], [ 0.5000+5.0000e-01j, 1.0000+0.0000e+00j]], [[ 0.0000+6.1232e-17j, -0.5000+5.0000e-01j], [-0.5000-5.0000e-01j, 1.0000+0.0000e+00j]]])
- quairkit.database.gell_mann(dim)¶
Generate a set of Gell-Mann matrices for a given dimension. These matrices span the entire space of dim-by-dim matrices, and they generalize the Pauli operators when dim = 2 and the Gell-Mann operators when dim = 3.
- Parameters:¶
- dim : int¶
a positive integer indicating the dimension.
- Returns:¶
A set of Gell-Mann matrices.
- Return type:¶
Tensor
Examples
dim = 2 matrices = gell_mann(dim) print(f'The Gell-Mann matrices are:\n{matrices}')
The Gell-Mann matrices are: tensor([[[ 0.+0.j, 1.+0.j], [ 1.+0.j, 0.+0.j]], [[ 0.+0.j, -0.-1.j], [ 0.+1.j, 0.+0.j]], [[ 1.+0.j, 0.+0.j], [ 0.+0.j, -1.+0.j]]])
-
quairkit.database.zero_state(num_systems=
None
, system_dim=2
)¶ Generate a zero state.
Examples
num_systems = 2 system_dim = [2, 3] state = zero_state(num_systems, system_dim) print(f'The zero state is:\n{state}')
The zero state is: --------------------------------------------------- Backend: state_vector System dimension: [2, 3] System sequence: [0, 1] [1.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j] ---------------------------------------------------
-
quairkit.database.one_state(num_systems=
None
, system_dim=2
)¶ Generate a one state.
Examples
num_systems = 2 system_dim = [1, 3] state = one_state(num_systems, system_dim) print(f'The one state is:\n{state}')
The one state is: --------------------------------------------------- Backend: state_vector System dimension: [1, 3] System sequence: [0, 1] [0.+0.j 1.+0.j 0.+0.j] ---------------------------------------------------
-
quairkit.database.computational_state(num_systems=
None
, index=0
, system_dim=2
)¶ Generate a computational state \(|e_{i}\rangle\), whose i-th element is 1 and all the other elements are 0.
- Parameters:¶
- num_systems : int | None¶
Number of systems in this state. If None, inferred from system_dim. Alias of
num_qubits
.- index : int¶
Index \(i\) of the computational basis state \(|e_{i}\rangle\).
- system_dim : List[int] | int¶
Dimension of systems. Can be a list of system dimensions or an int representing the dimension of all systems. Defaults to qubit case.
- Returns:¶
The generated quantum state.
- Return type:¶
StateSimulator | StateOperator
Examples
num_systems = 2 system_dim = [2, 3] index = 4 state = computational_state(num_systems, index, system_dim) print(f'The state is:\n{state}')
The state is: --------------------------------------------------- Backend: state_vector System dimension: [2, 3] System sequence: [0, 1] [0.+0.j 0.+0.j 0.+0.j 0.+0.j 1.+0.j 0.+0.j] ---------------------------------------------------
-
quairkit.database.bell_state(num_systems=
None
, system_dim=2
)¶ Generate a Bell state.
Its matrix form is:
\[|\Phi_{D}\rangle=\frac{1}{\sqrt{D}} \sum_{j=0}^{D-1}|j\rangle_{A}|j\rangle_{B}\]Examples
num_systems = 2 system_dim = [2, 2] state = bell_state(num_systems, system_dim) print(f'The Bell state is:\n{state}')
The Bell state is: --------------------------------------------------- Backend: state_vector System dimension: [2, 2] System sequence: [0, 1] [0.71+0.j 0. +0.j 0. +0.j 0.71+0.j] ---------------------------------------------------
- quairkit.database.bell_diagonal_state(prob)¶
Generate a Bell diagonal state.
Its matrix form is:
\[p_{1}|\Phi^{+}\rangle\langle\Phi^{+}|+p_{2}|\Psi^{+}\rangle\langle\Psi^{+}|+p_{3}|\Phi^{-}\rangle\langle\Phi^{-}| + p_{4}|\Psi^{-}\rangle\langle\Psi^{-}|\]- Parameters:¶
- prob : List[float]¶
The probability of each Bell state.
- Raises:¶
Exception – The state should be a pure state if the backend is state_vector.
NotImplementedError – If the backend is wrong or not implemented.
- Returns:¶
The generated quantum state.
- Return type:¶
StateSimulator
Examples
prob = [0.2, 0.3, 0.4, 0.1] state = bell_diagonal_state(prob) print(f'The Bell diagonal state is:\n{state}')
The Bell diagonal state is: --------------------------------------------------- Backend: density_matrix System dimension: [2, 2] System sequence: [0, 1] [[ 0.3+0.j 0. +0.j 0. +0.j -0.1+0.j] [ 0. +0.j 0.2+0.j 0.1+0.j 0. +0.j] [ 0. +0.j 0.1+0.j 0.2+0.j 0. +0.j] [-0.1+0.j 0. +0.j 0. +0.j 0.3+0.j]] ---------------------------------------------------
- quairkit.database.w_state(num_qubits)¶
Generate a W-state.
- Parameters:¶
- num_qubits : int¶
The number of qubits in the quantum state.
- Raises:¶
NotImplementedError – If the backend is wrong or not implemented.
- Returns:¶
The generated quantum state.
- Return type:¶
StateSimulator | StateOperator
Examples
num_qubits = 2 w_state_inst = w_state(num_qubits) print(f'The W-state is:\n{w_state_inst}')
The W-state is: --------------------------------------------------- Backend: state_vector System dimension: [2, 2] System sequence: [0, 1] [0. +0.j 0.71+0.j 0.71+0.j 0. +0.j] ---------------------------------------------------
- quairkit.database.ghz_state(num_qubits)¶
Generate a GHZ-state.
- Parameters:¶
- num_qubits : int¶
The number of qubits in the quantum state.
- Raises:¶
NotImplementedError – If the backend is wrong or not implemented.
- Returns:¶
The generated quantum state.
- Return type:¶
StateSimulator | StateOperator
Examples
num_qubits = 2 ghz_state_inst = ghz_state(num_qubits) print(f'The GHZ-state is:\n{ghz_state_inst}')
The GHZ-state is: --------------------------------------------------- Backend: state_vector System dimension: [2, 2] System sequence: [0, 1] [0.71+0.j 0. +0.j 0. +0.j 0.71+0.j] ---------------------------------------------------
- quairkit.database.completely_mixed_computational(num_qubits)¶
Generate the density matrix of the completely mixed state.
- Parameters:¶
- num_qubits : int¶
The number of qubits in the quantum state.
- Raises:¶
Exception – The state should be a pure state if the backend is state_vector.
NotImplementedError – If the backend is wrong or not implemented.
- Returns:¶
The generated quantum state.
- Return type:¶
StateSimulator
Examples
num_qubits = 1 state = completely_mixed_computational(num_qubits) print(f'The density matrix of the completely mixed state is:\n{state}')
The density matrix of the completely mixed state is: --------------------------------------------------- Backend: density_matrix System dimension: [2] System sequence: [0] [[0.5+0.j 0. +0.j] [0. +0.j 0.5+0.j]] ---------------------------------------------------
- quairkit.database.r_state(prob)¶
Generate an R-state.
Its matrix form is:
\[p|\Psi^{+}\rangle\langle\Psi^{+}| + (1 - p)|11\rangle\langle11|\]- Parameters:¶
- prob : float¶
The parameter of the R-state to be generated. It should be in \([0,1]\).
- Raises:¶
Exception – The state should be a pure state if the backend is state_vector.
NotImplementedError – If the backend is wrong or not implemented.
- Returns:¶
The generated quantum state.
- Return type:¶
StateSimulator
Examples
prob = 0.5 r_state_inst = r_state(prob) print(f'The R-state is:\n{r_state_inst}')
The R-state is: --------------------------------------------------- Backend: density_matrix System dimension: [2, 2] System sequence: [0, 1] [[0. +0.j 0. +0.j 0. +0.j 0. +0.j] [0. +0.j 0.25+0.j 0.25+0.j 0. +0.j] [0. +0.j 0.25+0.j 0.25+0.j 0. +0.j] [0. +0.j 0. +0.j 0. +0.j 0.5 +0.j]] ---------------------------------------------------
- quairkit.database.s_state(prob)¶
Generate the S-state.
Its matrix form is:
\[p|\Phi^{+}\rangle\langle\Phi^{+}| + (1 - p)|00\rangle\langle00|\]- Parameters:¶
- prob : float¶
The parameter of the S-state to be generated. It should be in \([0,1]\).
- Raises:¶
Exception – The state should be a pure state if the backend is state_vector.
NotImplementedError – If the backend is wrong or not implemented.
- Returns:¶
The generated quantum state.
- Return type:¶
StateSimulator
Examples
prob = 0.5 s_state_inst = s_state(prob) print(f'The S-state is:\n{s_state_inst}')
The S-state is: --------------------------------------------------- Backend: density_matrix System dimension: [2, 2] System sequence: [0, 1] [[0.75+0.j 0. +0.j 0. +0.j 0.25+0.j] [0. +0.j 0. +0.j 0. +0.j 0. +0.j] [0. +0.j 0. +0.j 0. +0.j 0. +0.j] [0.25+0.j 0. +0.j 0. +0.j 0.25+0.j]] ---------------------------------------------------
- quairkit.database.isotropic_state(num_qubits, prob)¶
Generate the isotropic state.
Its matrix form is:
\[p\left(\frac{1}{\sqrt{D}} \sum_{j=0}^{D-1}|j\rangle_{A}|j\rangle_{B}\right) + (1 - p)\frac{I}{2^n}\]- Parameters:¶
- Raises:¶
Exception – The state should be a pure state if the backend is state_vector.
NotImplementedError – If the backend is wrong or not implemented.
- Returns:¶
The generated quantum state.
- Return type:¶
StateSimulator
Examples
num_qubits = 2 prob = 0.5 isotropic_state_inst = isotropic_state(num_qubits, prob) print(f'The isotropic state is:\n{isotropic_state_inst}')
The isotropic state is: --------------------------------------------------- Backend: density_matrix System dimension: [2, 2] System sequence: [0, 1] [[0.38+0.j 0. +0.j 0. +0.j 0.25+0.j] [0. +0.j 0.12+0.j 0. +0.j 0. +0.j] [0. +0.j 0. +0.j 0.12+0.j 0. +0.j] [0.25+0.j 0. +0.j 0. +0.j 0.38+0.j]] ---------------------------------------------------
- quairkit.database.hamiltonian
- quairkit.database.matrix
- quairkit.database.matrix.phase
- quairkit.database.matrix.shift
- quairkit.database.matrix.grover_matrix
- quairkit.database.matrix.qft_matrix
- quairkit.database.matrix.h
- quairkit.database.matrix.s
- quairkit.database.matrix.sdg
- quairkit.database.matrix.t
- quairkit.database.matrix.tdg
- quairkit.database.matrix.eye
- quairkit.database.matrix.x
- quairkit.database.matrix.y
- quairkit.database.matrix.z
- quairkit.database.matrix.p
- quairkit.database.matrix.rx
- quairkit.database.matrix.ry
- quairkit.database.matrix.rz
- quairkit.database.matrix.u3
- quairkit.database.matrix.cnot
- quairkit.database.matrix.cy
- quairkit.database.matrix.cz
- quairkit.database.matrix.swap
- quairkit.database.matrix.cp
- quairkit.database.matrix.crx
- quairkit.database.matrix.cry
- quairkit.database.matrix.crz
- quairkit.database.matrix.cu
- quairkit.database.matrix.rxx
- quairkit.database.matrix.ryy
- quairkit.database.matrix.rzz
- quairkit.database.matrix.ms
- quairkit.database.matrix.cswap
- quairkit.database.matrix.toffoli
- quairkit.database.matrix.ccx
- quairkit.database.matrix.universal2
- quairkit.database.matrix.universal3
- quairkit.database.matrix.universal_qudit
- quairkit.database.matrix.Uf
- quairkit.database.matrix.Of
- quairkit.database.matrix.permutation_matrix
- quairkit.database.matrix.phase_gate
- quairkit.database.matrix.shift_gate
- quairkit.database.matrix.h_gate
- quairkit.database.matrix.s_gate
- quairkit.database.matrix.sdg_gate
- quairkit.database.matrix.t_gate
- quairkit.database.matrix.tdg_gate
- quairkit.database.matrix.eye_gate
- quairkit.database.matrix.x_gate
- quairkit.database.matrix.y_gate
- quairkit.database.matrix.z_gate
- quairkit.database.matrix.p_gate
- quairkit.database.matrix.rx_gate
- quairkit.database.matrix.ry_gate
- quairkit.database.matrix.rz_gate
- quairkit.database.matrix.u3_gate
- quairkit.database.matrix.cnot_gate
- quairkit.database.matrix.cy_gate
- quairkit.database.matrix.cz_gate
- quairkit.database.matrix.swap_gate
- quairkit.database.matrix.cp_gate
- quairkit.database.matrix.crx_gate
- quairkit.database.matrix.cry_gate
- quairkit.database.matrix.crz_gate
- quairkit.database.matrix.cu_gate
- quairkit.database.matrix.rxx_gate
- quairkit.database.matrix.ryy_gate
- quairkit.database.matrix.rzz_gate
- quairkit.database.matrix.ms_gate
- quairkit.database.matrix.cswap_gate
- quairkit.database.matrix.toffoli_gate
- quairkit.database.matrix.ccx_gate
- quairkit.database.matrix.universal2_gate
- quairkit.database.matrix.universal3_gate
- quairkit.database.matrix.Uf_gate
- quairkit.database.matrix.Of_gate
- quairkit.database.random
- quairkit.database.random.random_pauli_str_generator
- quairkit.database.random.random_state
- quairkit.database.random.random_hamiltonian_generator
- quairkit.database.random.random_hermitian
- quairkit.database.random.random_projector
- quairkit.database.random.random_orthogonal_projection
- quairkit.database.random.random_density_matrix
- quairkit.database.random.random_unitary
- quairkit.database.random.random_unitary_hermitian
- quairkit.database.random.random_unitary_with_hermitian_block
- quairkit.database.random.random_lcu
- quairkit.database.random.haar_orthogonal
- quairkit.database.random.haar_unitary
- quairkit.database.random.haar_state_vector
- quairkit.database.random.haar_density_operator
- quairkit.database.random.random_channel
- quairkit.database.random.random_clifford
- quairkit.database.representation
- quairkit.database.representation.bit_flip_kraus
- quairkit.database.representation.phase_flip_kraus
- quairkit.database.representation.bit_phase_flip_kraus
- quairkit.database.representation.amplitude_damping_kraus
- quairkit.database.representation.generalized_amplitude_damping_kraus
- quairkit.database.representation.phase_damping_kraus
- quairkit.database.representation.depolarizing_kraus
- quairkit.database.representation.generalized_depolarizing_kraus
- quairkit.database.representation.pauli_kraus
- quairkit.database.representation.reset_kraus
- quairkit.database.representation.thermal_relaxation_kraus
- quairkit.database.representation.replacement_choi
- quairkit.database.set
- quairkit.database.set.pauli_basis
- quairkit.database.set.pauli_group
- quairkit.database.set.pauli_str_basis
- quairkit.database.set.pauli_str_povm
- quairkit.database.set.qft_basis
- quairkit.database.set.std_basis
- quairkit.database.set.bell_basis
- quairkit.database.set.heisenberg_weyl
- quairkit.database.set.phase_space_point
- quairkit.database.set.gell_mann
- quairkit.database.state
- quairkit.database.state.zero_state
- quairkit.database.state.one_state
- quairkit.database.state.computational_state
- quairkit.database.state.bell_state
- quairkit.database.state.bell_diagonal_state
- quairkit.database.state.w_state
- quairkit.database.state.ghz_state
- quairkit.database.state.completely_mixed_computational
- quairkit.database.state.r_state
- quairkit.database.state.s_state
- quairkit.database.state.isotropic_state