qml.devices.qubit_mixed.apply_operation¶
- apply_operation(op, state, is_state_batched=False, debugger=None, **_)[source]¶
Apply an operation to a given state.
- Parameters
op (Operator) – The operation to apply to
state
state (TensorLike) – The starting state.
is_state_batched (bool) – Boolean representing whether the state is batched or not.
debugger (_Debugger) – The debugger to use.
- Keyword Arguments
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. Only for simulation using JAX. If None, anumpy.random.default_rng
will be used for sampling.tape_shots (Shots) – The shots object of the tape.
- Returns
The output state.
- Return type
ndarray
Warning
apply_operation
is an internal function, and thus subject to change without a deprecation cycle.Warning
apply_operation
applies no validation to its inputs.This function assumes that the wires of the operator correspond to indices of the state. See
map_wires()
to convert operations to integer wire labels.The shape of the state should be
[2] * (num_wires * 2)
(the original tensor form) or[2**num_wires, 2**num_wires]
(the expanded matrix form), where2
is the dimension of the system.This is a
functools.singledispatch
function, so additional specialized kernels for specific operations can be registered like:@apply_operation.register def _(op: type_op, state, is_state_batched=False, **kwargs): # custom op application method here
Example:
>>> state = np.zeros((2, 2, 2, 2)) >>> state[0][0][0][0] = 1 >>> state array([[[[1., 0.], [0., 0.]], [[0., 0.], [0., 0.]]], [[[0., 0.], [0., 0.]], [[0., 0.], [0., 0.]]]]) >>> apply_operation(qml.PauliX(0), state) array([[[[0., 0.], [0., 0.]], [[0., 0.], [0., 0.]]], [[[0., 0.], [1., 0.]], [[0., 0.], [0., 0.]]]])