Skip to content

Commit

Permalink
Merge pull request #7 from QEC-pages/syndrome_weight
Browse files Browse the repository at this point in the history
added syndrome weight information
  • Loading branch information
LeonidPryadko authored Oct 16, 2024
2 parents e9d8931 + d5a2637 commit 0273dc5
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
29 changes: 25 additions & 4 deletions src/dist_cc.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ static inline void one_ordered_pos_del(one_vec_t * const err, _maybe_unused cons
*/
int start_CC_recurs(one_vec_t *err, one_vec_t *urr, one_vec_t * const syn[],
const int wmax, const int max_col_wt,
const csr_t * const mH, const csr_t * const mHT, const csr_t * const mL,
const csr_t * const mH, const csr_t * const mHT, const csr_t * const mL, int p_swei[],
const int debug){
const int w=err->wei;
int row = syn[w]->vec[0]; /** row with the first non-zero syndrome bit */
Expand Down Expand Up @@ -214,11 +214,24 @@ int start_CC_recurs(one_vec_t *err, one_vec_t *urr, one_vec_t * const syn[],
#endif
pos = one_ordered_ins(err,col);
int swei = one_csr_row_combine(syn[w+1],syn[w], mHT, col);
if(p_swei[err->wei] > swei){
//#ifndef NDEBUG
if(debug&64){
printf("# swei[%d]=%d -> %d change\n# err: ",
err->wei,p_swei[err->wei],swei);
one_vec_print(err);
printf("# syn: ");
one_vec_print(syn[w+1]);
}
//#endif
p_swei[err->wei]=swei;
}
int result = 0;
if (err->wei < wmax){
if (swei){ /** go up */
if(swei <= (wmax - err->wei)*max_col_wt){ /** reachable goal? */
result = start_CC_recurs(err,urr,syn,wmax,max_col_wt,mH,mHT,mL,debug);
result = start_CC_recurs(err,urr,syn,wmax,max_col_wt,
mH,mHT,mL,p_swei,debug);
if(result == 1)
return 1;
}
Expand Down Expand Up @@ -254,7 +267,7 @@ int start_CC_recurs(one_vec_t *err, one_vec_t *urr, one_vec_t * const syn[],
//! rewrite of the cluster method function using only sparse matrices
//! try recursive version first
int do_CC_dist(const csr_t * const mH, const csr_t * mL,
const int wmax, const int start, const int debug){
const int wmax, const int start, int p_swei[], const int debug){

const int nchk = mH->rows, nvar = mH->cols;
if((start<-1) || (start>=nvar))
Expand Down Expand Up @@ -290,9 +303,11 @@ int do_CC_dist(const csr_t * const mH, const csr_t * mL,
err->vec[0] = urr->vec[0] = i;
err->wei = urr->wei = 1;
int swei = one_csr_row_combine(syn[1], syn[0], mHT, i);
if(p_swei[1] > swei)
p_swei[1]=swei;
if (1<w){
if (swei){ /** go up */
result = start_CC_recurs(err,urr,syn,w,max_col_W,mH,mHT,mL,debug);
result = start_CC_recurs(err,urr,syn,w,max_col_W,mH,mHT,mL,p_swei,debug);
if(result == 1)
break;
}
Expand Down Expand Up @@ -324,6 +339,12 @@ int do_CC_dist(const csr_t * const mH, const csr_t * mL,
else
result = -wmax; /** not found a codeword up to wmax */

if(debug&2){
for(int i=1;i<=wmax; i++)
if(p_swei[i] <= mH->rows)
printf("# w=%d min syndrome weight %d\n",i,p_swei[i]);
}

for(int i=0; i<= wmax; i++)
free(syn[i]);
free(syn);
Expand Down
5 changes: 3 additions & 2 deletions src/dist_m4ri.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ int do_RW_dist(const csr_t * const spaH0, const csr_t * const spaL0,
#ifdef STANDALONE

int do_CC_dist(const csr_t * const mH, const csr_t * mL,
const int wmax, const int start, const int debug);
const int wmax, const int start, int p_swei[], const int debug);


int main(int argc, char **argv){
params_t * const p = &prm;
Expand All @@ -259,7 +260,7 @@ int main(int argc, char **argv){
}

if (prm.method & 2){ /* cluster method */
int dmin=do_CC_dist(p->spaH,p->spaL,p->wmax,p->start,p->debug);
int dmin=do_CC_dist(p->spaH,p->spaL,p->wmax,p->start,p->swei,p->debug);

if (dmin>0){
if (prm.debug&1)
Expand Down
14 changes: 10 additions & 4 deletions src/util_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,7 @@ void var_init(int argc, char **argv, params_t * const p){
ERROR("parameter steps=%d should be positive for RW method=%d", p->steps,p->method);
}

if(p->method &2 ){ /* CC */
if (p->wmax<=0)
ERROR("parameter wmax=%d should be positive for CC method=%d", p->wmax,p->method);
}


if((strlen(p->fin)!=0) && (!p->finH)){
int len = strlen(p->fin);
Expand Down Expand Up @@ -189,6 +186,15 @@ void var_init(int argc, char **argv, params_t * const p){
else
ERROR("need to specify H=Hx input file name; use fin=[str] or finH=[str]\n");

if(p->method &2 ){ /* CC */
if (p->wmax<=0)
ERROR("parameter wmax=%d should be positive for CC method=%d", p->wmax,p->method);
if(p->wmax>=MAX_W)
ERROR("increase MAX_W=%d defined in 'util_io.h'",MAX_W);
for(int i=0; i<=p->wmax; i++)
p->swei[i]=p->spaH->rows +1;
}

#if 0
if (p->method&2){ /* cluster */
p->max_row_wgt_H = csr_max_row_wght(p->spaH);
Expand Down
2 changes: 2 additions & 0 deletions src/util_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

//static const int max_row_wt=10;

#define MAX_W 100
typedef struct{
int debug; /* debug information */
int classical; /* 1 for a classical code, i.e., no `G=Hz` matrix*/
Expand All @@ -37,6 +38,7 @@ typedef struct{
int max_row_wgt_H; /* needed for C */
int max_col_wgt_H; /* needed ? */
//! int max_row_wt; /* WARNING: this is defined in `util_io.h` as `static const int` */
int swei[MAX_W]; /** minimum syndrome weight for each error weight */
int start;
// int linear; /* not supported */
int n0; /* code length, =nvar for css, (nvar/2) for non-css */
Expand Down

0 comments on commit 0273dc5

Please sign in to comment.