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

Apply an operation to a given state.

  • 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


output state

Return type



apply_operation is an internal function, and thus subject to change without a deprecation cycle.


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:

def _(op: type_op, state):
    # custom op application method here


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