quairkit.database.state

The library of common quantum states.

quairkit.database.state.zero_state(num_systems, system_dim=2)

Generate a zero state.

Parameters:
num_systems : int

Number of systems in this state. Alias of num_qubits.

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:

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.state.one_state(num_systems, system_dim=2)

Generate a one state.

Parameters:
num_systems : int

Number of systems in this state. Alias of num_qubits.

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:

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, index, 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

Number of systems in this state. 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:

State

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, 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}\]
Parameters:
num_systems : int

Number of systems in this state. Alias of num_qubits.

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:

State

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.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:

State

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.

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:

State

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.state.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:

State

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.state.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:

State

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.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:

State

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:

State

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:
num_qubits : int

The number of qubits in the quantum state.

prob : float

The parameter of the isotropic 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:

State

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]]
---------------------------------------------------