@@ -1645,6 +1645,7 @@ def reduced_density_matrix(
1645
1645
state: Union[Tensor, QuOperator],
1646
1646
cut: Union[int, List[int]],
1647
1647
p: Optional[Tensor] = None,
1648
+ normalize: bool = True,
1648
1649
) -> Union[Tensor, QuOperator]:
1649
1650
"""
1650
1651
Compute the reduced density matrix from the quantum state ``state``.
@@ -1658,6 +1659,7 @@ def reduced_density_matrix(
1658
1659
:type p: Optional[Tensor]
1659
1660
:return: The reduced density matrix.
1660
1661
:rtype: Union[Tensor, QuOperator]
1662
+ :normalize: if True, returns a trace 1 density matrix. Otherwise does not normalize.
1661
1663
"""
1662
1664
if isinstance(cut, list) or isinstance(cut, tuple) or isinstance(cut, set):
1663
1665
traceout = list(cut)
@@ -1700,7 +1702,9 @@ def reduced_density_matrix(
1700
1702
rho = backend.reshape(
1701
1703
rho, [2 ** (freedom - len(traceout)), 2 ** (freedom - len(traceout))]
1702
1704
)
1703
- rho /= backend.trace(rho)
1705
+ if normalize:
1706
+ rho /= backend.trace(rho)
1707
+
1704
1708
1705
1709
else:
1706
1710
w = state / backend.norm(state)
@@ -1715,7 +1719,9 @@ def reduced_density_matrix(
1715
1719
rho = w @ backend.adjoint(w)
1716
1720
else:
1717
1721
rho = w @ backend.diagflat(p) @ backend.adjoint(w)
1718
- rho /= backend.trace(rho)
1722
+ if normalize:
1723
+ rho /= backend.trace(rho)
1724
+
1719
1725
return rho
1720
1726
1721
1727
0 commit comments