1
$\begingroup$

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?

$\endgroup$

1 Answer 1

2
$\begingroup$

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'):

enter image description here

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.

$\endgroup$
4
  • $\begingroup$ Thank you very much. It is very helpful. Glad to get an answer from the developer. $\endgroup$
    – kaluza19
    Commented Jan 25, 2023 at 13:20
  • $\begingroup$ Incidentally, in lattice surgery, if we apply the z-gate according to the evenness of parity from the results of two syndrome measurements, is it correct to recognize that we apply the cz-gate twice? Also, is lattice surgery supported in stim? Do we need to build the circuit by ourselves? $\endgroup$
    – kaluza19
    Commented Jan 25, 2023 at 14:30
  • $\begingroup$ @kaluza19 Yes, if you want multiple classical bits XOR'd together to control a Z, you do that with a separate CZ for each bit. A system executing these operations is responsible for combining them (or optimizing them out, e.g. see stim.Circuit.with_inlined_feedback). -- Stim supports lattice surgery in the sense that it is able to understand lattice surgery circuits, but no it doesn't include functionality to generate such circuits so yes you have to make them yourself. $\endgroup$ Commented Jan 25, 2023 at 19:11
  • $\begingroup$ Thank you for your response. I would like to try different problems with the this high performance tool! $\endgroup$
    – kaluza19
    Commented Jan 26, 2023 at 0:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.