2

Can I increment the value of 'i' in OBSERVABLE_INCLUDE(i) for each iteration within REPEAT in Stim? For example, I would like the 'i' in OBSERVABLE_INCLUDE(i) to become 0,1,2,3,4,5,6,7,8 when the circuit is repeated three times, resulting in a total of nine OBSERVABLE_INCLUDE(i).

circuit=stim.Circuit('''    
    REPEAT 3 {
        M 1 2 3
        OBSERVABLE_INCLUDE(0) rec[-3]
        OBSERVABLE_INCLUDE(1) rec[-2]
        OBSERVABLE_INCLUDE(2) rec[-1]
    }
''')
kong
  • 21
  • 2

1 Answers1

2

No, there's no way to offset the observable indices or make them depend on the loop iteration.

To achieve the effect you want, you can unroll the loop (i.e. actually repeat its content multiple times in the circuit) and tweak each unrolled iteration. It's not succinct, but it'll work.

circuit=stim.Circuit('''    
    # iteration 0
        M 1 2 3
        OBSERVABLE_INCLUDE(0) rec[-3]
        OBSERVABLE_INCLUDE(1) rec[-2]
        OBSERVABLE_INCLUDE(2) rec[-1]
    # iteration 1
        M 1 2 3
        OBSERVABLE_INCLUDE(1) rec[-3]
        OBSERVABLE_INCLUDE(2) rec[-2]
        OBSERVABLE_INCLUDE(3) rec[-1]
    # iteration 2
        M 1 2 3
        OBSERVABLE_INCLUDE(2) rec[-3]
        OBSERVABLE_INCLUDE(3) rec[-2]
        OBSERVABLE_INCLUDE(4) rec[-1]
''')

A hack that would almost work entirely within a loop is to use feedback operations onto ancilla qubits to accumulate the observables, rotate the ancilla qubits using swaps to switch which was being targeted, and at the end of the circuit add the ancilla measurements into the observables. I wouldn't recommend doing it this way, since it pretty seriously diverges the intent of the circuit from the actual operations (e.g. if you applied a noise model it would likely mistakenly add noise to the swaps rotating the ancilla qubits). But it'd look like this:

REPEAT 3 {
    M 1 2 3
    # Accumulate onto ancilla qubits using feedback.
    CX rec[-3] 100
    CX rec[-2] 101
    CX rec[-1] 102
    # Right-rotate the ancilla qubit register.
    SWAP 104 103
    SWAP 103 102
    SWAP 102 101
    SWAP 101 100
}

Unpack ancilla qubits into observables.

M 103 104 100 101 102 OBSERVABLE_INCLUDE(0) rec[-1] OBSERVABLE_INCLUDE(1) rec[-2] OBSERVABLE_INCLUDE(2) rec[-3] OBSERVABLE_INCLUDE(3) rec[-4] OBSERVABLE_INCLUDE(4) rec[-5]

Craig Gidney
  • 36,389
  • 1
  • 29
  • 95