Skip to content

Fix type check of SerializableDevice gate_definitions #5447

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 14 commits into from
Jun 16, 2022

Conversation

pavoljuhas
Copy link
Collaborator

@pavoljuhas pavoljuhas commented Jun 4, 2022

The type(cirq.Gate) is cirq.ABCMetaImplementAnyOneOf which could
match unrelated instances. Use subclass check instead and remove
isinstance() check which should never happen.
Clarify typing of the gate_definitions dictionary keys in SeriazableDevice.
Finally, turn off Gateset unroll_circuit_op flag when gate_definitions indicate
device does not support subcircuits.

The type(cirq.Gate) is cirq.ABCMetaImplementAnyOneOf which could
match unrelated instances.  Use subclass check instead.
@pavoljuhas pavoljuhas requested review from wcourtney, a team, vtomole, cduck and verult as code owners June 4, 2022 01:18
@pavoljuhas pavoljuhas requested a review from viathor June 4, 2022 01:18
@CirqBot CirqBot added the Size: XS <10 lines changed label Jun 4, 2022
These can be only of cirq.FrozenCircuit or cirq.Gate types;
instances should not happen.  Also turn off Gateset unroll_circuit_op
flag when gate_definitions indicate device does not support subcircuits.
The keys of the gate_definitions argument can be one of
(cirq.Gate, cirq.FrozenCircuit) types.
Avoid shadowing import of the serializer module.
@CirqBot CirqBot added the size: S 10< lines changed <50 label Jun 7, 2022
Copy link
Collaborator

@viathor viathor left a comment

Choose a reason for hiding this comment

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

Thanks!

Copy link
Collaborator

@dstrain115 dstrain115 left a comment

Choose a reason for hiding this comment

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

Is there a test (that would have failed and now passes) that would illuminate what the problem was?

@pavoljuhas
Copy link
Collaborator Author

Is there a test (that would have failed and now passes) that would illuminate what the problem was?

Test added to the master with 62926b8 where it fails, because argument filter keeps NoiseModel type.

$ pytest cirq-google/cirq_google/devices/serializable_device_test.py
...
E           ValueError: Gate <class 'cirq.devices.noise_model.NoiseModel'> must be an instance or subclass of `cirq.Gate`.

The test passes after merging to this PR - 2b12d1a.

@pavoljuhas
Copy link
Collaborator Author

@dstrain115 - perhaps this is ready for the automerge flag?

Copy link
Collaborator

@dstrain115 dstrain115 left a comment

Choose a reason for hiding this comment

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

Sure, LGTM, feel free to merge when ready or put the automerge flag on.

@dstrain115 dstrain115 added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Jun 16, 2022
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Jun 16, 2022
@CirqBot
Copy link
Collaborator

CirqBot commented Jun 16, 2022

Automerge cancelled: A status check is failing.

@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 Jun 16, 2022
@pavoljuhas pavoljuhas added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Jun 16, 2022
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Jun 16, 2022
@CirqBot CirqBot merged commit e14f9ad into quantumlib:master Jun 16, 2022
@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 Jun 16, 2022
@pavoljuhas pavoljuhas deleted the fix-typo-in-type-check branch June 17, 2022 00:06
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
The type(cirq.Gate) is cirq.ABCMetaImplementAnyOneOf which could
match unrelated instances.  Use subclass check instead and remove
`isinstance()` check which should never happen.  
Clarify typing of the `gate_definitions` dictionary keys in SeriazableDevice.
Finally, turn off Gateset unroll_circuit_op flag when gate_definitions indicate
device does not support subcircuits.
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 Size: XS <10 lines changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants