CSS product code  0.1
C++ library to estimate distance of CSS codes. Some particular construction of CSS codes are implemented.
random_concatenation.c
Go to the documentation of this file.
1 //Weilei Zeng, Nov 26 2018
2 /*
3 This code produce two random quantum codes and construct concatenated codes and reduced code. Then check their distance.
4  */
5 #include "weilei_lib/my_lib.h"
6 #include <itpp/itbase.h>
7 using namespace itpp;
8 using namespace std;
9 /*
10 bool is_quantum_code(GF2mat &Gx,GF2mat &Gz, GF2mat &Cx,GF2mat &Cz){
11  if (!(Gx*Gz.transpose()).is_zero()){
12  cout<<"(Gx*Gz.transpose()) is not zero"<<endl;return false;
13  }
14  if (!(Gx*Cz.transpose()).is_zero()){
15  cout<<"(Gx*Cz.transpose()) is not zero"<<endl;return false;
16  }
17  if (!(Gz*Cx.transpose()).is_zero()){
18  cout<<"(Gz*Cx.transpose()) is not zero"<<endl;return false;
19  }
20  int rank_of_Gx=Gx.row_rank();
21  int rank_of_Gz=Gz.row_rank();
22  int rank_of_Cx=Cx.row_rank();
23  int rank_of_Cz=Cz.row_rank();
24  int n=Gx.cols();
25  if (rank_of_Gx+rank_of_Gz+rank_of_Cx != n){
26  cout<<"(rank_of_Gx+rank_of_Gz+rank_of_Cx != n)"<<endl;
27  return false;
28  }
29  if(rank_of_Cx != rank_of_Cz){
30  cout<<"(rank_of_Cx != rank_of_Cz)"<<endl;return false;
31  }
32  // cout<<"is_quantum_code(): It is a quantum code!"<<endl;
33  return true;
34 }
35 
36 / *int getRandomQuantumCode(GF2mat &Gx,GF2mat &Gz, GF2mat &Cx,GF2mat &Cz){
37  int n=21;//sample input
38  int Gx_row=8;
39  int Gz_row=8;
40  getRandomQuantumCode(n,Gx_row,Gz_row,Gx,Gz,Cx,Cz);
41  return 0;
42  }* /
43 
44 int getRandomQuantumCode(int n,int Gx_row,int Gz_row, GF2mat &Gx,GF2mat &Gz, GF2mat &Cx,GF2mat &Cz){
45 
46  Gx = GF2mat(Gx_row,n);
47  Gz = GF2mat(Gz_row,n);
48  for ( int i =0;i<Gx_row;i++){//random G_x
49  Gx.set_row(i,randb(n));//equally 0 and 1s
50  }
51  GF2mat T,U; ivec P;
52  int rank_of_Gx = Gx.transpose().T_fact(T,U,P);
53  // GF2matPrint(T,"T");
54  GF2mat Q=T.get_submatrix(rank_of_Gx,0,n-1,n-1);
55  // Q.permute_cols(P,true); no need for T, only need for U which is not used here
56  // GF2matPrint(Q,"Q");
57  GF2mat alpha(Gz_row,Q.rows()); //a random binary matrix to select G_z
58  for ( int i=0;i<Gz_row;i++){
59  alpha.set_row(i,randb(Q.rows()));
60  }
61  Gz=alpha*Q;
62  // Gz=Q.get_submatrix(0,0,Gz_row-1,n-1);
63  //Cz=Q.get_submatrix(Gz_row,0,Q.rows()-1,n-1);
64  // GF2matPrint(Gz,"Gz");
65  // GF2matPrint(Cz,"Cz");
66  Cx=getC(Gx,Gz);
67  Cz=getC(Gx,Gz,1);
68  return 0;
69 }
70 */
71 
72 int test(GF2mat &G){//test how to change a matrix in a function
73  G.set(1,2,1);
74  cout<<dec2bin(7,10)<<endl;
75  cout<<dec2bin(7,8)<<endl;
76  return 0;
77 }
78 
79 int main(int args, char ** argv){
80  RNG_randomize(); Real_Timer timer; timer.tic();
81 
82  GF2mat Gax,Gaz,Cax,Caz;
83  GF2mat Gbx,Gbz,Cbx,Cbz;
84  int na,ka, Gax_row,Gaz_row;//k is not necessary number of qubits
85  int nb,kb, Gbx_row,Gbz_row;
86 
87  int mode=atof(argv[1]);
88  char * title = argv[2];
89  char filename_Gax[256];char filename_Gaz[256];char filename_Gbx[256];char filename_Gbz[256];
90  sprintf(filename_Gax,"%sGax.mm",title); sprintf(filename_Gaz,"%sGaz.mm",title); sprintf(filename_Gbx,"%sGbx.mm",title); sprintf(filename_Gbz,"%sGbz.mm",title);
91 
92  // cout<<mode<<endl<<title<<endl;
93  switch( mode ){
94  case 1://generate random codes and save
95  na=randi(7,10); ka = randi(1,2);Gax_row=randi(1,na-ka-1); Gaz_row=na-ka-Gax_row;
96  getRandomQuantumCode(na,Gax_row,Gaz_row,Gax,Gaz,Cax,Caz);
97  nb=randi(7,10); kb = randi(1,2);Gbx_row=randi(1,nb-kb-1); Gbz_row=nb-kb-Gbx_row;
98  getRandomQuantumCode(nb,Gbx_row,Gbz_row,Gbx,Gbz,Cbx,Cbz);
99  GF2mat_to_MM(Gax,filename_Gax); GF2mat_to_MM(Gaz,filename_Gaz);
100  GF2mat_to_MM(Gbx,filename_Gbx); GF2mat_to_MM(Gbz,filename_Gbz);
101  break;
102  case 2: //from given input. This is to manually double check some result
103  cout<<"check "<<title<<endl;
104  Gax=MM_to_GF2mat(filename_Gax); Gaz=MM_to_GF2mat(filename_Gaz);
105  Gbx=MM_to_GF2mat(filename_Gbx); Gbz=MM_to_GF2mat(filename_Gbz);
106  na=Gax.cols();
107  nb=Gbx.cols();
108 
109  cout<<"Gax "<<Gax<<endl; cout<<"Gaz "<<Gaz<<endl;
110  cout<<"Gbx "<<Gbx<<endl; cout<<"Gbz "<<Gbz<<endl;
111  //cout<<"Cax "<<Cax<<endl; cout<<"Caz "<<Caz<<endl;
112  break;
113  }
114 
115  // int nb=21; int Gbx_row=8; int Gbz_row=8;
116 
117  // is_quantum_code(Gax,Gaz,Cax,Caz);
118  // cout<<"Gax "<<Gax<<endl; cout<<"Gaz "<<Gaz<<endl; cout<<"Cax "<<Cax<<endl; cout<<"Caz "<<Caz<<endl;
119  int dax = quantum_dist_v2(Gax,Gaz);
120  int daz = quantum_dist_v2(Gax,Gaz,1);
121  cout<<"[Code A] na = "<<na<<", ";
122  cout<<"dax = "<<dax<<", daz = "<<daz<<endl;
123 
124  // is_quantum_code(Gax,Gaz,Cax,Caz);
125  // cout<<"Gbx "<<Gbx<<endl; cout<<"Gbz "<<Gbz<<endl; cout<<"Cbx "<<Cbx<<endl; cout<<"Cbz "<<Cbz<<endl;
126  int dbx = quantum_dist_v2(Gbx,Gbz);
127  int dbz = quantum_dist_v2(Gbx,Gbz,1);
128  cout<<"[Code B] nb = "<<nb<<", ";
129  cout<<"dbx = "<<dbx<<", dbz = "<<dbz<<endl;
130  reduce(Gax,Gaz,Gbx,Gbz,dax,daz,dbx,dbz);
131  concatenate(Gax,Gaz,Gbx,Gbz,dax,daz,dbx,dbz);
132 
133  cout<<"finish "<<title<<endl;
134  timer.toc_print();
135  return 0;
136 }
MM_to_GF2mat
itpp::GF2mat MM_to_GF2mat(std::string file_name)
Definition: mm_read.cpp:36
GF2mat_to_MM
int GF2mat_to_MM(itpp::GF2mat G, char *file_name, int debug)
Definition: mm_write.cpp:18
getRandomQuantumCode
int getRandomQuantumCode(int n, int Gx_row, int Gz_row, itpp::GF2mat &Gx, itpp::GF2mat &Gz, itpp::GF2mat &Cx, itpp::GF2mat &Cz)
Definition: product_lib.cpp:158
common::quantum_dist_v2
int quantum_dist_v2(itpp::GF2mat G_x, itpp::GF2mat G_z, int flip=0)
Definition: dist.cpp:179
main
int main(int args, char **argv)
Definition: random_concatenation.c:79
test
int test(GF2mat &G)
Definition: random_concatenation.c:72