33 printf(
" w=%d [ ",pvec->
wei);
34 for(
int i=0; i < pvec->
wei; i++)
35 printf(
"%d ",pvec->
vec[i]);
55 const int w_limit,
const int max_col_wt,
56 const csr_t *
const mH,
const csr_t *
const mHT,
59 assert(urr->
wei == err->
wei);
60 int row = syn[w]->
vec[0];
62 int *p_swei =
p->
swei;
63 const int smax =
p->
smax;
64 const int debug =
p->
debug;
67 printf(
"starting CC recurs w=%d row=%d:\n urr: ",w,row);
71 for(
int i=0; i <= w; i++){
72 printf(
"# syn[i=%d] ",i);
77 const int col_min=urr->
vec[0];
78 for(
int i1 = mH->
p[row]; i1 < mH->
p[row+1]; i1++){
79 const int col = mH->
i[i1];
81 int pos = one_ordered_search(err, col);
87 printf(
" pos=%d urr: ",pos);
91 pos = one_ordered_ins(err,col);
93 int swei = one_csr_row_combine(syn[w+1],syn[w], mHT, col);
99 int current_limit = w_limit;
101 current_limit = minint(w_limit,
p->
min_w +
p->
dW);
103 if (err->
wei < current_limit){
116 assert(err->
wei == current_limit);
119 (sparse_syndrome_non_zero(mL, err->
wei, err->
vec))){
121 printf(
"swei=%d *** success ***\n",swei);
134 else if(swei <= smax){
136 printf(
"# try adding to the hash ewei=%d swei=%d smax=%d p_swei[%d]=%d\n",err->
wei,swei,smax,w+1,p_swei[w+1]);
139 errors = hash_add_maybe(syn[w+1],err,
errors, p_swei, debug);
143 one_ordered_pos_del(err,col,pos);
152 printf(
"exiting CC recurs\n\n");
162 const int wmax =
p->
wmax;
164 int *p_swei =
p->
swei;
165 const int smax =
p->
smax;
166 const int debug =
p->
debug;
168 const int nvar = mH->
cols;
172 if((mHT->
cols<150)||(debug&2048))
180 if((!syn) || (!err) || (!urr))
181 ERROR(
"memory allocation");
183 for(
int i=0; i <= wmax; i++){
185 if(!syn[i])
ERROR(
"i=%d memory allocation",i);
189 const int w_start = noscan ? wmax : (
p->
dmin > 1 ?
p->
dmin : 1);
190 int w_limit_dynamic = wmax;
193 w_limit_dynamic = minint(wmax > 0 ? wmax :
p->
dmax +
p->
dW,
p->
dmax +
p->
dW);
195 w_limit_dynamic = minint(wmax > 0 ? wmax :
p->
dmax,
p->
dmax);
198 for(
int w=w_start; w <= w_limit_dynamic; w++){
202 if (w > w_limit_dynamic) {
206 int end = (
p->
cend >= 0) ? minint(
p->
cend, nvar - w) : nvar - w;
208 printf(
"# recursively searching for w=%d codewords wmax=%d beg=%d end=%d\n",w,wmax,beg,end);
209 for(
int i = beg; i <= end; i++){
211 err->
vec[0] = urr->
vec[0] = i;
214 int swei = one_csr_row_combine(syn[1], syn[0], mHT, i);
225 (sparse_syndrome_non_zero(mL, err->
wei, err->
vec))){
237 else if(swei <= smax)
238 errors = hash_add_maybe(syn[1],err,
errors,p_swei, debug);
245 if (
p->
min_w > w && w < w_limit_dynamic) {
248 }
else if (
p->
min_w <= w &&
p->
dW >= 0 && w <= w_limit_dynamic) {
250 fprintf(stderr,
"# CC round w=%d finished: searched with dW=%d (min_w=%d, total %lld codewords)\n",
259 assert( 0 == sparse_syndrome_non_zero(mH, err->
wei, err->
vec));
260 if(mL) assert(sparse_syndrome_non_zero(mL, err->
wei, err->
vec));
263 printf(
"# wmax=%d found cw of weight %d: [",wmax,result);
264 int max = ((result<50) || (debug&2048)) ? result : 50 ;
265 for(
int i=0; i< max; i++)
266 printf(
"%d%s",err->
vec[i], i+1!=max?
" ": (result==max ?
"]\n" :
"...]\n"));
280 for(
int i=1;i<=wmax; i++) {
281 if(p_swei[i] <= mH->
rows) {
282 printf(
"# w=%d min non-zero syndrome weight %d\n",i,p_swei[i]);
289 printf(
"# confinement: ");
290 for(
int i=1;i<=wmax; i++) {
291 if(p_swei[i] <= mH->
rows) {
292 printf(
"%d%s",p_swei[i],i<wmax?
",":
"");
295 printf(
"?%s",i<wmax?
",":
"");
301 printf(
"# Note: Some weights were skipped in confinement profile. Try increasing smax (current: %d)\n", smax);
305 for(
int i=0; i<= wmax; i++)
int do_CC_dist(params_t *const p)
void one_vec_print(const one_vec_t *const pvec)
distance of a classical or quantum CSS code
int start_CC_recurs(one_vec_t *err, one_vec_t *urr, one_vec_t *const syn[], const int w_limit, const int max_col_wt, const csr_t *const mH, const csr_t *const mHT, params_t *const p)
recursively construct codewords
structure to hold two sparse vectors (syndrome,error) in a hash
int swei[MAX_W]
int max_row_wt; /* WARNING: this is defined in util_io.h as static const int */
#define HASH_DEL(head, delptr)
#define HASH_ITER(hh, head, el, tmp)
Utility functions for use with uthash.h
cw_vec_t * codeword_add_maybe(params_t *const p, const int arr[], int weight)
Add a candidate codeword to the hash table if it meets weight limits.
csr_t * csr_transpose(csr_t *dst, const csr_t *const p)
Transpose a compressed CSR sparse matrix.
void csr_print(const csr_t *const smat, const char str[])
Print a CSR matrix with a label string (formatted output).
csr_t * csr_free(csr_t *p)
Free memory allocated for a CSR sparse matrix.
int csr_max_row_wght(const csr_t *const p)
return max row weight of CSR matrix p TODO: add code for List of Pairs