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

print_matrix only prints the matix if it's the last output operation in a cell #145

Closed
dlyongemallo opened this issue Sep 3, 2023 · 4 comments · Fixed by #213
Closed

Comments

@dlyongemallo
Copy link
Contributor

The function print_matrix returns a Label widget (and says so in the documentation). However, it really only prints the matrix if it's the last function called in a cell which produces any output. In particular, the following behaviour is unintutive based on the function name.

This only prints the matrix of c2:

print_matrix(c1)
print_matrix(c2)

This draws the circuit of c but does not print its matrix (but reversing the order works):

print_matrix(c)
zx.draw(c)

Suggestion: either change the name of the function, or change it so it does actually print the matrix when it is run.

@jvdwetering
Copy link
Collaborator

Hmm yes, maybe splitting it up into two functions, one that just returns the Label, and the other that also prints it and has this name would be the thing to do here.

dlyongemallo added a commit to dlyongemallo/pyzx that referenced this issue Apr 17, 2024
Split off a function `get_matrix_label` which only returns the Jupyter `Label`.

(Also: update "AKLT hexagonal lattice.ipynb" so it no longer uses the hack of wrapping `print_matrix` with a call to `display`.)

Fixes zxcalc#145.
@dlyongemallo
Copy link
Contributor Author

Hmm yes, maybe splitting it up into two functions, one that just returns the Label, and the other that also prints it and has this name would be the thing to do here.

I've added a get_matrix_label separate from print_label in #213 as requested, but I'm not really sure that it is all that necessary. Is there really a use case for getting the Label but not immediately also displaying it? If not, we can just drop get_matrix_label so as to not increase complexit in the API.

@jvdwetering
Copy link
Collaborator

Yeah I guess we don't really need the `get_matrix_label' function. If you want to change back your PR so that it always just displays, then that is fine.

dlyongemallo added a commit to dlyongemallo/pyzx that referenced this issue Apr 18, 2024
(Also: update "AKLT hexagonal lattice.ipynb" so it no longer uses the hack of wrapping print_matrix with a call to display.)

Fixes zxcalc#145.
@dlyongemallo
Copy link
Contributor Author

I've removed get_matrix_label from #213.

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 a pull request may close this issue.

2 participants