qml.devices.qutrit_mixed.apply_operation

apply_operation(op, state, is_state_batched=False, debugger=None, **_)[source]
apply_operation(op, state, is_state_batched=False, debugger=None, **execution_kwargs)
apply_operation(op, state, is_state_batched=False, debugger=None, **_)

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, a numpy.random.default_rng will be used for sampling.

  • tape_shots (Shots) – the shots object of the tape

Returns

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 state should be [QUDIT_DIM]*(num_wires * 2), where QUDIT_DIM 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):
    # custom op application method here

Example:

>>> state = np.zeros((3,3))
>>> state[0][0] = 1
>>> state
tensor([[1., 0., 0.],
    [0., 0., 0.],
    [0., 0., 0.]], requires_grad=True)
>>> apply_operation(qml.TShift(0), state)
tensor([[0., 0., 0.],
    [0., 1., 0],
    [0., 0., 0.],], requires_grad=True)

Contents

Using PennyLane

Release news

Development

API

Internals