qrisp.operators.fermionic.FermionicOperator.get_measurement#

FermionicOperator.get_measurement(qarg, mapping_type='jordan_wigner', **measurement_kwargs)[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.

mapping_typestr

The strategy on how to map the FermionicOperator to a QubitOperator. Default is jordan_wigner

measurement_kwargsdict

The keyword arguments of QubitOperator.get_measurement().

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 create a FermionicOperator and perform a measurement.

>>> from qrisp.operators import *
>>> from qrisp import QuantumVariable
>>> qv = QuantumVariable(4)
>>> O = a(0)*a(1) + a(2)*c(1) + c(2)*a(3)
>>> print(O.get_measurement(qv))
-0.007968127490039834