qrisp.operators.qubit.QubitOperator.get_measurement#
- QubitOperator.get_measurement(qarg, precision=0.01, backend=None, shots=1000000, compile=True, compilation_kwargs={}, subs_dic={}, precompiled_qc=None, diagonalisation_method='commuting_qw', measurement_data=None)[source]#
This method returns the expected value of a Hamiltonian for the state of a quantum argument. Note that this method measures the hermitized version of the operator:
\[H = (O + O^\dagger)/2\]- Parameters:
- qargQuantumVariable or list[Qubit]
The quantum argument to evaluate the Hamiltonian on.
- precision: float, optional
The precision with which the expectation of the Hamiltonian is to be evaluated. The default is 0.01. The number of shots scales quadratically with the inverse precision.
- backendBackendClient, optional
The backend on which to evaluate the quantum circuit. The default can be specified in the file default_backend.py.
- shotsinteger, optional
The maximum amount of shots to evaluate the expectation of the Hamiltonian. The default is 1000000.
- compilebool, optional
Boolean indicating if the .compile method of the underlying QuantumSession should be called before. The default is True.
- compilation_kwargsdict, optional
Keyword arguments for the compile method. For more details check
QuantumSession.compile
. The default is{}
.- subs_dicdict, optional
A dictionary of Sympy symbols and floats to specify parameters in the case of a circuit with unspecified, abstract parameters. The default is {}.
- precompiled_qcQuantumCircuit, optional
A precompiled quantum circuit.
- measurement_dataQubitOperatorMeasurement
Cached data to accelerate the measurement procedure. Automatically generated by default.
- Returns:
- float
The expected value of the Hamiltonian.
- Raises:
- Exception
If the containing QuantumSession is in a quantum environment, it is not possible to execute measurements.
Examples
We define a Hamiltonian, and measure its expected value for the state of a QuantumVariable.
from qrisp import QuantumVariable, h from qrisp.operators.qubit import X,Y,Z qv = QuantumVariable(2) h(qv) H = Z(0)*Z(1) res = H.get_measurement(qv) print(res) #Yields 0.0011251406425802912