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::DriveStatsStatistics / diagnostics returned by parse_and_drive().
Fields
| Name | Declaration | Description |
|---|---|---|
instructions_parsed | size_t instructions_parsed = 0 | total instruction lines seen |
instructions_replayed | size_t instructions_replayed = 0 | lines that successfully drove the API |
unknown_opcodes | size_t unknown_opcodes = 0 | opcode strings the parser doesn't handle |
skipped_lines | size_t skipped_lines = 0 | malformed lines (args missing, etc.) |
modulus_table | std::vector<uint64_t> modulus_table | |
errors | std::vector<std::string> errors | human-readable diagnostics |
inputs_materialized | size_t inputs_materialized = 0 | source addrs with real input values |
outputs_tagged | size_t outputs_tagged = 0 | source addrs tagged as outputs |
struct niobium::fhetch::DriveInputs
struct niobium::fhetch::DriveInputsInput 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
| Name | Declaration | Description |
|---|---|---|
data | std::unordered_map<uint64_t, Element> data | source-file address (N in the trace) -> polynomial values. |
struct niobium::fhetch::DriveInputs::Element
struct niobium::fhetch::DriveInputs::ElementFields
| Name | Declaration | Description |
|---|---|---|
values | std::vector<uint64_t> values | |
modulus | uint64_t modulus = 0 |
struct niobium::fhetch::DriveOutputs
struct niobium::fhetch::DriveOutputsMaps 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
| Name | Declaration | Description |
|---|---|---|
map | std::unordered_map<uint64_t, Tag> map |
struct niobium::fhetch::DriveOutputs::Tag
struct niobium::fhetch::DriveOutputs::TagFields
| Name | Declaration | Description |
|---|---|---|
name | std::string name | output name (e.g. "result") |
poly_index | size_t poly_index = 0 | position 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
path— Path to the .fhetch trace.ring_dim— Ring dimension N used to build polynomial placeholders.stats— Populated with counts + any diagnostics.inputs— Optional — per-source-address input data.outputs— Optional — per-source-address output probe tags.
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.