NeuroMANCER

repository·master·Indexed 23 days ago

https://github.com/pnnl/neuromancer

A PyTorch-based differentiable programming library for solving parametric constrained optimization, physics-informed system identification, and model-based optimal control. Version 1.5.6 features Differentiable Predictive Control (DPC), support for Neural ODEs, Universal Differential Equations (UDEs), and Neural State Space Models (NSSMs). It includes the KANBlock for Kolmogorov-Arnold Networks and integrates with LitTrainer for custom training logic and profiling.

Tokens
30.6K
Snippets
38
Records
158
Agent score
76%

What's inside neuromancer

  1. What is SLiM (Structured Linear Maps)?

    master

    SLiM (Structured Linear Maps) is a package providing a suite of structured linear maps designed as drop-in replacements for PyTorch's nn.Linear module.

    These parametrizations are intended to:

    • Enhance learning stability.
    • Embed inductive priors that encode domain-specific knowledge.
    • Facilitate exploration of neural networks from a dynamical systems perspective.

    All structured maps in this package share a common API to ensure they can be easily swapped into existing PyTorch architectures.

  2. System Identification for ODEs in Neuromancer

    master

    Neuromancer supports differentiable system identification (System ID) methods for both discrete-time and continuous-time dynamical systems. This allows for learning unknown parameters $\theta$ of a model $f_{\theta}$ from observational data using gradient-based optimization.

    Supported methods include:

    • Neural Ordinary Differential Equations (NODEs): Continuous-time models.
    • Neural State Space Models (NSSMs): Discrete-time models.
    • Universal Differential Equations (UDEs): Hybrid models incorporating prior physical knowledge.

    For continuous systems, Neuromancer uses ODE solvers (like Euler or Runge-Kutta) to obtain a discretized system $x_{k+1} = \text{ODESolve}(f_{\theta}(x_k))$ that can be trained.

  3. What is Differentiable Predictive Control (DPC)?

    master

    Differentiable Predictive Control (DPC) is a flagship capability in Neuromancer. It allows for learning control policy parameters by backpropagating Model Predictive Control (MPC) objective functions and constraints through a differentiable model of a dynamical system.

    Supported Differentiable Models:

    • Ordinary Differential Equations (ODEs)
    • Neural ODEs
    • Universal Differential Equations (UDEs)
    • Neural State Space Models (SSMs)

    The DPC Workflow:

    1. System Identification: Learn the unknown parameters of a differentiable 'digital twin' model.
    2. Closed-Loop Training: Combine the digital twin with a control policy (parametrized by neural networks) to create a differentiable closed-loop dynamics model. This allows using automatic differentiation (AD) to solve parametric optimal control problems by computing sensitivities to initial conditions, boundary conditions, and time-varying reference tracking.
  4. What is Differentiable Parametric Programming (DPP) in Neuromancer

    master

    Differentiable Parametric Programming (DPP) is a method used to learn solutions (explicit solvers) to constrained optimization problems where the solution $x$ depends on varying problem parameters $\xi$.

    Neuromancer implements DPP by allowing you to formulate optimization problems within a differentiable computational graph. By leveraging PyTorch's automatic differentiation (AD), you can compute the sensitivities of constrained optimization problems with respect to their parameters. This enables the use of gradient-based optimizers (like Adam or SGD) to train a neural network (a 'solution map') to approximate the optimal solution.

    Key Advantage: Compared to classical online solvers (e.g., IPOPT), a trained DPP model provides significantly faster online evaluation, often by orders of magnitude, making it suitable for real-time applications.

  5. How NeuroMANCER core abstractions work together

    master

    NeuroMANCER uses a symbolic programming paradigm to bridge machine learning and scientific computing. The core workflow involves:

    1. Defining Modules: Using nm.modules (like MLP) to define neural architectures.
    2. Symbolic Wrapping: Wrapping modules in a nm.system.Node to define input/output relationships (e.g., map(p) -> x).
    3. Variables and Constraints: Using nm.constraint.variable to define decision variables and parameters, and defining constraints using standard mathematical syntax.
    4. Objectives: Defining objective functions via .minimize() on symbolic expressions.
    5. Loss and Problem Construction: Combining objectives and constraints into a nm.loss.PenaltyLoss and passing them along with Node objects into an nm.problem.Problem to create a fully differentiable optimization task.
  6. How Physics-Informed Neural Networks (PINNs) work in Neuromancer

    master

    In Neuromancer, PINNs are used to find approximate solutions to differential equations by incorporating physical laws (PDEs) into the neural network training process as regularization.

    Architecture

    The neural network acts as a function approximator $NN_{\theta}(x,t)$ that maps spatio-temporal coordinates to a solution $\hat{u}$. Derivatives (e.g., $\frac{\partial NN_{\theta}}{\partial t}$) are obtained via Automatic Differentiation to satisfy the PDE equations.

    Dataset Components

    Training requires three types of data points:

    1. Collocation Points (CP): Points within the spatio-temporal domain used to minimize PDE residuals.
    2. Initial Conditions (IC): Samples defining the state at $t=0$.
    3. Boundary Conditions (BC): Samples defining the state at the spatial boundaries.

    Loss Function Composition

    The total PINN loss $\ell_{\text{PINN}}$ is the sum of several terms:

    • PDE Collocation Loss ($\ell_{f}$): Minimizes the residual of the PDE at collocation points.
    • IC/BC Loss ($\ell_{u}$): A supervised loss term that ensures the network matches known initial and boundary conditions.
    • Domain Constraint Loss ($\ell_{y}$): (Optional) Uses RELU penalties to bound the network output within a specific range $[u_{min}, u_{max}]$.
  7. DPC Problem Formulation and Optimization

    master

    DPC formulates the control problem as a parametric optimal control problem.

    Mathematical Formulation:

    • Control Policy: $\mathbf{u}=\pi_{\theta}(\mathbf{x}(t), \mathbf{\xi}(t))$, where $\theta$ are trainable weights, $\mathbf{x}(t)$ is the state, and $\mathbf{\xi}(t)$ are problem parameters.
    • Continuous Dynamics: $\frac{d\mathbf{x}(t)}{dt}=\mathbf{f}(\mathbf{x}(t), \mathbf{u}(t))$
    • Discrete Dynamics: $\mathbf{x}_{k+1}=\mathbf{f}(\mathbf{x}_k, \mathbf{u}_k)$

    Optimization via Backpropagation: Because the closed-loop model is differentiable, you can use backpropagation through time (BPTT) to compute the policy gradient $\nabla L$ of the loss function $L$ with respect to the policy parameters $W$. This is achieved by representing the problem as a computational graph and leveraging the chain rule.

    Comparison to Reinforcement Learning (RL): While DPC can be viewed from an RL perspective (where the DPC loss $L$ is the reward function), DPC is more sample-efficient than model-free RL because the reward function is fully parametrized by a closed-loop system dynamics model, avoiding the approximation errors common in RL reward functions.

  8. How Node and System patterns work

    master

    NeuroMANCER utilizes a Node and System Pattern as its core abstraction:

    • Nodes: Represent individual computational elements.
    • Systems: Represent composed collections of nodes.

    This is complemented by Symbolic Programming, which allows users to define constraints, objectives, and optimization problems using symbolic representations that interface directly with the Node class.

  9. Enforce constraints using different loss functions

    master

    When learning a solution map $\pi_{\Theta}(\xi)$ for a differentiable constrained optimization problem, you must enforce constraints during training. Neuromancer supports several methods to incorporate constraints into the loss function:

    1. Penalty Loss: The simplest approach, which augments the objective loss by penalizing constraint violations. Use neuromancer.loss.PenaltyLoss for this.
    2. Barrier Loss: Uses barrier functions to prevent the solution from leaving the feasible region.
    3. Augmented Lagrangian: A more sophisticated method for handling constraints.

    All these methods allow the loss function to be differentiated, enabling end-to-end training of the solution map.

  10. Understand NeuroMANCER problem paradigms (L2O, L2M, L2C)

    master

    NeuroMANCER is designed to solve three primary types of problems using its Problem class wrapper:

    • Learning to Optimize (L2O): Focuses on parametric programming. Users interface with Modules (specifically Node and Variable classes) and construct constraints by composing symbolic variables.
    • Learning to Model (L2M): Focuses on modeling dynamics (e.g., ODEs, PDEs, KANs). Users use neural blocks (found in modules/blocks.py) to model data dynamics. Supported methods include neural state space models, neural ODEs, neural SDEs, PINNs, and KANs.
    • Learning to Control (L2C): Focuses on control methodologies, specifically Differential Predictive Control. Users combine L2M modeling (system identification) with a neural control block in a closed-loop configuration, often incorporating constraints similar to L2O.
  11. Default NODE model configuration

    master

    When using the NODE implementation in the train.py benchmark script, the following default settings are applied to the model:

    • Architecture: 4-layer neural network with 128 nodes per layer modeling the right-hand side of the ODE.
    • Observability: Fully observable state space.
    • Integration: Euler integration method.
    • Time Step: Inferred from the PSL (Physics-based Symbolic Language) system.
  12. Data ingestion and simulation entry points

    master

    Users can ingest data or generate it using several entry points:

    • PSL (Physics Simulation Library): Provides ready-to-use, physics-based models for fast setup of canonical problems (especially in controls), though it offers less flexibility than custom models.
    • Dynamics/ode.py: Provides ODESystem, a flexible base for building custom ODE models and performing grey-box or physics-informed neural ODE modeling.
    • DictDataset API: For custom data ingestion (e.g., L2M/L2C workflows), data should be converted to the DictDataset format.