# Precise definition of a DETECTOR in Stim

I would like to check I precisely understand the definition of what a detector does in Stim. Below is my understanding and I am looking for confirmation that I understood correctly. If not, please correct me.

My current understanding of how detector work by definition:

I call $$\{x_i\}_i$$ a family of qubit measurement outcomes. We have $$x_i \in \{0,1\}$$.

A detector takes as input a family of measurements $$\{x_i \}_{i=1}^N$$.

Then, one considers two circuits: one with the noise "off". In this case, the family of measurement outcomes will be $$\{x^{\text{no noise}}_i \}_{i=1}^N$$.

The other family is with the noise "on". In this case, the family of measurement outcomes will be $$\{x^{\text{noise}}_i \}_{i=1}^N$$.

If the sum (modulo 2) $$x^{\text{no noise}}_1 \oplus x^{\text{no noise}}_2 \oplus ... \oplus x^{\text{no noise}}_N=x^{\text{noise}}_1 \oplus x^{\text{noise}}_2 \oplus ... \oplus x^{\text{noise}}_N$$, then, the detector returns FALSE. If not, it returns TRUE.

To give an example, the command DETECTOR rec[-1] rec[-2] rec[-3] (i) computes the sum of the last 3 measurements for a noiseless circuit run and compares it to the sum of the measurements of the noisy circuit run. It returns FALSE if they agree, TRUE if they disagree.

Am I correct?

Yes, this is a good definition of a detector. Note that the binary sum of a set of measurement outcomes needs to be deterministic to be able to use it as a detector. For example, a single measurement outcome from measuring a qubit in the state $$|0>$$ in the + basis can't be used as a detector. But if the measurement is done in the computational basis one can define a detector: $$m_1 = 0$$.
• Technically stim allows non-deterministic detectors; but you need to pass allow_gauge_detectors=True to stim.Circuit.detector_error_model for it to work. What it does, essentially, is turn every anticommutation into a 50% error mechanism by using Gaussian elimination. But I recommend not using this feature. Commented Mar 13 at 20:28