Replies: 1 comment
-
|
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Dear @lululxvi and DeepXDE community
I am working to simulate the composition profile starting from a stepped profile wherein my initial profile is not fitted as a soft constraint so I have tried to implement it as a hard constraint but came across the following error message as -
`Using backend: pytorch
Other supported backends: tensorflow.compat.v1, tensorflow, jax, paddle.
paddle supports more examples now and is recommended.
Warning: 10000 points required, but 10045 points sampled.
Compiling model...
'compile' took 0.000099 s
Training model...
Traceback (most recent call last):
File "/home/pushkar/DeepXDE/WorkSpace/Binary_Diffusion/ManufacturedSolution/manufactured_sol.py", line 99, in
losshistory, train_state = model.train(iterations=100000,callbacks=[variable,checkpointer],model_save_path='DiffusionModel')
File "/home/pushkar/DeepXDE/lib/python3.10/site-packages/deepxde/utils/internal.py", line 22, in wrapper
result = f(*args, **kwargs)
File "/home/pushkar/DeepXDE/lib/python3.10/site-packages/deepxde/model.py", line 619, in train
self._test()
File "/home/pushkar/DeepXDE/lib/python3.10/site-packages/deepxde/model.py", line 808, in _test
) = self._outputs_losses(
File "/home/pushkar/DeepXDE/lib/python3.10/site-packages/deepxde/model.py", line 528, in outputs_losses
outs = outputs_losses(inputs, targets)
File "/home/pushkar/DeepXDE/lib/python3.10/site-packages/deepxde/model.py", line 308, in outputs_losses_train
return outputs_losses(True, inputs, targets, self.data.losses_train)
File "/home/pushkar/DeepXDE/lib/python3.10/site-packages/deepxde/model.py", line 296, in outputs_losses
losses = losses_fn(targets, outputs, loss_fn, inputs, self)
File "/home/pushkar/DeepXDE/lib/python3.10/site-packages/deepxde/data/data.py", line 13, in losses_train
return self.losses(targets, outputs, loss_fn, inputs, model, aux=aux)
File "/home/pushkar/DeepXDE/lib/python3.10/site-packages/deepxde/data/pde.py", line 140, in losses
f = self.pde(inputs, outputs_pde)
File "/home/pushkar/DeepXDE/WorkSpace/Binary_Diffusion/ManufacturedSolution/manufactured_sol.py", line 19, in pde
dy_t = dde.grad.jacobian(y, x, i=0, j=1)
File "/home/pushkar/DeepXDE/lib/python3.10/site-packages/deepxde/gradients.py", line 181, in jacobian
return jacobian._Jacobians(ys, xs, i=i, j=j)
File "/home/pushkar/DeepXDE/lib/python3.10/site-packages/deepxde/gradients.py", line 153, in call
return self.Js[key](i, j)
File "/home/pushkar/DeepXDE/lib/python3.10/site-packages/deepxde/gradients.py", line 50, in call
self.J[i] = torch.autograd.grad(
File "/home/pushkar/DeepXDE/lib/python3.10/site-packages/torch/autograd/init.py", line 303, in grad
return Variable._execution_engine.run_backward( # Calls into the C++ engine to run the backward pass
RuntimeError: One of the differentiated Tensors appears to not have been used in the graph. Set allow_unused=True if this is the desired behavior.
The corresponding DeepXDE code that I have used isimport deepxde as dde
import numpy as np
import pandas as pd
import time
import matplotlib.pyplot as plt
import torch
Exponential Constants in Diffusivity Function to be Determined in Inverse Problem
a = dde.Variable(1.0)
b = dde.Variable(1.0)
c = dde.Variable(1.0)
d0 = dde.Variable(10.0)
def get_derivative(x,y):
return dde.grad.jacobian(y, x, i=0, j=0)
def pde(x, y):
dy_t = dde.grad.jacobian(y, x, i=0, j=1)
dy_x = dde.grad.jacobian(y,x,i=0,j=0)
dy_xx = dde.grad.jacobian(d0torch.exp(ay + byy + cyy*y)*dy_x,x,i=0,j=0)#Added variable Diffusivity in Fick's Second Law
return (dy_t-dy_xx)
def ZeroBC(x):
return np.zeros((len(x),1))
def step_function(x):
comp=np.zeros((len(x),1))
for i in range(len(x)):
if i <= len(x)/2.0:
comp[i] = 0.75
else:
comp[i] = 0.25
return comp
def modify_output(x,y):
pos , time = x[:,0:1],x[:,1:2]
comp_cpu = y[:,0:].cpu()
pos_cpu = pos.cpu()
time_cpu = time.cpu()
comp = comp_cpu.detach().numpy()
Time = time_cpu.detach().numpy()
Pos = pos_cpu.detach().numpy()
initial_conditions = np.where(Time == 0.0)
for i in initial_conditions[0]:
if float(Pos[i]) <= 300.0:
comp[i] = 0.75
else:
comp[i] = 0.25
comp = torch.from_numpy(comp)
comp.requires_grad_(True)
return comp
start = time.time()
#geom = dde.geometry.Interval(0, 0.0006)
geom = dde.geometry.Interval(0, 600)
#timedomain = dde.geometry.TimeDomain(0,360348.34834834834)
timedomain = dde.geometry.TimeDomain(0,99.996996996997)
geomtime = dde.geometry.GeometryXTime(geom, timedomain)
bc = dde.icbc.NeumannBC(geomtime, ZeroBC, lambda _, on_boundary: on_boundary)#Here we need to have Homogeneous Neumann BCs
ic = dde.icbc.IC(geomtime, step_function, lambda _, on_initial: on_initial)#Here the initial condition is applied
#Reading the Data
df = pd.read_fwf('/home/pushkar/jupy/jup_notebook/notebook/PINNs/BinaryAlloy/RawData_Scaled.txt',header=None)
df = df[0].str.split(' ', expand=True)
df.columns = ['Position','Time','Composition']
observe_x = np.vstack((df['Position'].to_numpy(),df['Time'].to_numpy())).T
observe_x = observe_x.astype(float)
comp_y = df['Composition'].to_numpy()
comp_y = comp_y.astype(float)
comp_y = comp_y.reshape((len(comp_y),1))
observe_y = dde.icbc.PointSetBC(observe_x,comp_y, component=0)
data = dde.data.TimePDE(
geomtime,
pde,
[bc,ic,observe_y],
num_domain=1000,
num_boundary=20,
num_initial=1000,
anchors=observe_x,
num_test=10000
)
layer_size = [2] + [50] * 8 + [1]
activation = "tanh"
initializer = "Glorot uniform"
net = dde.nn.FNN(layer_size, activation, initializer)
net.apply_output_transform(modify_output)
model = dde.Model(data, net)
weights = [1] + [1,100,1]
model.compile(
"adam", lr=1e-3, external_trainable_variables=[a,b,c,d0],loss_weights = weights
)
variable = dde.callbacks.VariableValue([a,b,c,d0], period=1000,filename="Trained_Variable.dat")
checkpointer = dde.callbacks.ModelCheckpoint("DiffusionBestModel.ckpt", verbose=1, save_better_only=True)
losshistory, train_state = model.train(iterations=100000,callbacks=[variable,checkpointer],model_save_path='DiffusionModel')
'''
#Restore the model and run it for next 10000 epoches
model = dde.Model(data, net)
model.compile("adam", lr=0.001, external_trainable_variables=[a,b,c,d0],loss_weights = weights)
model.restore("DiffusionBestModel-" + str(train_state.best_step), verbose=1)
losshistory, train_state = model.train(iterations=100000,callbacks=[variable,checkpointer],model_save_path='DiffusionModel')
'''
end = time.time()
print(f'Elapsed Time : {(end - start)/3600.0} hours')
dde.saveplot(losshistory, train_state, issave=True, isplot=True)
#Get the prediction from model and compare it with final composition
comp_NN = model.predict(observe_x)
plt.plot(observe_x[:,0:1],comp_NN,'r-',label='NNSol')
plt.plot(observe_x[:,0:1],comp_y,label='FDMSol')
plt.title('FinalCompositionComparison - FDM Vs NN')
plt.legend()
plt.savefig('ComparisionPlotDeepXDE.png')
plt.show()
f = model.predict(observe_x, operator=get_derivative)
np.savetxt(f"Derivative.dat",np.hstack((observe_x,f)))
`
Any headers why I am facing this error would be quite helpful.
Thanks in Advance
Pushkar
Beta Was this translation helpful? Give feedback.
All reactions