deepxde icon indicating copy to clipboard operation
deepxde copied to clipboard

Errors running provided examples

Open mattragoza opened this issue 3 years ago • 3 comments

Hello, this looks like a really cool library that I would love to use in my research. However, I am not able to run the provided example code using either the PyTorch or JAX backend. Specifically, here are the errors I run into with examples/pinn_forward/ode_system.py:

For PyTorch backend:

Traceback (most recent call last):
  File "/ocean/projects/asc170022p/mtragoza/deepxde/examples/pinn_forward/ode_system.py", line 30, in <module>
    ic1 = dde.icbc.IC(geom, np.sin, boundary, component=0)
  File "/ocean/projects/asc170022p/mtragoza/deepxde/deepxde/icbc/initial_conditions.py", line 17, in __init__
    self.func = npfunc_range_autocache(utils.return_tensor(func))
  File "/ocean/projects/asc170022p/mtragoza/deepxde/deepxde/icbc/boundary_conditions.py", line 245, in npfunc_range_autocache
    if utils.get_num_args(func) == 1:
  File "/ocean/projects/asc170022p/mtragoza/deepxde/deepxde/utils/internal.py", line 171, in get_num_args
    sig = inspect.signature(func)
  File "/ocean/projects/asc170022p/mtragoza/.conda/envs/MRE-XDE/lib/python3.10/inspect.py", line 3247, in signature
    return Signature.from_callable(obj, follow_wrapped=follow_wrapped,
  File "/ocean/projects/asc170022p/mtragoza/.conda/envs/MRE-XDE/lib/python3.10/inspect.py", line 2995, in from_callable
    return _signature_from_callable(obj, sigcls=cls,
  File "/ocean/projects/asc170022p/mtragoza/.conda/envs/MRE-XDE/lib/python3.10/inspect.py", line 2558, in _signature_from_callable
    raise ValueError('callable {!r} is not supported by signature'.format(obj))
ValueError: callable <ufunc 'sin'> is not supported by signature

And for JAX backend:

Traceback (most recent call last):
  File "/ocean/projects/asc170022p/mtragoza/deepxde/examples/pinn_forward/ode_system.py", line 41, in <module>
    losshistory, train_state = model.train(epochs=20000)
  File "/ocean/projects/asc170022p/mtragoza/deepxde/deepxde/utils/internal.py", line 22, in wrapper
    result = f(*args, **kwargs)
  File "/ocean/projects/asc170022p/mtragoza/deepxde/deepxde/model.py", line 427, in train
    self._test()
  File "/ocean/projects/asc170022p/mtragoza/deepxde/deepxde/model.py", line 559, in _test
    ) = self._outputs_losses(
  File "/ocean/projects/asc170022p/mtragoza/deepxde/deepxde/model.py", line 360, in _outputs_losses
    outs = self.outputs_losses(training, inputs, targets)
  File "/ocean/projects/asc170022p/mtragoza/deepxde/deepxde/model.py", line 318, in outputs_losses
    _outputs, _losses = inner_outputs_losses(
  File "/ocean/projects/asc170022p/mtragoza/deepxde/deepxde/model.py", line 294, in inner_outputs_losses
    losses = self.data.losses(targets, _outputs, loss_fn, self, aux=None)
  File "/ocean/projects/asc170022p/mtragoza/deepxde/deepxde/data/pde.py", line 130, in losses
    f = self.pde(model.net.inputs, outputs)
AttributeError: "FNN" object has no attribute "inputs"

I think the JAX error is due to incomplete support for the JAX backend, in which case I would love to know how to contribute and what the estimated amount of effort/complexity it would be to fully support JAX.

As for the PyTorch error, I don't think I understand enough about this library to debug the problem. Could you provide any pointers?

Thank you.

mattragoza avatar May 06 '22 20:05 mattragoza

  • For PyTorch error, this seems due to a very recent code modification. Are you using the code in Github, not the one from conda or pip, right? I have fixed it. Please try the updated example code.
  • Yes, we are currently working on JAX backend. It would be great if you would like to contribute the code. The effort/complexity depends on the specific functionality you will contribute. For most cases, it is simply a "translation" from TensorFlow/PyTorch code to JAX code, which is straightforward. In some cases, it may be a little tricky and require a good understanding of DeepXDE source code, because JAX is pure functional.

lululxvi avatar May 06 '22 23:05 lululxvi

Thank you for the quick response. You are correct- I cloned the master branch of the git repo instead of using pip or conda. After pulling your recent changes, I was able to get a few examples to work using PyTorch.

However, it seems that there are some features missing in the PyTorch backend as well, for instance the inverse Poisson problem example uses PFNN (parallel networks) which is only implemented in the tensorflow v1 backend. I would love to contribute a PyTorch implementation as a first contribution.

mattragoza avatar May 13 '22 17:05 mattragoza

I have opened a pull request #667 with a pytorch implementation of PFNN that allows running the inverse Poisson problem and time-independent reaction-diffusion examples using the pytorch backend.

mattragoza avatar May 13 '22 20:05 mattragoza