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

Draw layout and register on the same plot #772

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

BrFle
Copy link

@BrFle BrFle commented Dec 3, 2024

First draft to add option to draw the layout.
Still missing tests !
Fixes #726

Copy link
Collaborator

@a-corni a-corni left a comment

Choose a reason for hiding this comment

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

Thanks for your PR @BrFle !
It already looks quite good ! I have a suggestion regarding the display of the empty traps. Let me know what you think about it.
As per the testing. It is really not easy to test these kind of function with pytest, since we can't see the display. You will have to add a test to tests/test_register.py, where you would do reg.draw(draw_empty_sites=True) (and that it raises an error with a register not having a layout associated to it).
I suggest that you add draw_empty_sites=True in the two examples on "Register Definition" in the tutorial on Register Layout: https://pulser.readthedocs.io/en/stable/tutorials/reg_layouts.html#Register-definition

@@ -404,6 +404,8 @@ def draw(
kwargs_savefig: dict = {},
custom_ax: Optional[Axes] = None,
show: bool = True,
draw_empty_sites: bool = False,
empty_color: Optional[str] = None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

May I suggest to have the default color instead of None ? I also suggest we have the default color to be gray instead of red, to be consistent with the current color of a layout ?

Another idea I had, which might make the life of the user easier, would be to have the empty sites displayed as a trap in the layout, a black circle filled with white. What do you think of this alternative ? An advantage I see with this is that there will be no conflict with qubit_colors (in the current implementation, what happens if the user provide qubit_colors=empty_color ? The visualization will not be great...)

image

Suggested change
empty_color: Optional[str] = None,
empty_color: str = "gray",

@@ -434,6 +436,8 @@ def draw(
show: Whether or not to call `plt.show()` before returning. When
combining this plot with other ones in a single figure, one may
need to set this flag to False.
draw_empty_sites: If True, draws the empty sites as well.
empty_color: The color of the empty sites. Default is 'r'.
Copy link
Collaborator

Choose a reason for hiding this comment

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

As in my comment above, I am wondering if empty_color is necessary, and I would perhaps suggest to have default to "gray" instead of "r".

empty_layout = self.layout.define_register(
*layout_ids, qubit_ids=layout_ids
)
breakpoint()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should not leave this breakpoint() in the code :)

)

if draw_empty_sites:
RegDrawer._draw_2D(empty_layout,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you can use super instead of RegDrawer :)

if draw_empty_sites:
RegDrawer._draw_2D(empty_layout,
ids=empty_layout._ids,
pos=empty_pos,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Your implementation looks good. It enables you to implement the alternative I have presented above, where the empty spots are circles filled with white. To implement it fully, you might want to take out the positions of the atoms in the Register in empty_pos, because at the moment you are super-imposing two symbols for these filled positions and the symbol of the circle with white inside is larger than the symbol for the atoms (a disk of green by default, or a color defined in qubit_colors).

@a-corni
Copy link
Collaborator

a-corni commented Dec 3, 2024

If you want to draw the empty sites as traps in a RegisterLayout, you should specify them as traps in the RegisterDrawer._draw_2D, by saying as_traps=True when calling it with empty_traps https://github.com/pasqal-io/Pulser/blob/develop/pulser-core/pulser/register/register_layout.py#L189. If you want to extract the ids of the trap in the Register Layout that are in the Register, you might want to use get_traps_from_coordinates, see https://github.com/pasqal-io/Pulser/blob/develop/pulser-core/pulser/register/traps.py#L87

@HGSilveri HGSilveri changed the title 726 draw layout same plot Draw layout and register on the same plot Dec 3, 2024
@a-corni
Copy link
Collaborator

a-corni commented Dec 11, 2024

Hey @BrFle, is everything going well with this PR ? 😄
Just let us know if you need some help to finish it !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option to draw layout associated to register on the same plot as the Register
2 participants