question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Remove implicit assumption that Operations have Gates

See original GitHub issue

Is 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 Operations are GateOperations, meaning that this field is not always populated.

Until recently this has been a relatively minor problem, since the vast majority of Operations are GateOperations. 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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
95-martin-orioncommented, Jan 19, 2021

@daxfohl: Subcircuits as they are implemented today are just as “instantaneous” as any other operation. Consider this circuit:

a, b, = cirq.LineQubit.range(2)
circuit = cirq.Circuit(
  cirq.Moment(
    cirq.H(a),
    cirq.H(b),
  ),
  cirq.Moment(
    cirq.measure(a, key='m1'),
    cirq.CircuitOperation(
      cirq.FrozenCircuit(
        cirq.Moment(cirq.T(b)),
        cirq.Moment(cirq.H(b)),
        cirq.Moment(cirq.X(b)**0.5),
      )
    ),
  ),
  cirq.Moment(
    cirq.X(a),
    cirq.measure(b, key='m2'),
  ),
)

There are two things to note about the second moment of the top-level circuit:

  • The 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.
  • On many types of quantum hardware, the measure operation will actually take longer than the CircuitOperation, despite being a single operation. Hardware durations of operations can vary considerably.

(These items are true even without explicit cirq.Moments 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.

0reactions
mpharrigancommented, May 19, 2021
  • Violates some software engineering principles
  • Changing it would be too hard
  • @95-martin-orion says there’s more tools now so he’s less annoyed.

Short term solution: #3893 Long term solution: #2536

Read more comments on GitHub >

github_iconTop Results From Across the Web

Quantum Information and Computation Chapter 5
Each operation is called a gate. The result of the computation is the final value of all remaining bits, after all the elementary...
Read more >
Circuit Construction — pytket-manual documentation
Basic quantum gates represent some unitary operation applied to some qubits. Adding them to a Circuit just requires specifying which qubits you want...
Read more >
Transmission Gate as a CMOS Bilateral Switch
Electronics Tutorial about the CMOS Transmission Gate which uses NMOS and PMOS transistors as a voltage-controlled bilateral switch.
Read more >
US20160259718A1 - Identifying implicit assumptions associated ...
A framework is described herein for identifying implicit assumptions associated ... In this form, certain operations are described as constituting distinct ...
Read more >
The Fed - Chapter 3. Property and Equipment
Fixed assets have three primary characteristics: Acquired and held for use in operations (i.e., not held for sale).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found