Dist m4ri 0.0.1.alpha
Computing distance of a classical or quantum CSS code
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Functions | Variables
util_io.h File Reference
#include <inttypes.h>
#include <strings.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <limits.h>
#include <m4ri/m4ri.h>
#include "mmio.h"
#include "uthash.h"
#include "util_hash.h"
#include "util_m4ri.h"
Include dependency graph for util_io.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  params_t
 

Macros

#define UTIL_IO_H
 
#define _maybe_unused   __attribute__((unused))
 
#define MAX_W   100
 
#define USAGE
 
#define BRIEF_HELP    "try \"%s -h\" for help"
 

Typedefs

typedef struct CW_VEC_T cw_vec_t
 

Functions

void var_init (int argc, char **argv, params_t *const p)
 Initialize parameters and load matrices from command line arguments.
 
void var_kill (params_t *const p)
 Clean up and free memory allocated in the params_t structure.
 
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.
 
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.
 
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.
 
cw_vec_tcodeword_add_maybe (params_t *const p, const int arr[], int weight)
 Add a candidate codeword to the hash table if it meets weight limits.
 

Variables

params_t prm
 

Macro Definition Documentation

◆ _maybe_unused

#define _maybe_unused   __attribute__((unused))

Definition at line 24 of file util_io.h.

◆ BRIEF_HELP

#define BRIEF_HELP    "try \"%s -h\" for help"

Definition at line 227 of file util_io.h.

◆ MAX_W

#define MAX_W   100

Definition at line 28 of file util_io.h.

◆ USAGE

#define USAGE

Definition at line 165 of file util_io.h.

◆ UTIL_IO_H

#define UTIL_IO_H

Definition at line 9 of file util_io.h.

Typedef Documentation

◆ cw_vec_t

typedef struct CW_VEC_T cw_vec_t

Definition at line 30 of file util_io.h.

Function Documentation

◆ codeword_add_maybe()

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.

Compares the candidate codeword weight with the current minimum weight and dW limit. If it is within the limits, it is added to the hash. If a new strictly smaller minimum weight is found, it updates the global minimum weight and prunes heavier codewords from the hash.

Parameters
pPointer to the params_t structure.
arrArray of indices representing the support of the codeword.
weightWeight of the codeword (length of arr).
Returns
Pointer to the added/existing codeword structure, or NULL if not added.

Definition at line 797 of file util_io.c.

References CW_VEC_T::arr, CW_VEC_T::cnt, params_t::codewords, params_t::dW, ERROR, HASH_ADD, HASH_DEL, HASH_FIND, HASH_ITER, params_t::maxC, params_t::min_w, params_t::num_cws, p, and CW_VEC_T::weight.

Referenced by do_CC_dist(), do_RW_dist(), nzlist_read(), and start_CC_recurs().

◆ nzlist_read()

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.

Reads the file, verifies that each codeword satisfies the code requirements (orthogonal to H, not orthogonal to L for quantum codes), and adds valid ones to the hash table in params_t.

Parameters
fnamPath to the .nz file.
pPointer to the params_t structure containing the code matrices and hash.
Returns
Number of valid codewords successfully read and added, or -1 on error.

Definition at line 840 of file util_io.c.

References CW_VEC_T::arr, codeword_add_maybe(), params_t::codewords, params_t::debug, ERROR, params_t::maxC, params_t::num_cws, nzlist_r_one(), nzlist_r_open(), params_t::outC, p, params_t::spaH, params_t::spaL, CW_VEC_T::weight, and params_t::wmax.

Referenced by main().

◆ nzlist_write()

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.

Exports all codewords currently stored in the hash table to a file in NZLIST format.

Parameters
fnamPath to the output .nz file.
commentAn optional comment string to include in the file header.
pPointer to the params_t structure containing the codeword hash.
Returns
Number of codewords written, or -1 on error.

Definition at line 893 of file util_io.c.

References params_t::codewords, CW_VEC_T::hh, UT_hash_handle::next, nzlist_w_append(), nzlist_w_new(), and p.

Referenced by main().

◆ read_dem_file()

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.

Parses a DEM file (e.g. from Stim), filters error events based on pmin, and builds the corresponding sparse check matrix H and logical matrix L.

Parameters
fnamPath to the DEM file.
p_spaHPointer to store the constructed sparse check matrix H.
p_spaLPointer to store the constructed sparse logical matrix L.
pminMinimum error probability threshold to keep an error event.
debugDebug print level bitmap.

Definition at line 663 of file util_io.c.

References csr_from_pairs(), and ERROR.

Referenced by var_init().

◆ var_init()

void var_init ( int  argc,
char **  argv,
params_t *const  p 
)

Initialize parameters and load matrices from command line arguments.

Parses command line arguments, sets up the parameter structure, loads matrices from specified files (Matrix Market or DEM), constructs logical matrices if needed, and performs consistency checks.

Parameters
argcNumber of command line arguments.
argvArray of command line argument strings.
pPointer to the params_t structure to initialize.

debug

finH

< allow space before file name

finL

< allow space before file name

finG degeneracy generator matrix

< allow space before file name

create Lx

WARNING: this does not necessarily have minimal row weights

Definition at line 54 of file util_io.c.

References BRIEF_HELP, params_t::cbeg, params_t::cend, params_t::classical, csr_t::cols, csr_csr_mul_non_zero(), csr_free(), csr_mm_read(), csr_print(), params_t::css, params_t::debug, params_t::dexp, params_t::dmax, params_t::dmin, params_t::dW, ERROR, params_t::fdem, params_t::fin, params_t::finC, params_t::finG, params_t::finH, params_t::finL, Lx_for_CSS_code(), MAX_W, params_t::maxC, params_t::method, params_t::n0, params_t::nchk, params_t::noscan, params_t::nvar, params_t::outC, p, params_t::pmin, read_dem_file(), csr_t::rows, params_t::seed, params_t::smax, params_t::spaG, params_t::spaH, params_t::spaL, params_t::start, params_t::steps, params_t::swei, params_t::threads, params_t::timeout, USAGE, params_t::wmax, and params_t::wmin.

Referenced by main().

◆ var_kill()

void var_kill ( params_t *const  p)

Clean up and free memory allocated in the params_t structure.

Frees sparse matrices (spaH, spaG, spaL) and codeword lists.

Parameters
pPointer to the params_t structure to clean up.

Definition at line 473 of file util_io.c.

References params_t::codewords, csr_free(), params_t::fin, params_t::finG, params_t::finH, HASH_DEL, HASH_ITER, p, params_t::spaG, params_t::spaH, and params_t::spaL.

Referenced by main().

Variable Documentation

◆ prm

params_t prm
extern

Definition at line 7 of file util_io.c.

Referenced by main(), and mzd_generator_from_csr().