Skip to content

Feature Request: Add LATEST InsertStrategy to complement EARLIEST #7611

@zlatko-minev

Description

@zlatko-minev

Is your feature request related to a use case or problem? Please explain

Yes. The current cirq.InsertStrategy enum includes EARLIEST, which provides a powerful way to schedule an operation as early as possible in the circuit, pushing it to the "left." However, there is no symmetric counterpart to schedule an operation as late as possible, i.e., pushing it to the "right."

This missing functionality is useful for various circuit optimization and scheduling tasks. For example, a user may want to delay a gate as much as possible to mitigate decoherence before a measurement or to align operations for a specific hardware layout. The absence of a LATEST strategy forces users to implement this logic manually, which is cumbersome and error-prone.


Describe the solution you would prefer

I propose adding a new InsertStrategy called LATEST. This strategy would be the logical inverse of EARLIEST.

Its behavior should be:

  • Scan forward from the given insert location.
  • Find the last possible moment where the new operation can be placed without conflicting with any existing operations on the same qubits.
  • The operation should never be inserted at an index before the originally specified insertion location.
  • If the scan reaches the end of the circuit without finding any conflicts, the operation should be added to the last moment if compatible, or a new moment at the very end.

A potential docstring could be:

InsertStrategy.LATEST = InsertStrategy(
    'LATEST',
    """
    Scans forward from the insert location until a moment with operations
    touching qubits affected by the operation to insert is found. The operation
    is added into the moment just before that conflicting location.

    If the scan reaches the end of the circuit without finding any conflicting
    operations, the operation is added into the last moment of the circuit
    if possible, otherwise in a new moment at the end.

    The operation is never added into moments before the initial insert
    location.
    """,
)

How urgent is this for you? Is it blocking important work?

P2 – I'm blocked by it, but will work around it.

Describe alternatives/workarounds you've considered

The primary workaround is to manually implement the logic. This involves getting the circuit's moments, iterating forward from the desired insertion index, checking for qubit conflicts at each moment (circuit.operation_at(qubit, moment_index)), and keeping track of the last valid placement. This is tedious, inefficient for users, and requires re-implementing logic that is core to the circuit construction API.

Provide additional information or context

Adding LATEST would create a satisfying symmetry with the existing EARLIEST strategy. It would make the InsertStrategy API more complete, intuitive, and powerful for users performing circuit scheduling.

Metadata

Metadata

Labels

kind/feature-requestDescribes new functionalitytriage/acceptedA consensus emerged that this bug report, feature request, or other action should be worked on

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions