Pyomo Error: "Error evaluating Param value (u[{t}]): The Param value is currently set to an invalid value.”

140 views
Skip to first unread message

TYLER HONGISTO

unread,
Sep 18, 2020, 5:55:49 PM9/18/20
to Pyomo Forum
Hi all,

I am new to Pyomo. As such, this may be a simple error with my model definition, but I am not sure. Essentially, I am solving an optimal control problem, and it stating that my control variable is set to an invalid value. I have attached the model definition and description below for context. Along with this, I have provided a screenshot of my code and the error. I would really appreciate any help that I can get!


Screen Shot 2020-09-18 at 4.34.09 PM.png

Best,

Tyler

Nicholson, Bethany L.

unread,
Sep 23, 2020, 7:57:35 PM9/23/20
to pyomo...@googlegroups.com

The problem is that you are not specifying values for the control input “m.u” correctly. From the perspective of the Simulator, m.u is a time-varying input. Meaning its value needs to be specified before running the simulation and its value could vary over time (because m.u is indexed by m.t). See the online documentation for specifying time-varying inputs here: https://pyomo.readthedocs.io/en/latest/modeling_extensions/dae.html#specifying-time-varing-inputs

 

In your case, swap out lines 55 and 57 with the following:

 

m.var_input = Suffix(direction=Suffix.LOCAL)

m.var_input[m.u] = {0:1}  # If you want u to be set to 0 over the whole simulation use {0:0} instead

 

sim = Simulator(m, package='scipy')

 

tsim, profiles = sim.simulate(numpoints=100, integrator='lsoda', varying_inputs=m.var_input)

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyomo-forum/2d7b68eb-27ba-43d1-a0b2-173ea15b2634n%40googlegroups.com.

TYLER HONGISTO

unread,
Sep 24, 2020, 7:19:00 PM9/24/20
to Pyomo Forum
Bethany,

That worked. Thanks for the help!

Best,

Tyler

Rune Lorits

unread,
Jul 24, 2022, 10:34:51 AM7/24/22
to Pyomo Forum
Hi,
I have been trying to figure out if it is possible to solve an optimization problem using the Simulator's interface to Scipy or CasADi (I am mainly interested in CasADi though)
I have implemented the example based on Tyler's screenshot and applied the changes suggested by Bethany, but the solution you get is simply a simulation of the system using the initialized values (u(t)=1 and tf = 2) i.e. not the optimal solution.
That means, the objective (m.OBJ) has been completely ignored.

The solution to the optimal control problem can be found using IPOPT by adding the following lines to the end of the script:
m.s[0].fix(0.0)
m.v[0].fix(0.0)
m.m[0].fix(1.0)
m.s[len(m.t)-1].fix(10.0)
m.v[len(m.t)-1].fix(0.0)

m.discretizer = TransformationFactory('dae.finite_difference')
m.discretizer.apply_to(m,nfe=100,wrt=m.t,scheme="BACKWARD")

solver = SolverFactory('ipopt')
results = solver.solve(m, tee=True)


I know CasADi can be used to solve optimal control problems.
My question is: Can it be done using the Simulator's interface between Pyomo and CasADi?

The script is attached.

Rune
OCP.ipynb

Nicholson, Bethany L.

unread,
Jul 25, 2022, 11:05:04 AM7/25/22
to pyomo...@googlegroups.com

Rune,

 

The Simulator interface to CasADi only supports simulation at this time. However, you could use the Simulator code as an example of how to convert your Pyomo model to a CasADi model (including the objective function and inequality constraints) and then use CasADi’s Python API to solve an optimal control problem.

 

Bethany

 

Best,

 

Tyler

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyomo-forum/2d7b68eb-27ba-43d1-a0b2-173ea15b2634n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.

Rune Lorits

unread,
Aug 1, 2022, 2:28:41 AM8/1/22
to Pyomo Forum
I suspected that to be the case.
Thanks for clearing that up, Bethany!

Rune

Reply all
Reply to author
Forward
0 new messages