swe_nonlinear_pino: physicsnemo_fdm_swe_nonlin slices batch dim ([1:-1]) -> empty PDE residual / NaN loss_pde with default batchsize=1

Open Beginner friendly
#2,214 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python, pytorch

Research direction

The bug is in physicsnemo_fdm_swe_nonlin in examples/cfd/swe_nonlinear_pino/train_utils/losses.py, where Dh, Du and Dv are sliced with [1:-1] along the batch dimension. Compare it with the reference fdm_swe_nonlin in the same file, which trims the last dimension. Run swe_nonlinear_pino with the default config (batchsize 1) and check that Dh.shape is (0, ...) and that test loss_pde is nan. Done when the residuals keep their full batch shape and loss_pde is finite and decreases.

Written by the indexing model from the issue text.

Description

In examples/cfd/swe_nonlinear_pino/train_utils/losses.py, physicsnemo_fdm_swe_nonlin slices the PDE residuals along the batch dimension:

Dh = pde_Dh["Dh"][1:-1]
Du = pde_Du["Du"][1:-1]
Dv = pde_Dv["Dv"][1:-1]

The reference implementation fdm_swe_nonlin in the same file trims the last dimension ([..., 1:-1]). The time trimming is also already applied to the inputs (1 : nt - 1, nt + 1 : 2 * nt - 1).

With the default batchsize: 1 in config_pino.yaml, the residual tensors become empty, e.g. Dh.shape == (0, 99, 128, 128):

  • loss_pde is NaN;
  • the PDE-term gradient is 0;
  • training proceeds without any error, so the physics loss silently has no effect.

With batch size 2 the residuals are also empty. With batch size 3, only 1 of 3 samples is used.

Reproduce (v2.2.2, pip install nvidia-physicsnemo[sym], A100):

  1. Run swe_nonlinear_pino with the default config and the physicsnemo derivative path.
  2. The log shows test loss_pde = nan.

Fix: remove the slice (Dh = pde_Dh["Dh"], and the same for Du and Dv). After this change loss_pde is finite and decreases (train 0.206 → 0.023, test 0.019 after 2 epochs). It then matches the behaviour of loss.derivative=original.

The lines are unchanged on main as of 2026-11-01.

Dominant language
Python
Stars
3.4k
Forks
828
Avg merge
4d 3h
Merged PRs (30d)
81

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from NVIDIA/physicsnemo

All issues in NVIDIA/physicsnemo

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.