Description
Summary
The Simulator reads only the initial guesses for the differential variables and provides them to the Casadi integrator instance.
Rationale
This change is particularly crucial in my case because the current approach results in a failure during the initial condition calculation of IDAS.
Description
I recommend that we enhance this process by obtaining the initial guesses for the algebraic variables from the Pyomo Var, which represents algebraic variables, and passing them to the Casadi integrator using the keyword argument 'z0'.
Additional information
To address this issue, I had to implement a workaround in my simulator, which looks like this:
pyomo.dae.simulator (line 982 and ongoing)
if len(self._algvars) != 0:
zalltemp = [self._templatemap[i] for i in self._simalgvars]
zall = casadi.vertcat(*zalltemp)
algalltemp = [convert_pyomo2casadi(i) for i in self._alglist]
algall = casadi.vertcat(*algalltemp)
dae['z'] = zall
dae['alg'] = algall
z0 = []
for v in self._simalgvars:
for idx, i in enumerate(v._args):
if type(i) is IndexTemplate:
break
initpoint = self._contset.first()
vidx = tuple(v._args[0:idx]) + (initpoint,) + tuple(v._args[idx + 1 :])
# This line will raise an error if no value was set
z0.append(value(v._base[vidx]))
integrator_options['grid'] = tsim
integrator_options['output_t0'] = True
F = casadi.integrator('F', integrator, dae, integrator_options)
if len(self._algvars) != 0:
sol = F(x0=initcon, z0=z0)
else:
sol = F(x0=initcon)
I must emphasize that this solution requires further testing and might be specific to my use case. However, it was essential for me to ensure that IDAS integrates my DAE without failing to solve for an initial condition.
If anyone has insights or would like to collaborate on implementing a more robust version of this workaround, I'm open to discussions and cooperation.
simulator.txt