quairkit.database.state¶
The library of common quantum states.
-
quairkit.database.state.zero_state(num_systems=
None, system_dim=2)¶ Generate a zero state \(|0\rangle^{\otimes n}\).
Examples
from quairkit.database import zero_state # Generate a 2-qubit zero state state = zero_state(2) print(f'2-qubit zero state:\n{state}')2-qubit zero state: --------------------------------------------------- Backend: state_vector System dimension: [2, 2] System sequence: [0, 1] [1.+0.j 0.+0.j 0.+0.j 0.+0.j] ---------------------------------------------------# Generate a qubit-qutrit zero state state = zero_state(2, system_dim=[2, 3]) print(f'Qubit-qutrit zero state:\n{state}')Qubit-qutrit zero state: --------------------------------------------------- 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.state.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.state.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.state.bell_state(num_systems=
None, system_dim=2)¶ Generate a Bell state (maximally entangled state).
Its matrix form is:
\[|\Phi_{D}\rangle=\frac{1}{\sqrt{D}} \sum_{j=0}^{D-1}|j\rangle_{A}|j\rangle_{B}\]where \(D\) is the dimension of each subsystem.
- Parameters:¶
- Returns:¶
The generated quantum state.
- Raises:¶
AssertionError – If the number of systems is not even.
- Return type:¶
StateSimulator | StateOperator
Examples
from quairkit.database import bell_state # Generate a 2-qubit Bell state state = bell_state(2) print(f'2-qubit Bell state:\n{state}')2-qubit Bell state: --------------------------------------------------- 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] ---------------------------------------------------# Generate a 4-qubit Bell state (two Bell pairs) state = bell_state(4) print(f'4-qubit Bell state:\n{state}')4-qubit Bell state: --------------------------------------------------- Backend: state_vector System dimension: [2, 2, 2, 2] System sequence: [0, 1, 2, 3] [0.5+0.j 0.+0.j ... 0.5+0.j] ---------------------------------------------------
- quairkit.database.state.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.state.w_state(num_qubits)¶
Generate a W-state \(|W_n\rangle = \frac{1}{\sqrt{n}}(|10...0\rangle + |01...0\rangle + ... + |00...1\rangle)\).
The W-state is a symmetric superposition of all states with exactly one qubit in state \(|1\rangle\).
- Parameters:¶
- num_qubits : int¶
The number of qubits in the quantum state. Must be at least 1.
- Returns:¶
The generated W-state.
- Raises:¶
NotImplementedError – If the backend is wrong or not implemented.
- Return type:¶
StateSimulator | StateOperator
Examples
from quairkit.database import w_state # Generate a 3-qubit W-state state = w_state(3) print(f'3-qubit W-state:\n{state}')3-qubit W-state: --------------------------------------------------- Backend: state_vector System dimension: [2, 2, 2] System sequence: [0, 1, 2] [0. +0.j 0.58+0.j 0.58+0.j 0. +0.j 0.58+0.j 0. +0.j 0. +0.j 0. +0.j] ---------------------------------------------------
- quairkit.database.state.ghz_state(num_qubits)¶
Generate a GHZ-state (Greenberger-Horne-Zeilinger state).
The GHZ-state is \(|GHZ_n\rangle = \frac{1}{\sqrt{2}}(|0\rangle^{\otimes n} + |1\rangle^{\otimes n})\).
- Parameters:¶
- num_qubits : int¶
The number of qubits in the quantum state. Must be at least 2.
- Returns:¶
The generated GHZ-state.
- Raises:¶
NotImplementedError – If the backend is wrong or not implemented.
- Return type:¶
StateSimulator | StateOperator
Examples
from quairkit.database import ghz_state # Generate a 3-qubit GHZ-state state = ghz_state(3) print(f'3-qubit GHZ-state:\n{state}')3-qubit GHZ-state: --------------------------------------------------- Backend: state_vector System dimension: [2, 2, 2] System sequence: [0, 1, 2] [0.71+0.j 0. +0.j 0. +0.j 0. +0.j 0. +0.j 0. +0.j 0. +0.j 0.71+0.j] ---------------------------------------------------
- quairkit.database.state.completely_mixed_computational(num_qubits)¶
Generate the density matrix of the completely mixed state \(\rho = I/2^n\).
The completely mixed state is the maximally mixed state with maximum von Neumann entropy.
- Parameters:¶
- num_qubits : int¶
The number of qubits in the quantum state.
- Returns:¶
The generated completely mixed quantum state (density matrix).
- Raises:¶
Exception – The state should be a pure state if the backend is state_vector.
NotImplementedError – If the backend is wrong or not implemented.
- Return type:¶
StateSimulator
Examples
from quairkit.database import completely_mixed_computational # Generate a 2-qubit completely mixed state state = completely_mixed_computational(2) print(f'2-qubit completely mixed state:\n{state}')2-qubit completely mixed state: --------------------------------------------------- Backend: density_matrix System dimension: [2, 2] System sequence: [0, 1] [[0.25+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. +0.j 0. +0.j 0.25+0.j 0. +0.j] [0. +0.j 0. +0.j 0. +0.j 0.25+0.j]] ---------------------------------------------------
- quairkit.database.state.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.state.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.state.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]] ---------------------------------------------------