use gresil::fixed::freeze;
use gresil::nir::Thousandths;
use gresil::trace::{Kind, Rows};
use gresil::{NirImport, NirImportOptions};
const GRAPH: &str = concat!(
env!("CARGO_MANIFEST_DIR"),
"/tests/nir_fixtures/snntorch_two_layer_sim.json"
);
const OUT: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/examples/board/graph.rs");
fn main() -> Result<(), Box<dyn std::error::Error>> {
std::fs::write(OUT, module(&std::fs::read(GRAPH)?)?)?;
println!("wrote {OUT}");
Ok(())
}
fn module(json: &[u8]) -> Result<String, Box<dyn std::error::Error>> {
let graph = NirImport::from_json(json, NirImportOptions::sim_units(100))?;
let (net, encoder, _report) = graph.build_network()?;
let on = encoder.encode(&[&[Thousandths(1_000)]]);
let off = encoder.encode(&[&[Thousandths(0)]]);
let drive = [(10, on.clone()), (40, off.clone()), (10, on), (40, off)];
Ok(freeze::module(
&net,
"stranger",
Kind::Stranger,
100,
Rows::All,
&drive,
))
}
#[cfg(test)]
mod tests {
#[test]
fn the_board_graph_is_what_this_writes() {
let json = std::fs::read(super::GRAPH).expect("the fixture");
let module = super::module(&json).expect("the fixture imports and freezes");
let file = std::fs::read_to_string(super::OUT).expect("examples/board/graph.rs");
assert_eq!(
file, module,
"examples/board/graph.rs is not what `freeze` writes: run `cargo run -p \
gresil --features unstable-freeze --example freeze` and commit it with the why"
);
}
}