tum-pbs / PhiFlow

A differentiable PDE solving framework for machine learning
MIT License
1.39k stars 189 forks source link

Troublesome NaNs in optimizations #129

Closed Alvf closed 11 months ago

Alvf commented 1 year ago

Hello!

I'm using PhiFlow with the torch backend to optimize a sequence of control forces in a fluid solver to match sequential frames in a hand-created morph animation, and I'm running into various issues.

It seems that for short sequences of frames, optimization finds a passable set of control forces, but for longer sequences of frames, the optimizer begins to throw NaNs and other errors associated with gradients of make_incompressible() and other things (found using torch.autograd.set_detect_anomaly(True)).

I've attached a minimal example of the issue I'm running into (using randomized tensor sequences just to keep things compact); any advice would be greatly appreciated. minimal_err.txt

Many thanks! Phiflow is quite enjoyable to use.

holl- commented 1 year ago

Hi, thanks for the feedback!

You can do a couple of things.

Hope that helps! Let me know if the error persists.