In qikit, there is a circuit called c_if that feeds back to the quantum circuit according to the measured results.
https://qiskit.org/documentation/stable/0.39/stubs/qiskit.circuit.InstructionSet.c_if.html
How can I do the same thing in stim?
In qikit, there is a circuit called c_if that feeds back to the quantum circuit according to the measured results.
https://qiskit.org/documentation/stable/0.39/stubs/qiskit.circuit.InstructionSet.c_if.html
How can I do the same thing in stim?
The first target given to the CX
, CY
, or CZ
operations can be a measurement record target like rec[-1]
. From the python API these targets are created like stim.target_rec(-1)
. Using a measurement record as the operation's control conditions the X, Y, or Z operation on a previous measurement.
For example, here is a teleportation circuit:
# Create entanglement between Alice and Bob
H 1
CX 1 9
# Alice prepares a state to send
H 0
S 0
# Alice does a Bell basis measurement
CX 0 1
H 0
M 0 1
# Alice communicates the bits to Bob, who performs the corrections
CZ rec[-2] 9
CX rec[-1] 9
# Bob now has the qubit that Alice prepared
S_DAG 9
H 9
M 9
DETECTOR rec[-1]
Output from stim.Circuit(...).diagram(type='timeline-svg')
:
Stim circuits only allow Pauli gates to be classically controlled, because classically controlling other gates breaks the algorithmic trick Stim uses to sample thousands of times faster after an initial reference sample is acquired.