pyzx icon indicating copy to clipboard operation
pyzx copied to clipboard

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

Open dlyongemallo opened this issue 1 year ago • 1 comments

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.

dlyongemallo avatar Sep 03 '23 05:09 dlyongemallo

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.

jvdwetering avatar Sep 04 '23 14:09 jvdwetering

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.

dlyongemallo avatar Apr 17 '24 14:04 dlyongemallo

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.

jvdwetering avatar Apr 17 '24 17:04 jvdwetering

I've removed get_matrix_label from #213.

dlyongemallo avatar Apr 23 '24 12:04 dlyongemallo