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
NirError::Ioif the file cannot be opened or is not valid HDF5NirError::MissingFieldif/nodeor a required node field is absentNirError::UnknownNodeTypefor atypestring outsidewire::WIRE_TYPESNirError::InvalidTensorfor a dataset whose element type has noDTyperepresentationNirError::InvalidGraphfor a file that reaches outside its own container (external links, external raw storage, virtual datasets)NirError::Unimplementedif thehdf5feature is off
§Examples
let graph = nir_rs::io::read("model.nir")?;
for (name, node) in &graph.nodes {
println!("{name}: {}", node.type_name());
}