Skip to content

Commit

Permalink
Merge branch 'main' into mindtpy-rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
ZedongPeng authored Aug 8, 2023
2 parents 8201e9b + cffefdd commit 6d0b94d
Show file tree
Hide file tree
Showing 115 changed files with 318 additions and 227 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ caf = "caf"
WRONLY = "WRONLY"
# Ignore the name Hax
Hax = "Hax"
# Big Sur
Sur = "Sur"
# AS NEEDED: Add More Words Below
4 changes: 2 additions & 2 deletions pyomo/contrib/appsi/utils/collect_vars_and_named_exprs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pyomo.core.expr.visitor import ExpressionValueVisitor, nonpyomo_leaf_types
from pyomo.core.expr import current as _expr
import pyomo.core.expr as EXPR


class _VarAndNamedExprCollector(ExpressionValueVisitor):
Expand All @@ -26,7 +26,7 @@ def visiting_potential_leaf(self, node):
self.named_expressions[id(node)] = node
return False, None

if type(node) is _expr.ExternalFunctionExpression:
if type(node) is EXPR.ExternalFunctionExpression:
self._external_functions[id(node)] = node
return False, None

Expand Down
2 changes: 1 addition & 1 deletion pyomo/contrib/community_detection/community_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from pyomo.common.dependencies import networkx as nx
from pyomo.core import Constraint, Objective, Var, ComponentMap, SortComponents
from pyomo.core.expr.current import identify_variables
from pyomo.core.expr import identify_variables
from pyomo.contrib.community_detection.event_log import _event_log


Expand Down
3 changes: 1 addition & 2 deletions pyomo/contrib/community_detection/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
ConstraintList,
)
from pyomo.core.base.objective import _GeneralObjectiveData
from pyomo.core.expr.current import identify_variables
from pyomo.core.expr.visitor import replace_expressions
from pyomo.core.expr.visitor import replace_expressions, identify_variables
from pyomo.contrib.community_detection.community_graph import generate_model_graph
from pyomo.common.dependencies import networkx as nx
from pyomo.common.dependencies.matplotlib import pyplot as plt
Expand Down
2 changes: 1 addition & 1 deletion pyomo/contrib/cp/interval_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from pyomo.core.base.global_set import UnindexedComponent_index
from pyomo.core.base.indexed_component import IndexedComponent, UnindexedComponent_set
from pyomo.core.base.initializer import BoundInitializer, Initializer
from pyomo.core.expr.current import GetItemExpression
from pyomo.core.expr import GetItemExpression


class IntervalVarTimePoint(ScalarVar):
Expand Down
42 changes: 14 additions & 28 deletions pyomo/contrib/cp/repn/docplex_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,7 @@
from pyomo.core.base.expression import ScalarExpression, _GeneralExpressionData
from pyomo.core.base.param import IndexedParam, ScalarParam
from pyomo.core.base.var import ScalarVar, _GeneralVarData, IndexedVar
import pyomo.core.expr.current as EXPR
from pyomo.core.expr.logical_expr import (
AndExpression,
OrExpression,
XorExpression,
NotExpression,
EquivalenceExpression,
ImplicationExpression,
ExactlyExpression,
AtMostExpression,
AtLeastExpression,
)
from pyomo.core.expr.numeric_expr import MinExpression, MaxExpression
from pyomo.core.expr.relational_expr import NotEqualExpression
from pyomo.core.expr.template_expr import CallExpression
import pyomo.core.expr as EXPR
from pyomo.core.expr.visitor import StreamBasedExpressionVisitor, identify_variables
from pyomo.core.base import Set, RangeSet
from pyomo.core.base.set import SetProduct
Expand Down Expand Up @@ -926,7 +912,7 @@ class LogicalToDoCplex(StreamBasedExpressionVisitor):
EXPR.Structural_GetAttrExpression: _handle_getattr,
EXPR.Numeric_GetAttrExpression: _handle_getattr,
EXPR.Boolean_GetAttrExpression: _handle_getattr,
CallExpression: _handle_call,
EXPR.CallExpression: _handle_call,
EXPR.NegationExpression: _handle_negation_node,
EXPR.ProductExpression: _handle_product_node,
EXPR.DivisionExpression: _handle_division_node,
Expand All @@ -935,19 +921,19 @@ class LogicalToDoCplex(StreamBasedExpressionVisitor):
EXPR.MonomialTermExpression: _handle_monomial_expr,
EXPR.SumExpression: _handle_sum_node,
EXPR.LinearExpression: _handle_sum_node,
MinExpression: _handle_min_node,
MaxExpression: _handle_max_node,
NotExpression: _handle_not_node,
EquivalenceExpression: _handle_equivalence_node,
ImplicationExpression: _handle_implication_node,
AndExpression: _handle_and_node,
OrExpression: _handle_or_node,
XorExpression: _handle_xor_node,
ExactlyExpression: _handle_exactly_node,
AtMostExpression: _handle_at_most_node,
AtLeastExpression: _handle_at_least_node,
EXPR.MinExpression: _handle_min_node,
EXPR.MaxExpression: _handle_max_node,
EXPR.NotExpression: _handle_not_node,
EXPR.EquivalenceExpression: _handle_equivalence_node,
EXPR.ImplicationExpression: _handle_implication_node,
EXPR.AndExpression: _handle_and_node,
EXPR.OrExpression: _handle_or_node,
EXPR.XorExpression: _handle_xor_node,
EXPR.ExactlyExpression: _handle_exactly_node,
EXPR.AtMostExpression: _handle_at_most_node,
EXPR.AtLeastExpression: _handle_at_least_node,
EXPR.EqualityExpression: _handle_equality_node,
NotEqualExpression: _handle_not_equal_node,
EXPR.NotEqualExpression: _handle_not_equal_node,
EXPR.InequalityExpression: _handle_inequality_node,
EXPR.RangedExpression: _handle_ranged_inequality_node,
BeforeExpression: _handle_before_expression_node,
Expand Down
3 changes: 1 addition & 2 deletions pyomo/contrib/cp/tests/test_interval_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
IntervalVarLength,
IntervalVarPresence,
)
from pyomo.core.expr.current import GetItemExpression
from pyomo.core.expr.template_expr import GetAttrExpression
from pyomo.core.expr import GetItemExpression, GetAttrExpression
from pyomo.environ import ConcreteModel, Integers, Set, value, Var


Expand Down
21 changes: 10 additions & 11 deletions pyomo/contrib/cp/transform/logical_to_disjunctive_walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
from pyomo.core.expr.visitor import StreamBasedExpressionVisitor
from pyomo.core.expr.numeric_expr import NumericExpression
from pyomo.core.expr.relational_expr import RelationalExpression
import pyomo.core.expr.current as EXPR
import pyomo.core.expr.logical_expr as LE
import pyomo.core.expr as EXPR
from pyomo.core.base import (
Binary,
Constraint,
Expand Down Expand Up @@ -198,15 +197,15 @@ def _dispatch_atmost(visitor, node, *args):


_operator_dispatcher = {}
_operator_dispatcher[LE.ImplicationExpression] = _dispatch_implication
_operator_dispatcher[LE.EquivalenceExpression] = _dispatch_equivalence
_operator_dispatcher[LE.NotExpression] = _dispatch_not
_operator_dispatcher[LE.AndExpression] = _dispatch_and
_operator_dispatcher[LE.OrExpression] = _dispatch_or
_operator_dispatcher[LE.XorExpression] = _dispatch_xor
_operator_dispatcher[LE.ExactlyExpression] = _dispatch_exactly
_operator_dispatcher[LE.AtLeastExpression] = _dispatch_atleast
_operator_dispatcher[LE.AtMostExpression] = _dispatch_atmost
_operator_dispatcher[EXPR.ImplicationExpression] = _dispatch_implication
_operator_dispatcher[EXPR.EquivalenceExpression] = _dispatch_equivalence
_operator_dispatcher[EXPR.NotExpression] = _dispatch_not
_operator_dispatcher[EXPR.AndExpression] = _dispatch_and
_operator_dispatcher[EXPR.OrExpression] = _dispatch_or
_operator_dispatcher[EXPR.XorExpression] = _dispatch_xor
_operator_dispatcher[EXPR.ExactlyExpression] = _dispatch_exactly
_operator_dispatcher[EXPR.AtLeastExpression] = _dispatch_atleast
_operator_dispatcher[EXPR.AtMostExpression] = _dispatch_atmost

_before_child_dispatcher = {}
_before_child_dispatcher[BV.ScalarBooleanVar] = _dispatch_boolean_var
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
Objective,
)
from pyomo.core.base import TransformationFactory
from pyomo.core.expr.current import log
from pyomo.core.expr import log
from pyomo.core.expr.compare import assertExpressionsEqual
from pyomo.gdp import Disjunction, Disjunct
from pyomo.repn.standard_repn import generate_standard_repn
Expand Down
2 changes: 1 addition & 1 deletion pyomo/contrib/gdp_bounds/compute_bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from pyomo.common.errors import InfeasibleConstraintException
from pyomo.contrib.fbbt.fbbt import fbbt, BoundsManager
from pyomo.core.base.block import Block, TraversalStrategy
from pyomo.core.expr.current import identify_variables
from pyomo.core.expr import identify_variables
from pyomo.core import Constraint, Objective, TransformationFactory, minimize, value
from pyomo.opt import SolverFactory
from pyomo.gdp.disjunct import Disjunct
Expand Down
2 changes: 1 addition & 1 deletion pyomo/contrib/gdpopt/solve_subproblem.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
get_main_elapsed_time,
)
from pyomo.core import Constraint, TransformationFactory, Objective, Block
from pyomo.core.expr import current as EXPR
import pyomo.core.expr as EXPR
from pyomo.opt import SolverFactory, SolverResults
from pyomo.opt import TerminationCondition as tc

Expand Down
2 changes: 1 addition & 1 deletion pyomo/contrib/incidence_analysis/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from pyomo.core.base.var import Var
from pyomo.core.base.constraint import Constraint
from pyomo.core.base.objective import Objective
from pyomo.core.expr.current import EqualityExpression
from pyomo.core.expr import EqualityExpression
from pyomo.util.subsystems import create_subsystem_block
from pyomo.common.collections import ComponentSet, ComponentMap
from pyomo.common.dependencies import (
Expand Down
2 changes: 1 addition & 1 deletion pyomo/contrib/mcpp/test_mcpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
ComponentMap,
log,
)
from pyomo.core.expr.current import identify_variables
from pyomo.core.expr import identify_variables


@unittest.skipIf(not mcpp_available(), "MC++ is not available")
Expand Down
2 changes: 1 addition & 1 deletion pyomo/contrib/mindtpy/algorithm_base_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"""Iteration loop for MindtPy."""
import math
from io import StringIO
from pyomo.core.expr import current as EXPR
import pyomo.core.expr as EXPR
from pyomo.repn import generate_standard_repn
import logging
from pyomo.contrib.fbbt.fbbt import fbbt
Expand Down
2 changes: 1 addition & 1 deletion pyomo/contrib/mindtpy/cut_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"""Cut generation."""
from math import copysign
from pyomo.core import minimize, value
from pyomo.core.expr import current as EXPR
import pyomo.core.expr as EXPR
from pyomo.contrib.gdpopt.util import time_code
from pyomo.contrib.mcpp.pyomo_mcpp import McCormick as mc, MCPP_Error

Expand Down
4 changes: 2 additions & 2 deletions pyomo/contrib/mindtpy/single_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from pyomo.contrib.mindtpy.cut_generation import add_oa_cuts, add_no_good_cuts
from pyomo.contrib.mcpp.pyomo_mcpp import McCormick as mc, MCPP_Error
from pyomo.repn import generate_standard_repn
from pyomo.core.expr import current as EXPR
import pyomo.core.expr as EXPR
from math import copysign
from pyomo.contrib.mindtpy.util import get_integer_solution
from pyomo.contrib.gdpopt.util import (
Expand All @@ -24,7 +24,7 @@
)
from pyomo.opt import TerminationCondition as tc
from pyomo.core import minimize, value
from pyomo.core.expr.current import identify_variables
from pyomo.core.expr import identify_variables

cplex, cplex_available = attempt_import('cplex')

Expand Down
10 changes: 4 additions & 6 deletions pyomo/contrib/mindtpy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@
from pyomo.repn import generate_standard_repn
from pyomo.contrib.mcpp.pyomo_mcpp import mcpp_available, McCormick
from pyomo.contrib.fbbt.fbbt import compute_bounds_on_expr
from pyomo.core.expr import differentiate
from pyomo.core.expr import current as EXPR
import pyomo.core.expr as EXPR
from pyomo.opt import ProblemSense
from pyomo.contrib.gdpopt.util import get_main_elapsed_time, time_code
from pyomo.util.model_size import build_model_size_report
from pyomo.core.expr.calculus.derivatives import differentiate
from pyomo.common.dependencies import attempt_import
from pyomo.solvers.plugins.solvers.gurobi_direct import gurobipy
from pyomo.solvers.plugins.solvers.gurobi_persistent import GurobiPersistent
Expand All @@ -59,12 +57,12 @@ def calc_jacobians(model, config):
# variable --> jacobian of constraint wrt. variable)
jacobians = ComponentMap()
if config.differentiate_mode == 'reverse_symbolic':
mode = differentiate.Modes.reverse_symbolic
mode = EXPR.differentiate.Modes.reverse_symbolic
elif config.differentiate_mode == 'sympy':
mode = differentiate.Modes.sympy
mode = EXPR.differentiate.Modes.sympy
for c in model.MindtPy_utils.nonlinear_constraint_list:
vars_in_constr = list(EXPR.identify_variables(c.body))
jac_list = differentiate(c.body, wrt_list=vars_in_constr, mode=mode)
jac_list = EXPR.differentiate(c.body, wrt_list=vars_in_constr, mode=mode)
jacobians[c] = ComponentMap(
(var, jac_wrt_var) for var, jac_wrt_var in zip(vars_in_constr, jac_list)
)
Expand Down
2 changes: 1 addition & 1 deletion pyomo/contrib/parmest/utils/model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import logging

import pyomo.environ as pyo
from pyomo.core.expr.current import replace_expressions, identify_mutable_parameters
from pyomo.core.expr import replace_expressions, identify_mutable_parameters
from pyomo.core.base.var import IndexedVar
from pyomo.core.base.param import IndexedParam

Expand Down
2 changes: 1 addition & 1 deletion pyomo/contrib/piecewise/piecewise_linear_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from pyomo.core.base.global_set import UnindexedComponent_index
from pyomo.core.base.indexed_component import UnindexedComponent_set
from pyomo.core.base.initializer import Initializer
import pyomo.core.expr.current as EXPR
import pyomo.core.expr as EXPR

# This is the default absolute tolerance in np.isclose... Not sure if it's
# enough, but we need to make sure that 'barely negative' values are assumed to
Expand Down
2 changes: 1 addition & 1 deletion pyomo/contrib/preprocessing/plugins/int_to_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
)
from pyomo.core.plugins.transform.hierarchy import IsomorphicTransformation
from pyomo.gdp import Disjunct
from pyomo.core.expr.current import identify_variables
from pyomo.core.expr import identify_variables
from pyomo.common.modeling import unique_component_name

logger = logging.getLogger('pyomo.contrib.preprocessing')
Expand Down
2 changes: 1 addition & 1 deletion pyomo/contrib/preprocessing/plugins/remove_zero_terms.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pyomo.core import quicksum
from pyomo.core.base.constraint import Constraint
from pyomo.core.base.transformation import TransformationFactory
from pyomo.core.expr import current as EXPR
import pyomo.core.expr as EXPR
from pyomo.core.plugins.transform.hierarchy import IsomorphicTransformation
from pyomo.repn import generate_standard_repn
from pyomo.common.config import ConfigDict, ConfigValue
Expand Down
2 changes: 1 addition & 1 deletion pyomo/contrib/preprocessing/plugins/var_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from pyomo.common.collections import ComponentMap, ComponentSet
from pyomo.core.base import Block, Constraint, VarList, Objective, TransformationFactory
from pyomo.core.expr.current import ExpressionReplacementVisitor
from pyomo.core.expr import ExpressionReplacementVisitor
from pyomo.core.expr.numvalue import value
from pyomo.core.plugins.transform.hierarchy import IsomorphicTransformation
from pyomo.repn import generate_standard_repn
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Tests detection of zero terms."""
import pyomo.common.unittest as unittest
from pyomo.environ import ConcreteModel, Constraint, TransformationFactory, Var
from pyomo.core.expr import current as EXPR
import pyomo.core.expr as EXPR
from pyomo.repn import generate_standard_repn


Expand Down
2 changes: 1 addition & 1 deletion pyomo/contrib/pynumero/sparse/tests/test_intrinsics.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

if not (numpy_available and scipy_available):
raise unittest.SkipTest(
"Pynumero needs scipy and numpy to run Sparse intrinsict tests"
"Pynumero needs scipy and numpy to run Sparse intrinsic tests"
)

from pyomo.contrib.pynumero.sparse import BlockVector
Expand Down
2 changes: 1 addition & 1 deletion pyomo/contrib/pyros/separation_problem_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SeparationResults,
)
from pyomo.opt import TerminationCondition as tc
from pyomo.core.expr.current import (
from pyomo.core.expr import (
replace_expressions,
identify_mutable_parameters,
identify_variables,
Expand Down
23 changes: 17 additions & 6 deletions pyomo/contrib/pyros/tests/test_grcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from pyomo.common.collections import ComponentSet
from pyomo.common.config import ConfigBlock, ConfigValue
from pyomo.core.base.set_types import NonNegativeIntegers
from pyomo.environ import *
from pyomo.core.expr.current import identify_variables, identify_mutable_parameters
from pyomo.core.expr import identify_variables, identify_mutable_parameters
from pyomo.contrib.pyros.util import (
selective_clone,
add_decision_rule_variables,
Expand All @@ -27,7 +26,6 @@
from pyomo.common.collections import Bunch
import time
from pyomo.contrib.pyros.util import time_code
from pyomo.core.expr import current as EXPR
from pyomo.contrib.pyros.uncertainty_sets import *
from pyomo.contrib.pyros.master_problem_methods import (
add_scenario_to_master,
Expand All @@ -47,7 +45,20 @@
TerminationCondition,
Solution,
)
from pyomo.environ import Objective, value, Var
from pyomo.environ import (
Constraint,
Expression,
Objective,
Param,
SolverFactory,
Var,
cos,
exp,
log,
sin,
sqrt,
value,
)


if not (numpy_available and scipy_available):
Expand Down Expand Up @@ -555,9 +566,9 @@ def test_uncertain_bounds_to_constraints(self):
# get variables, mutable params in the explicit constraints
cons = mod_2.uncertain_var_bound_cons
for idx in cons:
for p in EXPR.identify_mutable_parameters(cons[idx].expr):
for p in identify_mutable_parameters(cons[idx].expr):
params_in_cons.add(p)
for v in EXPR.identify_variables(cons[idx].expr):
for v in identify_variables(cons[idx].expr):
vars_in_cons.add(v)
# reduce only to uncertain mutable params found
params_in_cons = params_in_cons & uncertain_params
Expand Down
Loading

0 comments on commit 6d0b94d

Please sign in to comment.