madagra / basic-pinn

Basic implementation of physics-informed neural networks for solving differential equations
MIT License
64 stars 26 forks source link

Problems using PINNs #1

Closed neumannoskar closed 1 year ago

neumannoskar commented 1 year ago

I've tried to use the example for the logistic_equation_1d.py . It produces following error

line 94, in train_model loss_evolution.append(loss.detach().numpy()) RuntimeError: Numpy is not available

I'm using Python 3.10.4.

Thank's for any help.

fabioantonini commented 1 year ago

Hi I guess you need to install the package 'numpy' in your python environment. Take a look at the following link Hope this helps

neumannoskar commented 1 year ago

Hey, thank's for the quick reply. That's is not the problem, since the script logistic_equation_1d.py would produce an error earlier when trying to import numpy in line 7.

So the package 'numpy' is definitely installed.

fabioantonini commented 1 year ago

Hi

I found also this link helpful

https://stackoverflow.com/questions/71689095/how-to-solve-the-pytorch-runtimeerror-numpy-is-not-available-without-upgrading

On 04/08/22 10:57, neumannoskar wrote:

Hey, thank's for the quick reply. That's is not the problem, since the script |logistic_equation_1d.py| would produce an error earlier when trying to import numpy in line 7.

So the package 'numpy' is definitely installed.

— Reply to this email directly, view it on GitHub https://github.com/madagra/basic-pinn/issues/1#issuecomment-1204966971, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABNETHMGXROU2HVF6RGADPLVXOAYBANCNFSM55RTH3YQ. You are receiving this because you commented.Message ID: @.***>

neumannoskar commented 1 year ago

I found this post already, but unfortunately this version of torch is not available anymore. Trying to downgrade produces:

ERROR: Could not find a version that satisfies the requirement torch==0.9.1 (from versions: 1.11.0, 1.12.0) ERROR: No matching distribution found for torch==0.9.1

madagra commented 1 year ago

Hello,

I pinned the version in the requirements.txt file, but it is unnecessary. You can try to install the dependencies manually yourself in a virtual environment:

python -m venv .env
source .env/bin/activate
pip install numpy torch matplotlib

Try then to execute the code again.

fabioantonini commented 1 year ago

You are definitely right.

That piece of code is trying to convert the 'loss' torch tensor to a numpy array.

It sounds as if the numpy() method would not be available.

Are you using a CPU or a GPU?

Anyway try this

loss.detach().cpu().numpy()

On 04/08/22 10:57, neumannoskar wrote:

Hey, thank's for the quick reply. That's is not the problem, since the script |logistic_equation_1d.py| would produce an error earlier when trying to import numpy in line 7.

So the package 'numpy' is definitely installed.

— Reply to this email directly, view it on GitHub https://github.com/madagra/basic-pinn/issues/1#issuecomment-1204966971, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABNETHMGXROU2HVF6RGADPLVXOAYBANCNFSM55RTH3YQ. You are receiving this because you commented.Message ID: @.***>

madagra commented 1 year ago

I am going to close this issue since I assume the problem has been solved with the two comments above.