diff --git a/data b/data new file mode 120000 index 0000000..ee636c3 --- /dev/null +++ b/data @@ -0,0 +1 @@ +../../simulation/bp2019/data \ No newline at end of file diff --git a/pattern_observer.c b/pattern_observer.c new file mode 100644 index 0000000..776b0b5 --- /dev/null +++ b/pattern_observer.c @@ -0,0 +1,452 @@ +//Dec 11, modifief from bp_decoding4 +//to show how error pattern evolves in bp_decoding, frame by frame (iteration by iteration) + +#include +#include +#include +#include +#include "my_lib.h" +#include //usleep(ms) +using namespace std; +using namespace itpp; + +/* + +string color_text(string str){ + //return text in red color + string color = "\033[1;31m"+str+"\033[0m"; + return color; +} +int draw_toric_x_error(bvec error_bits){ + //draw ( but not print) error for the toric code + //in stabilizer generating matrix, we have vertex for X and plaquette for Z + //in this print, we print X error first and then Z errors to the right + //use plaquette to check X error and vertex to check Z errors + int N=error_bits.length(); + int n=(int) sqrt(N/2); + //cout<<"n="<L-1) { + G.set(i,i+2-L,1); + } else { + G.set(i,i+2,1); + } + if (i+3>L-1) { + G.set(i,i+3-L,1); + }else{ + G.set(i,i+3,1); + } + } + return G; +} + +//for check +LDPC_Code get_test_LDPC_Code(){ + //convert GF2mat saved in .mm file to LDPC_Code + // GF2mat G=MM_to_GF2mat(filename); + GF2mat G = get_check_code734(7*2); + GF2mat_sparse Gs=G.sparsify(); + GF2mat_sparse_alist Gsa; + Gsa.from_sparse(Gs); + LDPC_Parity H(Gsa); + LDPC_Code C(&H); + return C; +} + + +LDPC_Code MM_to_LDPC_Code(char * filename){ + //convert GF2mat saved in .mm file to LDPC_Code + GF2mat G=MM_to_GF2mat(filename); + GF2mat_sparse Gs=G.sparsify(); + GF2mat_sparse_alist Gsa; + Gsa.from_sparse(Gs); + LDPC_Parity H(Gsa); + LDPC_Code C(&H); + return C; +} + +int save_result(double p, double converge_rate, char * filename){ + mat mat_data(2,1); + mat_data.set(0,0,p); + mat_data.set(1,0,converge_rate); + mat_to_MM(mat_data,filename);//dosen't work here and not sure why. error recorded in mm_write.c + return 0; +} +*/ +//find another error with the same syndrome +//it is still wired to use the original error as an input +//result: it is okay to use the original error as input. They are equivalent if we find another error with same syndrome. That error will be substracted eventually, and there "should" be no difference in a BP decoder in these two cases. +/*bvec error_transform(bvec e_in, GF2mat H){ + //input: original error and parity check matrix + int L = (int) sqrt( H.cols()/2); //side length of toric code + //now, just do a munual change, add a vertex operator. + bvec e_transform(e_in); + bin b1=1; + e_transform(0)=b1-e_transform(0); + e_transform(1)=b1-e_transform(1); + int pos=7*7+1; + e_transform(pos)=b1-e_transform(pos); + + //e_transform(L*L-2)=1;//b1-e_transform(L*L+2); + e_transform(L*L*2-L+1)=b1-e_transform(L*L*2-L+1); + return e_transform; + +} +*/ +/* +bvec find_error(bvec e_in, GF2mat H){ + //input: original error and parity check matrix + //output: an error with same syndrome + //int L = (int) sqrt( H.cols()/2); //side length of toric code + // bvec syndrome=H*e_in; + + GF2mat H0=H; + bvec e_t = e_in;//change name + bvec s=H*e_t;//syndrome s=s_x;//(s_x,s_z); + + H.set_size(H.rows(),H.cols()+1,true);//H=(H_x,s)//H=(H_x,H_z,s) + H.set_col(H.cols()-1,s);//add syndrome + //cout<<"parity check matrix H=(S_x,S_z,s). The last column is the syndrome. "<"<=0){ + /*cout<<"llr="< 0 ){ + //cout<<"-------------------------------- ---------------------converge when i_iteration ="< ss; + // Vec aa = (abs(llr_output)); + //ss.sort(0,llr_output.size(),llr_output); + // cout<> data/toric/bp_converge3/bp_decoding.log & +#date >> data/toric/bp_converge3/bp_decoding.log &