CSS product code  0.1
C++ library to estimate distance of CSS codes. Some particular construction of CSS codes are implemented.
counter_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 #include <ctime> //to get current time
8 using namespace itpp;
9 using namespace std;
10 
11 
12 /*int test(GF2mat &G){//test how to change a matrix in a function
13  G.set(1,2,1);
14  cout<<dec2bin(7,10)<<endl;
15  cout<<dec2bin(7,8)<<endl;
16  return 0;
17  }*/
18 
19 int main(int args, char ** argv){
20  itpp::Parser parser;
21  parser.init(args,argv);
22  parser.set_silentmode(true);
23  int mode = 1; parser.get(mode,"mode");
24  int sub_mode = 1; parser.get(sub_mode,"sub_mode");
25  std::string title_str; parser.get(title_str,"title");
26  const char * title = title_str.c_str();
27  std::string note=""; parser.get(note,"note");
28  int debug = 1; //default debug on
29  parser.get(debug,"debug");
30  int seed=1; parser.get(seed,"seed");
31  // std::cout<<"\t seed:"<<seed;
32  if (debug) std::cout<<"input seed: "<<seed<<" --> ";
33  // seed = seed + std::time(nullptr);
34  // itpp::RNG_reset(std::time(nullptr));
35  // seed = seed + itpp::randi(1,1000000000);
36  itpp::RNG_reset(seed+get_time(3));
37  if (debug) std::cout<<"converted seed:"<<seed;
38  //std::cout<<std::endl;
39 
40  // int na_input; parser.get(na_input,"na_input");
41  int n_low; parser.get(n_low,"n_low");
42  int n_high; parser.get(n_high,"n_high");
43  int k_low; parser.get(k_low,"k_low");
44  int k_high; parser.get(k_high,"k_high");
45 
46 
47  // RNG_randomize();
48 
49  Real_Timer timer; timer.tic();
50 
51  GF2mat Gax,Gaz,Cax,Caz;
52  GF2mat Gbx,Gbz,Cbx,Cbz;
53  int na,ka, Gax_row,Gaz_row;//k is not necessary number of qubits
54  int nb,kb, Gbx_row,Gbz_row;
55 
56  //int mode=atof(argv[1]);
57  //char * title = argv[2];
58  char filename_Gax[256];char filename_Gaz[256];char filename_Gbx[256];char filename_Gbz[256];
59  sprintf(filename_Gax,"%sGax.mm",title); sprintf(filename_Gaz,"%sGaz.mm",title); sprintf(filename_Gbx,"%sGbx.mm",title); sprintf(filename_Gbz,"%sGbz.mm",title);
60 
61  if (debug) cout<<mode<<endl<<title<<endl;
62  switch( mode ){
63  case 1://generate random codes and save
64  na=randi(n_low,n_high); ka = randi(k_low,k_high);Gax_row=randi(1,na-ka-1); Gaz_row=na-ka-Gax_row;
65  getGoodQuantumCode(na,Gax_row,Gaz_row,Gax,Gaz,Cax,Caz,debug);
66  //getRandomQuantumCode(na,Gax_row,Gaz_row,Gax,Gaz,Cax,Caz);
67 
68  switch ( sub_mode){
69  case 1: //two random codes
70 
71  //random code B
72  nb=randi(n_low,n_high); kb = randi(k_low,k_high);Gbx_row=randi(1,nb-kb-1); Gbz_row=nb-kb-Gbx_row;
73  getGoodQuantumCode(nb,Gbx_row,Gbz_row,Gbx,Gbz,Cbx,Cbz,debug);
74  break;
75  case 2: // identical reverse code A for code B
76  //reverse X and Z of code A for code B
77  kb=ka;
78  nb=na;
79  Gbx_row=Gaz_row;
80  Gbz_row=Gax_row;
81  Gbx=Gaz;
82  Gbz=Gax;
83  Cbx=Caz;
84  Cbz=Cax;
85  break;
86  case 3: //identical code A for code B
87  kb=ka;
88  nb=na;
89  Gbx_row=Gax_row;
90  Gbz_row=Gaz_row;
91  Gbx=Gax;
92  Gbz=Gaz;
93  Cbx=Cax;
94  Cbz=Caz;
95  break;
96  }
97  // cout<<"got two good quantum code"<<endl;
98  GF2mat_to_MM(Gax,filename_Gax); GF2mat_to_MM(Gaz,filename_Gaz);
99  GF2mat_to_MM(Gbx,filename_Gbx); GF2mat_to_MM(Gbz,filename_Gbz);
100  break;
101  case 2: //from given input. This is to manually double check some result
102  if (debug) cout<<"check "<<title<<endl;
103  Gax=MM_to_GF2mat(filename_Gax); Gaz=MM_to_GF2mat(filename_Gaz);
104  Gbx=MM_to_GF2mat(filename_Gbx); Gbz=MM_to_GF2mat(filename_Gbz);
105  na=Gax.cols();
106  nb=Gbx.cols();
107 
108  Cax=getC(Gax,Gaz);
109  Caz=getC(Gax,Gaz,1);
110  Cbx=getC(Gbx,Gbz);
111  Cbz=getC(Gbx,Gbz,1);
112 
113 
114  if (debug) {cout<<"Gax "<<Gax<<endl; cout<<"Gaz "<<Gaz<<endl; cout<<"Cax "<<Cax<<endl; cout<<"Caz "<<Caz<<endl;}
115  if (debug) { cout<<"Gbx "<<Gbx<<endl; cout<<"Gbz "<<Gbz<<endl; cout<<"Cbx "<<Cbx<<endl; cout<<"Cbz "<<Cbz<<endl;}
116  // cout<<"debug"<<endl;
117  break;
118  }
119 
120 
121 
122 
123  // cout<<"check code A"<<endl;
124  if (! is_quantum_code(Gax,Gaz,Cax,Caz)) throw "invalid code";
125 
126  int dax = quantum_dist_v2(Gax,Gaz);
127  int daz = quantum_dist_v2(Gax,Gaz,1);
128 
129  // cout<<"check code B"<<endl;
130  if ( ! is_quantum_code(Gbx,Gbz,Cbx,Cbz)) throw "invalid code";
131  // cout<<"Gbx "<<Gbx<<endl; cout<<"Gbz "<<Gbz<<endl; cout<<"Cbx "<<Cbx<<endl; cout<<"Cbz "<<Cbz<<endl;
132  int dbx = quantum_dist_v2(Gbx,Gbz);
133  int dbz = quantum_dist_v2(Gbx,Gbz,1);//1 to flip X and Z
134 
135 
136  /*if ( debug) {
137  cout<<"[Code A] na = "<<na<<", ";
138  cout<<"dax = "<<dax<<", daz = "<<daz<<endl;
139  cout<<"[Code B] nb = "<<nb<<", ";
140  cout<<"dbx = "<<dbx<<", dbz = "<<dbz<<endl;
141  }*/
142 
143  // reduce(Gax,Gaz,Gbx,Gbz,dax,daz,dbx,dbz);
144  //concatenate(Gax,Gaz,Gbx,Gbz,dax,daz,dbx,dbz);
145  int flag_chain_complex=0; //run if 1
146  //0 for reduce/subsystem, distance x
147  if (product(Gax,Gaz,Gbx,Gbz,dax,daz,dbx,dbz,debug,0) == 2) {
148  std::cout<<title<<","<<note<<", time:"<<timer.toc()<<std::endl;
149  flag_chain_complex=1;
150  }
151  //1 for reduce/subsystem, distance z
152  if (product(Gax,Gaz,Gbx,Gbz,dax,daz,dbx,dbz,debug,1) == 2){
153  std::cout<<title<<","<<note<<", time:"<<timer.toc()<<std::endl;
154  // std::cout<<title<<","<<note<<std::endl;
155  // std::cout<<title<<","<<note<<", sub_mode:"<<sub_mode<<std::endl;
156  // std::cout<<title<<std::endl;
157  flag_chain_complex=1;
158  }
159  //2 for concatenate
160  // if ( product(Gax,Gaz,Gbx,Gbz,dax,daz,dbx,dbz,debug,2) == 2) std::cout<<title<<std::endl;
161  // flag_chain_complex=1;
162  if ( flag_chain_complex ){
163  // 3 for chain complex with two length-3, z distance
164  // 4 for chain complex with two length-3, x distance
165  // cout<<"mode 3 4"<<endl;
166  if (product(Gax,Gaz,Gbx,Gbz,dax,daz,dbx,dbz,debug,3) == 2)
167  std::cout<<title<<","<<note<<", time:"<<timer.toc()<<std::endl;
168  // std::cout<<title<<","<<note<<std::endl;
169  //std::cout<<title<<","<<note<<",sub_mode: "<<sub_mode<<std::endl;
170  //std::cout<<title<<std::endl;
171  if (product(Gax,Gaz,Gbx,Gbz,dax,daz,dbx,dbz,debug,4) == 2)
172  std::cout<<title<<","<<note<<", time:"<<timer.toc()<<std::endl;
173  // std::cout<<title<<","<<note<<std::endl;
174  //std::cout<<title<<","<<note<<",sub_mode: "<<sub_mode<<std::endl;
175  //std::cout<<title<<std::endl;
176  }
177 
178  if ( debug ) timer.toc_print();
179  return 0;
180 }
common::get_time
int get_time(int mode=1)
Definition: lib.cpp:53
MM_to_GF2mat
itpp::GF2mat MM_to_GF2mat(std::string file_name)
Definition: mm_read.cpp:36
product
int product(itpp::GF2mat Gax, itpp::GF2mat Gaz, itpp::GF2mat Gbx, itpp::GF2mat Gbz, int ddax, int ddaz, int ddbx, int ddbz, int debug, int mode)
Definition: product_lib.cpp:404
getGoodQuantumCode
int getGoodQuantumCode(int n, int Gx_row, int Gz_row, itpp::GF2mat &Gx, itpp::GF2mat &Gz, itpp::GF2mat &Cx, itpp::GF2mat &Cz, int debug)
Definition: product_lib.cpp:184
GF2mat_to_MM
int GF2mat_to_MM(itpp::GF2mat G, char *file_name, int debug)
Definition: mm_write.cpp:18
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: counter_concatenation.c:19
common::getC
itpp::GF2mat getC(itpp::GF2mat G_x, itpp::GF2mat G_z, int flip=0)
Definition: dist.cpp:143
common::is_quantum_code
bool is_quantum_code(itpp::GF2mat &G_x, itpp::GF2mat &G_z)
Definition: lib.cpp:77