SciML / ModelingToolkit.jl

An acausal modeling framework for automatically parallelized scientific machine learning (SciML) in Julia. A computer algebra system for integrated symbolics for physics-informed machine learning and automated transformations of differential equations
https://mtk.sciml.ai/dev/
Other
1.43k stars 207 forks source link

Implementing ControlSystem in ModelingToolkit #749

Open anujdave23 opened 3 years ago

anujdave23 commented 3 years ago

Hello fellas, I am trying to develop one simple example of controlsystem for the optimal control of any system but getting some error. I tried Moon Lander problem.But i didnt understand the error . Please to code that i have developed and give me some feedback to run it successfully moon_lander controlsystem_moon_lander

ChrisRackauckas commented 3 years ago

Can you post this as code?

anujdave23 commented 3 years ago

Can you post this as code?

using ModelingToolkit,QuadGK

@variables t x(t) v(t) h(t)
@parameters p , g
D = Differential(t)

loss = quadgk(u,0,p)
eqs = [
    D(h) ~ v 
    D(v) ~ -g + u
]

sys = ControlSystem(loss,eqs,t,[h,v],[u],[p,g])
dt = 0.1
tspan = (0.0,1.0)
sys = runge_kutta_discretize(sys,dt,tspan)

u0 = rand(112) # guess for the state values
prob = OptimizationProblem(sys,u0,[0.1],grad=true)
ChrisRackauckas commented 3 years ago

u isn't defined. The loss is supposed to be the integrand, so no need to write the integral.

anujdave23 commented 3 years ago

so if i initiate u(t) as an variable and in loss function only u , will that be fine?

u isn't defined. The loss is supposed to be the integrand, so no need to write the integral.

ChrisRackauckas commented 3 years ago

Use the test as an example: https://github.com/SciML/ModelingToolkit.jl/blob/master/test/controlsystem.jl. We're probably still a few months away from having a full blown tutorial there though.

anujdave23 commented 3 years ago

Use the test as an example: https://github.com/SciML/ModelingToolkit.jl/blob/master/test/controlsystem.jl. We're probably still a few months away from having a full blown tutorial there though.

Actually I am a Master Student and this is my embedded seminar topic, so i need to develop a simple optimal control system using controlsystem and i can't copy and paste your code. So i tried to develop a system but i am not getting what the error is

ChrisRackauckas commented 3 years ago

I'm saying right now the best documentation is the test, so use the test as an example of what works.

anujdave23 commented 3 years ago

Okay thanks for your information, i also have a doubt about equality_constarints and inequality_contraints in optimizationsystem of MoodelingToolkit . Is it possible to apply the condition if yes how? Can you please guide me through this?

ChrisRackauckas commented 3 years ago

That's not available yet. ControlSystem is pretty unfinished right now and I don't expect it to be completed for another couple months.

anujdave23 commented 3 years ago

That's not available yet. ControlSystem is pretty unfinished right now and I don't expect it to be completed for another couple months.

not in controlsystem. I am asking if its possible in "optimizationsystem".Because in the fields this contraints are mentioned

ChrisRackauckas commented 3 years ago

I'm not sure OptimizationSystem will do it all, but you can directly modify the OptimizationProblem.