paddle_quantum.state.state
The basic class of the quantum state.
- class paddle_quantum.state.state.State(data, num_qubits=None, backend=None, dtype=None, override=False)
Bases:
object
The quantum state class.
- Parameters:
data (Tensor | ndarray | QEnv) – The mathematical analysis 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.override (bool | None) – whether override the input test. ONLY for internal use. Defaults to
False
.
- Raises:
ValueError – Cannot recognize the backend.
- property ket: Tensor
Return the ket form in state_vector backend
- Raises:
ValueError – the backend must be in StateVector
- Returns:
ket form of the state
- property bra: Tensor
Return the bra form in state_vector backend
- Raises:
ValueError – the backend must be in StateVector
- Returns:
bra form of the state
- normalize()
Normalize this state
- Raises:
NotImplementedError – does not support normalization for the backend
- evolve(H, t)
Evolve the state under the Hamiltonian H i.e. apply unitary operator \(e^{-itH}\)
- Parameters:
H (ndarray | Tensor | Hamiltonian) – the Hamiltonian of the system
t (float) – the evolution time
- Raises:
NotImplementedError – does not support evolution for the backend
- kron(other)
Kronecker product between states
- numpy()
Get the data in numpy.
- Returns:
The numpy array of the data for the quantum state.
- Return type:
ndarray
- to(backend, dtype=None, device=None, blocking=None)
Change the property of the state.
- Parameters:
backend (str) – Specify the new backend of the state.
dtype (str | None) – Specify the new data type of the state.
device (str | None) – Specify the new device of the state.
blocking (str | None) – Specify the new blocking of the state.
- Raises
NotImplementedError: only support transformation between StateVector and DensityMatrix NotImplementedError: Transformation for device or blocking is not supported.
- clone()
Return a copy of the quantum state.
- Returns:
A new state which is identical to this state.
- Return type:
- property oper_history: List[Dict[str, str | List[int] | Tensor]]
The operator history stored for the QPU backend
- Raises:
NotImplementedError – This property should be called for the backend
quleaf
only.ValueError – This state does not have operator history: run the circuit first.
- expec_val(hamiltonian, shots=0)
The expectation value of the observable with respect to the quantum state.
- Parameters:
hamiltonian (Hamiltonian) – Input observable.
shots (int | None) – Number of measurement shots.
- Raises:
NotImplementedError – If the backend is wrong or not implemented.
- Returns:
The expectation value of the input observable for the quantum state.
- Return type:
float
- measure(shots=0, qubits_idx=None, plot=False, record=False)
Measure the quantum state
- Parameters:
shots (int | None) – the number of measurements on the quantum state output by the quantum circuit. Default is
0
, which means the exact probability distribution of measurement results are returned.qubits_idx (Iterable[int] | int | None) – The index of the qubit to be measured. Defaults to
None
, which means all qubits are measured.plot (bool | None) – Whether to draw the measurement result plot. Defaults to
False
which means no plot.record (bool | None) – Whether to return the original measurement record. Defaults to
False
which means no record.
- Raises:
ValueError – The number of shots should be greater than 0.
NotImplementedError – When the backend is Quleaf, record is not supprted .
NotImplementedError – If the backend is wrong or not implemented.
NotImplementedError – The qubit index is wrong or not supported.
ValueError – Returning records requires the number of shots to be greater than 0.
- Returns:
Measurement results
- Return type:
dict