analysiscenter / pydens

PyDEns is a framework for solving Ordinary and Partial Differential Equations (ODEs & PDEs) using neural networks
Apache License 2.0
283 stars 65 forks source link

compilation error in Google Collab #20

Closed sumantkrsoni closed 4 years ago

sumantkrsoni commented 4 years ago

I am getting compilation error in the coding line given below...Kindly tell me ....how to fix it.... I am using google collab for compilation

dg = Solver(config) dg.fit(batch_size=50, sampler=s, n_iters=300, bar='notebook')

OperatorNotAllowedInGraphError Traceback (most recent call last)

in () ----> 1 dg = Solver(config) 2 dg.fit(batch_size=50, sampler=s, n_iters=300, bar='notebook') 15 frames /usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/ops.py in _disallow_in_graph_mode(self, task) 521 raise errors.OperatorNotAllowedInGraphError( 522 "{} is not allowed in Graph execution. Use Eager execution or decorate" --> 523 " this function with @tf.function.".format(task)) 524 525 def _disallow_bool_casting(self): OperatorNotAllowedInGraphError: iterating over `tf.Tensor` is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function.
akoryagin commented 4 years ago

Hey, @SumantSoni !

Thanks for the interest! It looks like you use tensorflow 2.x, which isn't supported in pydens. Installing, say, tensorflow 1.15 should be enough to solve the problem.

Best, Alex

sumantkrsoni commented 4 years ago

Dear Alexander, I am still getting the same error message while compiling tensorflow 1.15 version. Can you suggest the algorithm behind coding such problems using Collocation method.

Regard, Sumant

On Wed, Mar 18, 2020 at 8:05 PM Alexander Koryagin notifications@github.com wrote:

Reopened #20 https://github.com/analysiscenter/pydens/issues/20.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/analysiscenter/pydens/issues/20#event-3141734873, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOXU37YXSOYKVSA2KJBTCV3RIDLZXANCNFSM4LHBITQQ .

akoryagin commented 4 years ago

Hello again!

Have you tried to uninstall tensorflow 2.0 before installing tensorflow 1.15? The commands would be

pip uninstall protobuf
pip uninstall tensorflow

As for the second part of the question, regarding collocation method: to my understanding, the essence of the method is to nullify differential equation in a certain set of points. The closest thing in pydens would be to generate points for training using only collocation points, rather than the whole domain.

For instance, you can easily make a sampler that randomly chooses batches of points from collocation set of [0, 0.25, 0.5, 1] in the following manner:

collocation_points = np.array([0, 0.25, 0.5, 1])
s = NumpySampler('choice', a=collocation_points) 

Best, Alex

sumantkrsoni commented 4 years ago

Dear Alex, Nice to see your reply. It helped me a lot to figure out my doubts but still I have one doubt. How are the coordinates values are implementing in the derivative terms.

Suppose, grad( u(x,y) ) has appeared in loss function and then a single point (x1,y1, t1) from collocation has been replaced in place of ( x,y) of u. but what about grad of u.

how are we dealing with grad of u.
I am confused for implementing the collocation point in place of unknown fn u(x,y) and also differentiation of unknown valued fn u(x,y).

Kindly figure it out for me.

and Thanks a lot for your clarification.

Sumant

joshdey commented 4 years ago

Hi all,

I'm using tf 1.15.0 but still getting the error: OperatorNotAllowedInGraphError: iterating over tf.Tensor is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function. Do you know of any possible reasons why that might be the case?

Best, Josh

SergeyTsimfer commented 4 years ago

Hello

The reason behind this type of error is the eager execution of TF. Disable it by using disable_eager_execution method and you should be good to go!

Sergey

joshdey commented 4 years ago

Hi @SergeyTsimfer,

Thanks for getting back so quickly! Sorry I'm still a little confused, isn't the error message telling us to use eager execution? Either way, have tried using the disable_eager_execution method both in the notebook I'm working in and inside letters.py inside the pydens folder. Am I thinking about this the wrong way? Thank you so much!

Josh

SergeyTsimfer commented 4 years ago

Can you share the code you are trying to run? or you can provide the link to your colab notebook

Sergey

joshdey commented 4 years ago

Here is the link to the Colab notebook: https://colab.research.google.com/drive/1SSaRsCpn01-yTf2twFGyVXUZlZelG-x4?usp=sharing

Josh

SergeyTsimfer commented 4 years ago

I was able to reproduce the error on my side: it is actually caused by the 1.15 version, and on 1.14 everything runs fine.

I deployed a fix for the 1.15 version: it allows to run all the notebooks from top to bottom. It is available to you in fix_tf branch #26 , and I am discussing merge to the main branch with my colleagues right now (so you can just use pip install).

Thanks for catching a bug!

Update: merged

Sergey

joshdey commented 4 years ago

Hi Sergey,

Thank you so much for the help!

Best, Josh