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.

Is it necessary to hold off on measurement key remapping in `CircuitOperation`?

See original GitHub issue

Is your design idea/issue related to a use case or problem? Please describe. Currently, CircuitOperation keeps a local Dict of measurement key remappings and does not propagate it to the actual underlying circuit, even though a new CircuitOperation is created on each with_measurement_key_mapping call. I suspect this was done for efficiency to avoid iterating over the circuit or create a copy of it.

But this behavior leads to some inconsistencies and additional complexity if you try to work with the underlying circuit, leading me to wonder if this optimization is worth it. Most of the interface of Circuit and CircuitOperation is consistent but this logic introduces some counter-intuitive behavior unless you know this implementation detail of CircuitOperation.

import cirq
q=cirq.LineQubit(0)
c = cirq.Circuit([cirq.MeasurementGate(1, key='a')(q)])
c_op = cirq.CircuitOperation(c.freeze())
remapped_c = cirq.with_measurement_key_mapping(c, {'a':'b'})
remapped_c_op = cirq.with_measurement_key_mapping(c_op, {'a':'b'})
print(remapped_c.all_measurement_keys())                  # {'b'}
print(remapped_c_op.circuit.all_measurement_keys())       # {'a'}  May be unexpected
print(cirq.measurement_keys(remapped_c))                  # {'b'}
print(cirq.measurement_keys(remapped_c_op.circuit))       # {'a'}  May be unexpected
# But the below works as expected.
print(cirq.measurement_keys(remapped_c_op))               # {'b'}

Describe your design idea/issue Rather than keeping a Dict of mappings in CircuitOperation, we can pass down the remapping of keys to the underlying Circuit similar to how key remapping on a Circuit passes it on to Moments and then Operations. This will make the behavior consistent and easier to understand but there is a (small?) performance penalty at the time of circuit construction in the python code.

This will also make other logic or additional features dealing with measurements in CircuitOperations cleaner.

Note: This does not include the repetition_id path update on the keys during “unrolling” of the sub-circuit. That is purely a CircuitOperation feature and should be kept local to CircuitOperation unless needed elsewhere.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
95-martin-orioncommented, Oct 22, 2021

Not propagating measurement key changes to the underlying circuit is intentional, as it allows us to reference the same FrozenCircuit object across multiple CircuitOperations. Without this, we would be unable to concisely serialize multiple copies of a measurement-containing CircuitOperation.

0reactions
95-martin-orioncommented, Nov 1, 2021

mapped_circuit(..., deep=False) and changing parent_path are used to facilitate CircuitOperation._decompose_. This is currently used by cirq_google.optimize_for_sycamore to convert the contents of a CircuitOperation to Sycamore-friendly gates while preserving the CircuitOperation structure which contains them.

It might be possible to do this without deep=False, but it would effectively involve doing decomposition work outside of the decomposition protocol.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to measure and evaluate binding affinities - eLife
Simple guidelines and a checklist are provided for performing high-quality equilibrium binding measurements.
Read more >
Multimeter - Wikipedia
A multimeter is a measuring instrument that can measure multiple electrical properties. A typical multimeter can measure voltage, resistance, and current, ...
Read more >
Missing a Key? How to Remap and Fix Your Keyboard Layout
Remapping keys on your computer's keyboard lets you replace one key with another, ... don't let that keyboard hold you back—you can just...
Read more >
DL750/DL750P ScopeCorder User's Manual - Yokogawa
Slope, and Trigger Level, Trigger Hysteresis, Trigger Hold-off, Action-on-Trigger, ... Automated Measurement of Waveform Parameters, Statistical Processing, ...
Read more >
How to measure and evaluate binding affinities - PMC - NCBI
These observations highlight an urgent need to revisit the criteria for reliable binding measurements. There is a parallel need to render these criteria ......
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