qml.devices.qubit.simulate¶
- simulate(circuit, debugger=None, state_cache=None, **execution_kwargs)[source]¶
Simulate a single quantum script.
This is an internal function that is used by``default.qubit``.
- Parameters
circuit (QuantumTape) – The single circuit to simulate
debugger (_Debugger) – The debugger to use
state_cache=None (Optional[dict]) – A dictionary mapping the hash of a circuit to the pre-rotated state. Used to pass the state between forward passes and vjp calculations.
rng (Optional[numpy.random._generator.Generator]) – A NumPy random number generator.
prng_key (Optional[jax.random.PRNGKey]) – An optional
jax.random.PRNGKey
. This is the key to the JAX pseudo random number generator. If None, a random key will be generated. Only for simulation using JAX.interface (str) – The machine learning interface to create the initial state with
postselect_mode (str) – Configuration for handling shots with mid-circuit measurement postselection. Use
"hw-like"
to discard invalid shots and"fill-shots"
to keep the same number of shots. Default isNone
.mcm_method (str) – Strategy to use when executing circuits with mid-circuit measurements.
"deferred"
is ignored. If mid-circuit measurements are found in the circuit, the device will use"tree-traversal"
if specified and the"one-shot"
method otherwise. For usage details, please refer to the dynamic quantum circuits page.
- Returns
The results of the simulation
- Return type
tuple(TensorLike)
Note that this function can return measurements for non-commuting observables simultaneously.
This function assumes that all operations provide matrices.
>>> qs = qml.tape.QuantumScript([qml.RX(1.2, wires=0)], [qml.expval(qml.Z(0)), qml.probs(wires=(0,1))]) >>> simulate(qs) (0.36235775447667357, tensor([0.68117888, 0. , 0.31882112, 0. ], requires_grad=True))