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

Remove op validation when inserting into Circuit #4669

Merged
merged 4 commits into from
Nov 17, 2021

Conversation

dabacon
Copy link
Collaborator

@dabacon dabacon commented Nov 12, 2021

Proposal to remove validation on op insertion methods #4667

@dabacon dabacon requested review from cduck, vtomole and a team as code owners November 12, 2021 04:00
@dabacon dabacon requested a review from mpharrigan November 12, 2021 04:00
@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label Nov 12, 2021
@CirqBot CirqBot added the size: M 50< lines changed <250 label Nov 12, 2021
Copy link
Contributor

@maffoo maffoo left a comment

Choose a reason for hiding this comment

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

I'm in favor of removing this validation from Circuit, but would be good to see if other maintainers have objectsions. Just a couple of minor comments.

@@ -853,17 +851,16 @@ def _validate_qid_shape(val: Any, qubits: Sequence['cirq.Qid']) -> None:
ValueError: The operation had qids that don't match it's qid shape.
"""
qid_shape = protocols.qid_shape(val)
if len(qubits) != len(qid_shape):
qubits_shape = protocols.qid_shape(qubits)
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a slight preference to revert to the previous implementation here because the qid_shape protocol seems to be slow, and we know here that it's the same as tuple(q.dimension for q in qubits) but we don't actually need to construct the tuple.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

reverted

@@ -120,7 +120,7 @@ def test_gate():
_ = g(a, c)
with pytest.raises(ValueError, match='Wrong number'):
_ = g(c, b, a)
with pytest.raises(ValueError, match='Wrong shape'):
with pytest.raises(ValueError, match='g'):
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

late night, fixed

@mpharrigan
Copy link
Collaborator

cc @MichaelBroughton re: devices api, which concerns itself with validation

@dabacon
Copy link
Collaborator Author

dabacon commented Nov 12, 2021

Updated per @maffoo's comments.

@MichaelBroughton
Copy link
Collaborator

Would this change mean a user gets no validation at all on a custom gate they write when putting it into a circuit ?

@MichaelBroughton MichaelBroughton self-assigned this Nov 12, 2021
Copy link
Contributor

@maffoo maffoo left a comment

Choose a reason for hiding this comment

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

LGTM, though may want to get comments from @MichaelBroughton or other maintainers before merging.

@MichaelBroughton
Copy link
Collaborator

We talked about this in the Cirq meeting today and I think we are fine to merge this in.

@MichaelBroughton MichaelBroughton added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Nov 17, 2021
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Nov 17, 2021
@CirqBot CirqBot merged commit 3af7e89 into quantumlib:master Nov 17, 2021
@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Nov 17, 2021
@@ -4025,37 +4025,6 @@ def test_moments_property(circuit_cls):
assert c.moments[1] == cirq.Moment([cirq.Y(q)])


@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
def test_operation_shape_validation(circuit_cls):
class BadOperation1(cirq.Operation):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we do validation in cirq.Operation base class ?

@dabacon dabacon deleted the validateme branch April 16, 2022 15:42
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
Proposal to remove validation on op insertion methods quantumlib#4667
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
Proposal to remove validation on op insertion methods quantumlib#4667
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Makes googlebot stop complaining. size: M 50< lines changed <250
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants