Comments (2)
Hi @Asseni ππ»
The code was almost fine but there were a few issues.
- The
Trainer
is not finding the point because you are passing thePINN
solver an instance of the problem, not theproblem
variable. The code should besolver = PINN(problem=problem, model=model)
instead ofsolver = PINN(problem=SimpleODE(), model=model)
. This is because when you callSimpleODE()
python creates an object (inherited fromAbstractProblem
) different than theproblem
you defined before for which you discretized the domain. - The
equations
in theSimpleODE
class was a bit off, here is how it should be written (I put some comments for the understanding):
def equations(input_, output_): # COMMENT: do not put self here, PINA uses static method for equations
t = input_.extract('t')
u = output_.extract('u')
# Define the differential equation du/dt = -u
du_dt = grad(output_, input_, components=['u'], d=['t']) # COMMENT: grad(u, t) this brakes the grad computation, use components and d for specifying the derivative
eq = du_dt + u
return eq # {'ode': eq} COMMENT: in PINA you need to resturn the residual
conditions = {
'initial_u': Condition(location=CartesianDomain({'t': [0, 0]}), equation=FixedValue(1.0)), # Initial condition u(0) = 1
'ode': Condition(location=CartesianDomain({'t': [0, 10]}), equation=Equation(equations))
}
The rest of the code was very good! Here the complete updated codeπ Let me know if you have further questions!
import torch
from pina.problem import TimeDependentProblem
from pina.operators import grad
from pina.equation import Equation, FixedValue
from pina import Condition
from pina.geometry import CartesianDomain
class SimpleODE(TimeDependentProblem):
output_variables = ['u']
temporal_domain = CartesianDomain({'t': [0, 10]}) # Define the temporal domain
def equations(input_, output_): # COMMENT: do not put self here, we use static method for equations
t = input_.extract('t')
u = output_.extract('u')
# Define the differential equation du/dt = -u
du_dt = grad(output_, input_, components=['u'], d=['t']) # COMMENT: grad(u, t) this brakes the grad computation, use components and d for specifying the derivative
eq = du_dt + u
return eq # {'ode': eq} COMMENT: in PINA you need to resturn the residual
conditions = {
'initial_u': Condition(location=CartesianDomain({'t': [0, 0]}), equation=FixedValue(1.0)), # Initial condition u(0) = 1
'ode': Condition(location=CartesianDomain({'t': [0, 10]}), equation=Equation(equations))
}
problem = SimpleODE()
problem.discretise_domain(n=1, mode='random', locations=['initial_u'])
problem.discretise_domain(n=10, mode='grid', locations=['ode'])
from pina import Plotter
pl = Plotter()
pl.plot_samples(problem=problem)
print('Input points:', problem.input_pts)
print('Initial condition points:', problem.input_pts['initial_u'].labels)
print('Domain points:', problem.input_pts['ode'].labels)
from pina.model import FeedForward
from pina.solvers import PINN
from pina.trainer import Trainer
model = FeedForward(
layers=[20, 20, 20], # Hidden layers configuration
func=torch.nn.Tanh,
output_dimensions=len(problem.output_variables),
input_dimensions=len(problem.input_variables)
)
solver = PINN(problem=problem, model=model)
trainer = Trainer(solver=solver, max_epochs=50)
trainer.train()
from pina.
Related Issues (20)
- Saving the trained model and used it in other code HOT 2
- How to evaluate the trained neural network on custom points HOT 5
- Implementing flux boundary condition
- Not able to solve simple PDE with flux condition HOT 4
- Tutorial for Equations Class HOT 2
- None
- Using custom arguments in boundary condition HOT 2
- Adaptive Activations Functions
- TimeDependentProblem, SpatialProblem, ParametricProblem HOT 2
- Tried using spatial, time and parametric domain HOT 3
- Solver Compilation HOT 1
- Tests and Monthly Automated Tag HOT 1
- Unkown parameters in InverseProblem can't go on device HOT 3
- Large-scale experiment HOT 2
- Benchmarks HOT 1
- KS mat generation HOT 3
- Residual-based attention PINN
- `add_points` assigns wrong labels to new data HOT 3
- Problem in the example of parametric elliptic control problem HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pina.