lululxvi / deepxde

A library for scientific machine learning and physics-informed learning
https://deepxde.readthedocs.io
GNU Lesser General Public License v2.1
2.5k stars 715 forks source link

MIONet: Bug in pytorch backend #1522

Open jalman99 opened 9 months ago

jalman99 commented 9 months ago

Hi, there seems to be a bug in the implementation of MIONet within the pytorch backend. When running the basic MIONet example https://github.com/lu-group/mionet/blob/main/training/MIONet_training.py (e.g. on DR = Diffusion-reaction), the following error appears:


losshistory, train_state = model.train(epochs=epochs, callbacks=[checker])

File ~\deepxde\deepxde\utils\internal.py:22 in wrapper result = f(*args, **kwargs)

File ~\deepxde\deepxde\model.py:631 in train self._test()

File ~\deepxde\deepxde\model.py:820 in _test ) = self._outputs_losses(

File ~\deepxde\deepxde\model.py:541 in _outputs_losses outs = outputs_losses(inputs, targets, auxiliary_vars)

File ~\deepxde\deepxde\model.py:316 in outputs_losses_train return outputs_losses(

File ~\deepxde\deepxde\model.py:298 in outputs_losses inputs = torch.as_tensor(inputs)

TypeError: can't convert np.ndarray of type numpy.object_. The only supported types are: float64, float32, float16, complex64, complex128, int64, int32, int16, int8, uint8, and bool.

Any help or hints on this ?

Just switching to the tf.compat.v1 backend as simple solution is not a real alternative, since tensorflow's GPU access often confuses with the CUDA version that is installed on a given machine (Pytorch is more stable here).

lululxvi commented 8 months ago

Pytorch works for DeepONet, see example https://deepxde.readthedocs.io/en/latest/demos/operator/antiderivative_aligned.html, so it should work with MIONet. If not, this can be fixed easily by comparing the code of DeepONet and MIONet.

HongtaoBi commented 5 months ago

Hi, @jalman99 I meet the same problem using MIONet with pytorch backend. Have you figured out how to fix it?

jalman99 commented 5 months ago

No, sorry. It doesn't work without further efforts on the source code of MIONet, therefore I decided to use the tensorflow backend; even it has its drawbacks ...

HongtaoBi commented 5 months ago

No, sorry. It doesn't work without further efforts on the source code of MIONet, therefore I decided to use the tensorflow backend; even it has its drawbacks ...

Thanks a lot!

lululxvi commented 4 months ago

Make sure your data is float32.