|
NEML2 2.1.0
|
Wraps a NEML2 nonlinear system into a `nonlinear.NonlinearRecursiveFunction`
Args:
sys: the NEML2 nonlinear system to wrap
Keyword Args:
exclude_parameters (list of str): exclude these parameters from being wrapped as a pytorch parameter
Additional args and kwargs are forwarded to NonlinearRecursiveFunction (and hence torch.nn.Module) verbatim

Public Member Functions | |
| __init__ (self, neml2.NonlinearSystem sys, *args, list[str] exclude_parameters=[], **kwargs) | |
| int | lookback (self) |
| lookback (self, int lookback) | |
| int | nstate (self) |
| int | nforce (self) |
| tuple[torch.Tensor, torch.Tensor] | forward (self, torch.Tensor state, torch.Tensor forces) |
Public Attributes | |
| sys = sys | |
| model = sys.model() | |
| list | parameter_names = [] |
| rlayout = self.sys.blayout() | |
| slayout = self.sys.ulayout() | |
| snlayout = _extract_sublayout(self.slayout, 0, 1) | |
| flayout = _extract_sublayout(glayout, 0) | |
| fnlayout = _extract_sublayout(glayout, 0, 1) | |
| svars = self.slayout.vars() | |
| fvars = self.flayout.vars() | |
Protected Member Functions | |
| _check_model (self) | |
| _setup_parameters (self, list[str] exclude_parameters) | |
| _update_parameter_values (self) | |
| _setup_maps (self) | |
| _update_sys (self, torch.Tensor state, torch.Tensor forces) | |
| tuple[torch.Tensor, torch.Tensor] | _adapt_for_pyzag (self, AssembledMatrix A, AssembledMatrix B, AssembledVector b) |
Protected Attributes | |
| int | _lookback = 1 |
| list | _sn_to_g_map = [-1] * self.snlayout.nvar() |
| __init__ | ( | self, | |
| neml2.NonlinearSystem | sys, | ||
| * | args, | ||
| list[str] | exclude_parameters = [], | ||
| ** | kwargs ) |
|
protected |
Assemble the residual and Jacobians from A, B, and b
Args:
A (AssembledMatrix): Jacobians w.r.t. unknowns
B (AssembledMatrix): Jacobians w.r.t. given variables
b (AssembledVector): (negative) residuals
Returns:
tuple of neml2.Tensor: residual, Jacobian w.r.t. unknowns, Jacobian w.r.t. old state
|
protected |
Simple consistency checks, could be a debug check but we only call this once
|
protected |
Setup the maps for assembly purposes In the C++ backend, the nonlinear system distinguishes between unknowns (u) and given variables (g). However, pyzag expects contiguous-in-time representation of the state and forces, where unknowns and old unknowns come from the state tensor, and forces and old forces come from the forces tensor. Note that the given variables include old unknowns, forces, and old forces. So we need to setup maps from the pyzag representation to the nonlinear system representation for both unknowns and given variables.
|
protected |
Mirror parameters of the NEML2 model with torch.nn.Parameter
Args:
exclude_parameters (list of str): NEML2 parameters to exclude
|
protected |
Copy over new parameter values
|
protected |
Disassemble the model input forces, old forces, and old state from
the flat tensors and update them in the nonlinear system
Args:
state (torch.Tensor): tensor containing the model state
forces (torch.Tensor): tensor containing the model forces
| tuple[torch.Tensor, torch.Tensor] forward | ( | self, | |
| torch.Tensor | state, | ||
| torch.Tensor | forces ) |
Actually call the NEML2 model and return the residual and Jacobian
Args:
state (torch.Tensor): tensor with the flattened state
forces (torch.Tensor): tensor with the flattened forces
| int lookback | ( | self | ) |
| lookback | ( | self, | |
| int | lookback ) |
| int nforce | ( | self | ) |
| int nstate | ( | self | ) |
|
protected |
|
protected |
| flayout = _extract_sublayout(glayout, 0) |
| fnlayout = _extract_sublayout(glayout, 0, 1) |
| fvars = self.flayout.vars() |
| model = sys.model() |
| list parameter_names = [] |
| rlayout = self.sys.blayout() |
| slayout = self.sys.ulayout() |
| snlayout = _extract_sublayout(self.slayout, 0, 1) |
| svars = self.slayout.vars() |
| sys = sys |