# qml.math.reduce_dm¶

reduce_dm(density_matrix, indices, check_state=False, c_dtype='complex128')[source]

Compute the density matrix from a state represented with a density matrix.

Parameters
• density_matrix (tensor_like) – 2D or 3D density matrix tensor. This tensor should be of size (2**N, 2**N) or (batch_dim, 2**N, 2**N), for some integer number of wiresN.

• indices (list(int)) – List of indices in the considered subsystem.

• check_state (bool) – If True, the function will check the state validity (shape and norm).

• c_dtype (str) – Complex floating point precision type.

Returns

Density matrix of size (2**len(indices), 2**len(indices)) or (batch_dim, 2**len(indices), 2**len(indices))

Return type

tensor_like

Example

>>> x = np.array([[1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]])
>>> reduce_dm(x, indices=[0])
[[1.+0.j 0.+0.j]
[0.+0.j 0.+0.j]]

>>> y = [[0.5, 0, 0.5, 0], [0, 0, 0, 0], [0.5, 0, 0.5, 0], [0, 0, 0, 0]]
>>> reduce_dm(y, indices=[0])
[[0.5+0.j 0.5+0.j]
[0.5+0.j 0.5+0.j]]

>>> reduce_dm(y, indices=[1])
[[1.+0.j 0.+0.j]
[0.+0.j 0.+0.j]]

>>> z = tf.Variable([[1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], dtype=tf.complex128)
>>> reduce_dm(x, indices=[1])
tf.Tensor(
[[1.+0.j 0.+0.j]
[0.+0.j 0.+0.j]], shape=(2, 2), dtype=complex128)

>>> x = np.array([[[1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],
...               [[0, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]])
>>> reduce_dm(x, indices=[1])
array([[[1.+0.j, 0.+0.j],
[0.+0.j, 0.+0.j]],
[[0.+0.j, 0.+0.j],
[0.+0.j, 1.+0.j]]])