Skip to content

Enhance transformers to preserve moment structure and operations order in Circuit #8131

Description

@pavoljuhas

Is your design idea/issue related to a use case or problem? Please explain

According to #8097 (comment) it is essential to support duplicate measurement keys in a single moment as this allows optimizations of internal QEC experiments. With such key reuse the measurement data form a single stream of bits where it is critical to know the order of measurements so result bits can be assigned to the individual measurement operations with a common key. Currently the cirq transformers such as cirq.map_operations have no guarantee that a transformed circuit would have the same moment structure or the order of transformed operations in a moment. As an example, a map_operation using an identity mapping splits a moment with a duplicate measurement key into two moments:

>>> q0, q1 = cirq.q(0), cirq.q(1)
>>> c = cirq.Circuit(cirq.Moment(cirq.M(q0, key="m"), cirq.M(q1, key="m")))
>>> print(c)

0: ───M('m')───

1: ───M('m')───

>>> c1 = cirq.map_operations(c, lambda op, index: op)
>>> print(c1)

0: ───M('m')────────────

1: ────────────M('m')───

While map_operations has a lot of flexibility in that it allows converting single operation to an OP_TREE it is a frequent the use case that an operation just needs to be transformed to a modified operation (or dropped).

The proposal here is to provide cirq transformers with an option to preserve the moment structure of the circuit and also the order of transformed operations within their moments. Such transformers should provide a native safe conversion for circuits with duplicate measurement keys, and should eliminate workarounds that are currently needed to obtain circuits with a desired order of measurements.

Describe your design idea/issue

The initial idea is to add a preserve_moments flag argument to map_operations which will require the map-function results from a source Moment to be packed to one target Moment in the same order. The transformer would fail if mapped operations cannot fit in a single moment, e.g., if several new operations act on the same qubit.

Before going any further, we need to check with the QEC colleagues to get a full picture of their requirements and understand what should be changed or added to Cirq (within its backward compatibility requirements) to support them.

Refs

cc: @maffoo

Metadata

Metadata

Assignees

Labels

kind/design-issueA conversation around designpriority/after-1.7Leave for after the Cirq 1.7 releasetriage/discussNeeds decision / discussion, bring these up during Cirq Cynque

Fields

No fields configured for Enhancement.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions