`ClassicallyControlledOperation` breaks assumption that disjoint operations commute.
See original GitHub issueDescription 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.
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
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
Seems to be an issue with CI, something unrelated in Pandas is broken for that PR but the test passes locally.