Skip to content

Commit

Permalink
Removing qml.from_qasm_file from source code and tests (#5659)
Browse files Browse the repository at this point in the history
**Context:** ***Part of  deprecations and removals for pennylane-0.37***

**Description of the Change:** Removed `qml.from_qasm_file` in favor of
more specific functions.

[sc-58985]
  • Loading branch information
PietropaoloFrisoni authored May 7, 2024
1 parent 420c72b commit 9b13456
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 56 deletions.
10 changes: 5 additions & 5 deletions doc/development/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ Other deprecations
- Deprecated in v0.36
- Will be removed in v0.37

* ``qml.from_qasm_file`` is deprecated. Instead, the user can open the file and then load its content using ``qml.from_qasm``.
Completed deprecation cycles
----------------------------

* ``qml.from_qasm_file`` has been removed. Instead, the user can open the file and then load its content using ``qml.from_qasm``.

>>> with open("test.qasm", "r") as f:
... circuit = qml.from_qasm(f.read())

- Deprecated in v0.36
- Will be removed in v0.37

Completed deprecation cycles
----------------------------
- Removed in v0.37

* The ``qml.load`` function is a general-purpose way to convert circuits into PennyLane from other
libraries. It has been removed in favour of the more specific functions ``from_qiskit``, ``from_qasm``, etc.
Expand Down
1 change: 0 additions & 1 deletion doc/introduction/circuits.rst
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ be loaded by using the following functions:

~pennylane.from_qiskit
~pennylane.from_qasm
~pennylane.from_qasm_file
~pennylane.from_pyquil
~pennylane.from_quil
~pennylane.from_quil_file
Expand Down
1 change: 0 additions & 1 deletion doc/introduction/importing_workflows.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ differentiate and optimize the circuit using :ref:`quantum-specific optimizers <

~pennylane.from_pyquil
~pennylane.from_qasm
~pennylane.from_qasm_file
~pennylane.from_qiskit
~pennylane.from_quil
~pennylane.from_quil_file
Expand Down
3 changes: 3 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@

<h3>Breaking changes 💔</h3>

* ``qml.from_qasm_file`` has been removed. The user can open files and load their content using `qml.from_qasm`.
[(#5659)](https://github.com/PennyLaneAI/pennylane/pull/5659)

* ``qml.load`` has been removed in favour of more specific functions, such as ``qml.from_qiskit``, etc.
[(#5654)](https://github.com/PennyLaneAI/pennylane/pull/5654)

Expand Down
40 changes: 0 additions & 40 deletions pennylane/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@
This module contains functions to load circuits from other frameworks as
PennyLane templates.
"""
import warnings
from collections import defaultdict
from importlib import metadata
from sys import version_info

import pennylane as qml

# Error message to show when the PennyLane-Qiskit plugin is required but missing.
_MISSING_QISKIT_PLUGIN_MESSAGE = (
"Conversion from Qiskit requires the PennyLane-Qiskit plugin. "
Expand Down Expand Up @@ -450,43 +447,6 @@ def from_qasm(quantum_circuit: str):
return plugin_converter(quantum_circuit)


def from_qasm_file(qasm_filename: str):
"""Loads quantum circuits from a QASM file using the converter in the
PennyLane-Qiskit plugin.
**Example:**
>>> my_circuit = qml.from_qasm_file("hadamard_circuit.qasm")
The ``my_circuit`` template can now be used within QNodes, as a
two-wire quantum template.
>>> @qml.qnode(dev)
>>> def circuit(x):
>>> qml.RX(x, wires=1)
>>> my_circuit(wires=(1, 0))
>>> return qml.expval(qml.Z(0))
Args:
qasm_filename (str): path to a QASM file containing a valid quantum circuit
Returns:
function: the PennyLane template created based on the QASM file
.. warning::
qml.from_qasm_file is deprecated and will be removed in a future release.
Please use qml.from_qasm instead.
"""
warnings.warn(
"qml.from_qasm_file is deprecated and will be removed in a future release. "
"Please use qml.from_qasm instead.",
qml.PennyLaneDeprecationWarning,
)
plugin_converter = plugin_converters["qasm_file"].load()
return plugin_converter(qasm_filename)


def from_pyquil(pyquil_program):
"""Loads pyQuil Program objects by using the converter in the
PennyLane-Rigetti plugin.
Expand Down
10 changes: 1 addition & 9 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"""
Unit tests for the :mod:`pennylane.io` module.
"""
from unittest.mock import Mock, mock_open, patch
from unittest.mock import Mock

import pytest

Expand Down Expand Up @@ -109,14 +109,6 @@ def test_qiskit_converter_load_fails(self, monkeypatch, method, entry_point_name
with pytest.raises(ValueError, match=r"Some Other Error"):
method("Test")

def test_from_qasm_file_deprecated(self, monkeypatch):
"""Tests that qml.from_qasm_file is deprecated."""
mock_converter_dict = {entry: MockPluginConverter(entry) for entry in load_entry_points}
monkeypatch.setattr(qml.io, "plugin_converters", mock_converter_dict)
with pytest.warns(qml.PennyLaneDeprecationWarning, match="deprecated"):
with patch("builtins.open", mock_open(read_data="Test")):
_ = qml.from_qasm_file("test.qasm")

@pytest.mark.parametrize(
"method, entry_point_name",
[
Expand Down

0 comments on commit 9b13456

Please sign in to comment.