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

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))

Contents

Using PennyLane

Release news

Development

API

Internals