33 printf(
" w=%d [ ",pvec->
wei);
34 for(
int i=0; i < pvec->
wei; i++)
35 printf(
"%d ",pvec->
vec[i]);
56 const int w_limit,
const int max_col_wt,
57 const csr_t *
const mH,
const csr_t *
const mHT,
60 assert(urr->
wei == err->
wei);
61 int row = syn[w]->
vec[0];
62 const csr_t *
const mL =
p->spaL;
63 int *p_swei =
p->swei;
64 const int smax =
p->smax;
65 const int debug =
p->debug;
68 printf(
"starting CC recurs w=%d row=%d:\n urr: ",w,row);
72 for(
int i=0; i <= w; i++){
73 printf(
"# syn[i=%d] ",i);
80 const int col_min = (
p->start_num > 0 && !
p->start_scan) ? -1 : urr->
vec[0];
81 int current_limit = w_limit;
82 if (
p->min_w != INT_MAX &&
p->dW >= 0) {
83 current_limit = minint(w_limit,
p->min_w +
p->dW);
85 const int syn_w_wei = syn[w]->
wei;
86 const int rem = current_limit - (w + 1);
87 const int max_reach = rem * max_col_wt + (smax > 0 ? smax : 0);
89 for(
int i1 = mH->
p[row]; i1 < mH->
p[row+1]; i1++){
90 const int col = mH->
i[i1];
92 const int col_wt = mHT->
p[col+1] - mHT->
p[col];
93 if (w + 1 == current_limit) {
94 if (abs(syn_w_wei - col_wt) > (smax > 0 ? smax : 0))
continue;
96 if (syn_w_wei - col_wt > max_reach)
continue;
98 int pos = one_ordered_search(err, col);
104 printf(
" pos=%d urr: ",pos);
108 pos = one_ordered_ins(err,col);
110 int swei = one_csr_row_combine(syn[w+1],syn[w], mHT, col);
116 if (
p->min_w != INT_MAX &&
p->dW >= 0) {
117 current_limit = minint(w_limit,
p->min_w +
p->dW);
119 if (err->
wei < current_limit){
120 if (swei > 0 && swei <= (current_limit - err->
wei) * max_col_wt + (smax > 0 ? smax : 0)){
130 assert(err->
wei == current_limit);
133 (sparse_syndrome_non_zero(mL, err->
wei, err->
vec))){
135 printf(
"swei=%d *** success ***\n",swei);
143 if (!
p->outC &&
p->maxC == 0) {
148 else if(swei <= smax){
150 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]);
153 errors = hash_add_maybe(syn[w+1],err,
errors, p_swei, debug);
157 one_ordered_pos_del(err,col,pos);
166 printf(
"exiting CC recurs\n\n");
174 const csr_t *
const mH =
p->spaH;
175 const csr_t *
const mL =
p->spaL;
176 const int wmax =
p->wmax;
177 const int noscan =
p->noscan;
178 int *p_swei =
p->swei;
179 const int smax =
p->smax;
180 const int debug =
p->debug;
182 const int nvar = mH->
cols;
191 if((!syn) || (!err) || (!urr))
192 ERROR(
"memory allocation");
194 for(
int i=0; i <= wmax; i++){
196 if(!syn[i])
ERROR(
"i=%d memory allocation",i);
200 const int w_start = noscan ? wmax : (
p->dmin > 1 ?
p->dmin : 1);
203 const int d0 = (
p->dmin > 1) ?
p->dmin : 1;
204 const int certified = (w_start <= d0);
205 int w_limit_dynamic = wmax;
207 if (
p->outC &&
p->dW > 0) {
208 w_limit_dynamic = minint(wmax > 0 ? wmax :
p->dmax +
p->dW,
p->dmax +
p->dW);
210 w_limit_dynamic = minint(wmax > 0 ? wmax :
p->dmax,
p->dmax);
213 for(
int w=w_start; w <= w_limit_dynamic; w++){
214 if (
p->min_w != INT_MAX &&
p->dW >= 0) {
215 w_limit_dynamic = minint(wmax > 0 ? wmax :
p->min_w +
p->dW,
p->min_w +
p->dW);
217 if (w > w_limit_dynamic) {
221 if (
p->start_num > 0) {
223 end =
p->start_num - 1;
225 printf(
"# recursively searching for w=%d codewords wmax=%d from %d listed start column(s)\n",
226 w, wmax,
p->start_num);
229 beg = (
p->cbeg >= 0) ?
p->cbeg : 0;
230 end = (
p->cend >= 0) ? minint(
p->cend, nvar - w) : nvar - w;
232 printf(
"# recursively searching for w=%d codewords wmax=%d beg=%d end=%d\n",w,wmax,beg,end);
234 for(
int k = beg; k <= end; k++){
235 const int i = (
p->start_num > 0) ?
p->start_list[k] : k;
237 err->
vec[0] = urr->
vec[0] = i;
240 int swei = one_csr_row_combine(syn[1], syn[0], mHT, i);
251 (sparse_syndrome_non_zero(mL, err->
wei, err->
vec))){
257 if (!
p->outC &&
p->maxC == 0) {
263 else if(swei <= smax)
264 errors = hash_add_maybe(syn[1],err,
errors,p_swei, debug);
271 if (
p->min_w > w && w < w_limit_dynamic) {
274 }
else if (
p->min_w <= w &&
p->dW >= 0 && w <= w_limit_dynamic) {
276 fprintf(stderr,
"# CC round w=%d finished: searched with dW=%d (min_w=%d, total %lld codewords)\n",
277 w,
p->dW,
p->min_w,
p->num_cws);
285 assert( 0 == sparse_syndrome_non_zero(mH, err->
wei, err->
vec));
286 if(mL) assert(sparse_syndrome_non_zero(mL, err->
wei, err->
vec));
289 printf(
"# wmax=%d found cw of weight %d: [",wmax,result);
290 int max = ((result<50) || (debug &
DBG_LARGE)) ? result : 50 ;
291 for(
int i=0; i< max; i++)
292 printf(
"%d%s",err->
vec[i], i+1!=max?
" ": (result==max ?
"]\n" :
"...]\n"));
296 if (
p->min_w <= wmax) {
298 }
else if (certified) {
308 for(
int i=1;i<=wmax; i++) {
309 if(p_swei[i] <= mH->
rows) {
310 printf(
"# w=%d min non-zero syndrome weight %d\n",i,p_swei[i]);
317 printf(
"# confinement: ");
318 for(
int i=1;i<=wmax; i++) {
319 if(p_swei[i] <= mH->
rows) {
320 printf(
"%d%s",p_swei[i],i<wmax?
",":
"");
323 printf(
"?%s",i<wmax?
",":
"");
329 printf(
"# Note: Some weights were skipped in confinement profile. Try increasing smax (current: %d)\n", smax);
333 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
#define HASH_DEL(head, delptr)
#define HASH_ITER(hh, head, el, tmp)
Utility functions for use with uthash.h.
struct TWO_VEC_T two_vec_t
structure to hold two sparse vectors (syndrome,error) in a hash
struct ONE_VEC_T one_vec_t
int codeword_maxc_reached(const params_t *const p)
Returns 1 if maxC > 0 and maxC codewords of the collection window are collected.
cw_vec_t * codeword_add_maybe(params_t *const p, const int arr[], int weight, int src)
Add a candidate codeword to the hash table, or count one more hit of a known codeword.
void csr_dump(FILE *stream, const csr_t *const M, const char name[], const int debug)
Print a binary CSR matrix row by row ('1': nonzero, '.': zero), for DBG_MATRICES.
csr_t * csr_transpose(csr_t *dst, const csr_t *const p)
Transpose a compressed CSR sparse matrix.
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