NEML2 1.4.0
Loading...
Searching...
No Matches
Model Class Reference

Detailed Description

A thin wrapper around neml2::Model

Public Member Functions

dict[str, Modeldependency (self)
 
TensorValue get_parameter (self, str arg0)
 
tensors.LabeledAxis input_axis (self)
 
tensors.TensorType input_type (self, tensors.LabeledAxisAccessor variable)
 
dict[str, TensorValuenamed_buffers (self)
 
dict[str, TensorValuenamed_parameters (self)
 
dict[str, Modelnamed_submodels (self)
 
tensors.LabeledAxis output_axis (self)
 
tensors.TensorType output_type (self, tensors.LabeledAxisAccessor variable)
 
None reinit (self, tuple[int,...] batch_shape=(), int deriv_order=0, torch.device device=..., torch.dtype dtype=...)
 
None set_parameter (self, str arg0, tensors.Tensor arg1)
 
None set_parameters (self, dict[str, tensors.Tensor] arg0)
 
typing.Any value (self, typing.Any arg0)
 
tuple value_and_dvalue (self, typing.Any arg0)
 
bool is_AD_enabled (self)
 
str name (self)
 
str type (self)
 

Member Function Documentation

◆ dependency()

dict[str, Model] dependency ( self)
Get the dictionary describing this model's dependency information, if any.

◆ get_parameter()

TensorValue get_parameter ( self,
str arg0 )
Get a model parameter given its name

◆ input_axis()

tensors.LabeledAxis input_axis ( self)
Input axis of the model. The axis contains information on variable names and their associated slicing indices.

◆ input_type()

tensors.TensorType input_type ( self,
tensors.LabeledAxisAccessor variable )
Introspect the underlying tensor type of an input variable. @returns tensors.TensorType

◆ is_AD_enabled()

bool is_AD_enabled ( self)
Whether automatic differentiation is enabled for this model. This property cannot be modified once the model is created. Use the `enable_AD` option of base.load_model or base.get_model to control this property.

◆ name()

str name ( self)
Name of the model

◆ named_buffers()

dict[str, TensorValue] named_buffers ( self)
Get the model buffers. The keys of the returned dictionary are the buffers' names.

◆ named_parameters()

dict[str, TensorValue] named_parameters ( self)
Get the model parameters. The keys of the returned dictionary are the parameters' names.

◆ named_submodels()

dict[str, Model] named_submodels ( self)
Get the sub-models registered to this model

◆ output_axis()

tensors.LabeledAxis output_axis ( self)
Input axis of the model. The axis contains information on variable names and their associated slicing indices.

◆ output_type()

tensors.TensorType output_type ( self,
tensors.LabeledAxisAccessor variable )
Introspect the underlying tensor type of an output variable. @returns tensors.TensorType

◆ reinit()

None reinit ( self,
tuple[int, ...] batch_shape = (),
int deriv_order = 0,
torch.device device = ...,
torch.dtype dtype = ... )
(Re)initialize the model with given batch shape, derivative order, device, and dtype.

:param batch_shape: Batch shape used to allocate input, output, and derivative storage
:param deriv_order: An integer ranging from 0-2. When set to 0, only the output storage
    will be allocated; when set to 1, both the output and the first derivative storage
    are allocated; when set to 2, the second derivative storage is additionally allocated.
:param device:      Device on which the model will be evaluated. All parameters, buffers,
    and custom data are synced to the given device.
:param dtype:       Floating point scalar type used throughout the model.

◆ set_parameter()

None set_parameter ( self,
str arg0,
tensors.Tensor arg1 )
Set the value for a model parameter

◆ set_parameters()

None set_parameters ( self,
dict[str, tensors.Tensor] arg0 )
Set the values for multiple model parameters

◆ type()

str type ( self)
Type of the model

◆ value()

typing.Any value ( self,
typing.Any arg0 )
Evaluate the model with given input and return the output. Note that the input can either be of type torch.Tensor, tensors.Tensor, or tensors.LabeledVector. The returned output will be of the covariant type of the input.

◆ value_and_dvalue()

tuple value_and_dvalue ( self,
typing.Any arg0 )
Evaluate the model with given input and return the output as well the first derivative. Note that the input can either be of type torch.Tensor, tensors.Tensor, or tensors.LabeledVector. The returned output and derivative will be of the covariant type of the input.