Developer Interfaces
This page documents extension points for packages that build on NeuralPDE. These interfaces are versioned developer APIs, not the recommended application-level entry points. Users should prefer the concrete discretizations, algorithms, and training strategies in the manual.
PDE Discretizations
NeuralPDE.AbstractPINN — Type
AbstractPINNAbstract supertype for PDE discretizations that use a physics-informed neural network.
Fields
This abstract type has no fields. Concrete discretizations define the state needed by their symbolic_discretize method.
Extension Rules
A concrete subtype must add a method for SciMLBase.symbolic_discretize(pde_system::PDESystem, discretization::MyPINN). The method must translate the symbolic PDESystem and the discretization into the symbolic representation consumed by the package's training workflow. Callers should use the generic SciMLBase.symbolic_discretize entry point; the concrete type is the dispatch extension point.
This is a developer interface. Application code should normally use one of the concrete discretizations exported by NeuralPDE.
Example
using ModelingToolkit: PDESystem
struct MyPINN <: NeuralPDE.AbstractPINN end
function SciMLBase.symbolic_discretize(
pde_system::PDESystem, discretization::MyPINN
)
return (; pde_system, discretization)
endThe concrete subtype is the dispatch extension point for SciMLBase.symbolic_discretize. Its method should translate the symbolic PDESystem into the representation consumed by its training workflow. The abstract type and application-facing examples are documented on the PINN manual page.
Training Strategies
NeuralPDE.AbstractTrainingStrategy — Type
AbstractTrainingStrategyAbstract supertype for the sampling and loss-construction strategies used by NeuralPDE discretizations.
Fields
This abstract type has no fields. Concrete strategies define the configuration needed by their training-data and loss-construction methods.
Extension Rules
A custom strategy must implement the generic get_loss_function(init_params, loss_function, training_data, T, strategy; kwargs...) interface. For an interval-based strategy, the training data may instead be passed as lower and upper bounds: get_loss_function(init_params, loss_function, lower_bounds, upper_bounds, T, strategy; kwargs...). In either form, the method must return a callable scalar objective whose first argument is the optimization parameter container.
loss_function receives the strategy's training data and that parameter container and returns the residuals to aggregate. T is the element type used for generated training data. Keyword arguments are strategy-specific and are forwarded by the generic training workflow. Implement generate_training_sets or get_bounds only when the strategy needs those representations.
This is a developer interface. User code should generally use the built-in training strategies.
Example
struct MyTraining <: NeuralPDE.AbstractTrainingStrategy end
function NeuralPDE.get_loss_function(
init_params, loss_function, training_data, T, ::MyTraining; scale = 1
)
return θ -> scale * sum(abs2, loss_function(training_data, θ))
endA custom training strategy implements the generic NeuralPDE.get_loss_function interface, which is documented on the developer debugging page. It returns a callable scalar objective. The interval form receives lower and upper bounds as separate arguments. NeuralPDE.generate_training_sets and NeuralPDE.get_bounds are optional extension points for strategies that construct grid or bound-based data.
using Statistics: mean
struct MyTraining <: NeuralPDE.AbstractTrainingStrategy
points::Int
end
function NeuralPDE.get_loss_function(
init_params, residual, training_data, T, strategy::MyTraining; kwargs...
)
return θ -> mean(abs2, residual(training_data, θ))
endODE Algorithms
NeuralPDE.NeuralPDEAlgorithm — Type
NeuralPDEAlgorithmAbstract supertype for NeuralPDE's ODE algorithms. A concrete subtype must provide the corresponding SciMLBase.__solve method for an SciMLBase.AbstractODEProblem and return a solution supporting the SciMLBase callable-solution interface.
Fields
This abstract type has no fields. Concrete algorithms define the solver configuration consumed by their SciMLBase.__solve method.
Extension Rules
Implement SciMLBase.__solve(prob::SciMLBase.AbstractODEProblem, alg::MyAlgorithm; kwargs...) and return a SciMLBase solution. Define SciMLBase.allowscomplex(::MyAlgorithm) when the algorithm supports complex-valued training and interpolation. This is a developer interface; users should select a concrete algorithm such as NNODE or PINOODE.
Example
using SciMLBase: AbstractODEProblem, ReturnCode, build_solution
struct MyAlgorithm <: NeuralPDE.NeuralPDEAlgorithm end
function SciMLBase.__solve(
prob::SciMLBase.AbstractODEProblem, ::MyAlgorithm; kwargs...
)
t = collect(prob.tspan)
u = fill(prob.u0, length(t))
return build_solution(prob, MyAlgorithm(), t, u;
dense = false, retcode = ReturnCode.Success)
endA concrete algorithm extends SciMLBase.__solve for an SciMLBase.AbstractODEProblem, returns a callable SciMLBase solution, and declares complex-number support with SciMLBase.allowscomplex when applicable.