# partial_trace

Source: https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/partial_trace

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

Calculate the partial trace of a density matrix.

### Parameters
* **density_matrix** (*np.ndarray* *or* [*Tensor*](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Tensor.md#boulderopal.graph.Tensor)) – The density matrix $\rho$ of the system to be reduced.
  Can be a single square matrix or a batch of matrices
  with dimension `(..., 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.
### Returns
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
[Tensor](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Tensor.md#boulderopal.graph.Tensor)

## Notes

Given a density matrix $\rho$ of two subsystems $A$
and $B$, the partial trace over subsystem $B$ is defined as

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

For more information about the partial trace, see [partial trace](https://en.wikipedia.org/wiki/Partial_trace) on Wikipedia.

## Examples

```pycon
>>> 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]])
```

```pycon
>>> 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](https://docs.q-ctrl.com/boulder-opal/user-guides/how-to-simulate-large-open-system-dynamics) user guide.
