Skip to content

Support for circuit repeats in cirq-web #7540

@seunomonije

Description

@seunomonije

Describe the issue

Repeats in circuits cause issues in cirq-web. This can be fixed by:

  1. Adjusting the code on the Python side where we serialize and build the 3D symbols for the Typescript to detect operations inside of a repeating block.
  2. Introducing some symbol or sprite on the Typescript side that points to the Moment(s) that the user wants repeated. Similar to how a qubit is added, we can create a unique mesh that lives outside of the circuit and surrounds the moment(s) that are being repeated.

For starters, it might be best to only show a bracket. Eventually it would be nice to have the option to expand out the repetitions.

A patch could also just ignore the repeat and show the moment.

Explain how to reproduce the bug or problem

When running a circuit with repeats (for brevity, this stim circuit is invalid):

stim_circuit = stim.Circuit("""
REPEAT 999 {
    TICK
    H 2 11 16 25
    DEPOLARIZE1(0.001) 2 11 16 25
    TICK
    CX 2 3 16 17 11 12 15 14 10 9 19 18
    DEPOLARIZE2(0.001) 2 3 16 17 11 12 15 14 10 9 19 18
    TICK
    CX 2 1 16 15 11 10 8 14 3 9 12 18
    DEPOLARIZE2(0.001) 2 1 16 15 11 10 8 14 3 9 12 18
    TICK
    CX 16 10 11 5 25 19 8 9 17 18 12 13
    DEPOLARIZE2(0.001) 16 10 11 5 25 19 8 9 17 18 12 13
    TICK
    CX 16 8 11 3 25 17 1 9 10 18 5 13
    DEPOLARIZE2(0.001) 16 8 11 3 25 17 1 9 10 18 5 13
    TICK
    H 2 11 16 25
    DEPOLARIZE1(0.001) 2 11 16 25
    TICK
    MR 2 9 11 13 14 16 18 25
    SHIFT_COORDS(0, 0, 1)
    DETECTOR(2, 0, 0) rec[-8] rec[-16]
    DETECTOR(2, 2, 0) rec[-7] rec[-15]
    DETECTOR(4, 2, 0) rec[-6] rec[-14]
    DETECTOR(6, 2, 0) rec[-5] rec[-13]
    DETECTOR(0, 4, 0) rec[-4] rec[-12]
    DETECTOR(2, 4, 0) rec[-3] rec[-11]
    DETECTOR(4, 4, 0) rec[-2] rec[-10]
    DETECTOR(4, 6, 0) rec[-1] rec[-9]
}
""")
cirq_circuit = stimcirq.stim_circuit_to_cirq_circuit(stim_circuit)
print(cirq_circuit)
cirq_web.Circuit3D(cirq_circuit).generate_html_file(
    file_name="stim_circuit_viewer.html",
    open_in_browser=True,
)

Cirq-web does not display any meaningful information.

Image

However, when removing the repeat code:

stim_circuit = stim.Circuit("""
    TICK
    H 2 11 16 25
    DEPOLARIZE1(0.001) 2 11 16 25
    TICK
    CX 2 3 16 17 11 12 15 14 10 9 19 18
    DEPOLARIZE2(0.001) 2 3 16 17 11 12 15 14 10 9 19 18
    TICK
    CX 2 1 16 15 11 10 8 14 3 9 12 18
    DEPOLARIZE2(0.001) 2 1 16 15 11 10 8 14 3 9 12 18
    TICK
    CX 16 10 11 5 25 19 8 9 17 18 12 13
    DEPOLARIZE2(0.001) 16 10 11 5 25 19 8 9 17 18 12 13
    TICK
    CX 16 8 11 3 25 17 1 9 10 18 5 13
    DEPOLARIZE2(0.001) 16 8 11 3 25 17 1 9 10 18 5 13
    TICK
    H 2 11 16 25
    DEPOLARIZE1(0.001) 2 11 16 25
    TICK
    MR 2 9 11 13 14 16 18 25
    SHIFT_COORDS(0, 0, 1)
    DETECTOR(2, 0, 0) rec[-8] rec[-16]
    DETECTOR(2, 2, 0) rec[-7] rec[-15]
    DETECTOR(4, 2, 0) rec[-6] rec[-14]
    DETECTOR(6, 2, 0) rec[-5] rec[-13]
    DETECTOR(0, 4, 0) rec[-4] rec[-12]
    DETECTOR(2, 4, 0) rec[-3] rec[-11]
    DETECTOR(4, 4, 0) rec[-2] rec[-10]
    DETECTOR(4, 6, 0) rec[-1] rec[-9]
""")
cirq_circuit = stimcirq.stim_circuit_to_cirq_circuit(stim_circuit)
print(cirq_circuit)
cirq_web.Circuit3D(cirq_circuit).generate_html_file(
    file_name="stim_circuit_viewer.html",
    open_in_browser=True,
)

The circuit is handled properly.

Image

Tell us the version of Cirq where this happens

1.6.0

Metadata

Metadata

Assignees

Labels

kind/bug-reportSomething doesn't seem to work.triage/acceptedA consensus emerged that this bug report, feature request, or other action should be worked on

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions