Pyomo / pyomo

An object-oriented algebraic modeling language in Python for structured optimization problems.
https://www.pyomo.org
Other
1.97k stars 505 forks source link

Hard to tell what ContinuousSet(s) a disc_eq is discretizing #1411

Open Robbybp opened 4 years ago

Robbybp commented 4 years ago

When solving for consistent initial conditions (among other applications, I'm sure), it is useful to know which ContinuousSets a ..._disc_eq is discretizing. For some simple cases, this can be done by:

for var in identify_variables(disc_eq[index].expr):
    if isinstance(var, DerivativeVar):
        wrt = var.get_continuousset_list()

This is slower than necessary and not reliable if multiple derivatives are present in the discretization equation. I think the current most reliable way identify _disc_eqs with respect to a particular set is to iterate over DerivativeVars, check for those with respect to the set, then find the constraint with the corresponding ..._disc_eq name. This is non-intuitive (to find some Constraints we iterate over Vars?) and relies on discretization equations having the correct name.

How hard would it be to give disc_eqs a continuousset_list attribute or method? It would be nice if we had a DiscEq subclass of Constraint, although this may cause its own trouble.

blnicho commented 4 years ago

These are good suggestions. The problem with the current implementation is that there is only ever 1 discretization equation for each DerivativeVar. If a DerivativeVar is a mixed partial derivative, only 1 discretization equation is written that "nests" the discretizations for each individual ContinuousSet. This is the reason Pyomo.DAE does not currently support the "method of lines" approach for PDEs. I think I can support these changes when I refactor the discretization transformations to better support PDEs.