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

Raise DeprecationWarning only when the qasm code contains measurements #5904

Merged
merged 4 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions doc/development/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ Pending deprecations
- Will be removed in v0.38

* ``qml.from_qasm`` will no longer remove measurements from the QASM code. Calling ``qml.from_qasm``
without specifying ``measurements`` will raise a deprecation warning in v0.37, and in v0.38,
the default behaviour will be changed to keeping measurements. Use ``measurements=[]`` to remove
measurements from the original circuit.
on a circuit containing measurements without specifying ``measurements`` will raise a deprecation
warning in v0.37, and in v0.38, the default behaviour will be changed to keeping measurements. Use
``measurements=[]`` to remove measurements from the original circuit.

- Deprecated in v0.37
- Default behaviour will be changed in v0.38
Expand Down
2 changes: 1 addition & 1 deletion doc/releases/changelog-0.37.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@
* The `qml.data` module now supports PyTree data types as dataset attributes
[(#5732)](https://github.com/PennyLaneAI/pennylane/pull/5732)


* `qml.ops.Conditional` now inherits from `qml.ops.SymbolicOp`, thus it inherits several useful common functionalities. Other properties such as adjoint and diagonalizing gates have been added using the `base` properties.
[(##5772)](https://github.com/PennyLaneAI/pennylane/pull/5772)

Expand Down Expand Up @@ -416,6 +415,7 @@

* The default behaviour of `qml.from_qasm()` to remove measurements in the QASM code is deprecated. Use `measurements=[]` to keep this behaviour or `measurements=None` to keep the measurements from the QASM code.
[(#5882)](https://github.com/PennyLaneAI/pennylane/pull/5882)
[(#5904)](https://github.com/PennyLaneAI/pennylane/pull/5904)

<h3>Documentation 📝</h3>

Expand Down
15 changes: 8 additions & 7 deletions pennylane/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,14 +505,15 @@ def circuit():
"""
plugin_converter = plugin_converters["qasm"].load()
if measurements is False:
warnings.warn(
"The current default behaviour of removing measurements in the QASM code is "
"deprecated. Set measurements=None to keep the existing measurements in the QASM "
"code or set measurements=[] to remove them from the returned circuit. Starting "
"in version 0.38, measurements=None will be the new default.",
qml.PennyLaneDeprecationWarning,
)
measurements = []
if "measure" in quantum_circuit:
warnings.warn(
"The current default behaviour of removing measurements in the QASM code "
"is deprecated. Set measurements=None to keep existing measurements in the QASM "
"code or set measurements=[] to remove them from the returned circuit. Starting "
"in version 0.38, measurements=None will be the new default.",
qml.PennyLaneDeprecationWarning,
)
return plugin_converter(quantum_circuit, measurements=measurements)


Expand Down
6 changes: 3 additions & 3 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def test_convenience_functions(self, method, entry_point_name, mock_plugin_conve
def test_from_qasm(self, mock_plugin_converters):
"""Tests that the correct entry point is called for from_qasm."""

qml.from_qasm("Test", measurements=None)
qml.from_qasm("Test")
astralcai marked this conversation as resolved.
Show resolved Hide resolved
assert mock_plugin_converters["qasm"].called
assert mock_plugin_converters["qasm"].last_args == ("Test",)

Expand All @@ -149,10 +149,10 @@ def test_from_qasm_deprecated(self, mock_plugin_converters):
"""Tests that the current default behaviour of from_qasm is deprecated."""

with pytest.warns(qml.PennyLaneDeprecationWarning, match="The current default behaviour"):
qml.from_qasm("Test")
qml.from_qasm("measure q[i] -> c[i];")

called_args, called_kwargs = mock_plugin_converters["qasm"].call_args
assert called_args == ("Test",)
assert called_args == ("measure q[i] -> c[i];",)
assert called_kwargs == {"measurements": []}
dwierichs marked this conversation as resolved.
Show resolved Hide resolved

@pytest.mark.parametrize(
Expand Down
Loading