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

Matplotlib circuit drawer #1370

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
ef1e964
integration of matplotlib circuit drawer
sergiomtzlosa Jun 20, 2024
5a776fc
integration of matplotlib circuit drawer
sergiomtzlosa Jun 20, 2024
62ef4c0
integration of matplotlib circuit drawer
sergiomtzlosa Jun 20, 2024
e094baa
integration of matplotlib circuit drawer
sergiomtzlosa Jun 20, 2024
6ee3ff8
integration of matplotlib circuit drawer
sergiomtzlosa Jun 20, 2024
b1600a5
integration of matplotlib circuit drawer
sergiomtzlosa Jun 20, 2024
1894f03
integration of matplotlib circuit drawer
sergiomtzlosa Jun 20, 2024
fcf66cb
integration of matplotlib circuit drawer
sergiomtzlosa Jun 20, 2024
017e205
integration of matplotlib circuit drawer
sergiomtzlosa Jun 20, 2024
ebb6454
integration of matplotlib circuit drawer
sergiomtzlosa Jun 20, 2024
ed9e964
Merge branch 'qiboteam:master' into matplotlib-circuit-drawer
sergiomtzlosa Jun 20, 2024
527904d
integration of matplotlib circuit drawer
sergiomtzlosa Jun 21, 2024
5c1e244
Merge branch 'matplotlib-circuit-drawer' of https://github.com/sergio…
sergiomtzlosa Jun 21, 2024
2e5c594
integration of matplotlib circuit drawer
sergiomtzlosa Jun 21, 2024
ff5e077
integration of matplotlib circuit drawer
sergiomtzlosa Jun 21, 2024
45d737d
integration of matplotlib circuit drawer
sergiomtzlosa Jun 21, 2024
ddd91bc
integration of matplotlib circuit drawer
sergiomtzlosa Jun 21, 2024
0cd600b
integration of matplotlib circuit drawer
sergiomtzlosa Jun 21, 2024
a56b9b6
integration of matplotlib circuit drawer
sergiomtzlosa Jun 21, 2024
4f9c4d0
integration of matplotlib circuit drawer
sergiomtzlosa Jun 21, 2024
7822914
integration of matplotlib circuit drawer
sergiomtzlosa Jun 21, 2024
d604d03
integration of matplotlib circuit drawer
sergiomtzlosa Jun 21, 2024
739d576
integration of matplotlib circuit drawer
sergiomtzlosa Jun 21, 2024
7633b21
integration of matplotlib circuit drawer
sergiomtzlosa Jun 21, 2024
4392cab
integration of matplotlib circuit drawer
sergiomtzlosa Jun 21, 2024
94e6948
integration of matplotlib circuit drawer
sergiomtzlosa Jun 21, 2024
529ce0e
integration of matplotlib circuit drawer
sergiomtzlosa Jun 21, 2024
716f263
integration of matplotlib circuit drawer
sergiomtzlosa Jun 21, 2024
c4f2598
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 21, 2024
4407266
integration of matplotlib circuit drawer
sergiomtzlosa Jun 22, 2024
6f37dfe
Merge branch 'matplotlib-circuit-drawer' of https://github.com/sergio…
sergiomtzlosa Jun 22, 2024
7505599
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 22, 2024
843bd32
integration of matplotlib circuit drawer
sergiomtzlosa Jun 23, 2024
2359536
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 23, 2024
1aaec6b
added new analysis data review
sergiomtzlosa Jun 23, 2024
08221e9
moved drawing mpl circuit to new module
sergiomtzlosa Jun 24, 2024
12991bf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 24, 2024
6e777ee
moved drawing mpl circuit to new module with new styles
sergiomtzlosa Jun 24, 2024
16ab2a7
Merge branch 'matplotlib-circuit-drawer' of https://github.com/sergio…
sergiomtzlosa Jun 24, 2024
392d47b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 24, 2024
ffdf9b0
added enhancements based on feedback, reformat drawing class, new plo…
sergiomtzlosa Jun 24, 2024
72ba82e
added enhancements based on feedback, reformat drawing class, new plo…
sergiomtzlosa Jun 24, 2024
cfeb572
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 24, 2024
2d724b0
removed unused imaging folder
sergiomtzlosa Jun 24, 2024
7fbabcc
Update src/qibo/ui/plot_styles.py
sergiomtzlosa Jun 24, 2024
6b07d48
rework styles dictionary and return default style
sergiomtzlosa Jun 24, 2024
93943ce
deleted save plot to file
sergiomtzlosa Jun 24, 2024
2ed13be
added documentation on plot function
sergiomtzlosa Jun 24, 2024
fcf73be
added one last built-in style in red and black
sergiomtzlosa Jun 24, 2024
0d3ce92
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 24, 2024
ff1a8e2
converted style dictionary to constant
sergiomtzlosa Jun 24, 2024
d95f8a5
converted style dictionary to constant
sergiomtzlosa Jun 24, 2024
96c47ed
fixed merge confict
sergiomtzlosa Jun 24, 2024
14ebac4
review set_style function
sergiomtzlosa Jun 24, 2024
9b1e1f7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 24, 2024
974fbdf
redraw symbols in matplotlib for complex gates
sergiomtzlosa Jun 25, 2024
8fd7e0f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 25, 2024
7b96656
deleted _set_style function for code reduction
sergiomtzlosa Jun 25, 2024
5cbdbc7
rework clustering method to make it simple
sergiomtzlosa Jun 25, 2024
0a5a784
draw invaric input form I and M gates
sergiomtzlosa Jun 25, 2024
2a83750
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 25, 2024
7525fcd
added noise and channels to plot
sergiomtzlosa Jun 26, 2024
596630e
added channel and noise on plots
sergiomtzlosa Jun 26, 2024
c83c430
added json files for styles and symbols
sergiomtzlosa Jun 26, 2024
3209b4b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 26, 2024
b91ea54
added fix due to black breaks json files
sergiomtzlosa Jun 26, 2024
7922b4a
fix json for styles
sergiomtzlosa Jun 26, 2024
703ee94
deleted mplstyle file
sergiomtzlosa Jun 26, 2024
ca5a9cc
added support to plot fused gates
sergiomtzlosa Jun 27, 2024
607e05b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 27, 2024
ab6428a
Merge branch 'qiboteam:master' into matplotlib-circuit-drawer
sergiomtzlosa Jun 28, 2024
a58550c
review for gate plotting enhancement
sergiomtzlosa Jul 1, 2024
7b2ea6a
added support for dagger operator in gate plot
sergiomtzlosa Jul 1, 2024
880b66f
review gate size on plot
sergiomtzlosa Jul 2, 2024
9d6e773
added support for framing clutered gates
sergiomtzlosa Jul 4, 2024
a993caa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2024
ed0d2be
added new drawing cells and information in drawing notebook example
sergiomtzlosa Aug 1, 2024
cce8a2b
Update src/qibo/ui/mpldrawer.py
sergiomtzlosa Aug 1, 2024
415c30e
review unused dead code on circuit drawing
sergiomtzlosa Aug 1, 2024
a759c5a
Merge branch 'matplotlib-circuit-drawer' of https://github.com/sergio…
sergiomtzlosa Aug 1, 2024
20a8268
Update src/qibo/ui/mpldrawer.py
sergiomtzlosa Aug 1, 2024
332c6ab
Merge branch 'matplotlib-circuit-drawer' of https://github.com/sergio…
sergiomtzlosa Aug 1, 2024
980318b
Update src/qibo/ui/mpldrawer.py
sergiomtzlosa Aug 1, 2024
41e545f
Merge branch 'matplotlib-circuit-drawer' of https://github.com/sergio…
sergiomtzlosa Aug 1, 2024
9d3f239
Update src/qibo/ui/mpldrawer.py
sergiomtzlosa Aug 1, 2024
106c4d7
Update src/qibo/ui/mpldrawer.py
sergiomtzlosa Aug 1, 2024
a8def39
review global variables on mpldrawer.py
sergiomtzlosa Aug 1, 2024
6777699
review if clauses on gate clasification
sergiomtzlosa Aug 1, 2024
3039e58
review load json style files
sergiomtzlosa Aug 1, 2024
aa0db70
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 1, 2024
5f46dc2
added more information to example notebook
sergiomtzlosa Aug 1, 2024
6714138
Merge branch 'matplotlib-circuit-drawer' of https://github.com/sergio…
sergiomtzlosa Aug 1, 2024
33bc78d
deep style review on example notebook
sergiomtzlosa Aug 1, 2024
0283e1f
Update src/qibo/ui/mpldrawer.py
sergiomtzlosa Aug 1, 2024
8f9706c
Update src/qibo/ui/mpldrawer.py
sergiomtzlosa Aug 1, 2024
f6d59aa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 1, 2024
d4b7420
Update src/qibo/ui/mpldrawer.py
sergiomtzlosa Aug 1, 2024
5cdd095
review global params style dict to local variable
sergiomtzlosa Aug 1, 2024
92c11de
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 1, 2024
5347400
plot circuit function code reduction and unification
sergiomtzlosa Aug 2, 2024
fd5bb5a
postreview for plot circuit function code
sergiomtzlosa Aug 2, 2024
7939c84
added _plot_params function
sergiomtzlosa Aug 2, 2024
c775cda
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 2, 2024
d94b443
plotting function review along style methods and variables
sergiomtzlosa Aug 14, 2024
5d68cd1
plotting function review along style methods and variables
sergiomtzlosa Aug 14, 2024
2b49b40
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 14, 2024
6464a6d
update documentation for new matplotlib circuit plot
sergiomtzlosa Sep 4, 2024
232c455
Merge branch 'matplotlib-circuit-drawer' of https://github.com/sergio…
sergiomtzlosa Sep 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions doc/source/code-examples/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,48 @@ For example
q2: ──────o──|──|────o──|──|──H─U1─U1────────|─|─
q3: ─────────o──|───────o──|────o──|──H─U1───|─x─
q4: ────────────o──────────o───────o────o──H─x───

How to visualize a circuit with style?
--------------------------------------

Qibo is able to draw a circuit using ``matplotlib`` library by calling the function ``plot_circuit``. It also have built-in styles ready to use
and also it is possible to apply custom styles to the circuit. The function is able to cluster the gates to reduce the circuit depth.
The built-in styles are: ``garnacha``, ``fardelejo``, ``quantumspain``, ``color-blind``, ``cachirulo`` or custom dictionary.

For example, we can draw the QFT circuit for 5-qubits:

.. testcode::

import matplotlib.pyplot as plt
import qibo
from qibo import gates, models
from qibo.models import QFT

# new plot function based on matplotlib
from qibo.ui import plot_circuit

%matplotlib inline

# create a 5-qubits QFT circuit
c = QFT(5)
c.add(gates.M(qubit) for qubit in range(2))

# print circuit with default options (default black & white style, scale factor of 0.6 and clustered gates)
plot_circuit(c);

# print the circuit with built-int style "garnacha", clustering gates and a custom scale factor
# built-in styles: "garnacha", "fardelejo", "quantumspain", "color-blind", "cachirulo" or custom dictionary
plot_circuit(c, scale = 0.8, cluster_gates = True, style="garnacha");

# plot the Qibo circuit with a custom style
custom_style = {
"facecolor" : "#6497bf",
"edgecolor" : "#01016f",
"linecolor" : "#01016f",
"textcolor" : "#01016f",
"fillcolor" : "#ffb9b9",
"gatecolor" : "#d8031c",
"controlcolor" : "#360000"
}

plot_circuit(c, scale = 0.8, cluster_gates = True, style=custom_style);
470 changes: 470 additions & 0 deletions examples/circuit-draw-mpl/qibo-draw-circuit-matplotlib.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/qibo/ui/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from qibo.ui.mpldrawer import plot_circuit
42 changes: 42 additions & 0 deletions src/qibo/ui/drawer_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from qibo.gates.abstract import Gate


class FusedStartGateBarrier(Gate):
"""
:class:`qibo.ui.drawer_utils.FusedStartGateBarrier` gives room to fused group of gates.
Inherit from ``qibo.gates.abstract.Gate``. A special gate barrier gate to pin the starting point of fused gates.
"""

def __init__(self, q_ctrl, q_trgt, nfused, equal_qbits=False):

super().__init__()
self.name = (
"FusedStartGateBarrier"
+ str(nfused)
+ ("" if not equal_qbits else "@EQUAL")
)
self.draw_label = ""
self.control_qubits = (q_ctrl,)
self.target_qubits = (q_trgt,) if q_ctrl != q_trgt else ()
self.init_args = [q_trgt, q_ctrl] if q_ctrl != q_trgt else [q_ctrl]
self.unitary = False
self.is_controlled_by = False
self.nfused = nfused


class FusedEndGateBarrier(Gate):
"""
:class:`qibo.ui.drawer_utils.FusedEndGateBarrier` gives room to fused group of gates.
Inherit from ``qibo.gates.abstract.Gate``. A special gate barrier gate to pin the ending point of fused gates.
"""

def __init__(self, q_ctrl, q_trgt):

super().__init__()
self.name = "FusedEndGateBarrier"
self.draw_label = ""
self.control_qubits = (q_ctrl,)
self.target_qubits = (q_trgt,) if q_ctrl != q_trgt else ()
self.init_args = [q_trgt, q_ctrl] if q_ctrl != q_trgt else [q_ctrl]
self.unitary = False
self.is_controlled_by = False
Loading