This document is relevant for: Inf2, Trn1, Trn2, Trn3
nrtpy configuration#
This page documents the module-level functions that configure and manage the
nrtpy runtime singleton.
Overview#
nrtpy uses a single-runtime execution model: one Python process holds one
runtime singleton managing one libnrt instance. The singleton is created
lazily the first time you use an NrtpyTensor or
NrtpyModel.
Call
configure()before the first runtime operation to set which NeuronCores are visible.Call
reset()to close the runtime and clear configuration state. Afterreset(), you may callconfigure()again before the next operation.
Functions#
- nrtpy.configure(visible_cores=None)#
Set runtime configuration before initialization. This only sets the
NEURON_RT_VISIBLE_CORESenvironment variable — it does not initialize the runtime. The runtime is initialized lazily on the firstnrtpyoperation afterconfigure().Can only be called when the runtime is not active — either before the first
nrtpyoperation, or afterreset()(which closes the runtime and clears state). Callingconfigure()is optional; if not called, the runtime uses the system default (all NeuronCores visible).- Parameters:
visible_cores (collections.abc.Iterable[int] or None) – Iterable of NeuronCore IDs, for example
[0, 1, 2]orrange(4). IfNone, visible cores are left unchanged (uses the currentNEURON_RT_VISIBLE_CORESvalue or system default).- Raises:
RuntimeError – If the runtime is already active. Call
reset()first.TypeError – If
visible_coresis anintrather than an iterable, or contains a non-integer value.ValueError – If any core ID is negative.
- nrtpy.reset()#
Close the current runtime and clear configuration state. If the runtime has not been initialized yet, this is a no-op. Call
configure()afterward to set new visible cores before the nextnrtpyoperation.Warning
All existing
NrtpyTensorandNrtpyModelobjects become invalid after this call. Any operations on them will raise errors.
Example#
import nrtpy
from nrtpy import NrtpyModel, NrtpyTensor
# Configure visible NeuronCores before first use
nrtpy.configure(visible_cores=[0, 1])
# The singleton is created lazily on first operation
model = NrtpyModel.load_from_neff("model.neff")
tensor = NrtpyTensor.from_numpy(data, name="input")
# Switch to different cores: reset, then reconfigure
del model, tensor
nrtpy.reset()
nrtpy.configure(visible_cores=[2, 3])
# New runtime uses cores 2 and 3
model2 = NrtpyModel.load_from_neff("model.neff", core_id=0)