-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix type check of SerializableDevice gate_definitions #5447
Conversation
The type(cirq.Gate) is cirq.ABCMetaImplementAnyOneOf which could match unrelated instances. Use subclass check instead.
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.
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.
Thanks!
Avoid importing module-private object from another module.
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.
Is there a test (that would have failed and now passes) that would illuminate what the problem was?
Keys in the `gate_definitions` dictionary should be ignored if not of the cirq.Gate or derived type.
…typo-in-type-check
Test added to the master with 62926b8 where it fails, because argument filter keeps NoiseModel type.
The test passes after merging to this PR - 2b12d1a. |
@dstrain115 - perhaps this is ready for the automerge flag? |
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.
Sure, LGTM, feel free to merge when ready or put the automerge flag on.
Automerge cancelled: A status check is failing. |
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 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.