vn_entropy(tape, wires, base=None, **kwargs)[source]

Compute the Von Neumann entropy from a QuantumTape returning a state().

\[S( \rho ) = -\text{Tr}( \rho \log ( \rho ))\]
  • tape (QNode or QuantumTape or Callable) – A quantum circuit returning a state().

  • wires (Sequence(int)) – List of wires in the considered subsystem.

  • base (float) – Base for the logarithm, default is None the natural logarithm is used in this case.


The transformed circuit as described in qml.transform. Executing this circuit will provide the Von Neumann entropy in the form of a tensor.

Return type

qnode (QNode) or quantum function (Callable) or tuple[List[QuantumTape], function]


It is possible to obtain the entropy of a subsystem from a QNode returning a state().

dev = qml.device("default.qubit", wires=2)
def circuit(x):
    qml.IsingXX(x, wires=[0, 1])
    return qml.state()
>>> vn_entropy(circuit, wires=[0])(np.pi/2)

The function is differentiable with backpropagation for all interfaces, e.g.:

>>> param = np.array(np.pi/4, requires_grad=True)
>>> qml.grad(vn_entropy(circuit, wires=[0]))(param)
tensor(0.62322524, requires_grad=True)