Dist m4ri 0.0.1.alpha
Computing distance of a classical or quantum CSS code
Loading...
Searching...
No Matches
util_io.h
Go to the documentation of this file.
1#ifndef UTIL_IO_H
2/************************************************************************
3 * qLDPC code input utility routines for distance/decoder package
4 *
5 * currently: CSS only
6 *
7 * author: Leonid Pryadko <leonid.pryadko@ucr.edu>
8 ************************************************************************/
9#define UTIL_IO_H
10
11#include <inttypes.h>
12#include <strings.h>
13#include <stdlib.h>
14#include <time.h>
15#include <stdio.h>
16#include <limits.h>
17#include <m4ri/m4ri.h>
18
19#include "mmio.h"
20#include "uthash.h"
21#include "util_hash.h"
22#include "util_m4ri.h"
23
24#define _maybe_unused __attribute__((unused))
25
26//static const int max_row_wt=10;
27
28#define MAX_W 100
29struct CW_VEC_T;
30typedef struct CW_VEC_T cw_vec_t;
31typedef struct{
32 int debug; /* debug information */
33 int classical; /* 1 for a classical code, i.e., no `G=Hz` matrix*/
34 int css; /* 1: css, 0: non-css -- currently not supported */
35 int method; /* bitmap. 1: random window; 2: cluster; 3: both */
36 int steps; /* how many RW decoding steps */
37 int smax;
41 int wmax;
42 int dmin;
43 int dmax;
44 int wmin;
48 int noscan;
49 int seed;/* rng seed, set=0 for automatic */
50 int dist; /* target distance of the code */
51 int dist_max; /* distance actually checked */
52 int dist_min; /* distance actually checked */
53 int max_row_wgt_H; /* needed for C */
54 int max_col_wgt_H; /* needed ? */
56 int swei[MAX_W];
57 int start;
58 int cbeg;
59 int cend;
60 // int linear; /* not supported */
61 int n0; /* code length, =nvar for css, (nvar/2) for non-css */
62 int nvar; /* actual n = matrix size */
63 int nchk; /* actual k = number of codewords */
64 long long int maxC;
65 int dW;
66 char *finC;
67 char *outC;
69 long long int num_cws;
70 int min_w;
71 char *fdem;
72 double pmin;
73 char *finH;
74 char *finG;
75 char *finL;
76 char *fin;
80 int threads; /* number of threads to use (0 for auto) */
81 int dexp; /* expected distance value (0 for auto/none) */
82 double timeout; /* timeout in seconds (default 60.0) */
83} params_t;
84
85static inline int minint(const int a, const int b) { return (a < b) ? a : b; }
86// #define MININT(a,b) do{ int t1=(a); int t2=(b); t1<t2? t1 :t2; } while(0)
87
88extern params_t prm;
100void var_init(int argc, char **argv, params_t * const p);
101
109void var_kill(params_t * const p);
110
123void read_dem_file(char *fnam, csr_t **p_spaH, csr_t **p_spaL, double pmin, int debug);
124
136long long int nzlist_read(const char fnam[], params_t *p);
137
148long long int nzlist_write(const char fnam[], const char comment[], params_t *p);
149
163cw_vec_t * codeword_add_maybe(params_t * const p, const int arr[], int weight);
164
165#define USAGE \
166 "%s: distance of a classical or quantum CSS code\n" \
167 "\tusage: %s parameter=value [...]\n\n" \
168 " Required parameter:\n" \
169 "\tmethod=[int]: bitmap for method used (no default): \n" \
170 "\n" \
171 "\t\t1: random window (RW) algorithm. Options:\n" \
172 "\t\t steps=[int]: how many information sets to use (1000)\n" \
173 "\t\t wmin=[int]: minimum distance of interest (1)\n" \
174 "\t\t\t immediately stop and return '-w' on a cw of weight w<=wmin\n" \
175 "\t\t\t use this option to quickly scan over a large number of codes\n" \
176 "\n" \
177 "\t\t2: connected cluster (CC) algorithm. Options:\n" \
178 "\t\t wmax=[int]: maximum cluster weight to construct, inclusive (0)\n" \
179 "\t\t\t optional if timeout>0 or dmax>0 is set; otherwise required for CC only\n" \
180 "\t\t smax=[int]: maximum syndrome weight of interest, inclusive (5)\n" \
181 "\t\t\t must be non-zero to calculate confinement profile\n" \
182 "\t\t start=[int]: use only this position to start (equiv. to cbeg=cend=start) (-1)\n" \
183 "\t\t cbeg=[int]: start column to begin CC search (-1)\n" \
184 "\t\t cend=[int]: end column to limit CC search (-1)\n" \
185 "\t\t noscan=[int]: start CC directly with wmax (0)\n" \
186 "\t\t3: bracketing mode (balanced concurrent RW and CC)\n" \
187 "\n" \
188 " Execution and multithreading parameters:\n" \
189 "\tthreads=[int]: number of threads to use (0 for auto CPU count) (0)\n" \
190 "\ttimeout=[sec]: timeout in seconds (60.0)\n" \
191 "\tdexp=[int]: expected distance value for method=3 (alias: dest) (0)\n" \
192 "\n" \
193 " Distance bounds parameters:\n" \
194 "\tdmin=[int]: known lower bound on distance, inclusive (w starts from dmin in CC) (1)\n" \
195 "\tdmax=[int]: known upper bound on distance, inclusive (RW ignores codewords of weight >= dmax) (0)\n" \
196 "\n" \
197 " General parameters:\n" \
198 "\tfdem=[str]: detector error model (DEM) file from stim (NULL)\n" \
199 "\tpmin=[float]: minimum error probability to keep for DEM (0.0)\n" \
200 "\tfinH=[str]: parity check matrix Hx (NULL)\n" \
201 "\tfinG=[str]: matrix Hz (quantum CSS code only) (NULL)\n" \
202 "\tfinL=[str]: matrix Lx (quantum CSS code only) (NULL)\n" \
203 "\t\t Either L=Lx or G=Hz matrix is required for a quantum CSS code\n" \
204 "\tfin=[str]: base name for input files (\"try\")\n" \
205 "\t\t set finH->\"${fin}X.mtx\" finG->\"${fin}Z.mtx\"\n" \
206 "\tcss=[int]: reserved for future use (1)\n" \
207 "\tseed=[int]: rng seed [use 0 for time(NULL)] (0)\n" \
208 "\tdebug=[int]:\t bitmap for aux information to output (3)\n" \
209 "\t\t0: clear the entire debug bitmap to 0.\n" \
210 "\t\t1: output misc general info (on by default)\n" \
211 "\t\t2: output more general info (on by default)\n" \
212 "\t\t4: debug command line arguments parsing\n" \
213 "\t\t8: output progress reports every 1000 steps\n" \
214 "\t\t16: output new min-weight codewords found (cut large vectors)\n" \
215 "\t\t32: output matrices (unless n is large)\n" \
216 "\t\t64: debug confinement hash updates (swei changes)\n" \
217 "\t\t128: debug duplicate syndromes in confinement hash (debug build only)\n" \
218 "\t\t256: reserved\n" \
219 "\t\t512: reserved\n" \
220 "\t\t1024: reserved\n" \
221 "\t\t2048: allow big matrix / large vector output\n" \
222 "\t\t see the source code for more options\n" \
223 "\t Multiple 'debug' parameters are XOR combined except for 0.\n" \
224 "\t Use debug=0 as the 1st argument to suppress all debug messages.\n"\
225 " -h gives this help (also '--help')\n"
226
227#define BRIEF_HELP \
228 "try \"%s -h\" for help"
229
230#endif /* UTIL_IO_H */
int arr[0]
Definition util_hash.h:40
int weight
Definition util_hash.h:38
double timeout
Definition util_io.h:82
char * finC
Definition util_io.h:66
long long int maxC
Definition util_io.h:64
int dmin
Definition util_io.h:42
int dist_max
Definition util_io.h:51
int dexp
Definition util_io.h:81
int n0
Definition util_io.h:61
char * finH
Definition util_io.h:73
int nchk
Definition util_io.h:63
int max_col_wgt_H
Definition util_io.h:54
int noscan
Definition util_io.h:48
csr_t * spaL
Definition util_io.h:79
char * outC
Definition util_io.h:67
csr_t * spaG
Definition util_io.h:78
csr_t * spaH
Definition util_io.h:77
int min_w
Definition util_io.h:70
int cbeg
Definition util_io.h:58
int dist_min
Definition util_io.h:52
int smax
Definition util_io.h:37
int nvar
Definition util_io.h:62
int method
Definition util_io.h:35
int wmax
Definition util_io.h:41
int dmax
Definition util_io.h:43
int wmin
Definition util_io.h:44
char * finG
Definition util_io.h:74
char * finL
Definition util_io.h:75
double pmin
Definition util_io.h:72
char * fin
Definition util_io.h:76
int cend
Definition util_io.h:59
int steps
Definition util_io.h:36
int dW
Definition util_io.h:65
int start
Definition util_io.h:57
int debug
Definition util_io.h:32
char * fdem
Definition util_io.h:71
long long int num_cws
Definition util_io.h:69
int dist
Definition util_io.h:50
int threads
Definition util_io.h:80
int classical
Definition util_io.h:33
int css
Definition util_io.h:34
cw_vec_t * codewords
Definition util_io.h:68
int max_row_wgt_H
Definition util_io.h:53
int seed
Definition util_io.h:49
Utility functions for use with uthash.h
params_t *const p
Definition util_io.c:52
void read_dem_file(char *fnam, csr_t **p_spaH, csr_t **p_spaL, double pmin, int debug)
Read a Detector Error Model (DEM) file and construct H and L matrices.
Definition util_io.c:663
void var_kill(params_t *const p)
Clean up and free memory allocated in the params_t structure.
Definition util_io.c:473
long long int nzlist_read(const char fnam[], params_t *p)
Read codewords from a .nz list file and add them to the codeword hash.
Definition util_io.c:840
cw_vec_t * codeword_add_maybe(params_t *const p, const int arr[], int weight)
Add a candidate codeword to the hash table if it meets weight limits.
Definition util_io.c:797
long long int nzlist_write(const char fnam[], const char comment[], params_t *p)
Write the found codewords from the hash table to a .nz file.
Definition util_io.c:893
#define MAX_W
Definition util_io.h:28
params_t prm
Definition util_io.c:7
void var_init(int argc, char **argv, params_t *const p)
Initialize parameters and load matrices from command line arguments.
Definition util_io.c:54