-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add MatrixGate.with_name method. #5941
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
Conversation
de07e84
to
ecbdcc0
Compare
@@ -66,6 +67,8 @@ def __init__( | |||
qid_shape: The shape of state tensor that the matrix applies to. | |||
If not specified, this value is inferred by assuming that the | |||
matrix is supposed to apply to qubits. | |||
unitary_check: If True, check that the supplied matrix is unitary up to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to add this new argument to support the with_name
method? Or Is it just a performance optimization ?
The docstring implies that the matrix should always be unitary, and enabling users to construct the gate with non-unitary matrices by passing unitary_check=False
seems bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just a performance optimization to allow skipping the check if you already know the matrix is unitary (as is the case in with_name
). I agree it would be bad if a user uses this to construct matrix gates with non-unitary matrices, but they would have to do this explicitly and there's only so much we can do to protect users from themselves :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a note in the docstring saying that it should be set to false only for performance optimizations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM % nit
@@ -66,6 +67,8 @@ def __init__( | |||
qid_shape: The shape of state tensor that the matrix applies to. | |||
If not specified, this value is inferred by assuming that the | |||
matrix is supposed to apply to qubits. | |||
unitary_check: If True, check that the supplied matrix is unitary up to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a note in the docstring saying that it should be set to false only for performance optimizations?
Fixes #5938