Graph.partial_trace(density_matrix, subsystem_dimensions, traced_subsystems, *, name=None)

Calculate the partial trace of a density matrix.


  • density_matrix (np.ndarray or Tensor) – The density matrix ρ\rho(..., D, D).
  • subsystem_dimensions (list [ int ]) – The dimension of each subsystem. The product of the subsystem dimensions is the dimension of the system D.
  • traced_subsystems (int or list [ int ]) – The indices (starting from zero) of the subsystems to be traced out. Each index refers to a different subsystem.
  • name (str or None , optional) – The name of the node.


The reduced density matrix of shape (..., d, d). The reduced dimension d is equal to the system dimension D divided by the product of the traced out subsystem dimensions.

Return type



Given a density matrix ρ\rho of two subsystems AA and BB, the partial trace over subsystem BB

(TrBρ)ij=kρik,jk. ({\mathrm{Tr}_{B}} \rho)_{ij} = \sum_k \rho_{ik,jk}.

For more information about the partial trace, see partial trace on Wikipedia.


>>> graph.partial_trace(np.diag([1, 0, 0, 0]), [2, 2], 1, name="partial")
<Tensor: name="partial", operation_name="partial_trace", shape=(2, 2)>
>>> result = bo.execute_graph(graph=graph, output_node_names="partial")
>>> result["output"]["partial"]["value"]
array([[[1, 0], [0, 0]])
>>> graph.partial_trace(np.eye(10)/10, [2, 5], 1, name="partial2")
<Tensor: name="partial2", operation_name="partial_trace", shape=(2, 2)>
>>> result = bo.execute_graph(graph=graph, output_node_names="partial2")
>>> result["output"]["partial2"]["value"]
array([[[0.5, 0], [0, 0.5]])

See more examples in the How to simulate large open system dynamics user guide.

Was this useful?