partial_trace

partial_trace(matrix, sub_dims, keep)

Compute the partial trace of a matrix. The matrix may be a multidimensional array, with the partial trace taken over the last two dimensions.

Parameters:
  • matrix (ndarray | Array) – The input matrix to compute the partial trace of.

  • sub_dims (List[int]) – The dimensions of the subsystems.

  • keep (list) – Indices of the subsystems to keep.

Return type:

ndarray | Array

Returns:

The resulting matrix after tracing out the specified subsystems.

Raises:

SimphonyError – If the matrix does not have at least two dimensions, is not square in its last two dimensions, or if the subdimensions do not match the matrix size.