Hello,
I want to code according to the pydens and during compilation I am using an error at "dg solver line".
Kindly fix it ASAP so that I can move further to code my problem.
I am using tensorflow 1.15 version
======================code================
%tensorflow_version 1.x
import os
import sys
Stop TF from showing unnecessary deprecation warnings
import numpy as np
import tensorflow as tf
from tqdm import tqdm_notebook
import matplotlib.pyplot as plt
sys.path.append('..') # this line is not needed if PyDEns is installed as package
from pydens import Solver, NumpySampler, cart_prod, add_tokens
from pydens import plot_loss, plot_pair_1d, plot_2d, plot_sections_2d, plot_sections_3d
in ()
40
41 # train the network on batches of 100 points
---> 42 dg = Solver(config)
43 dg.fit(batch_size=100, sampler=s, n_iters=2000, bar='notebook')
44
15 frames
/tensorflow-1.15.2/python3.6/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.
Hello, I want to code according to the pydens and during compilation I am using an error at "dg solver line". Kindly fix it ASAP so that I can move further to code my problem.
I am using tensorflow 1.15 version ======================code================
%tensorflow_version 1.x import os import sys
Stop TF from showing unnecessary deprecation warnings
import warnings warnings.filterwarnings('ignore') from tensorflow import logging logging.set_verbosity(logging.ERROR) os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
import numpy as np import tensorflow as tf from tqdm import tqdm_notebook import matplotlib.pyplot as plt
sys.path.append('..') # this line is not needed if PyDEns is installed as package from pydens import Solver, NumpySampler, cart_prod, add_tokens from pydens import plot_loss, plot_pair_1d, plot_2d, plot_sections_2d, plot_sections_3d
add_tokens()
describing pde-problem in pde-dict
pde = { 'n_dims': 1, 'form': lambda u, t: D(u, t) - 2 np.pi cos(2 np.pi t), 'initial_condition': 1 }
put it together in model-config
config = { 'pde': pde, 'track': {'dt': lambda u, t: D(u, t)} # allows to later fetch this value from the model }
uniform sampling scheme
s = NumpySampler('uniform')
train the network on batches of 100 points
dg = Solver(config) dg.fit(batch_size=100, sampler=s, n_iters=2000, bar='notebook')
plot_loss(dg.loss, color='cornflowerblue')
plot real solution and network approximation
pts = np.linspace(0, 1, 200).reshape(-1, 1) sol = lambda t: np.sin(2 np.pi t) + 1 true = [sol(t[0]) for t in pts] approxs = dg.solve(pts)
plt.plot(pts, true, 'b--', linewidth=3, label='True solution') plt.plot(pts, approxs, 'r', label='Network approximation') plt.xlabel(r'$t$', fontdict={'fontsize': 14}) plt.legend() plt.show()
plot approximation of solution-derivative
der = lambda t: 2 np.pi np.cos(2 np.pi t) true_der = [der(t[0]) for t in pts] ders = dg.solve(pts, fetches='dt')
plt.plot(pts, true_der, 'b--', linewidth=3, label=r'True derivative') plt.plot(pts, ders, 'r', label=r'Network approximation of $\frac{d u}{d t}$') plt.xlabel(r'$t$', fontdict={'fontsize': 14}) plt.legend() plt.show()
plot_pair_1d(model=dg, solution=lambda t: np.sin(2np.pit)+1, confidence=0.15, alpha=0.2)
plot_pair_1d(model=dg, solution=lambda t: 2 np.pi np.cos(2 np.pi t), fetches='dt')
======================error is==================== OperatorNotAllowedInGraphError Traceback (most recent call last)