Remove implicit assumption that Operations have Gates
See original GitHub issueIs your feature request related to a use case or problem? Please describe.
The Operation
has a gate
property which is frequently used to identify its type. However, not all Operation
s are GateOperation
s, meaning that this field is not always populated.
Until recently this has been a relatively minor problem, since the vast majority of Operation
s are GateOperation
s. However, with the introduction of CircuitOperation
(#3580) this issue is becoming more pronounced.
Related issue: #3235.
Describe the solution you’d like
Remove gate
field in Operation
and replace with a get_operator
abstract method, defined in implementations. This will require deprecating the field and replacing it across the Cirq repo.
[optional] Describe alternatives/workarounds you’ve considered
- Add local fixes to sections of code that need to recognize CircuitOperation, and leave the rest unchanged.
- Issue: eventually, CircuitOperation should be supported everywhere.
- Make Circuit a subclass of Gate, with CircuitOperations containing CircuitGates
- Rejected during review (#3509): treating circuits as gates introduces undesirable behavior
What is the urgency from your perspective for this issue? Is it blocking important work?
P1 - I need this no later than the next release (end of quarter)
This confounds work on CircuitOperations, as they do not have a value in their gate
field. Continuing work in that space without resolving this issue requires workarounds which will increase the cost of an eventual fix.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
@daxfohl: Subcircuits as they are implemented today are just as “instantaneous” as any other operation. Consider this circuit:
There are two things to note about the second moment of the top-level circuit:
CircuitOperation
runs entirely within the second moment, alongside the measurement. It will not “spill over” into the third moment - the moments it contains are “sub-moments” of the second top-level moment, in a sense.measure
operation will actually take longer than theCircuitOperation
, despite being a single operation. Hardware durations of operations can vary considerably.(These items are true even without explicit
cirq.Moment
s wrapping each moment; I just added those to clarify the structure.)For more details on why
CircuitOperation
was implemented as it is, you can read the original RFC here: https://tinyurl.com/cirq-circuitoperation-rfc.Short term solution: #3893 Long term solution: #2536