PintUnitExtractionVisitor
(class from pyomo.core.base.units_container
)
- class pyomo.core.base.units_container.PintUnitExtractionVisitor(pyomo_units_container, units_equivalence_tolerance=1e-12)[source]
Bases:
StreamBasedExpressionVisitor
- __init__(pyomo_units_container, units_equivalence_tolerance=1e-12)[source]
Visitor class used to determine units of an expression. Do not use this class directly, but rather use “py:meth:PyomoUnitsContainer.assert_units_consistent or
PyomoUnitsContainer.get_units()
- Parameters:
pyomo_units_container (PyomoUnitsContainer) – Instance of the PyomoUnitsContainer that was used for the units in the expressions. Pyomo does not support “mixing” units from different containers
units_equivalence_tolerance (float (default 1e-12)) – Floating point tolerance used when deciding if units are equivalent or not.
Notes
This class inherits from the
StreamBasedExpressionVisitor
to implement a walker that returns the pyomo units and pint units corresponding to an expression.There are class attributes (dicts) that map the expression node type to the particular method that should be called to return the units of the node based on the units of its child arguments. This map is used in exitNode.
Methods
__init__
(pyomo_units_container[, ...])Visitor class used to determine units of an expression.
beforeChild
(node, child, child_idx)exitNode
(node, data)Visitor callback when moving up the expression tree.
finalizeResult
(result)initializeWalker
(expr)walk_expression
(expr)Walk an expression, calling registered callbacks.
Nonrecursively walk an expression, calling registered callbacks.
Attributes
client_methods
node_type_method_map
unary_function_method_map
Member Documentation
- exitNode(node, data)[source]
Visitor callback when moving up the expression tree.
Callback for
pyomo.core.current.StreamBasedExpressionVisitor
. This method is called when moving back up the tree in a depth first search.
- walk_expression(expr)
Walk an expression, calling registered callbacks.
This is the standard interface for running the visitor. It defaults to using an efficient recursive implementation of the visitor, falling back on
walk_expression_nonrecursive()
if the recursion stack gets too deep.
- walk_expression_nonrecursive(expr)
Nonrecursively walk an expression, calling registered callbacks.
This routine is safer than the recursive walkers for deep (or unbalanced) trees. It is, however, slightly slower than the recursive implementations.