Skip to content

Commit

Permalink
minor change 6
Browse files Browse the repository at this point in the history
  • Loading branch information
Weilei Zeng at qlab01 committed Apr 26, 2024
1 parent 9d00186 commit 024c43f
Showing 1 changed file with 63 additions and 3 deletions.
66 changes: 63 additions & 3 deletions test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <itpp/itbase.h>
#include <fstream>

#include "json.hpp"
using json=nlohmann::json;

#include <ctime> //get time in seconds
#include <chrono> // get time in milli seconds
Expand Down Expand Up @@ -368,6 +370,7 @@ void product_code_test(){
*@param error, en error with weight w
*@param n, lenght of error
*/
/*
bool next_error(itpp::bvec & error, int n, int w){
// std::cout<<"input: "<<error<<std::endl;
// for ( int i =0; i<n;i++){
Expand Down Expand Up @@ -398,6 +401,8 @@ bool next_error(itpp::bvec & error, int n, int w){
}
void array_size_test(){
//max int 10000*100
// static array max: const int length=10000*10000*3;
Expand All @@ -423,15 +428,23 @@ void array_size_test(){
// std::cout<<"debug"<<std::endl;
CSSCode code;
code.n=7;
code.get_713_code();
// code.n=7;
// code.get_713_code();
code.n = 20;
code.Gx_row = 8;
code.Gz_row = 8;
code.getGoodCode(0);
code.Gx=common::make_it_full_rank(code.Gx);
code.Gz=common::make_it_full_rank(code.Gz);
std::cout<<code.Gx;
int table_size_temp=int (pow(2,code.Gx.rows()));
//const int table_size=128;
//static itpp::bvec syndrome_table[table_size];
int table_size=1024*1024/32;//table_size_temp;
if (code.Gx.rows()>15) {
std::cout<<"Gx is too big. Cannot save syndrome table";
throw "Gx is too big";
}
itpp::bvec syndrome_table[table_size];
itpp::bvec b_zero=itpp::zeros_b(code.n);
for ( int i =0;i<table_size;i++){
Expand Down Expand Up @@ -470,6 +483,51 @@ void array_size_test(){
std::cout<<"output:"<<error_output<<std::endl;
return;
}
*/


bool json_test(){
std::string code_prefix="tmp";
std::ifstream jsonfile(code_prefix+".json");
json data;
try{
data = json::parse(jsonfile);
} catch (std::exception& e){//Exception e){
//json.exception.parse_error.101 e){
std::cout<<e.what()<<std::endl;
std::cout<<"json parse error with file: "<<code_prefix<<std::endl;
return false;
}
jsonfile.close();

std::cout<<data<<std::endl;

CSSCode code;
code.load(code_prefix);
/* rho_x = code.Gx.density();
rho_z = code.Gz.density();
n_Gx = code.Gx.rows()*code.Gx.cols();
n_Gz = code.Gz.rows()*code.Gz.cols();*/

// std::cout<< data["verified"]<<std::endl;
if (data["verified"]==1 ){
std::cout<<"the code has been verified. skip"<<std::endl;
return true;
}

code.dist();

if (code.d == data["d"]){
data["verified"]=1;
std::string filename_json = code_prefix +".json";
std::ofstream filejson(filename_json);
filejson << data;//j_object_t;
filejson.close();
return true;
}else{
return false;
}
}

int main(int args, char ** argvs){
// cout<<"begin test"<<endl;
Expand Down Expand Up @@ -520,7 +578,9 @@ int main(int args, char ** argvs){

//product_code_test();

array_size_test();
// array_size_test();

json_test();
cout<<"finish test"<<endl;
return 0;
}

0 comments on commit 024c43f

Please sign in to comment.