Skip to content

Commit

Permalink
Add saving possibility to register layout draw method (#446)
Browse files Browse the repository at this point in the history
* Correcting typos

* Add fig-name and kwargs-savefig

* Delete blankspace
  • Loading branch information
a-corni authored Jan 9, 2023
1 parent 8fd2484 commit 38f0c91
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pulser-core/pulser/register/register_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ def draw(
draw_graph: bool = False,
draw_half_radius: bool = False,
projection: bool = True,
fig_name: str = None,
kwargs_savefig: dict = {},
) -> None:
"""Draws the entire register layout.
Expand All @@ -211,6 +213,11 @@ def draw(
if the `blockade_radius` is defined.
projection: If the layout is in 3D, draws it
as projections on different planes.
fig_name: The name on which to save the figure.
If None the figure will not be saved.
kwargs_savefig: Keywords arguments for
``matplotlib.pyplot.savefig``. Not applicable if `fig_name`
is ``None``.
Note:
When drawing half the blockade radius, we say there is a blockade
Expand Down Expand Up @@ -252,6 +259,8 @@ def draw(
draw_half_radius=draw_half_radius,
are_traps=True,
)
if fig_name is not None:
plt.savefig(fig_name, **kwargs_savefig)
plt.show()

def make_mappable_register(
Expand Down
8 changes: 8 additions & 0 deletions tests/test_register_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,20 @@ def test_draw(layout, layout3d):
with patch("matplotlib.pyplot.show"):
layout.draw()

with patch("matplotlib.pyplot.show"):
with patch("matplotlib.pyplot.savefig"):
layout.draw(fig_name="my_registerlayout.pdf")

with patch("matplotlib.pyplot.show"):
layout3d.draw()

with patch("matplotlib.pyplot.show"):
layout3d.draw(projection=False)

with patch("matplotlib.pyplot.show"):
with patch("matplotlib.pyplot.savefig"):
layout3d.draw(fig_name="my_registerlayout.pdf")


def test_repr(layout):
hash_ = sha256(bytes(2))
Expand Down

0 comments on commit 38f0c91

Please sign in to comment.