Skip to content

Commit

Permalink
Merge branch 'master' into qutrit_channel_depolarizing
Browse files Browse the repository at this point in the history
  • Loading branch information
glassnotes authored May 7, 2024
2 parents 998d21d + 9b13456 commit e098c4e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 131 deletions.
15 changes: 7 additions & 8 deletions doc/development/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,22 @@ 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
- Removed in v0.37

* The ``qml.load`` function is a general-purpose way to convert circuits into PennyLane from other
libraries. It is being deprecated in favour of the more specific functions ``from_qiskit``,
``from_qasm``, etc.
libraries. It has been removed in favour of the more specific functions ``from_qiskit``, ``from_qasm``, etc.

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

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

* ``single_tape_transform``, ``batch_transform``, ``qfunc_transform``, ``op_transform``,
``gradient_transform`` and ``hessian_transform`` are deprecated. Instead switch to using the new
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
6 changes: 6 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@

<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)

<h3>Deprecations 👋</h3>

<h3>Documentation 📝</h3>
Expand Down
105 changes: 0 additions & 105 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 All @@ -40,71 +37,6 @@
plugin_converters = {entry.name: entry for entry in __plugin_devices}


def load(quantum_circuit_object, format: str, **load_kwargs):
r"""Load external quantum assembly and quantum circuits from supported frameworks
into PennyLane templates.
.. warning::
``qml.load`` is deprecated. Instead, please use the functions outlined in the
:ref:`Importing Circuits <intro_ref_importing_circuits>` quickstart guide, such as ``qml.from_qiskit``.
.. note::
For more details on which formats are supported
please consult the corresponding plugin documentation:
https://pennylane.ai/plugins.html
**Example:**
>>> qc = qiskit.QuantumCircuit(2)
>>> qc.rz(0.543, [0])
>>> qc.cx(0, 1)
>>> my_circuit = qml.load(qc, format='qiskit')
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:
quantum_circuit_object: the quantum circuit that will be converted
to a PennyLane template
format (str): the format of the quantum circuit object to convert from
**load_kwargs: keyword arguments to pass when converting the quantum circuit
using the plugin. See below for details about supported keyword arguments.
Keyword Args:
measurements (list[MeasurementProcess]): the list of PennyLane measurements that
overrides the terminal measurements that may be present in the imput circuit.
Currently, only supported for Qiskit's `QuantumCircuit <https://docs.pennylane.ai/projects/qiskit>`_.
Returns:
function: the PennyLane template created from the quantum circuit object
"""

_format = "pyquil" if format == "pyquil_program" else format
warnings.warn(
f"qml.load() is deprecated. Instead, please use the more specific qml.from_{_format}()",
qml.PennyLaneDeprecationWarning,
)

if format in plugin_converters:
# loads the plugin load function
plugin_converter = plugin_converters[format].load()
# calls the load function of the converter on the quantum circuit object
return plugin_converter(quantum_circuit_object, **load_kwargs)

raise ValueError(
"Converter does not exist. Make sure the required plugin is installed "
"and supports conversion."
)


def from_qiskit(quantum_circuit, measurements=None):
r"""Converts a Qiskit `QuantumCircuit <https://docs.quantum.ibm.com/api/qiskit/qiskit.circuit.QuantumCircuit>`_
into a PennyLane :ref:`quantum function <intro_vcirc_qfunc>`.
Expand Down Expand Up @@ -515,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
17 changes: 1 addition & 16 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 @@ -73,13 +73,6 @@ def mock_plugin_converters_fixture(monkeypatch):
class TestLoad:
"""Test that the convenience load functions access the correct entrypoint."""

def test_load_is_deprecated(self, monkeypatch):
"""Test that qml.load 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"):
_ = qml.load("test", format="qiskit")

@pytest.mark.parametrize(
"method, entry_point_name",
[(qml.from_qiskit, "qiskit"), (qml.from_qiskit_op, "qiskit_op")],
Expand Down Expand Up @@ -116,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 e098c4e

Please sign in to comment.