0
$\begingroup$

I am using the explain_detector_error_model_errors() method, unfortunately I am receiving this: [no single circuit error had these exact symptoms]. May I ask why it's giving me this? And is there any other ways to extract the actual errors in Stim? Thanks.

$\endgroup$

1 Answer 1

1
$\begingroup$

That method is for turning the detection events of a single dem error into possible circuit errors causing that dem error. It doesn't do general decoding, as that is way way harder. So it doesn't work on entire shots, only on single errors.

You would typically get individual errors from your decoder, from the list returned by a search-for-logical-error method like stim.Circuit.shortest_graphlike_error, or from the sampler itself. For example, you can use the detector error model sampler to record the indices of error mechanisms that were used, then use explain error to turn those back into compatible circuit errors:

import stim
import numpy as np

circuit = stim.Circuit.generated(
    "surface_code:rotated_memory_x",
    distance=5,
    rounds=5,
    after_clifford_depolarization=3e-3,
    before_measure_flip_probability=3e-3,
    after_reset_flip_probability=3e-3,
)

dem = circuit.detector_error_model()

# List out the errors, for later lookup
error_instructions = []
for instruction in dem.flattened():
    if instruction.type == 'error':
        error_instructions.append(instruction)

# Sample with error collection
sampler = dem.compile_sampler()
detectors, observables, errors = sampler.sample(shots=1, return_errors=True)

# Print out all errors and their circuit equivalents
for shot_index, shot_errors in enumerate(errors):
    dem_filter = stim.DetectorErrorModel()
    for error_index in np.flatnonzero(shot_errors):
        dem_filter.append(error_instructions[error_index])
    circuit_errors = circuit.explain_detector_error_model_errors(
        dem_filter=dem_filter,
        reduce_to_one_representative_error=True,
    )
    for k, circuit_err in enumerate(circuit_errors):
        print(f"Shot #{shot_index} Error #{k}")
        print(f"dem: [{', '.join(str(e) for e in circuit_err.dem_error_terms)}]")
        print("circuit: ", circuit_err.circuit_error_locations[0])

Which can print nothing due to sampling no errors in the shot, but if you run it a few times you'll see something like:

Shot #0 Error #0
dem: [D33[coords 8,8,1]]
circuit:  CircuitErrorLocation {
    flipped_pauli_product: X52[coords 8,8]
    Circuit location stack trace:
        (after 0 TICKs)
        at instruction #53 (X_ERROR) in the circuit
        at target #22 of the instruction
        resolving to X_ERROR(0.003) 52[coords 8,8]
}
Shot #0 Error #1
dem: [D40[coords 6,2,2], D61[coords 6,0,3], D63[coords 4,2,3]]
circuit:  CircuitErrorLocation {
    flipped_pauli_product: Y5[coords 5,1]
    Circuit location stack trace:
        (after 18 TICKs)
        at instruction #88 (a REPEAT 4 block) in the circuit
        after 1 completed iterations
        at instruction #12 (DEPOLARIZE2) in the REPEAT block
        at targets #5 to #6 of the instruction
        resolving to DEPOLARIZE2(0.003) 15[coords 4,2] 5[coords 5,1]
}
Shot #0 Error #2
dem: [D55[coords 4,8,2], D58[coords 4,10,2], D73[coords 4,6,3]]
circuit:  CircuitErrorLocation {
    flipped_pauli_product: Y47[coords 3,9]*Y48[coords 4,8]
    Circuit location stack trace:
        (after 18 TICKs)
        at instruction #88 (a REPEAT 4 block) in the circuit
        after 1 completed iterations
        at instruction #12 (DEPOLARIZE2) in the REPEAT block
        at targets #27 to #28 of the instruction
        resolving to DEPOLARIZE2(0.003) 47[coords 3,9] 48[coords 4,8]
}
$\endgroup$
1
  • $\begingroup$ Thanks for all this. Would you say that it's generally better to use heralded errors in my circuit if I were to really need to know the locations of error, be it for decoding or research? Cheers. $\endgroup$
    – user29731
    Commented Jun 8 at 10:45

Your Answer

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