qml.qinfo.transforms.reduced_dm¶
- reduced_dm(tape, wires, **kwargs)[source]¶
Compute the reduced density matrix from a
QNode
returningstate()
.Warning
The
qml.qinfo.reduced_dm
transform is deprecated and will be removed in v0.40. Instead, include thepennylane.density_matrix()
measurement process in the return line of your QNode.- Parameters
tape (QuantumTape or QNode or Callable)) – A quantum circuit returning
state()
.wires (Sequence(int)) – List of wires in the considered subsystem.
- Returns
The transformed circuit as described in
qml.transform
. Executing this circuit will provide the reduced density matrix in the form of a tensor.- Return type
qnode (QNode) or quantum function (Callable) or tuple[List[QuantumTape], function]
Example
import numpy as np dev = qml.device("default.qubit", wires=2) @qml.qnode(dev) def circuit(x): qml.IsingXX(x, wires=[0,1]) return qml.state()
>>> transformed_circuit = reduced_dm(circuit, wires=[0]) >>> transformed_circuit(np.pi/2) tensor([[0.5+0.j, 0. +0.j], [0. +0.j, 0.5+0.j]], requires_grad=True)
This is equivalent to the state of the wire
0
after measuring the wire1
:@qml.qnode(dev) def measured_circuit(x): qml.IsingXX(x, wires=[0,1]) m = qml.measure(1) return qml.density_matrix(wires=[0]), qml.probs(op=m)
>>> dm, probs = measured_circuit(np.pi/2) >>> dm tensor([[0.5+0.j, 0. +0.j], [0. +0.j, 0.5+0.j]], requires_grad=True) >>> probs tensor([0.5, 0.5], requires_grad=True)
See also