Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into solver-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmundt committed Jan 30, 2024
2 parents f126bc4 + a02be9d commit 21f5a77
Show file tree
Hide file tree
Showing 172 changed files with 1,262 additions and 1,248 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ ed13c8c65d6c3f56973887744be1c62a5d4756de
0d93f98aa608f892df404ad8015885d26e09bb55
63a3c602a00a2b747fc308c0571bbe33e55a3731
363a16a609f519b3edfdfcf40c66d6de7ac135af
d024718991455519e09149ede53a38df1c067abe
017e21ee50d98d8b2f2083e6880f030025ed5378

2 changes: 1 addition & 1 deletion doc/OnlineDocs/src/kernel/examples.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
5 Declarations: SOS2_y_index SOS2_y SOS2_constraint_index SOS2_constraint SOS2_sosconstraint

1 Suffix Declarations
dual : Direction=Suffix.IMPORT, Datatype=Suffix.FLOAT
dual : Direction=IMPORT, Datatype=FLOAT
Key : Value

27 Declarations: b s q p pd v vd vl_index vl c cd_index cd cl_index cl e ed o od ol_index ol sos1 sos2 sd_index sd dual f pw
Expand Down
2 changes: 1 addition & 1 deletion doc/OnlineDocs/src/scripting/abstract2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# abstract2.py

from __future__ import division

from pyomo.environ import *

model = AbstractModel()
Expand Down
1 change: 0 additions & 1 deletion doc/OnlineDocs/src/scripting/concrete1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import division
from pyomo.environ import *

model = ConcreteModel()
Expand Down
2 changes: 1 addition & 1 deletion doc/OnlineDocs/src/scripting/driveabs2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# driveabs2.py
from __future__ import division

import pyomo.environ as pyo
from pyomo.opt import SolverFactory

Expand Down
2 changes: 1 addition & 1 deletion doc/OnlineDocs/src/scripting/driveconc1.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# driveconc1.py
from __future__ import division

import pyomo.environ as pyo
from pyomo.opt import SolverFactory

Expand Down
1 change: 1 addition & 0 deletions doc/OnlineDocs/src/scripting/spy4Constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
David L. Woodruff and Mingye Yang, Spring 2018
Code snippets for Constraints.rst in testable form
"""

from pyomo.environ import *

model = ConcreteModel()
Expand Down
1 change: 1 addition & 0 deletions doc/OnlineDocs/src/scripting/spy4Expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
David L. Woodruff and Mingye Yang, Spring 2018
Code snippets for Expressions.rst in testable form
"""

from pyomo.environ import *

model = ConcreteModel()
Expand Down
1 change: 1 addition & 0 deletions doc/OnlineDocs/src/scripting/spy4PyomoCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
David L. Woodruff and Mingye Yang, Spring 2018
Code snippets for PyomoCommand.rst in testable form
"""

from pyomo.environ import *

model = ConcreteModel()
Expand Down
1 change: 1 addition & 0 deletions doc/OnlineDocs/src/scripting/spy4Variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
David L. Woodruff and Mingye Yang, Spring 2018
Code snippets for Variables.rst in testable form
"""

from pyomo.environ import *

model = ConcreteModel()
Expand Down
2 changes: 1 addition & 1 deletion examples/dae/stochpdegas_automatic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# stochastic pde model for natural gas network
# victor m. zavala / 2013

# from __future__ import division
#

from pyomo.environ import *
from pyomo.dae import *
Expand Down
1 change: 0 additions & 1 deletion examples/gdp/constrained_layout/cons_layout_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
with each other.
"""
from __future__ import division

from pyomo.environ import ConcreteModel, Objective, Param, RangeSet, Set, Var, value

Expand Down
1 change: 0 additions & 1 deletion examples/gdp/eight_process/eight_proc_logical.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
http://dx.doi.org/10.1016/0098-1354(95)00219-7
"""
from __future__ import division

from pyomo.core.expr.logical_expr import land, lor
from pyomo.core.plugins.transform.logical_to_linear import (
Expand Down
1 change: 0 additions & 1 deletion examples/gdp/eight_process/eight_proc_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
http://dx.doi.org/10.1016/0098-1354(95)00219-7
"""
from __future__ import division

from pyomo.environ import (
ConcreteModel,
Expand Down
1 change: 0 additions & 1 deletion examples/gdp/eight_process/eight_proc_verbose_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
eight_proc_model.py.
"""
from __future__ import division

from pyomo.environ import (
ConcreteModel,
Expand Down
1 change: 1 addition & 0 deletions examples/gdp/nine_process/small_process.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Small process synthesis-inspired toy GDP example.
"""

from pyomo.core import ConcreteModel, RangeSet, Var, Constraint, Objective
from pyomo.core.expr.current import exp, log, sqrt
from pyomo.gdp import Disjunction
Expand Down
1 change: 1 addition & 0 deletions examples/gdp/small_lit/basic_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Pyomo model implementation by @RomeoV
"""

from pyomo.environ import *
from pyomo.gdp import *
from pyomo.gdp.basic_step import apply_basic_step
Expand Down
1 change: 0 additions & 1 deletion examples/gdp/small_lit/ex_633_trespalacios.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
Pyomo model implementation by @bernalde and @qtothec.
"""
from __future__ import division

from pyomo.environ import *
from pyomo.gdp import *
Expand Down
1 change: 0 additions & 1 deletion examples/gdp/small_lit/nonconvex_HEN.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
Pyomo model implementation by @RomeoV
"""


from pyomo.environ import (
ConcreteModel,
Constraint,
Expand Down
2 changes: 0 additions & 2 deletions examples/gdp/strip_packing/strip_packing_8rect.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
"""

from __future__ import division

from pyomo.environ import (
ConcreteModel,
NonNegativeReals,
Expand Down
1 change: 0 additions & 1 deletion examples/gdp/strip_packing/strip_packing_concrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
cutting fabric.
"""
from __future__ import division

from pyomo.environ import ConcreteModel, NonNegativeReals, Objective, Param, Set, Var

Expand Down
1 change: 0 additions & 1 deletion examples/gdp/two_rxn_lee/two_rxn_model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Two reactor model from literature. See README.md."""
from __future__ import division

from pyomo.core import ConcreteModel, Constraint, Objective, Param, Var, maximize

Expand Down
4 changes: 1 addition & 3 deletions examples/kernel/mosek/power1.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ def solve_nonlinear():

m.c = pmo.constraint(body=m.x + m.y + 0.5 * m.z, rhs=2)

m.o = pmo.objective(
(m.x**0.2) * (m.y**0.8) + (m.z**0.4) - m.x, sense=pmo.maximize
)
m.o = pmo.objective((m.x**0.2) * (m.y**0.8) + (m.z**0.4) - m.x, sense=pmo.maximize)

m.x.value, m.y.value, m.z.value = (1, 1, 1)
ipopt = pmo.SolverFactory("ipopt")
Expand Down
2 changes: 1 addition & 1 deletion examples/performance/dae/stochpdegas1_automatic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# stochastic pde model for natural gas network
# victor m. zavala / 2013

# from __future__ import division
#

from pyomo.environ import *
from pyomo.dae import *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ def create_model(k1, k2, k3, caf):

model.cc_bal = pyo.Constraint(expr=(0 == -model.sv * model.cc + k2 * model.cb))

model.cd_bal = pyo.Constraint(
expr=(0 == -model.sv * model.cd + k3 * model.ca**2.0)
)
model.cd_bal = pyo.Constraint(expr=(0 == -model.sv * model.cd + k3 * model.ca**2.0))

return model

Expand Down
6 changes: 3 additions & 3 deletions examples/pyomobook/pyomo-components-ch/suffix_declaration.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

*** suffixsimple ***
2 Suffix Declarations
dual : Direction=Suffix.IMPORT_EXPORT, Datatype=Suffix.FLOAT
dual : Direction=IMPORT_EXPORT, Datatype=FLOAT
Key : Value
priority : Direction=Suffix.EXPORT, Datatype=Suffix.INT
priority : Direction=EXPORT, Datatype=INT
Key : Value

2 Declarations: priority dual
Expand All @@ -16,7 +16,7 @@
Not constructed

1 Suffix Declarations
foo : Direction=Suffix.LOCAL, Datatype=Suffix.FLOAT
foo : Direction=LOCAL, Datatype=FLOAT
Not constructed

3 Declarations: x c foo
Expand Down
1 change: 0 additions & 1 deletion examples/pyomobook/pyomo-components-ch/var_declaration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import pyomo.environ as pyo

model = pyo.ConcreteModel()
Expand Down
25 changes: 17 additions & 8 deletions pyomo/common/collections/component_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,25 @@ def update(self, *args, **kwargs):
return self._dict.update(args[0]._dict)
return super().update(*args, **kwargs)

# We want to avoid generating Pyomo expressions due to
# comparison of values, so we convert both objects to a
# plain dictionary mapping key->(type(val), id(val)) and
# compare that instead.
# We want to avoid generating Pyomo expressions due to comparing the
# keys, so look up each entry from other in this dict.
def __eq__(self, other):
if not isinstance(other, collections_Mapping):
if self is other:
return True
if not isinstance(other, collections_Mapping) or len(self) != len(other):
return False
return {(type(key), id(key)): val for key, val in self.items()} == {
(type(key), id(key)): val for key, val in other.items()
}
# Note we have already verified the dicts are the same size
for key, val in other.items():
other_id = id(key)
if other_id not in self._dict:
return False
self_val = self._dict[other_id][1]
# Note: check "is" first to help avoid creation of Pyomo
# expressions (for the case that the values contain the same
# Pyomo component)
if self_val is not val and self_val != val:
return False
return True

def __ne__(self, other):
return not (self == other)
Expand Down
6 changes: 3 additions & 3 deletions pyomo/common/collections/component_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ def discard(self, val):
# plain dictionary mapping key->(type(val), id(val)) and
# compare that instead.
def __eq__(self, other):
if self is other:
return True
if not isinstance(other, collections_Set):
return False
return set((type(val), id(val)) for val in self) == set(
(type(val), id(val)) for val in other
)
return len(self) == len(other) and all(id(key) in self._data for key in other)

def __ne__(self, other):
return not (self == other)
Expand Down
8 changes: 5 additions & 3 deletions pyomo/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1412,9 +1412,11 @@ def _item_body(self, indent, obj):
None,
[
'dict' if isinstance(obj, ConfigDict) else obj.domain_name(),
'optional'
if obj._default is None
else f'default={repr(obj._default)}',
(
'optional'
if obj._default is None
else f'default={repr(obj._default)}'
),
],
)
)
Expand Down
2 changes: 1 addition & 1 deletion pyomo/common/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ def assertExpressionsEqual(self, a, b, include_named_exprs=True, places=None):
def assertExpressionsStructurallyEqual(
self, a, b, include_named_exprs=True, places=None
):
from pyomo.core.expr.compare import assertExpressionsEqual
from pyomo.core.expr.compare import assertExpressionsStructurallyEqual

return assertExpressionsStructurallyEqual(
self, a, b, include_named_exprs, places
Expand Down
12 changes: 6 additions & 6 deletions pyomo/contrib/community_detection/community_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ def generate_model_graph(
]

# Update constraint_variable_map
constraint_variable_map[
numbered_constraint
] = numbered_variables_in_constraint_equation
constraint_variable_map[numbered_constraint] = (
numbered_variables_in_constraint_equation
)

# Create a list of all the edges that need to be created based on the variables in this constraint equation
edges_between_nodes = [
Expand All @@ -145,9 +145,9 @@ def generate_model_graph(
]

# Update constraint_variable_map
constraint_variable_map[
numbered_objective
] = numbered_variables_in_objective
constraint_variable_map[numbered_objective] = (
numbered_variables_in_objective
)

# Create a list of all the edges that need to be created based on the variables in the objective function
edges_between_nodes = [
Expand Down
39 changes: 17 additions & 22 deletions pyomo/contrib/community_detection/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Original implementation developed by Rahul Joglekar in the Grossmann research group.
"""

from logging import getLogger

from pyomo.common.dependencies import attempt_import
Expand Down Expand Up @@ -453,16 +454,14 @@ def visualize_model_graph(
if type_of_graph != self.type_of_community_map:
# Use the generate_model_graph function to create a NetworkX graph of the given model (along with
# number_component_map and constraint_variable_map, which will be used to help with drawing the graph)
(
model_graph,
number_component_map,
constraint_variable_map,
) = generate_model_graph(
self.model,
type_of_graph=type_of_graph,
with_objective=self.with_objective,
weighted_graph=self.weighted_graph,
use_only_active_components=self.use_only_active_components,
(model_graph, number_component_map, constraint_variable_map) = (
generate_model_graph(
self.model,
type_of_graph=type_of_graph,
with_objective=self.with_objective,
weighted_graph=self.weighted_graph,
use_only_active_components=self.use_only_active_components,
)
)
else:
# This is the case where, as mentioned above, we can use the networkX graph that was made to create
Expand Down Expand Up @@ -726,13 +725,10 @@ def generate_structured_model(self):
variable_in_new_model = structured_model.find_component(
new_variable
)
blocked_variable_map[
variable_in_stored_constraint
] = blocked_variable_map.get(
variable_in_stored_constraint, []
) + [
variable_in_new_model
]
blocked_variable_map[variable_in_stored_constraint] = (
blocked_variable_map.get(variable_in_stored_constraint, [])
+ [variable_in_new_model]
)

# Update replace_variables_in_expression_map accordingly
replace_variables_in_expression_map[
Expand Down Expand Up @@ -802,11 +798,10 @@ def generate_structured_model(self):
variable_in_new_model = structured_model.find_component(
new_variable
)
blocked_variable_map[
variable_in_objective
] = blocked_variable_map.get(variable_in_objective, []) + [
variable_in_new_model
]
blocked_variable_map[variable_in_objective] = (
blocked_variable_map.get(variable_in_objective, [])
+ [variable_in_new_model]
)

# Update the dictionary that we will use to replace the variables
replace_variables_in_expression_map[
Expand Down
Loading

0 comments on commit 21f5a77

Please sign in to comment.