Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
74 lines (54 loc) · 1.84 KB
/
Copy pathmain.py
File metadata and controls
74 lines (54 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""
ILPQEC - ILP-based Quantum Error Correction Decoder
Run basic functionality test.
"""
import numpy as np
from ilpqec import Decoder, get_available_solvers
def main():
"""Run basic functionality test."""
print("ILPQEC - ILP-based QEC Decoder (direct HiGHS backend)")
print("=" * 50)
available = get_available_solvers()
print(f"\nAvailable solvers: {available}")
if not available:
print("\nNo solver available!")
print("Please install one of:")
print(" - HiGHS: pip install highspy")
print(" - Gurobi: pip install ilpqec[gurobi]")
print(" - Pyomo solvers: pip install ilpqec[pyomo]")
return 1
# Test with simple repetition code
print("\n--- Test: 5-qubit Repetition Code ---")
H = np.array([
[1, 1, 0, 0, 0],
[0, 1, 1, 0, 0],
[0, 0, 1, 1, 0],
[0, 0, 0, 1, 1],
])
decoder = Decoder.from_parity_check_matrix(H)
print(f"Created decoder: {decoder}")
syndrome = [0, 1, 1, 0]
print(f"\nSyndrome: {syndrome}")
correction = decoder.decode(syndrome)
print(f"Correction: {correction}")
computed_syndrome = (H @ correction) % 2
is_valid = np.array_equal(computed_syndrome, syndrome)
print(f"Valid: {is_valid}")
# Test with DEM
print("\n--- Test: Simple Detector Error Model ---")
dem_str = """
error(0.1) D0 L0
error(0.1) D0 D1
error(0.1) D1 L1
"""
decoder = Decoder.from_stim_dem(dem_str)
print(f"Created decoder: {decoder}")
detector_outcomes = [1, 0]
print(f"\nDetector outcomes: {detector_outcomes}")
_, observables = decoder.decode(detector_outcomes)
print(f"Predicted observables: {observables}")
print("\n" + "=" * 50)
print("All tests passed!")
return 0
if __name__ == "__main__":
exit(main())