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)[source]#
Method for quick access to the measurement results of the state of the variable. This method returns a dictionary of the type {value : p} where p indicates the probability with which that value is measured.
- Parameters:
- plotBool, optional
Plots the measurement results as a historgram. The default is False.
- 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 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.
- Returns:
- dict
A dictionary of values and their corresponding measurement probabilities.
- Raises:
- Exception
If the containing QuantumSession is in a quantum environment, it is not possible to execute measurements.
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(transpilation_kwargs = {"basis_gates" : ["cx", "u"]}) # noqa:501 >>> print(mes_results) {1.0: 0.5, 3.0: 0.5}