CSS product code  0.1
C++ library to estimate distance of CSS codes. Some particular construction of CSS codes are implemented.
product_lib.cpp
Go to the documentation of this file.
1 //outdated, not in use
2 //Weilei Zeng Nov 21, 2018
3 //to implement quantum concatenated codes. There are several ways of concatenation, see hypergraph_product_code.pdf
4 
5 
6 #include "dist.h"
7 #include <itpp/itbase.h>
8 #include <itpp/itcomm.h>
9 #include <stdio.h>
10 //#include "my_lib.h"
11 //#include "concatenation_lib.h"
12 #include "product_lib.h"
13 //using namespace common;
14 
15 
16  //constructor
17 
19 }
20 ClassicalCode::ClassicalCode(itpp::GF2mat G, itpp::GF2mat H){
21  G=G;H=H;
22  return;
23 }
24 
25 //distance estimator
27  return rand_dist();
28 }
30  return common::min_wt_decoding(G);
31 }
33  return common::rand_dist(G);
34 }
35 
36 
37 
38 //function
40  std::cout<<"Classical code: n = "<<n<<std::endl
41  <<"codeword generating matrix G"<<G
42  <<"parity check matrix H"<<H<<std::endl;
43  return;
44 }
46  ClassicalCode dual_code(H,G);
47  return dual_code;
48 }
49 
53 }
54 
55 //generate sample code
58  G = itpp::GF2mat(itpp::ones_b(n), false);
59  return;
60 }
64  return;
65 }
69  return;
70 }
71 
72 
73 
75 CSSCode::CSSCode(int na, int Gax_row, int id_Gax, int Gaz_row, int id_Gaz){
76  n=na;Gx_row=Gax_row; id_Gx=id_Gax;
77  Gz_row=Gaz_row;id_Gz=id_Gaz;
78  is_defined=1;
79 }
80 int CSSCode::generate_by_id(int debug){
81  return generate_code(Gx, Gz, n, Gx_row, id_Gx, Gz_row, id_Gz, debug);
82 }
83 
86  return getRandomQuantumCode(n, Gx_row, Gz_row, Gx, Gz, Cx, Cz);
87 }
88 
89 int CSSCode::getGoodCode(int debug){
90  return getGoodQuantumCode(n, Gx_row, Gz_row, Gx, Gz, Cx, Cz, debug);
91 }
92 
94  if ( is_C_defined ) {
95  return common::is_quantum_code(Gx, Gz, Cx, Cz);
96  }
97  return common::is_quantum_code(Gx, Gz);
98 }
99 
101  dx = rand_dist_x();
102  dz = rand_dist_z();
103  return;
104 }
105 
107  return common::min_wt_decoding(Cx, Gx);
108 }
110  return common::min_wt_decoding(Cz, Gz);
111 }
112 
114  return common::quantum_dist_v2(Gx, Gz);
115 }
117  return common::quantum_dist_v2(Gx, Gz, 1);
118 }
119 
123  return;
124 
125 }
126 
127 
128 itpp::GF2mat remove_col(itpp::GF2mat G, int col){
129  int n = G.cols();
130  if ( col ==0 ) return G.get_submatrix(0,1,G.rows()-1,G.cols()-1);
131  if ( col == n-1 ) return G.get_submatrix(0,0,G.rows()-1,G.cols()-2);
132  return G.get_submatrix(0,0,G.rows()-1,col-1).concatenate_horizontal(
133  G.get_submatrix(0,col+1,G.rows()-1,G.cols()-1)
134  );
135 }
136 
137 void remove_singleton(itpp::GF2mat &Gx, itpp::GF2mat &Gz){
138  //remove zero columns in Gx and Gz
139  //not in use, just discard code with distance 1, easier solution
140  int n = Gx.cols();
141  itpp::bvec to_remove(n);//1 fro remove, 0 remain
142  for ( int i=0;i<n;i++){
143  if (itpp::GF2mat(Gx.get_col(i)).is_zero()) to_remove.set(i,1);
144  if (itpp::GF2mat(Gz.get_col(i)).is_zero()) to_remove.set(i,1);
145  }
146  for ( int i=0;i<n;i++){
147  if ( to_remove(n-i-1) ){
148  Gx=remove_col(Gx,n-i-1);
149  Gz=remove_col(Gz,n-i-1);
150  }
151  }
154  std::cout<<"singleton removed"<<std::endl;
155  return;
156 }
157 
158 int getRandomQuantumCode(int n,int Gx_row,int Gz_row, itpp::GF2mat &Gx,itpp::GF2mat &Gz, itpp::GF2mat &Cx,itpp::GF2mat &Cz){
159 
160  Gx = itpp::GF2mat(Gx_row,n);
161  Gz = itpp::GF2mat(Gz_row,n);
162  for ( int i =0;i<Gx_row;i++){//random G_x
163  Gx.set_row(i,itpp::randb(n));//equally 0 and 1s
164  }
165  //Gx might not be full rank at this point
166 
167  itpp::GF2mat T,U; itpp::ivec P;
168  int rank_of_Gx = Gx.transpose().T_fact(T,U,P);
169  itpp::GF2mat Q=T.get_submatrix(rank_of_Gx,0,n-1,n-1);
170 
171 
172  itpp::GF2mat alpha(Gz_row,Q.rows()); //a random binary matrix to select G_z
173  for ( int i=0;i<Gz_row;i++){
174  alpha.set_row(i,itpp::randb(Q.rows()));
175  }
176  Gz=alpha*Q;
177  Cx=common::getC(Gx,Gz);
178  Cz=common::getC(Gx,Gz,1);
179  // if (! is_quantum_code(Gx,Gz,Cx,Cz)) throw "invalid code";
180 
181  return 0;
182 }
183 
184 int getGoodQuantumCode(int n,int Gx_row,int Gz_row, itpp::GF2mat &Gx,itpp::GF2mat &Gz, itpp::GF2mat &Cx,itpp::GF2mat &Cz, int debug){
185  // return best codes among multip trial
186  //repeat multiple times to get the best distance
187  itpp::GF2mat Gx_temp, Gz_temp,Cx_temp,Cz_temp;
188  int search_trial=1000;
189  int flag_find_good_code=0;
190  for ( int i =0; i<search_trial; i++){
191 
192  getRandomQuantumCode( n, Gx_row,Gz_row, Gx_temp, Gz_temp,Cx_temp,Cz_temp);
193  //check distance and update if get larger distance
194  int dx = common::quantum_dist_v2(Gx_temp,Gz_temp);
195  if ( dx >1 ){
196  int dz = common::quantum_dist_v2(Gx_temp,Gz_temp,1);
197  if (dz >1 ){
198  flag_find_good_code=1;
199  // Gx = Gx_temp; Gz = Gz_temp; Cx = Cx_temp; Cz = Cz_temp;
200  if (debug) std::cout<<common::blue_text("get good code when i =")<<i<<std::endl;
201  break;
202  // return 0;
203  }
204  }
205  }
206  Gx = Gx_temp; Gz = Gz_temp; Cx = Cx_temp; Cz = Cz_temp;
207 
208  // if ( flag_find_good_code){
209  if ( debug ) std::cout<<"Gx 1st row:"<<Gx.get_row(0)<<std::endl; // for debug the random seed
210  //make sure both Gx and Gz are full rank
211  if ( Gx.row_rank() < Gx.rows() ) {
212  if (debug ) std::cout<<"getGoodQuantumCode: Gx not full rank. now make it full rank"<<std::endl;
213  Gx = common::make_it_full_rank(Gx);
214  }
215  if ( Gz.row_rank() < Gz.rows() ) {
216  if (debug) std::cout<<"getGoodQuantumCode: Gz not full rank. now make it full rank"<<std::endl;
217  Gz = common::make_it_full_rank(Gz);
218  }
219 
220  if ( debug) if ( ! flag_find_good_code ) std::cout<<common::color_text("didn't find good code after ")<<search_trial<<" trials"<<std::endl;
221 
222 
223  return 0;
224 }
225 
226 void set_submatrix(itpp::GF2mat & G, itpp::GF2mat sub, int row, int col){
227  //put sub into G, start from (row,col)
228  for ( int i =0 ; i < sub.rows(); i ++)
229  for ( int j = 0; j< sub.cols(); j++ ){
230  G.set(i+row, j+col, sub.get(i,j));
231  }
232  return;
233 }
234 
235 
236 int is_row_reduced_echelon_form(itpp::GF2mat & alpha_Gaz, int debug = 0){
237  //check it column by column, from bottom to top
238  int get_one=0; //flag on if hit one in that column
239  int position_one=-1;//position for one in that column
240  int columns_one=0;//columns has a single one. exit for loop when reach alpha_Gaz.rows()
241  for ( int i = 0; i<alpha_Gaz.cols();i++){
242  get_one=0;
243  for ( int j = alpha_Gaz.rows()-1; j > -1; j--){
244  if (alpha_Gaz.get(j,i)){
245  if (get_one){
246  //get one twice in that column
247  if (debug) std::cout<<"get one twice in that column i="<<i<<std::endl;
248  // std::cout<<"*";
249  return 0;
250  }else{
251  if (j <= position_one){
252  //skip this column, this column is not independent
253  if (debug) std::cout<<"break the inner for loop for dependent column i = "<<i<<std::endl;
254  break;
255  // continue;
256  }else {
257  get_one=1;
258  position_one=j;
259  columns_one++;
260  }
261  }
262  }
263  }
264  //if (debug) std::cout<<"broke the inner for loop"<<std::endl;
265  if ( columns_one == alpha_Gaz.rows() ){
266  break;
267  }
268  }
269  if ( columns_one < alpha_Gaz.rows() ){
270  if (debug) std::cout<<"columns_one:"<<columns_one<<" is not full rank"<<alpha_Gaz.rows()<<std::endl;
271  // std::cout<<"*";
272  return 0;
273  }
274  return 1;
275 }
276 
277 // generate all code with size na systematically
278 int generate_code(itpp::GF2mat & Gax, itpp::GF2mat & Gaz, int na, int Gax_row, int id_Gax, int Gaz_row, int id_Gaz, int debug){
279  if (debug) std::cout<<na<<","<<Gax_row<<","<<Gaz_row<<std::endl;
280  //sanity check
281  if (Gaz_row+Gax_row > na-1){
282  std::cout<<"generate_code: no logical qubit"<<std::endl;
283  throw 2;
284  }
285  const int id_Gax_MAX = (int) pow(2, Gax_row * (na-Gax_row) ) -1 ; //maximun all one
286  if ( id_Gax <1 || id_Gax > id_Gax_MAX ) {
287  std::cout<<"illegal id_Gax: "<<id_Gax<<", id_Gax_MAX = "<<id_Gax_MAX<<std::endl;
288  throw 2;
289  }
290  const int id_Gaz_MAX = (int) pow(2, Gaz_row*(na - Gax_row)) - 1; //maximun all one
291  if ( id_Gaz < 1 || id_Gaz > id_Gaz_MAX ){
292  std::cout<<"illegal id_Gaz: "<<id_Gaz<<", id_Gaz_MAX = "<<id_Gaz_MAX<<std::endl;
293  throw 2;
294  }
295  //remove duplicate cases for id_Gax and id_Gaz
296 
297  itpp::GF2mat beta_Gaz = itpp::GF2mat(itpp::dec2bin(Gaz_row*(na-Gax_row),id_Gaz),false);
298  itpp::GF2mat alpha_Gaz(Gaz_row, na-Gax_row);
299  if ( debug ) std::cout<<"beta_Gaz = "<<beta_Gaz<<std::endl;
300  for ( int i =0;i<Gaz_row;i++){
301  if (debug) std::cout<<"set submatrix i = "<<i<<std::endl<<beta_Gaz.get_submatrix(0,i*(na-Gax_row),0, (i+1)*(na-Gax_row)-1)<<std::endl;
302  set_submatrix(alpha_Gaz, beta_Gaz.get_submatrix(0,i*(na-Gax_row),0, (i+1)*(na-Gax_row)-1), i,0);
303  }
304  if (debug) std::cout<<"alpha_Gaz"<<alpha_Gaz<<std::endl;
305  /* decreasing order is ensured in reduced row echelon form, hence not checked here
306  for ( int i =0;i<Gaz_row-1;i++){
307  if ( itpp::bin2dec(alpha_Gaz.get_row(i)) <= itpp::bin2dec(alpha_Gaz.get_row(i+1))){
308  if (debug) std::cout<< "duplicate Gaz with this id_Gaz. no calculation needed. alpha_Gaz/id_Gaz must be in decreasing order"<<std::endl;
309  return 2;
310  }
311  }*/
312  //make sure alpa_Gaz is in reduce row echelon form, to remove duplicate cases. return 2 if not in the form
313  //this duplicate the check to make sure alpha_Gaz is in decreasing order
314  if ( ! is_row_reduced_echelon_form( alpha_Gaz, debug) ) return 2;
315 
316 
317  //finish check
318 
319 
320 
321  Gax = itpp::GF2mat(Gax_row,na);
322  // identity matrix in the left part to make it reduce row echelon form.
323  set_submatrix(Gax,itpp::gf2dense_eye(Gax_row),0,0);
324  // if (debug) std::cout<<"Gax"<<Gax<<std::endl;
325 
326 
327  itpp::GF2mat alpha_Gax = itpp::GF2mat( itpp::dec2bin(Gax_row*(na-Gax_row), id_Gax), false);//false for row vector
328  if (debug) std::cout<<"alpha_Gax give the right part of Gax"<<std::endl<<alpha_Gax<<std::endl;
329  for ( int i = 0 ; i < Gax_row; i++){
330  set_submatrix(Gax,alpha_Gax.get_submatrix(0, i*(na-Gax_row), 0, (i+1)*(na-Gax_row)-1), i, Gax_row);
331  }
332  if (debug) std::cout<<"Gax"<<Gax<<std::endl;
333 
334 
335  //remove duplicate in id_Gax. They could be equal, but permute any two rows give equivalent code, so enfore all rows ( in the right part ) in decreasing order
336  for ( int i =0;i<Gax_row-1;i++){
337  if ( itpp::bin2dec(Gax.get_submatrix(0,Gax_row,Gax_row-1,na-1).get_row(i))
338  < itpp::bin2dec(Gax.get_submatrix(0,Gax_row,Gax_row-1,na-1).get_row(i+1)) ){
339  //itpp::bin2dec(alpha_Gaz.get_row(i+1))){
340  if (debug) std::cout<< "duplicate Gax with this id_Gax. no calculation needed. id_Gax must be in decreasing order. zero allowed"<<std::endl;
341  return 2;
342  }
343  }
344  //check singleton in Gax: row weight = 1
345  itpp::bvec bvec_zero = itpp::zeros_b(na);
346  for ( int i = 0; i < Gax_row; i++){
347  if ( itpp::BERC::count_errors(bvec_zero, Gax.get_row(i)) == 1){
348  // std::cout<<".";
349  return 2;
350  }
351  }
352 
353  itpp::GF2mat H = common::nullSpace(Gax);
354  if (debug) std::cout<<"nullSpace: H"<<H<<std::endl;
355 
356  //check singleton in H: row weight = 1
357  for ( int i = 0; i < na - Gax_row; i++){
358  if ( itpp::BERC::count_errors(bvec_zero, H.get_row(i)) == 1){
359  // std::cout<<"+";
360  return 2;
361  }
362  }
363 
364 
365 
366 
367  //check id_Gaz
368 
369 
370  // if (debug) std::cout<<"rows_to_remove: "<<rows_to_remove<<std::endl;
371  // remove_rows(&H, rows_to_remove );
372  if (debug) std::cout<<"alpha_Gaz"<<alpha_Gaz<<std::endl;
373  Gaz=alpha_Gaz*H;
374  //itpp::GF2mat(itpp::dec2bin(), false);
375 
376 
377  //check singleton in Gaz: col weight = 0
378  // itpp::GF2mat Haz = nullSpace(Gaz);
379  itpp::bvec bvec_zero_col=itpp::zeros_b(Gaz.rows());
380  for ( int i = 0; i < Gaz.cols(); i++){
381  if ( itpp::BERC::count_errors(bvec_zero_col, Gaz.get_col(i)) == 0){
382  // std::cout<<"+";
383  return 2;
384  }
385  }
386 
387  // Gaz = alpha_Gaz*H;
388  if (debug) std::cout<<"Gaz"<<Gaz<<std::endl;
389  return 0;
390 }
391 
392 
393 int generate_code(CSSCode & code, int debug){
394  return generate_code(code.Gx, code.Gz, code.n, code.Gx_row, code.id_Gx, code.Gz_row, code.id_Gz, debug);
395  }
396 
397 
398 
399 
400 // a version include both reduce and concatenation
401 // mode=1 for reduce/subsystem product
402 // mode=2 for concatenation
403 //only dz is checked cause dx is known to be tight
404 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){
405  //construct code C and calculate the distance; Compare it with the input (estimated) value
406  int na=Gax.cols(),nb=Gbx.cols();//,nc=na*nb;//size of the codes
407 
408  itpp::GF2mat Cax = common::getC(Gax,Gaz), Cbx = common::getC(Gbx,Gbz);//This line doesn't allow C to be empty
409  itpp::GF2mat Caz = common::getC(Gax,Gaz,1),Cbz = common::getC(Gbx,Gbz,1);//This line doesn't allow C to be empty
410 
411  // Gcz=make_it_full_rank(Gcz);//not needed for calculating distance
412  itpp::GF2mat Gcx,Gcz;
413 
414  switch ( mode ){
415  case 0://reduce/subsystem product, x distance
416 
417  Gcx = common::kron(Gax,itpp::gf2dense_eye(nb)).concatenate_vertical(common::kron(itpp::gf2dense_eye(na),Gbx));
418  Gcz=common::kron(Gaz,Gbz).concatenate_vertical(
419  common::kron(Caz,Gbz)
420  .concatenate_vertical(common::kron(Gaz,Cbz))
421  );
422  break;
423  case 1://reduce/subsystem product, z distance
424  Gcz = common::kron(Gaz,itpp::gf2dense_eye(nb)).concatenate_vertical(common::kron(itpp::gf2dense_eye(na),Gbz));
425  Gcx=common::kron(Gax,Gbx)
426  .concatenate_vertical(
427  common::kron(Cax,Gbx)
428  .concatenate_vertical(common::kron(Gax,Cbx))
429  );
430  break;
431  case 2://concatenation
432  Gcz = common::kron(Gaz,Cbz).concatenate_vertical(common::kron(itpp::gf2dense_eye(na),Gbz));
433  Gcx=common::kron(itpp::gf2dense_eye(na),Gbx).concatenate_vertical( common::kron(Gax,Cbx) );
434  break;
435  case 3:
436  // chain complex to two CSS codes.
437  case 4:
438  {
439  // chain complex to two CSS codes.
440  Gcx=common::kron(Gaz.transpose(), itpp::gf2dense_eye(Gbx.rows()))
441  .concatenate_horizontal(common::kron(itpp::gf2dense_eye(Gax.cols()),Gbx))
442  .concatenate_horizontal(common::kron(itpp::GF2mat(Gax.cols(),Gax.rows()),itpp::GF2mat(Gbx.rows(),Gbz.rows())));
443  Gcx = Gcx
444  .concatenate_vertical(
445  common::kron(itpp::GF2mat(Gax.rows(),Gaz.rows()),itpp::GF2mat(Gbx.cols(),Gbx.rows()))
446  .concatenate_horizontal(common::kron(Gax, itpp::gf2dense_eye(Gbx.cols())))
447  .concatenate_horizontal(common::kron(itpp::gf2dense_eye(Gax.rows()),Gbz.transpose()))
448  );
449  Gcz=common::kron(itpp::gf2dense_eye(Gaz.rows()), Gbx.transpose())
450  .concatenate_horizontal(common::kron(Gaz,itpp::gf2dense_eye(Gbx.cols())))
451  .concatenate_horizontal(common::kron(itpp::GF2mat(Gaz.rows(),Gax.rows()),itpp::GF2mat(Gbz.cols(),Gbz.rows())));
452  Gcz=Gcz
453  .concatenate_vertical(
454  common::kron(itpp::GF2mat( Gaz.cols(),Gaz.rows() ), itpp::GF2mat( Gbz.rows(),Gbx.rows() ))
455  .concatenate_horizontal(common::kron(itpp::gf2dense_eye(Gaz.cols()),Gbz))
456  .concatenate_horizontal(common::kron(Gax.transpose(),itpp::gf2dense_eye(Gbz.rows())))
457  );
458 
459  }
460  break;
461 
462  }
463 
464 
465  int flag_dist_flip=1;
466  switch ( mode ){
467  case 0:
468  case 4:
469  //x distance
470  flag_dist_flip=0;
471  break;
472  case 1:
473  case 2:
474  case 3:
475  // z distance
476  flag_dist_flip=1;
477  break;
478  }
479  if ( debug ){
480  switch ( mode ){
481  case 3:
482  std::cout<<"mode (3)"<<std::endl;
483  break;
484  case 4:
485  std::cout<<"mode (4)"<<std::endl;
486  break;
487  }
488  }
489  if (debug){common::GF2matPrint(Gcx,"Gcx"); common::GF2matPrint(Gcz,"Gcz");}
490 
491  if ( ! (Gcx*Gcz.transpose()).is_zero() ){
492  std::cout<<"concatenation_lib: not a quantum code "<<std::endl;
493  throw "not a quantum code";
494  }else{
495  if ( debug) std::cout<<"mode ("<<mode<<") is quantum code"<<std::endl;
496  }
497 
498  // Gcx=make_it_full_rank(Gcx);//not sure if I need it here
499  /* int daz = quantum_dist(Gax,Gaz,ddaz,1);
500  std::cout<<"daz="<<daz<<",ddaz="<<ddaz<<std::endl;
501  int dbz = quantum_dist(Gbx,Gbz,ddbz,1);
502  std::cout<<"dbz="<<dbz<<",ddbz="<<ddbz<<std::endl;*/
503  /* if (is_quantum_code(Gcx,Gcz) ){
504  std::cout<<"C is a quantum Code."<<std::endl;
505  }*/
506  // if ( debug ) std::cout<<"Gcx"<<Gcx<<"Gcz"<<Gcz<<std::endl;
507 
508  switch ( flag_dist_flip ){
509  case 0:
510  //x distance
511  {
512  // if ( debug ) std::cout<<"Gcx"<<Gcx<<"Gcz"<<Gcz<<std::endl;
513  int dax=ddax,dbx=ddbx;
514  int dcx = common::quantum_dist(Gcx,Gcz,dax*dbx,debug,0);//donot use estimated value ddaz and ddbz
515  if (debug) std::cout<<"dax,daz,dbx,dbz = "<<ddax<<","<<ddaz<<","<<ddbx<<","<<ddbz<<","<<std::endl;
516  if (dcx == dax*dbx){
517  if (debug) std::cout<<"dcx = dax*dbx = "<<dcx<<std::endl;
518  return 0;
519  }else if(dcx == common::INF) {
520  if (debug) std::cout<<"dcx = "<<dcx<<", dax = "<<dax<<", dbx = "<<dbx<<std::endl;
521  return 1;
522  }else{
523  if (dcx > dax*dbx) std::cout<<"PSEUDO ";
524  std::cout<<common::red_text("CASE:")<<" mode ("<<mode<<") dax*dbx="<<dax*dbx<<", dcx="<<dcx;
525  std::cout<<". dax,daz,dbx,dbz = "<<ddax<<","<<ddaz<<","<<ddbx<<","<<ddbz<<";";
526  std::cout<<"na,nb,nc,"<<Gax.cols()<<","<<Gbx.cols()<<","<<Gcx.cols()<<";";
527  std::cout<<"ka,kb="<<Cax.rows()<<","<<Cbx.rows()<<";";
528  return 2;
529  }
530  }
531 
532  break;
533  case 1:
534  //z distance
535  {
536  int daz=ddaz,dbz=ddbz;
537  int dcz = common::quantum_dist(Gcx,Gcz,daz*dbz,debug,1);//donot use estimated value ddaz and ddbz
538  if (debug) std::cout<<"dax,daz,dbx,dbz = "<<ddax<<","<<ddaz<<","<<ddbx<<","<<ddbz<<","<<std::endl;
539  if (dcz == daz*dbz){
540  if (debug) std::cout<<"dcz = daz*dbz = "<<dcz<<std::endl;
541  return 0;
542  }else if(dcz == common::INF) {
543  if (debug) std::cout<<"dcz = "<<dcz<<", daz = "<<daz<<", dbz = "<<dbz<<std::endl;
544  return 1;
545  }else{
546  if (dcz > daz*dbz) std::cout<<"PSEUDO ";
547  std::cout<<common::red_text("CASE:")<<" mode ("<<mode<<") daz*dbz="<<daz*dbz<<", dcz="<<dcz;
548  std::cout<<". dax,daz,dbx,dbz = "<<ddax<<","<<ddaz<<","<<ddbx<<","<<ddbz<<";";
549  std::cout<<"na,nb,nc="<<Gax.cols()<<","<<Gbx.cols()<<","<<Gcx.cols()<<";";
550  std::cout<<"ka,kb="<<Cax.rows()<<","<<Cbx.rows()<<";";
551  return 2;
552  }
553  }
554  }
555  return 0;
556 
557 }
ClassicalCode::H
itpp::GF2mat H
parity check matrix
Definition: product_lib.h:23
ClassicalCode
Definition: product_lib.h:20
CSSCode::get_713_code
void get_713_code()
Definition: product_lib.cpp:120
CSSCode::is_C_defined
int is_C_defined
Definition: product_lib.h:66
CSSCode::min_weight_dist_x
int min_weight_dist_x()
Definition: product_lib.cpp:106
CSSCode::Gz
itpp::GF2mat Gz
Definition: product_lib.h:57
ClassicalCode::info
void info()
Definition: product_lib.cpp:39
CSSCode::id_Gz
int id_Gz
Definition: product_lib.h:63
common::nullSpace
itpp::GF2mat nullSpace(itpp::GF2mat G)
Definition: dist.cpp:133
common::get_check_code734
itpp::GF2mat get_check_code734(int L)
Definition: dist.cpp:471
CSSCode::Gx
itpp::GF2mat Gx
Definition: product_lib.h:56
common::blue_text
std::string blue_text(std::string str)
Definition: lib.cpp:42
ClassicalCode::dual
ClassicalCode dual()
Definition: product_lib.cpp:45
CSSCode::is_defined
int is_defined
Definition: product_lib.h:66
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
CSSCode::dist
void dist()
Definition: product_lib.cpp:100
CSSCode::CSSCode
CSSCode()
Definition: product_lib.cpp:74
dist.h
distance related functions, defined within namespace common
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
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::red_text
std::string red_text(std::string str)
Definition: lib.cpp:37
CSSCode::rand_dist_x
int rand_dist_x()
Definition: product_lib.cpp:113
set_submatrix
void set_submatrix(itpp::GF2mat &G, itpp::GF2mat sub, int row, int col)
Definition: product_lib.cpp:226
ClassicalCode::full_rank
void full_rank()
Definition: product_lib.cpp:50
CSSCode::generate_by_id
int generate_by_id(int debug)
Definition: product_lib.cpp:80
common::INF
const int INF
Definition: dist.h:19
common::quantum_dist_v2
int quantum_dist_v2(itpp::GF2mat G_x, itpp::GF2mat G_z, int flip=0)
Definition: dist.cpp:179
remove_col
itpp::GF2mat remove_col(itpp::GF2mat G, int col)
Definition: product_lib.cpp:128
ClassicalCode::dist
int dist()
Definition: product_lib.cpp:26
CSSCode::dz
int dz
Definition: product_lib.h:65
product_lib.h
ClassicalCode::n
int n
Number of bits.
Definition: product_lib.h:24
common::kron
itpp::GF2mat kron(itpp::GF2mat A, itpp::GF2mat B)
Definition: lib.cpp:162
remove_singleton
void remove_singleton(itpp::GF2mat &Gx, itpp::GF2mat &Gz)
Definition: product_lib.cpp:137
CSSCode::getRandomCode
int getRandomCode()
Definition: product_lib.cpp:85
generate_code
int generate_code(itpp::GF2mat &Gax, itpp::GF2mat &Gaz, int na, int Gax_row, int id_Gax, int Gaz_row, int id_Gaz, int debug)
Definition: product_lib.cpp:278
common::make_it_full_rank
itpp::GF2mat make_it_full_rank(itpp::GF2mat fat)
Definition: lib.cpp:123
CSSCode::n
int n
Definition: product_lib.h:61
ClassicalCode::rand_dist
int rand_dist()
Definition: product_lib.cpp:32
ClassicalCode::get_734_code
void get_734_code()
Definition: product_lib.cpp:66
CSSCode::Cx
itpp::GF2mat Cx
Definition: product_lib.h:58
ClassicalCode::min_weight_dist
int min_weight_dist()
Definition: product_lib.cpp:29
CSSCode::Gx_row
int Gx_row
Definition: product_lib.h:62
CSSCode::rand_dist_z
int rand_dist_z()
Definition: product_lib.cpp:116
ClassicalCode::get_743_code
void get_743_code()
Definition: product_lib.cpp:61
CSSCode::is_valid
bool is_valid()
Definition: product_lib.cpp:93
CSSCode::dx
int dx
Definition: product_lib.h:65
common::rand_dist
int rand_dist(itpp::GF2mat C, int perm_try=10)
Definition: dist.cpp:82
ClassicalCode::G
itpp::GF2mat G
codeword generating matrix
Definition: product_lib.h:22
common::get_check_code743
itpp::GF2mat get_check_code743(int L)
Definition: dist.cpp:490
common::get_check_rept
itpp::GF2mat get_check_rept(int L)
Definition: dist.cpp:513
CSSCode::Cz
itpp::GF2mat Cz
Definition: product_lib.h:59
common::color_text
std::string color_text(std::string str)
Definition: lib.cpp:32
CSSCode::min_weight_dist_z
int min_weight_dist_z()
Definition: product_lib.cpp:109
CSSCode::Gz_row
int Gz_row
Definition: product_lib.h:62
common::quantum_dist
int quantum_dist(itpp::GF2mat G_x, itpp::GF2mat G_z, int dist_expected, int debug, int flip=0)
Definition: dist.cpp:228
common::getC
itpp::GF2mat getC(itpp::GF2mat G_x, itpp::GF2mat G_z, int flip=0)
Definition: dist.cpp:143
ClassicalCode::get_repetition_code
void get_repetition_code()
Definition: product_lib.cpp:56
CSSCode::id_Gx
int id_Gx
Definition: product_lib.h:63
is_row_reduced_echelon_form
int is_row_reduced_echelon_form(itpp::GF2mat &alpha_Gaz, int debug=0)
Definition: product_lib.cpp:236
common::min_wt_decoding
int min_wt_decoding(itpp::GF2mat C)
Definition: dist.cpp:12
CSSCode::getGoodCode
int getGoodCode(int debug)
Definition: product_lib.cpp:89
common::GF2matPrint
int GF2matPrint(itpp::GF2mat &G, std::string name)
Definition: lib.cpp:144
CSSCode
Definition: product_lib.h:54
ClassicalCode::ClassicalCode
ClassicalCode()
Definition: product_lib.cpp:18
common::is_quantum_code
bool is_quantum_code(itpp::GF2mat &G_x, itpp::GF2mat &G_z)
Definition: lib.cpp:77