qp.math.partial_trace¶
- partial_trace(matrix, indices, c_dtype='complex128')[source]¶
Compute the reduced density matrix by tracing out the provided indices.
- Parameters:
matrix (tensor_like) – 2D or 3D density matrix tensor. For a 2D tensor, the size is assumed to be
(2**n, 2**n), for some integer number of wiresn. For a 3D tensor, the first dimension is assumed to be the batch dimension,(batch_dim, 2**N, 2**N).indices (list(int)) – List of indices to be traced.
- Returns:
(reduced) Density matrix of size
(2**len(wires), 2**len(wires))- Return type:
tensor_like
Example
We can compute the partial trace of the matrix
xwith respect to its 0th index.>>> x = np.array([[1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]) >>> partial_trace(x, indices=[0]) array([[1.+0.j, 0.+0.j], [0.+0.j, 0.+0.j]])
We can also pass a batch of matrices
xto the function and return the partial trace of each matrix with respect to each matrix’s 0th index.>>> 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]] ... ]) >>> partial_trace(x, indices=[0]) 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]]])