niobium/fhetch_parser.h

.fhetch trace parser/driver.

Reads a .fhetch text trace and re-drives the FHETCH Polynomial IR API (sr_addp, sr_ntt, ...) instruction-by-instruction. Each line in the input trace becomes a call to the corresponding niobium::fhetch:: free function, which in turn emits a secondary trace through the normal recording path.

Intended use: a test harness that exercises the FHETCH API from a prior trace recording, without re-running the original OpenFHE workload.

The caller is responsible for bracketing the parse/drive step with the usual Compiler session lifecycle:

niobium::compiler().init(argc, argv);
niobium::compiler().set_program_info(...);
niobium::compiler().cache_parameters(...);
niobium::compiler().set_ring_dimension(ring_dim);
niobium::compiler().start();
niobium::fhetch::DriveStats stats;
niobium::fhetch::parse_and_drive(path, ring_dim, stats);
niobium::compiler().stop();
niobium::compiler().replay();

Addresses referenced in the input .fhetch file are mapped to Polynomial objects on first use. Any address that is read before it is written gets a zero-initialized Polynomial that is tagged as an input via niobium::fhetch::tag_input(), so Compiler::replay() can populate the simulator memory at those live-in addresses.

Include: #include "niobium/fhetch_parser.h"

Declarations

struct niobium::fhetch::DriveStats

struct niobium::fhetch::DriveStats

Statistics / diagnostics returned by parse_and_drive().

Fields

NameDeclarationDescription
instructions_parsedsize_t instructions_parsed = 0total instruction lines seen
instructions_replayedsize_t instructions_replayed = 0lines that successfully drove the API
unknown_opcodessize_t unknown_opcodes = 0opcode strings the parser doesn't handle
skipped_linessize_t skipped_lines = 0malformed lines (args missing, etc.)
modulus_tablestd::vector<uint64_t> modulus_table
errorsstd::vector<std::string> errorshuman-readable diagnostics
inputs_materializedsize_t inputs_materialized = 0source addrs with real input values
outputs_taggedsize_t outputs_tagged = 0source addrs tagged as outputs

struct niobium::fhetch::DriveInputs

struct niobium::fhetch::DriveInputs

Input polynomial values provided by the caller for specific source-file addresses in the .fhetch trace. When a referenced source address is in the map, the parser creates a Polynomial::from_data() with those values (instead of the default zero-initialized placeholder) and tags it as an input via niobium::fhetch::tag_input.

Fields

NameDeclarationDescription
datastd::unordered_map<uint64_t, Element> datasource-file address (N in the trace) -> polynomial values.

struct niobium::fhetch::DriveInputs::Element

struct niobium::fhetch::DriveInputs::Element

Fields

NameDeclarationDescription
valuesstd::vector<uint64_t> values
modulusuint64_t modulus = 0

struct niobium::fhetch::DriveOutputs

struct niobium::fhetch::DriveOutputs

Maps source-file addresses to named output probes. When the parser emits an instruction whose destination address is in this map, the resulting Polynomial is tagged via niobium::fhetch::tag_output with the stored name (suffixed by poly_index) so Compiler::result() can reconstruct the ciphertext after replay.

Fields

NameDeclarationDescription
mapstd::unordered_map<uint64_t, Tag> map

struct niobium::fhetch::DriveOutputs::Tag

struct niobium::fhetch::DriveOutputs::Tag

Fields

NameDeclarationDescription
namestd::string nameoutput name (e.g. "result")
poly_indexsize_t poly_index = 0position of this tower within the ciphertext

niobium::fhetch::parse_and_drive

bool parse_and_drive(const std::filesystem::path &path, uint64_t ring_dim, DriveStats &stats, const DriveInputs &inputs={}, const DriveOutputs &outputs={})

Parse a .fhetch file and drive the FHETCH API for each instruction.

Parameters

Returns: true if the file was read and at least one instruction replayed.

niobium::fhetch::parse_and_drive_text

bool parse_and_drive_text(const std::string &text, uint64_t ring_dim, DriveStats &stats, const DriveInputs &inputs={}, const DriveOutputs &outputs={})

Same as parse_and_drive() but reads from an in-memory string instead of a file on disk. Useful in unit tests.

Something not looking right? Suggest a change on GitHub.