qrisp.QuantumVariable.get_measurement#
- QuantumVariable.get_measurement(plot=False, backend=None, shots=None, compile=True, compilation_kwargs={}, subs_dic={}, circuit_preprocessor=None, filename=None, precompiled_qc=None) DecodedMeasurementResult[source]#
Get the measurement results of the state of the variable.
Method for quick access to the measurement results of the state of the variable. Returns a
DecodedMeasurementResult, which behaves like a dictionary of the type{value: p}wherepis the measurement probability.- Parameters:
- plotBool, optional
Plots the measurement results as a historgram. The default is False.
- backendBackendLike, optional
The backend on which to evaluate the quantum circuit. The default can be specified in the file default_backend.py.
- shotsinteger, optional
The amount of shots to evaluate the circuit. The default is given by the backend it runs on.
- 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 {}.
- circuit_preprocessorPython function, optional
A function which recieves a QuantumCircuit and returns one, which is applied after compilation and parameter substitution. The default is None.
- filenamestring, optional
The location of where to save a generated plot. The default is None.
- precompiled_qcQuantumCircuit, optional
A circuit that has already been compiled from the containing QuantumSession. If given, it is used (as a copy) instead of compiling the session, and
compileandcompilation_kwargsare ignored. Parameter binding andcircuit_preprocessorare still applied. The circuit must contain the qubits of this QuantumVariable. The default is None.
- Returns:
- DecodedMeasurementResult
A lazy
DecodedMeasurementResultmapping each decoded value to its measurement probability.
- Raises:
- Exception
If the containing QuantumSession is in a quantum environment, it is not possible to execute measurements.
- TracingModeError
If the QuantumVariable is registered in a
TracingQuantumSession(i.e. while tracing), measurements are not supported.
Examples
We create an integer QuantumFloat, encode the value 1 and bring the qubit with significance 2 in superposition. We utilize the Qiskit transpiler by transpiling into the gate set \(\{\text{CX}, \text{U}\}\)
>>> from qrisp import QuantumFloat, h >>> qf = QuantumFloat(3,-1) >>> qf[:] = 1 >>> h(qf[2]) >>> mes_results = qf.get_measurement(circuit_preprocessor=lambda qc: qc.transpile(basis_gates=["cx", "u"])) >>> print(mes_results) {1.0: 0.5, 3.0: 0.5}