Skip to content

Don't construct huge repetition id lists for CircuitOperation when use_repetition_ids=False #5418

@Strilanc

Description

@Strilanc

Do not run this repro code unless you like thrashing your machine.

import cirq
op = cirq.CircuitOperation(
    cirq.FrozenCircuit(),
    repetitions=1_000_000_000_000,
    use_repetition_ids=False)

Expected behavior

Because use_repetition_ids is set to False, no list of repetition ids is ever created and the code finishes in under a second. This remains true when using the operation for other actions that don't affect the repetition ids, like transforming its qubits or putting it into a diagram.

Actual behavior

Internally, the code attempts to create a list of one trillion repetition ids. This list will never be used and also does not fit in memory. The code takes forever and eventually crashes.


For context, I know that Mike Newman has used stim to run circuits with hundreds of millions of rounds. If he ever attempted to use stimcirq to convert that circuit into a cirq circuit... *KABOOM*.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bug-reportSomething doesn't seem to work.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions