Skip to content

Unable to create the decoder for Y noise modelled using PAULI_CHANNEL_1(0, p, 0) #175

@isolatedinformation

Description

@isolatedinformation

When I use the following script, adapted from the README to only add data qubit Y error modelled using the PAULI_CHANNEL_1 instruction from stim, the script seg-faults occasionally when creating the decoder object with correlations enabled.

  • If correlations are turned off, there are no segmentation faults.
  • When correlations are turned on, if p_x is set very small like 1e-15, the decoder creation doesn't seg-fault
  • Same behavior repeated across Mac and Ubuntu mcahines
  • Also happens if I set approximate_disjoint_errors=False

Is this expected behavior for correlated matching? If yes, then it would be nice to throw an error that this is cannot be supported.

Script

import numpy as np
import stim
import pymatching
distance = 5
p = 0.1
circuit = stim.Circuit.generated(
    "surface_code:rotated_memory_x", 
    distance=7, 
    rounds=7, 
    before_round_data_depolarization=p
)

circ_str = circuit.__str__()
circ_str = circ_str.replace(f"DEPOLARIZE1({p})", f"PAULI_CHANNEL_1(0, {p}, 0)")
stim_direct = stim.Circuit(circ_str)
model = stim_direct.detector_error_model(decompose_errors=True, approximate_disjoint_errors=True)
print("created DEM succesfully")
matching = pymatching.Matching.from_detector_error_model(model, enable_correlations=True)
print("created matching")
sampler = stim_direct.compile_detector_sampler()
syndrome, actual_observables = sampler.sample(shots=1000, separate_observables=True)
predicted_observables_corr = matching.decode_batch(syndrome, enable_correlations=True)
num_errors = np.sum(np.any(predicted_observables_corr != actual_observables, axis=1))
print(num_errors) 

Traceback with 4 consecutive runs

external/test-env via 🐍 v3.13.4 (.venv) on ☁️  varun took 37s 
❯ python matching.py
created DEM succesfully
created matching
339

external/test-env via 🐍 v3.13.4 (.venv) on ☁️  varun
❯ python matching.py
created DEM succesfully
created matching
329

external/test-env via 🐍 v3.13.4 (.venv) on ☁️  varun 
❯ python matching.py
created DEM succesfully
[1]    49910 segmentation fault  python matching.py

external/test-env via 🐍 v3.13.4 (.venv) on ☁️  varun
❯ python matching.py
created DEM succesfully
Traceback (most recent call last):
  File "/Users/varunseshadri/repos/external/test-env/matching.py", line 22, in <module>
    matching = pymatching.Matching.from_detector_error_model(model, enable_correlations=True)
  File "/Users/varunseshadri/repos/external/test-env/.venv/lib/python3.13/site-packages/pymatching/matching.py", line 1295, in from_detector_error_model
    m._load_from_detector_error_model(model, enable_correlations=enable_correlations)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/varunseshadri/repos/external/test-env/.venv/lib/python3.13/site-packages/pymatching/matching.py", line 1407, in _load_from_detector_error_model
    self._matching_graph = _cpp_pm.detector_error_model_to_matching_graph(
                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        str(model), enable_correlations=enable_correlations
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
ValueError: vector

Doing this removed the seg-faults,

-circ_str = circ_str.replace(f"DEPOLARIZE1({p})", f"PAULI_CHANNEL_1(0, {p}, 0)")
+circ_str = circ_str.replace(f"DEPOLARIZE1({p})", f"PAULI_CHANNEL_1(1e-15, {p}, 0)")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions