forked from QEC-pages/how-to-use-weilei-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverification.cpp
More file actions
89 lines (78 loc) · 2.48 KB
/
Copy pathverification.cpp
File metadata and controls
89 lines (78 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "weilei_lib/weilei_lib.h" //general include goes to weilei_lib_h
#include "json.hpp"
using json=nlohmann::json;
#include <chrono> //print computation time
#include <ctime>
//code_prefix=code_folder+code_name
bool verify(std::string code_prefix){
CSSCode code;
code.load(code_prefix);
code.dist();
std::ifstream jsonfile(code_prefix+".json");
json data = json::parse(jsonfile);
jsonfile.close();
return code.d == data["d"];
// std::cout<<data<<std::endl;
// std::cout<<"saved distance d="<<data["d"]<<std::endl;
// std::cout<<"caculated distance d="<<code.d<<std::endl;
}
int count_lines(std::string filename){
int code_total = 0;
std::string line;
std::ifstream file(filename);
if (file.is_open()) {
while (std::getline(file, line))
code_total++;
}
file.close();
return code_total;
}
/** Verify data in CSS code zoo.
*@param debug
*/
int main(int args, char ** argv){
std::cout<<"============begin verification========="<<std::endl;
itpp::Parser parser;parser.init(args,argv);
// parser.set_silentmode(true);
std::string filename_list="filelist-run2.txt";
parser.get(filename_list,"filename_list");
std::string code_folder="../data/CSS-Codes/run2/";
parser.get(code_folder,"code_folder");
int num_cores=4; parser.get(num_cores,"num_cores");
//get number of codes
const int code_total=count_lines(filename_list);
std::cout<<"Number of codes: "<<code_total<<std::endl;
std::cout<<"No printing on srun due to slow network"<<std::endl;
int code_count=0,code_mistake=0;
std::ifstream file(filename_list);
if (file.is_open()) {
#pragma omp parallel for schedule(guided) num_threads(num_cores)
for ( int i=0; i<code_total; i++){
std::string jsonfile_name,code_name;
#pragma omp critical
{
if (code_count % 100 == 0) {
//printing on nodes are very slow
printf("%i codes counted, %i mistakes.\n",code_count,code_mistake);
}
std::getline(file, jsonfile_name);
}
code_name = jsonfile_name.substr(0, jsonfile_name.size()-5);
// printf("%s", line.c_str());
// printf("%s", code_name.c_str());
code_count++;
if (verify(code_folder+code_name)){
// std::cout<<"equal"<<std::endl;
}else{
code_mistake++;
// std::cout<<code_name<<":\td = "<<data["d"]
// <<", code.d = " <<code.d<<std::endl;
}
// break;
}//pragma for
file.close();
}//if
std::cout<<code_count<<" codes checked, "
<<code_mistake<<" mistakes found"<<std::endl;
return 0;
}