Skip to content

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

Merged
merged 4 commits into from
Nov 8, 2022
Merged

Add MatrixGate.with_name method. #5941

merged 4 commits into from
Nov 8, 2022

Conversation

maffoo
Copy link
Contributor

@maffoo maffoo commented Nov 4, 2022

Fixes #5938

@maffoo maffoo requested review from a team, vtomole and cduck as code owners November 4, 2022 17:08
@maffoo maffoo requested a review from mpharrigan November 4, 2022 17:08
@CirqBot CirqBot added the size: S 10< lines changed <50 label Nov 4, 2022
@maffoo maffoo force-pushed the u/maffoo/with-name branch from de07e84 to ecbdcc0 Compare November 6, 2022 16:13
@@ -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
Copy link
Collaborator

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.

Copy link
Contributor Author

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 :-)

Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@maffoo maffoo requested a review from tanujkhattar November 7, 2022 16:42
Copy link
Collaborator

@tanujkhattar tanujkhattar left a 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
Copy link
Collaborator

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?

@maffoo maffoo added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Nov 8, 2022
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Nov 8, 2022
@CirqBot CirqBot merged commit 7d3bf5e into master Nov 8, 2022
@CirqBot CirqBot removed the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Nov 8, 2022
@CirqBot CirqBot deleted the u/maffoo/with-name branch November 8, 2022 22:58
@CirqBot CirqBot removed the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Nov 8, 2022
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: S 10< lines changed <50
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MatrixGate: the name is not taken over during exponentiation
3 participants