Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QInfo broadcasting (1/3)] Support for qml.math density matrix functions #4173

Merged
merged 14 commits into from
May 26, 2023
5 changes: 5 additions & 0 deletions doc/development/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ Pending deprecations
- Still accessible in v0.31
- Removed in v0.32

* ``qml.math.reduced_dm`` has been deprecated. Please use ``qml.math.reduce_dm`` or ``qml.math.reduce_statevector`` instead.

- Still accessible in v0.31
- Removed in v0.32

* The ``qml.specs`` dictionary will no longer support direct key access to certain keys. Instead
these quantities can be accessed as fields of the new ``Resources`` object saved under
``specs_dict["resources"]``:
Expand Down
5 changes: 5 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@
and now inherits from `qml.ops.op_math.ControlledOp`.
[(#4116)](https://github.com/PennyLaneAI/pennylane/pull/4116/)

* Added support for broadcasting in `qml.math.reduce_dm` and `qml.math.reduce_statevector`.
eddddddy marked this conversation as resolved.
Show resolved Hide resolved
[(#4173)](https://github.com/PennyLaneAI/pennylane/pull/4173)

<h3>Breaking changes 💔</h3>

Expand Down Expand Up @@ -176,6 +178,9 @@

* `qml.grouping` module is removed. The functionality has been reorganized in the `qml.pauli` module.

* `qml.math.reduced_dm` has been deprecated. Please use `qml.math.reduce_dm` or `qml.math.reduce_statevector` instead.
[(#4173)](https://github.com/PennyLaneAI/pennylane/pull/4173)

<h3>Documentation 📝</h3>

* The description of `mult` in the `qchem.Molecule` docstring now correctly states the value
Expand Down
2 changes: 1 addition & 1 deletion pennylane/_qubit_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,7 @@ def density_matrix(self, wires):
"""
state = getattr(self, "state", None)
wires = self.map_wires(wires)
return qml.math.reduced_dm(state, indices=wires, c_dtype=self.C_DTYPE)
return qml.math.reduce_statevector(state, indices=wires, c_dtype=self.C_DTYPE)

def vn_entropy(self, wires, log_base):
r"""Returns the Von Neumann entropy prior to measurement.
Expand Down
14 changes: 14 additions & 0 deletions pennylane/devices/default_mixed.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,20 @@ def state(self):
# User obtains state as a matrix
return qnp.reshape(self._pre_rotated_state, (dim, dim))

def density_matrix(self, wires):
"""Returns the reduced density matrix over the given wires.

Args:
wires (Wires): wires of the reduced system

Returns:
array[complex]: complex array of shape ``(2 ** len(wires), 2 ** len(wires))``
representing the reduced density matrix of the state prior to measurement.
"""
state = getattr(self, "state", None)
wires = self.map_wires(wires)
return qml.math.reduce_dm(state, indices=wires, c_dtype=self.C_DTYPE)

def reset(self):
"""Resets the device"""
super().reset()
Expand Down
2 changes: 2 additions & 0 deletions pennylane/math/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
mutual_info,
purity,
reduced_dm,
reduce_dm,
reduce_statevector,
relative_entropy,
sqrt_matrix,
vn_entropy,
Expand Down
Loading