tum-pbs/PhiFlow

Phiflow grid to Pytorch tensor/model

muacq opened this issue · 4 comments

muacq commented

Hi, I have encountered several problems while combining PhiFlow with Pytorch:

When combining PhiFlow with the self-defined PyTorch model, how to gracefully input PhiFlow grid data, and output grid data (with/without the same layout)?

  • I tried using field.native_call(model, grid) and it worked. But how can I make sure the native call processes the grid data in the right dimension I trained (e.g. 'vector, y, x' or 'vector, x, y')?

  • What if the model's output doesn't have the same layout as the input (e.g. input 'vector, y, x' output 'y, x')?

  • Also, I tried converting the PhiFlow tensor to Pytorch tensor (e.g. CenterGrid velocity.values.native("vector,y,x"), then input the Pytorch tensor into the Pytorch model. I wondered if there is a graceful way to input and output grid data for the Pytorch model.

Looking forward to your reply!

holl- commented

Sorry for the late response.

  • field.native_call(model, grid) is the right approach. For PyTorch, it will always use the order batch, channel, spatial.
  • If your output does not have the vector/channel dimension, it should insert a singleton dimension (size 1). You can also use the channel_dim and spatial_dim arguments to describe the output if its shape varies from the input.
muacq commented

Thanks for your reply!
I have another question...Where can I see all solver's names supported by PhiFlow?
I just found some names in the demo code like:
'auto', 'CG', 'CG-adaptive', 'CG-native', 'direct', 'GMres', 'lGMres', 'biCG', 'CGS', 'QMR', 'GCrotMK'
Is there a Jacobian or Gauss-Seidel solver?

holl- commented

Only 'CG' and 'CG-adaptive' (and soon biCG) are currently supported by all backends. If you use NumPy, you can also use the ones you mentioned but they won't work with TensorFlow or PyTorch.

muacq commented

Got it, Thanks for your reply!