-
Notifications
You must be signed in to change notification settings - Fork 575
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
Add matplotlib style configuration for circuit drawing #1811
Merged
Merged
Changes from all commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
bef8060
add mpl drawer styles
albi3ro 0384d9c
Merge branch 'master' into drawer_styles
albi3ro 6e5a4e3
inverted style, tests
albi3ro 1f71430
Merge branch 'master' into drawer_styles
albi3ro cd694dc
Merge branch 'master' into drawer_styles
albi3ro aa11e19
Merge branch 'master' into drawer_styles
albi3ro 23796d5
Merge branch 'master' into drawer_styles
albi3ro d9084a9
dark own function, docs
albi3ro 682451a
Merge branch 'master' into drawer_styles
albi3ro b00d86d
doc for available attribute
albi3ro e6cb360
Merge branch 'master' into drawer_styles
albi3ro 69aa552
renaming, black, tests
albi3ro 42adc1b
reset styles at end of tests
albi3ro 7d3eacc
fix documentation
albi3ro 3648b6f
changelog
albi3ro 3acc771
Merge branch 'master' into drawer_styles
Jaybsoni 8ac6424
Merge branch 'master' into drawer_styles
albi3ro 93910e3
Merge branch 'master' into drawer_styles
Jaybsoni 2e27556
styles to style, add use and context functions
albi3ro 5c4d206
Merge branch 'drawer_styles' of https://github.com/PennyLaneAI/pennyl…
albi3ro 239f2ba
Merge branch 'master' into drawer_styles
Jaybsoni bf8f4d7
structural changes
albi3ro d10ee07
Merge branch 'drawer_styles' of https://github.com/PennyLaneAI/pennyl…
albi3ro 66f9ed0
merge
albi3ro 5188ceb
Merge branch 'master' into drawer_styles
albi3ro 6b1e5a9
some doc changes
albi3ro 3ba7dee
merge master
albi3ro 4eb731c
change the api again
albi3ro 2666454
did that fix the problem?
albi3ro cf72baf
Merge branch 'master' into drawer_styles
albi3ro 8cbe404
tests, more docs
albi3ro 1dbe78f
Merge branch 'master' into drawer_styles
albi3ro 4de1eee
trying something else
albi3ro 65d88d6
Merge branch 'master' into drawer_styles
albi3ro daff796
Merge branch 'master' into drawer_styles
albi3ro f54bdcc
trying something else
albi3ro aa81454
Merge branch 'master' into drawer_styles
albi3ro 19ea66f
Merge branch 'master' into drawer_styles
albi3ro f24ea26
trying this instead
albi3ro 27a9365
images in a table
albi3ro 0f40f13
remove image scaling, add title to graphs
albi3ro 2091844
Merge branch 'master' into drawer_styles
albi3ro 6d4efe0
hopefully this finally works
albi3ro 6db4256
I do not understand how width works
albi3ro c8eceb3
size tables the same , test coverage
albi3ro a9655c1
Merge branch 'master' into drawer_styles
albi3ro 29d1a2d
fix test, black
albi3ro e2f248f
Merge branch 'master' into drawer_styles
albi3ro 75560c5
Merge branch 'master' into drawer_styles
Jaybsoni 5e2e238
Merge branch 'master' into drawer_styles
Jaybsoni 582ee74
Merge branch 'master' into drawer_styles
Jaybsoni f9df22d
Update pennylane/drawer/tape_mpl.py
albi3ro 12d72a0
Merge branch 'master' into drawer_styles
albi3ro 8790b99
improved phrasing
albi3ro 03ef9f4
Merge branch 'drawer_styles' of https://github.com/PennyLaneAI/pennyl…
albi3ro 8a55ddd
more docstring changes
albi3ro 875eedd
Merge branch 'master' into drawer_styles
albi3ro 5fa9f1f
Merge branch 'master' into drawer_styles
albi3ro fb9fb65
updated images
albi3ro ba5224b
more image fixing
albi3ro 386e9b7
Merge branch 'master' into drawer_styles
Jaybsoni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Copyright 2018-2021 Xanadu Quantum Technologies Inc. | ||
|
||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
|
||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
""" | ||
This file automatically generates and saves a series of example pictures for the | ||
circuit drawer. This will be useful during early stages when the project is still | ||
undergoing cosmetic changes. | ||
""" | ||
|
||
import pathlib | ||
import matplotlib.pyplot as plt | ||
|
||
import pennylane as qml | ||
import matplotlib.pyplot as plt | ||
|
||
folder = pathlib.Path(__file__).parent | ||
|
||
def make_imag(circuit, style): | ||
qml.drawer.use_style(style) | ||
|
||
fig, ax = qml.draw_mpl(circuit)(1.2345,1.2345) | ||
fig.suptitle(style, fontsize='xx-large') | ||
|
||
plt.savefig(folder / (style + "_style.png")) | ||
plt.close() | ||
qml.drawer.use_style('default') | ||
|
||
if __name__ == "__main__": | ||
|
||
dev = qml.device('lightning.qubit', wires=(0,1,2,3)) | ||
@qml.qnode(dev) | ||
def circuit(x, z): | ||
qml.QFT(wires=(0,1,2,3)) | ||
qml.Toffoli(wires=(0,1,2)) | ||
qml.CSWAP(wires=(0,2,3)) | ||
qml.RX(x, wires=0) | ||
qml.CRZ(z, wires=(3,0)) | ||
return qml.expval(qml.PauliZ(0)) | ||
|
||
for style in qml.drawer.available_styles(): | ||
make_imag(circuit, style) | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,63 @@ | ||
qml.drawer | ||
========== | ||
|
||
The ``drawer`` module contains the code for generating visuals | ||
of circuits. | ||
|
||
.. currentmodule:: pennylane.drawer | ||
|
||
.. warning:: | ||
Styling Matplotlib Circuit Graphics | ||
----------------------------------- | ||
|
||
The ``drawer`` module provides two functions for modifying the style of matplotlib | ||
graphics, such as those generated by ``qml.draw_mpl``. The ``qml.drawer.use_style`` | ||
function modifies the ``plt.rcParams`` global styling variable. Any styling can | ||
be reset with ``qml.drawer.use_style('default')`` or ``plt.style.use('default')``. | ||
|
||
.. autosummary:: | ||
:toctree: api | ||
|
||
available_styles | ||
use_style | ||
|
||
The following images are generated via the code: | ||
|
||
.. code-block:: python | ||
|
||
@qml.qnode(qml.device('lightning.qubit', wires=(0,1,2,3))) | ||
def circuit(x, z): | ||
qml.QFT(wires=(0,1,2,3)) | ||
qml.Toffoli(wires=(0,1,2)) | ||
qml.CSWAP(wires=(0,2,3)) | ||
qml.RX(x, wires=0) | ||
qml.CRZ(z, wires=(3,0)) | ||
return qml.expval(qml.PauliZ(0)) | ||
|
||
qml.drawer.use_style(style) | ||
fig, ax = qml.draw_mpl(circuit)(1.2345, 1.2345) | ||
|
||
Currently Available Styles | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
.. |bws| image:: ../_static/style/black_white_style.png | ||
:width: 100% | ||
|
||
.. |bwd| image:: ../_static/style/black_white_dark_style.png | ||
:width: 100% | ||
|
||
.. |def| image:: ../_static/style/default_style.png | ||
:width: 100% | ||
|
||
+-----+-----+-----+ | ||
+|bws|+|bwd|+|def|+ | ||
+-----+-----+-----+ | ||
|
||
|
||
Unless you are a PennyLane or plugin developer, you likely do not need | ||
to use these classes directly. | ||
Developer Methods | ||
----------------- | ||
|
||
.. automodapi:: pennylane.drawer | ||
:no-heading: | ||
:no-inheritance-diagram: | ||
:no-inherited-members: | ||
:no-inherited-members: | ||
:skip: available_styles | ||
:skip: use_style |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rip solarize_light2