qml.density_matrix

density_matrix(wires)[source]

Quantum density matrix in the computational basis.

This function accepts no observables and instead instructs the QNode to return its density matrix or reduced density matrix. The wires argument gives the possibility to trace out a part of the system. It can result in obtaining a mixed state, which can be only represented by the reduced density matrix.

Parameters

wires (Sequence[int] or int) – the wires of the subsystem

Returns

Measurement process instance

Return type

DensityMatrixMP

Example:

dev = qml.device("default.qubit", wires=2)

@qml.qnode(dev)
def circuit():
    qml.Y(0)
    qml.Hadamard(wires=1)
    return qml.density_matrix([0])

Executing this QNode:

>>> circuit()
array([[0.+0.j 0.+0.j]
    [0.+0.j 1.+0.j]])

The returned matrix is the reduced density matrix, where system 1 is traced out.

Note

Calculating the derivative of density_matrix() is currently only supported when using the classical backpropagation differentiation method (diff_method="backprop") with a compatible device.

Contents

Using PennyLane

Development

API

Internals