Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying to calculate the number of errors #108

Open
golanor opened this issue Jan 27, 2025 · 1 comment
Open

Error when trying to calculate the number of errors #108

golanor opened this issue Jan 27, 2025 · 1 comment

Comments

@golanor
Copy link

golanor commented Jan 27, 2025

Following either stim's or pymatching's tutorial on counting the number of errors, I get the following error

ValueError('resize only works on single-segment arrays')

Here is my code:

import stim
import pymatching

# Base stim circuit
base_circuit = """
R 0 1 2 3 4
X_ERROR(0.001) 0 1 2 3 4
TICK
CX 0 1 2 3
DEPOLARIZE2(0.001) 0 1 2 3
DEPOLARIZE1(0.001) 4
TICK
CX 2 1 4 3
DEPOLARIZE1(0.001) 0
DEPOLARIZE2(0.001) 2 1 4 3
TICK
X_ERROR(0.001) 1 3
M 1 3
TICK
DEPOLARIZE1(0.001) 0 2 4
DETECTOR(1,0) rec[-2]
DETECTOR(3,0) rec[-1]

REPEAT 5 {
    R 1 3
    X_ERROR(0.001) 1 3
    DEPOLARIZE1(0.001) 0 2 4
    CX 0 1 2 3
    DEPOLARIZE2(0.001) 0 1 2 3
    DEPOLARIZE1(0.001) 4
    CX 2 1 4 3
    DEPOLARIZE1(0.001) 0
    DEPOLARIZE2(0.001) 2 1 4 3
    X_ERROR(0.001) 1 3
    M 1 3
    DEPOLARIZE1(0.001) 0 2 4
    SHIFT_COORDS(0, 1) # increase t of future detectors
    DETECTOR(1, 0) rec[-2] rec[-4]
    DETECTOR(3, 0) rec[-1] rec[-3]
}

X_ERROR(0.001) 0 2 4
M 0 2 4
SHIFT_COORDS(0, 1)
DETECTOR(1, 0) rec[-2] rec[-3] rec[-5]
DETECTOR(3, 0) rec[-1] rec[-2] rec[-4]
# Choose the measurement(s) that make up the logical observables:
OBSERVABLE_INCLUDE(0) rec[-1]
"""

sc = stim.Circuit(base_circuit)
dem = sc.detector_error_model()
matcher = pymatching.Matching.from_detector_error_model(dem)
sampler = sc.compile_detector_sampler()
syndrome, actual_observables = sampler.sample(shots=500, separate_observables=True)
predicted_observables = matcher.decode_batch(syndrome)  # this line fails
num_errors = np.sum(np.any(predicted_observables != actual_observables, axis=1))
@oscarhiggott
Copy link
Owner

This is a result of an incompatibility between python and numpy v2 (see issue #102). Currently pymatching is pinned to numpy==1.* until the issue is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants