Skip to main content

read

Function read 

Source
pub fn read(path: impl AsRef<Path>) -> Result<NirGraph>
Expand description

Read a NIR graph from a .nir (HDF5) path.

Absent optional fields are filled with the upstream Python defaults, so a graph read here matches what nir.read produces in memory: a missing v_reset becomes zeros shaped like v_threshold, and a missing w_in becomes ones shaped like v_leak.

Node parameters keep their on-disk float width — an f32 weight never becomes f64. Scalar metadata is the one exception: MetadataValue has no F32 variant, so a scalar float32 metadata value decodes as MetadataValue::F64 and is written back as a 64-bit dataset. The value survives exactly, since f32 widens to f64 losslessly; only the wire dtype of that one dataset changes. Narrower integers likewise widen into MetadataValue::I64.

Node order is not preserved. NirGraph::nodes is an order-preserving map, but this reads names in sorted order so that decoding one file twice gives the same order both times — HDF5 does not promise a link ordering worth carrying. edges is a Vec and is order-significant, so it is preserved exactly.

§Errors

§Examples

let graph = nir_rs::io::read("model.nir")?;
for (name, node) in &graph.nodes {
    println!("{name}: {}", node.type_name());
}