paddle_quantum.state.common

The common function of the quantum state.

paddle_quantum.state.common.to_state(data, num_qubits=None, backend=None, dtype=None)

The function to generate a specified state instance.

Parameters:
  • data (Tensor | ndarray | QEnv) – The analytical form of quantum state.

  • num_qubits (int | None) – The number of qubits contained in the quantum state. Defaults to None, which means it will be inferred by the data.

  • backend (Backend | None) – Used to specify the backend used. Defaults to None, which means to use the default backend.

  • dtype (str | None) – Used to specify the data dtype of the data. Defaults to None, which means to use the default data type.

Returns:

The generated quantum state.

Return type:

State

paddle_quantum.state.common.zero_state(num_qubits, backend=None, dtype=None)

The function to generate a zero state.

Parameters:
  • num_qubits (int) – The number of qubits contained in the quantum state.

  • backend (Backend | None) – Used to specify the backend used. Defaults to None, which means to use the default backend.

  • dtype (str | None) – Used to specify the data dtype of the data. Defaults to None, which means to use the default data type.

Raises:

NotImplementedError – If the backend is wrong or not implemented.

Returns:

The generated quantum state.

Return type:

State

paddle_quantum.state.common.computational_basis(num_qubits, index, backend=None, dtype=None)

Generate a computational basis state \(|e_{i}\rangle\) , whose i-th element is 1 and all the other elements are 0.

Parameters:
  • num_qubits (int) – The number of qubits contained in the quantum state.

  • index (int) – Index \(i\) of the computational basis state :math`|e_{i}rangle` .

  • backend (Backend | None) – Used to specify the backend used. Defaults to None, which means to use the default backend.

  • dtype (str | None) – Used to specify the data dtype of the data. Defaults to None, which means to use the default data type.

Raises:

NotImplementedError – If the backend is wrong or not implemented.

Returns:

The generated quantum state.

Return type:

State

paddle_quantum.state.common.bell_state(num_qubits, backend=None)

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_qubits (int) – The number of qubits contained in the quantum state.

  • backend (Backend | None) – Used to specify the backend used. Defaults to None, which means to use the default backend.

Raises:

NotImplementedError – If the backend is wrong or not implemented.

Returns:

The generated quantum state.

Return type:

State

paddle_quantum.state.common.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 prob 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

paddle_quantum.state.common.random_state(num_qubits, is_real=False, rank=None)

Generate a random quantum state.

Parameters:
  • num_qubits (int) – The number of qubits contained in the quantum state.

  • is_real (bool | None) – If the quantum state only contains the real number. Defaults to False.

  • rank (int | None) – The rank of the density matrix. Defaults to None which means full rank.

Raises:

NotImplementedError – If the backend is wrong or not implemented.

Returns:

The generated quantum state.

Return type:

State

paddle_quantum.state.common.w_state(num_qubits)

Generate a W-state.

Parameters:

num_qubits (int) – The number of qubits contained in the quantum state.

Raises:

NotImplementedError – If the backend is wrong or not implemented.

Returns:

The generated quantum state.

Return type:

State

paddle_quantum.state.common.ghz_state(num_qubits)

Generate a GHZ-state.

Parameters:

num_qubits (int) – The number of qubits contained in the quantum state.

Raises:

NotImplementedError – If the backend is wrong or not implemented.

Returns:

The generated quantum state.

Return type:

State

paddle_quantum.state.common.completely_mixed_computational(num_qubits)

Generate the density matrix of the completely mixed state.

Parameters:

num_qubits (int) – The number of qubits contained 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

paddle_quantum.state.common.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

paddle_quantum.state.common.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

paddle_quantum.state.common.isotropic_state(num_qubits, prob)

Generate the isotropic state.

Its matrix form is:

\[p(\frac{1}{\sqrt{D}} \sum_{j=0}^{D-1}|j\rangle_{A}|j\rangle_{B}) + (1 - p)\frac{I}{2^n}\]
Parameters:
  • num_qubits (int) – The number of qubits contained 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