NeuralPDE.jl icon indicating copy to clipboard operation
NeuralPDE.jl copied to clipboard

Any way to directly access the the Residual Vector in NeuralPDEs.jl?

Open IvanBioli opened this issue 8 months ago • 2 comments

Question❓

Hi,

I have a question regarding how to extract the residual vector in NeuralPDEs.jl. The loss function in PINNs is often written as:

$$ \sum_{i=1}^n (r_i(\theta))^2 $$

where $\theta$ are the neural network parameters. The residuals are typically defined as:

  • For internal points: $r_i(\theta) = \mathcal{D}u(x_i) - f(x_i)$, where $\mathcal{D}$ is the differential operator.
  • For boundary points: $r_i(\theta) = u(x_i) - g(x_i)$ (with optional weighting constants).

Is there a way to obtain the mapping from $\theta$ to the vector $[r_1(\theta), ..., r_N(\theta)]$ using NeuralPDEs.jl?

For reference, I am using the following tutorial: NeuralPDE GPU Tutorial. It seems like I should have all the necessary information after:

@named pde_system = PDESystem(eq, bcs, domains, [t, x, y], [u(t, x, y)])
prob = discretize(pde_system, discretization)
symprob = symbolic_discretize(pde_system, discretization)

However, I don't know how to extract the residual vector directly. Any guidance would be appreciated!

Thanks!

IvanBioli avatar Mar 07 '25 09:03 IvanBioli

It's a bit hard right now. We need to refactor the parser, which we plan to do over the summer.

ChrisRackauckas avatar Mar 09 '25 15:03 ChrisRackauckas

Thanks for your answer. Actually, I would only need to be able to evaluate the function $(\theta, x) \mapsto \mathcal{D}u_\theta (x) - f(x)$. Does it make it any easier?

IvanBioli avatar Mar 09 '25 15:03 IvanBioli