maziarraissi / PINNs

Physics Informed Deep Learning: Data-driven Solutions and Discovery of Nonlinear Partial Differential Equations
https://maziarraissi.github.io/PINNs
MIT License
3.45k stars 1.21k forks source link

error on tf.contrib.opt.ScipyOptimizerInterface #45

Open AmirNoori68 opened 1 year ago

AmirNoori68 commented 1 year ago

Hi, This code is based on the "TF1.X". There is no way to get "TF1.X" anymore on either Google colab or Jupyter. Just the "TF1.X" parts can be updated to "TF2.X" by two following lines: import tensorflow.compat.v1 as tf tf.disable_v2_behavior()

But I still get error in "self.optimizer = tf.contrib.opt.ScipyOptimizerInterface()." It says, "AttributeError: module 'tensorflow.compat.v1' has no attribute 'contrib' ." The reason is that "tf.contrib" is not changed, but moved from tensorflow! Can anyone help to solve this problem?

vl-dud commented 1 year ago

@AmirNoori68 you can just add ScipyOptimizerInterface to helper.py file from external_optimizer.py Then import from helper import ScipyOptimizerInterface and replace tf.contrib.opt.ScipyOptimizerInterface to ScipyOptimizerInterface

AmirNoori68 commented 1 year ago

@vldud-off Works fine. Thanks!

RoboticAutonomy commented 8 months ago

where is helper.py and how to add ScipyOptimizerInterface ?

AmirNoori68 commented 6 months ago

where is helper.py and how to add ScipyOptimizerInterface ?

First, download https://github.com/tensorflow/tensorflow/blob/876fc8dc4f40c75914dbfcb0a809feaf81be7412/tensorflow/contrib/opt/python/training/external_optimizer.py, give it a name like "helper.py" and put it in the main folder.

next, add "from helper import ScipyOptimizerInterface" to the main code.

Finally, replace the current Scipy optimizer ("tf.contrib.opt.ScipyOptimizerInterface") with the following code: self.optimizer = ScipyOptimizerInterface(self.loss, method = 'L-BFGS-B', options = {'maxiter': 50000, 'maxfun': 50000, 'maxcor': 50, 'maxls': 50, 'ftol' : 1.0 * np.finfo(float).eps})