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

move draw and draw_mpl to drawer module #2396

Merged
merged 9 commits into from
Mar 31, 2022
Merged
18 changes: 7 additions & 11 deletions doc/code/qml_drawer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ of circuits.

.. currentmodule:: pennylane.drawer

.. automodapi:: pennylane.drawer
:no-heading:
:no-inheritance-diagram:
:no-inherited-members:
:skip: available_styles
:skip: use_style

Styling Matplotlib Circuit Graphics
-----------------------------------

Expand Down Expand Up @@ -50,14 +57,3 @@ Currently Available Styles
+-----+-----+-----+
+|bws|+|bwd|+|def|+
+-----+-----+-----+


Developer Methods
-----------------

.. automodapi:: pennylane.drawer
Comment on lines -55 to -58
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come this was changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

draw and draw_mpl are not developer methods. In fact, they're the most important methods of the module, so I thought it would be important to move them to the top.

I think tape_text and tape_mpl are on the boundary between user-facing and developer-only. They have quite a bit of use for anyone working primarily with tapes instead of just qnodes.

:no-heading:
:no-inheritance-diagram:
:no-inherited-members:
:skip: available_styles
:skip: use_style
4 changes: 4 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@
* Circuit cutting now performs expansion to search for wire cuts in contained operations or tapes.
[(#2340)](https://github.com/PennyLaneAI/pennylane/pull/2340)

* The `qml.draw` and `qml.draw_mpl` transforms are now located in the `drawer` module. They can still be
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be considered a breaking change? It shouldn't have any user facing ramifications.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What comes to mind is that it could be breaking if there were occurrences of qml.transforms.draw anywhere in our codebase or in user code.

accessed via the top-level `qml` namespace.
[(#2396)](https://github.com/PennyLaneAI/pennylane/pull/2396)

<h3>Deprecations</h3>

<h3>Breaking changes</h3>
Expand Down
3 changes: 1 addition & 2 deletions pennylane/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from pennylane.about import about
from pennylane.circuit_graph import CircuitGraph
from pennylane.configuration import Configuration
from pennylane.drawer import draw, draw_mpl
from pennylane.tracker import Tracker
from pennylane.io import *
from pennylane.measurements import density_matrix, measure, expval, probs, sample, state, var
Expand All @@ -58,8 +59,6 @@
batch_input,
batch_transform,
cut_circuit,
draw,
draw_mpl,
ControlledOperation,
compile,
ctrl,
Expand Down
5 changes: 2 additions & 3 deletions pennylane/drawer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
"""
This module provides the circuit drawing functionality used to display circuits visually.

.. currentmodule:: pennylane.circuit_drawer
.. currentmodule:: pennylane.drawer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come this name changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name changed happened a few months ago. Seems like this line just slipped through that PR.

.. autosummary::
:toctree: api

"""

from .draw import draw, draw_mpl
from .tape_text import tape_text
from .tape_mpl import tape_mpl
from .mpldrawer import MPLDrawer
from .drawable_layers import drawable_layers
from .utils import convert_wire_order
Comment on lines -26 to -27
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two methods are only accessed internally by tape_text and tape_mpl. I don't see a reason we need to make them accessible from here.

from .style import available_styles, use_style
3 changes: 2 additions & 1 deletion pennylane/transforms/draw.py → pennylane/drawer/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"""
from functools import wraps

from pennylane.drawer import tape_mpl, tape_text
from .tape_mpl import tape_mpl
from .tape_text import tape_text


def draw(
Expand Down
3 changes: 0 additions & 3 deletions pennylane/transforms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
~transforms.classical_jacobian
~batch_params
~batch_input
~draw
~draw_mpl
~transforms.get_unitary_matrix
~metric_tensor
~adjoint_metric_tensor
Expand Down Expand Up @@ -177,7 +175,6 @@
from .control import ControlledOperation, ctrl
from .decompositions import zyz_decomposition, two_qubit_decomposition
from .defer_measurements import defer_measurements
from .draw import draw, draw_mpl
from .hamiltonian_expand import hamiltonian_expand
from .measurement_grouping import measurement_grouping
from .metric_tensor import metric_tensor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import pennylane as qml
from pennylane import numpy as np

from pennylane.transforms import draw
from pennylane.drawer import draw


@qml.qnode(qml.device("default.qubit", wires=(0, "a", 1.234)))
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion tests/test_qnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import pennylane as qml
from pennylane import numpy as pnp
from pennylane import qnode, QNode
from pennylane.transforms import draw
from pennylane.tape import QuantumTape


Expand Down