Skip to content

Commit

Permalink
Removing qml.load
Browse files Browse the repository at this point in the history
  • Loading branch information
PietropaoloFrisoni committed May 6, 2024
1 parent 8707c57 commit 9365929
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 77 deletions.
10 changes: 5 additions & 5 deletions doc/development/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ Other deprecations
- Deprecated in v0.36
- Will be removed in v0.37

Completed deprecation cycles
----------------------------

* 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``,
libraries. It has been deprecated 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
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>

* The ``qml.load`` has been deprecated in favour of the more specific functions.
[(#...)](https://github.com/PennyLaneAI/pennylane/pull/...)

<h3>Deprecations 👋</h3>

<h3>Documentation 📝</h3>
Expand Down
65 changes: 0 additions & 65 deletions pennylane/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,71 +40,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
7 changes: 0 additions & 7 deletions tests/test_io.py
Original file line number Diff line number Diff line change
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

0 comments on commit 9365929

Please sign in to comment.