Convert_Pyomo2Casadi_Visitor
(class from pyomo.dae.simulator
)
- class pyomo.dae.simulator.Convert_Pyomo2Casadi_Visitor[source]
Bases:
ExpressionValueVisitor
Expression walker that evaluates an expression generated by the Substitute_Pyomo2Casadi_Visitor walker.
In Coopr3 this walker was not necessary because the expression could be simply evaluated. But in Pyomo5, the evaluation logic was changed to be non-recursive, which involves checks on the types of leaves in the expression tree. Hence, the evaluation logic fails if leaves in the tree are not standard Pyomo5 variable types.
- __init__()
Methods
__init__
()dfs_postorder_stack
(node)Perform a depth-first search in postorder using a stack implementation.
finalize
(ans)This method defines the return value for the search methods in this class.
visit
(node, values)Visit nodes that have been expanded
visiting_potential_leaf
(node)Visiting a potential leaf.
Member Documentation
- dfs_postorder_stack(node)
Perform a depth-first search in postorder using a stack implementation.
Note
This method has the same functionality as the PyUtilib
ValueVisitor.dfs_postorder_stack
method. The difference is that this method is tailored to efficiently walk Pyomo expression trees.- Parameters:
node – The root node of the expression tree that is searched.
- Returns:
The return value is determined by the
finalize()
function, which may be defined by the user.
- finalize(ans)
This method defines the return value for the search methods in this class.
The default implementation returns the value of the initial node (aka the root node), because this visitor pattern computes and returns value for each node to enable the computation of this value.
- Parameters:
ans – The final value computed by the search method.
- Returns:
The final value after the search. Defaults to simply returning
ans
.