quairkit.loss.measure¶
The source file of the class for the measurement.
-
class quairkit.loss.measure.Measure(measure_op=
None
)¶ Compute the probability of the specified measurement result.
- Parameters:¶
- measure_op : str | List[str] | Tensor | None¶
Specify the basis of the measurement. Defaults to
'computational'
.
Note
the allowable input for measure_op are: - None, i.e., a ‘computational’ basis - a string composed of ‘i’, ‘x’, ‘y’, and ‘z’ - a projection-valued measurement (PVM) in torch.Tensor
-
forward(state, system_idx=
'full'
, desired_result=None
, keep_state=False
)¶ Compute the probability of measurement to the input state.
- Parameters:¶
- state : State¶
The quantum state to be measured.
- system_idx : Iterable[int] | int | str | None¶
The index of the systems to be measured. Defaults to
'full'
which means measure all the qubits.- desired_result : List[int | str] | int | str | None¶
Specify the results of the measurement to return. Defaults to
None
which means return the probability of all the results.- keep_state : bool | None¶
Whether return the measured state. Defaults to
False
.
- Returns:¶
The probability of the measurement.
- Return type:¶
Tensor | Tuple[Tensor, State] | Tuple[Dict, State]
- class quairkit.loss.measure.ExpecVal(hamiltonian)¶
The class of the loss function to compute the expectation value for the observable.
This interface can make you using the expectation value for the observable as the loss function.
- Parameters:¶
- hamiltonian : Hamiltonian¶
The input observable.
-
forward(state, decompose=
False
)¶ Compute the expectation value of the observable with respect to the input state.
The value computed by this function can be used as a loss function to optimize.