neml2.factory¶
Python-native HIT input file factory.
Mirrors the C++ Factory / Registry pattern for Python-native models:
register_neml2_object()— decorator that registers a model class under its C++ type name.Modelsubclasses usually inherit schema-backedfrom_hit(node, factory); non-model objects and special cases implement their own.load_input()— parse a HIT file and return a lazy_NativeInputFilefactory object.load_model()— convenience wrapper:load_input(path).get_model(name).
The factory is “dumb” — it dispatches only by type name. Each registered class
is responsible for reading its own parameters and resolving sub-object
dependencies via the factory’s get_model / get_solver /
get_equation_system methods (mirroring NEML2Object::get_model etc.).
- neml2.factory.load_input(path, *, pre=(), post=(), additional_args=())[source]¶
Parse a HIT input file and return a lazy native factory.
- Parameters:
pre (Sequence[str]) – Optional HIT snippets prepended / appended before parsing (same semantics as
nmhit.parse_file).post (Sequence[str]) – Optional HIT snippets prepended / appended before parsing (same semantics as
nmhit.parse_file).additional_args (Sequence[str]) – Trailing command-line HIT overrides (e.g.
["Models/elasticity/E:=210000"]). Each element is a HIT snippet appended afterpostso any:=override takes effect after the file’s own assignments. Mirrors the C++ side’sneml2::load_input(path, additional_cliargs).
- Return type:
_NativeInputFile
- neml2.factory.load_model(path, model_name)[source]¶
Load a named model from a HIT input file as a Python-native model.
Raises
KeyErrorif the model’s type (or any of its sub-object types) isn’t registered inNativeRegistry.
- neml2.factory.load_nonlinear_system(path, name)[source]¶
Load a named system from
[EquationSystems]as a Python-native object.Convenience wrapper around
load_input(path).get_equation_system(name)— mirrorsload_model(). Returns aNonlinearSystem(typically aModelNonlinearSystem).
- neml2.factory.load_string(text, *, pre=(), post=(), additional_args=())[source]¶
Parse an in-memory HIT snippet and return a lazy native factory.
Same semantics as
load_input()but reads from a string (vianmhit.parse_text) instead of a file. Used byneml2.drivers.ModelUnitTest.from_string()so a unit test can embed its[Models]/[Tensors]/[Drivers]blocks inline.
- neml2.factory.register_neml2_object(type_name)[source]¶
Decorator: register a Model (or solver/system) class under type_name.
The class must provide a
from_hit(cls, node, factory)classmethod that constructs an instance from the given nmhit Section node.Modelsubclasses inherit a default implementation backed byHitSchema; other registered object types implement it directly. The factory argument is a_NativeInputFileinstance whoseget_model,get_solver, andget_equation_systemmethods may be called to resolve named sub-objects — exactly as C++NEML2Object::get_model()does.