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.

`ClassicallyControlledOperation` breaks assumption that disjoint operations commute.

See original GitHub issue

Description of the issue

ClassicallyControlledOperation was recently introduced to enable classical controls in Cirq. The method takes as input a sub_operation and a list of conditions, which correspond to measurement keys of previous measurements.

https://github.com/quantumlib/Cirq/blob/6119620178d7d1d0f11c5f2b73998fb2b66fcd2d/cirq-core/cirq/ops/classically_controlled_operation.py#L49-L53

The operations is implemented in a way that the qubit set it acts on remains the same as the set of qubits of the underlying operation to be controlled, and the operation β€œassumes” that measurements corresponding to the conditions have already occurred to the left of the operation.

This is a big problem for transformers because this introduces an implicit dependency between a measurement operation and a classically controlled operation which makes use of these measurement results.

How to reproduce the issue

>>> import cirq
>>> q = cirq.LineQubit.range(2)
>>> c = cirq.Circuit(cirq.H(q[0]), cirq.measure(q[0], key='m'), cirq.X(q[1]).with_classical_controls('m'))
>>> print(c)
0: ───H───M───────
          β•‘
1: ───────╫───X───
          β•‘   β•‘
m: ═══════@═══^═══
>>> cirq.SynchronizeTerminalMeasurements().optimize_circuit(c)
>>> print(c)
0: ───H───────────M───
                  β•‘
1: ───────────X───╫───
              β•‘   β•‘
m: ═══════════^═══@═══
>>> cirq.Simulator().simulate(c)
ValueError: Measurement key m missing when testing classical control

Cirq version

0.14.0.dev

cc @95-martin-orion @daxfohl

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
daxfohlcommented, Jan 21, 2022

We already have logic in circuit.append to ensure that when you append a control, it does not fall back beyond the measurement that creates the key. https://github.com/quantumlib/Cirq/blob/39ce4f0e7c79479913491f9b434461c9397eb677/cirq-core/cirq/circuits/circuit.py#L1967

I don’t think it would be good for usability if we require users to state which qubits correspond to the measurement key when instantiating the classically controlled operation. Maybe there’d be some way to hack this in such that there’s a lookup somewhere that we can get the qubits corresponding to the key, and can avoid the user needing to specify it manually, but nothing comes to mind. Also the latter solution won’t work once we allow repeated measurement keys, as each measurement could correspond to different qubits (potentially, depending on the design).

So, I think the best solution is to reuse the logic from Circuit.append if possible.

0reactions
daxfohlcommented, Jan 22, 2022

Seems to be an issue with CI, something unrelated in Pandas is broken for that PR but the test passes locally.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Lecture Notes for Ph219/CS219: Quantum Information Chapter 2
In quantum mechanics, an observable is a self-adjoint operator. only if A and B commute. Note that AB + BA and i(AB βˆ’...
Read more >
arXiv:2009.00515v1 [quant-ph] 1 Sep 2020
A scenario for which the latter is true is said to have an indefinite causal order. To represent the events, one performs quantum...
Read more >
Quantum Computing
1 Classical and Quantum computation: circuit model ... Here comes our first assumption, which is different from classical circuits.
Read more >
The axiomatic and the operational approaches to resource ...
Stabilizer operations (SO) occupy a prominent role in fault-tolerant quantum computing. They are defined operationally by the use of Clifford gates, PauliΒ ...
Read more >
Commuting Compositions for Quantum Circuit Reduction
Most quantum computing devices support gates that operate on one or ... In this case, each gate's control lines are disjoint from the...
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