PyMatching
PyMatching copied to clipboard
Examples in README.md produce unexpected results
This is the second example README.md:
import numpy as np
from scipy.sparse import csc_matrix
import pymatching
H = csc_matrix([[1, 1, 0, 0, 0],
[0, 1, 1, 0, 0],
[0, 0, 1, 1, 0],
[0, 0, 0, 1, 1]])
observables = csc_matrix([[1, 0, 0, 0, 0]])
error_probability = 0.1
weights = np.ones(H.shape[1]) * np.log((1-error_probability)/error_probability)
matching = pymatching.Matching.from_check_matrix(H, weights=weights, faults_matrix=observables)
num_shots = 1000
num_errors = 0
for i in range(num_shots):
noise = (np.random.random(H.shape[1]) < error_probability).astype(np.uint8)
syndrome = H@noise % 2
predicted_observables = matching.decode(syndrome)
actual_observables = observables@noise % 2
num_errors += not np.array_equal(predicted_observables, actual_observables)
print(num_errors) # prints 6
However, running it locally prints 8 instead. Here is my local environment:
contourpy==1.2.0
cycler==0.12.1
fonttools==4.48.1
kiwisolver==1.4.5
matplotlib==3.8.2
networkx==3.2.1
numpy==1.26.4
packaging==23.2
pillow==10.2.0
PyMatching==2.1.0
pyparsing==3.1.1
python-dateutil==2.8.2
retworkx==0.14.0
rustworkx==0.14.0
scipy==1.12.0
six==1.16.0
stim==1.12.1
I'm realizing this should be nondeterministic?