Skip to content

Commit 7419659

Browse files
authored
gf2_util and logical codeword test function added
2 parents ef12424 + 689e587 commit 7419659

File tree

9 files changed

+1009
-686
lines changed

9 files changed

+1009
-686
lines changed

doc/circuit_distance_search.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
# We do not encourage running this script on laptops, unless parameter dont_explore_edges _increasing_symptom_degree is set to True
33
# For BPC code [[144,8,12]], we requested 100G memory on Duke computer cluster.
44
from quits.circuit import *
5-
from quits.simulation import get_stim_mem_result
6-
from quits.decoder import sliding_window_circuit_mem, detector_error_model_to_matrix
5+
from quits.decoder import detector_error_model_to_matrix
76
from quits.qldpc_code import *
87
import stim
98

doc/intro.ipynb

Lines changed: 142 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"source": [
1010
"import numpy as np\n",
1111
"import stim\n",
12-
"from tqdm import tqdm\n",
1312
"from quits.qldpc_code import *\n",
1413
"from quits.circuit import get_qldpc_mem_circuit, check_overlapping_CX\n",
1514
"from quits.decoder import sliding_window_bposd_circuit_mem\n",
@@ -63,6 +62,34 @@
6362
"# z-check qubits: 108 # x-check qubits: 108\n",
6463
"# layers of entangling gates: 8\n"
6564
]
65+
},
66+
{
67+
"data": {
68+
"text/plain": [
69+
"{'css_condition': True,\n",
70+
" 'lz_commutes_with_X': True,\n",
71+
" 'lx_commutes_with_Z': True,\n",
72+
" 'rank_hz': 108,\n",
73+
" 'rank_hx': 108,\n",
74+
" 'rank_lz': 9,\n",
75+
" 'rank_lx': 9,\n",
76+
" 'k_expected': 9,\n",
77+
" 'lz_independent_mod_Z_stabilizers': True,\n",
78+
" 'lx_independent_mod_X_stabilizers': True,\n",
79+
" 'rank_hz_plus_lz': 117,\n",
80+
" 'rank_hx_plus_lx': 117,\n",
81+
" 'dim_ker_hz': 117,\n",
82+
" 'dim_ker_hx': 117,\n",
83+
" 'hx_plus_lx_spans_ker_hz': True,\n",
84+
" 'hz_plus_lz_spans_ker_hx': True,\n",
85+
" 'pairing_rank': 9,\n",
86+
" 'pairing_is_identity': True,\n",
87+
" 'ok': True}"
88+
]
89+
},
90+
"execution_count": 3,
91+
"metadata": {},
92+
"output_type": "execute_result"
6693
}
6794
],
6895
"source": [
@@ -75,7 +102,9 @@
75102
"depth = sum(list(code.num_colors.values())) \n",
76103
"print('# data qubits: ', num_data, ' # logical qubits: ', num_logical)\n",
77104
"print('# z-check qubits: ', num_zcheck, ' # x-check qubits: ', num_xcheck)\n",
78-
"print('# layers of entangling gates: ', depth)"
105+
"print('# layers of entangling gates: ', depth)\n",
106+
"\n",
107+
"code.verify_css_logicals() # Verify that the logical operators are valid"
79108
]
80109
},
81110
{
@@ -176,6 +205,34 @@
176205
"# z-check qubits: 240 # x-check qubits: 240\n",
177206
"# layers of entangling gates: 12\n"
178207
]
208+
},
209+
{
210+
"data": {
211+
"text/plain": [
212+
"{'css_condition': True,\n",
213+
" 'lz_commutes_with_X': True,\n",
214+
" 'lx_commutes_with_Z': True,\n",
215+
" 'rank_hz': 232,\n",
216+
" 'rank_hx': 232,\n",
217+
" 'rank_lz': 80,\n",
218+
" 'rank_lx': 80,\n",
219+
" 'k_expected': 80,\n",
220+
" 'lz_independent_mod_Z_stabilizers': True,\n",
221+
" 'lx_independent_mod_X_stabilizers': True,\n",
222+
" 'rank_hz_plus_lz': 312,\n",
223+
" 'rank_hx_plus_lx': 312,\n",
224+
" 'dim_ker_hz': 312,\n",
225+
" 'dim_ker_hx': 312,\n",
226+
" 'hx_plus_lx_spans_ker_hz': True,\n",
227+
" 'hz_plus_lz_spans_ker_hx': True,\n",
228+
" 'pairing_rank': 80,\n",
229+
" 'pairing_is_identity': True,\n",
230+
" 'ok': True}"
231+
]
232+
},
233+
"execution_count": 7,
234+
"metadata": {},
235+
"output_type": "execute_result"
179236
}
180237
],
181238
"source": [
@@ -188,7 +245,9 @@
188245
"depth = sum(list(code.num_colors.values())) \n",
189246
"print('# data qubits: ', num_data, ' # logical qubits: ', num_logical)\n",
190247
"print('# z-check qubits: ', num_zcheck, ' # x-check qubits: ', num_xcheck)\n",
191-
"print('# layers of entangling gates: ', depth)"
248+
"print('# layers of entangling gates: ', depth)\n",
249+
"\n",
250+
"code.verify_css_logicals() # Verify that the logical operators are valid"
192251
]
193252
},
194253
{
@@ -246,6 +305,34 @@
246305
"# z-check qubits: 30 # x-check qubits: 30\n",
247306
"# layers of entangling gates: 8\n"
248307
]
308+
},
309+
{
310+
"data": {
311+
"text/plain": [
312+
"{'css_condition': True,\n",
313+
" 'lz_commutes_with_X': True,\n",
314+
" 'lx_commutes_with_Z': True,\n",
315+
" 'rank_hz': 30,\n",
316+
" 'rank_hx': 30,\n",
317+
" 'rank_lz': 5,\n",
318+
" 'rank_lx': 5,\n",
319+
" 'k_expected': 5,\n",
320+
" 'lz_independent_mod_Z_stabilizers': True,\n",
321+
" 'lx_independent_mod_X_stabilizers': True,\n",
322+
" 'rank_hz_plus_lz': 35,\n",
323+
" 'rank_hx_plus_lx': 35,\n",
324+
" 'dim_ker_hz': 35,\n",
325+
" 'dim_ker_hx': 35,\n",
326+
" 'hx_plus_lx_spans_ker_hz': True,\n",
327+
" 'hz_plus_lz_spans_ker_hx': True,\n",
328+
" 'pairing_rank': 5,\n",
329+
" 'pairing_is_identity': True,\n",
330+
" 'ok': True}"
331+
]
332+
},
333+
"execution_count": 10,
334+
"metadata": {},
335+
"output_type": "execute_result"
249336
}
250337
],
251338
"source": [
@@ -258,7 +345,9 @@
258345
"depth = sum(list(code.num_colors.values())) \n",
259346
"print('# data qubits: ', num_data, ' # logical qubits: ', num_logical)\n",
260347
"print('# z-check qubits: ', num_zcheck, ' # x-check qubits: ', num_xcheck)\n",
261-
"print('# layers of entangling gates: ', depth)"
348+
"print('# layers of entangling gates: ', depth)\n",
349+
"\n",
350+
"code.verify_css_logicals() # Verify that the logical operators are valid"
262351
]
263352
},
264353
{
@@ -316,6 +405,34 @@
316405
"# z-check qubits: 45 # x-check qubits: 45\n",
317406
"# layers of entangling gates: 8\n"
318407
]
408+
},
409+
{
410+
"data": {
411+
"text/plain": [
412+
"{'css_condition': True,\n",
413+
" 'lz_commutes_with_X': True,\n",
414+
" 'lx_commutes_with_Z': True,\n",
415+
" 'rank_hz': 41,\n",
416+
" 'rank_hx': 41,\n",
417+
" 'rank_lz': 8,\n",
418+
" 'rank_lx': 8,\n",
419+
" 'k_expected': 8,\n",
420+
" 'lz_independent_mod_Z_stabilizers': True,\n",
421+
" 'lx_independent_mod_X_stabilizers': True,\n",
422+
" 'rank_hz_plus_lz': 49,\n",
423+
" 'rank_hx_plus_lx': 49,\n",
424+
" 'dim_ker_hz': 49,\n",
425+
" 'dim_ker_hx': 49,\n",
426+
" 'hx_plus_lx_spans_ker_hz': True,\n",
427+
" 'hz_plus_lz_spans_ker_hx': True,\n",
428+
" 'pairing_rank': 8,\n",
429+
" 'pairing_is_identity': True,\n",
430+
" 'ok': True}"
431+
]
432+
},
433+
"execution_count": 13,
434+
"metadata": {},
435+
"output_type": "execute_result"
319436
}
320437
],
321438
"source": [
@@ -328,7 +445,9 @@
328445
"depth = sum(list(code.num_colors.values())) \n",
329446
"print('# data qubits: ', num_data, ' # logical qubits: ', num_logical)\n",
330447
"print('# z-check qubits: ', num_zcheck, ' # x-check qubits: ', num_xcheck)\n",
331-
"print('# layers of entangling gates: ', depth)"
448+
"print('# layers of entangling gates: ', depth)\n",
449+
"\n",
450+
"code.verify_css_logicals() # Verify that the logical operators are valid"
332451
]
333452
},
334453
{
@@ -341,15 +460,18 @@
341460
"name": "stdout",
342461
"output_type": "stream",
343462
"text": [
344-
"Z0 : [ 2 5 8 11 14 17 20 23 26 29] , X0 : [15 16 18 19 21 22 24 25 27 28]\n",
345-
"Z1 : [ 0 3 6 9 12 30 33 36 39 42] , X1 : [15 17 18 20 21 23 24 26 27 29]\n",
346-
"Z2 : [ 1 4 7 10 13 31 34 37 40 43] , X2 : [30 31 33 34 36 37 39 40 42 43]\n",
347-
"Z3 : [ 0 3 6 9 12 15 18 21 24 27] , X3 : [30 32 33 35 36 38 39 41 42 44]\n",
463+
"Z0 : [ 0 3 6 9 12 15 18 21 24 27] , X0 : [ 3 4 5 7 9 11 15 17 18 20 21 23 24 26 27 29 30 31 32 33 35 36 37 38\n",
464+
" 39 41 60 61 75 76]\n",
465+
"Z1 : [ 1 4 7 10 13 16 19 22 25 28] , X1 : [16 17 19 20 22 23 25 26 28 29]\n",
466+
"Z2 : [ 0 3 6 9 12 30 33 36 39 42] , X2 : [ 0 2 4 6 7 8 12 14 16 22 27 29 33 34 35 37 39 41 45 46 75 76]\n",
467+
"Z3 : [ 1 4 7 10 13 31 34 37 40 43] , X3 : [ 1 2 4 5 7 8 10 11 13 14 16 17 19 20 22 23 25 26 28 29]\n",
348468
"Z4 : [ 1 2 3 4 5 7 8 12 13 14 15 18 19 20 24 31 32 33 36 37 38 39 40 41\n",
349-
" 45 46] , X4 : [15 17 20 22 24 25 32 37 39 42 45 60]\n",
350-
"Z5 : [ 1 3 7 15 16 18 21 24 25 30 31 33 34 39 45 47] , X5 : [16 18 21 23 25 26 30 31 34 36 37 38 39 42 46 61]\n",
351-
"Z6 : [ 0 1 2 3 7 8 15 21 24 25 26 30 33 34 35 39 60 61] , X6 : [ 0 5 10 12 15 17 20 22 24 25 30 35 40 42 45 75]\n",
352-
"Z7 : [ 3 4 6 7 12 16 18 22 30 31 33 36 39 40 60 62] , X7 : [ 0 3 4 7 9 10 11 12 16 18 21 23 25 26 30 33 34 37 39 40 41 42 46 76]\n"
469+
" 45 46] , X4 : [ 0 3 4 7 9 10 11 12 17 18 19 20 21 22 28 29 30 33 34 37 39 40 41 42\n",
470+
" 46 76]\n",
471+
"Z5 : [ 1 3 7 15 16 18 21 24 25 30 31 33 34 39 45 47] , X5 : [ 3 4 5 7 9 11 15 16 17 18 20 21 22 23 24 26 33 34 35 37 39 41 45 46\n",
472+
" 75 76]\n",
473+
"Z6 : [ 0 1 2 3 7 8 15 21 24 25 26 30 33 34 35 39 60 61] , X6 : [ 0 1 2 3 5 8 9 12 13 14 31 33 36 38 40 41 61 76]\n",
474+
"Z7 : [ 3 4 6 7 12 16 18 22 30 31 33 36 39 40 60 62] , X7 : [ 3 4 5 7 9 11 30 31 32 33 35 36 37 38 39 41 60 61 75 76]\n"
353475
]
354476
}
355477
],
@@ -365,7 +487,7 @@
365487
"metadata": {},
366488
"outputs": [],
367489
"source": [
368-
"p = 2e-3 # physical error rate\n",
490+
"p = 1e-3 # physical error rate\n",
369491
"num_rounds = 15 # number of rounds (T-1)\n",
370492
"basis = 'Z' # 'Z' or 'X'\n",
371493
"\n",
@@ -393,14 +515,14 @@
393515
"name": "stderr",
394516
"output_type": "stream",
395517
"text": [
396-
"100%|██████████| 100/100 [00:10<00:00, 9.50it/s]"
518+
"100%|██████████| 100/100 [00:02<00:00, 33.96it/s]"
397519
]
398520
},
399521
{
400522
"name": "stdout",
401523
"output_type": "stream",
402524
"text": [
403-
"p: 0.0020000, LFR: 0.0006698\n"
525+
"p: 0.0010000, LFR: 0.0000000\n"
404526
]
405527
},
406528
{
@@ -414,10 +536,10 @@
414536
"source": [
415537
"num_trials = 100\n",
416538
"## Simulate the circuit using Stim. \n",
417-
"detection_events, observable_flips = get_stim_mem_result(circuit, num_trials, seed=2) # simulate the circuit using Stim\n",
539+
"detection_events, observable_flips = get_stim_mem_result(circuit, num_trials, seed=1) # simulate the circuit using Stim\n",
418540
"\n",
419541
"W, F = 5, 3 # sliding window parameters\n",
420-
"max_iter, osd_order = 20, 10 # BP-OSD decoder parameters \n",
542+
"max_iter, osd_order = 10, 1 # BP-OSD decoder parameters \n",
421543
"\n",
422544
"# Perform decoding of the detection_events generated from simulating the circuit. \n",
423545
"# Returns the logical observable flip predicted from decoding. \n",
@@ -448,13 +570,13 @@
448570
"name": "stderr",
449571
"output_type": "stream",
450572
"text": [
451-
"100%|██████████| 100/100 [00:09<00:00, 10.09it/s]\n"
573+
"100%|██████████| 100/100 [00:02<00:00, 33.67it/s]\n"
452574
]
453575
}
454576
],
455577
"source": [
456578
"#use the BP-OSD decoder from the LDPC package (https://software.roffe.eu/ldpc/) as an example\n",
457-
"from quits.decoder import sliding_window_bposd_circuit_mem,sliding_window_circuit_mem\n",
579+
"from quits.decoder import sliding_window_circuit_mem\n",
458580
"from ldpc.bposd_decoder import BpOsdDecoder\n",
459581
"'''\n",
460582
"Note that it is allowed to use a different decoder (Decoder2) for the last decoding window \n",

parity_check_matrices/n=20_dv=3_dc=4_dist=8.txt

Lines changed: 0 additions & 15 deletions
This file was deleted.

parity_check_matrices/n=28_dv=3_dc=4_dist=10.txt

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)