Skip to content

Commit

Permalink
fix import bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ZedongPeng committed Nov 1, 2023
1 parent 8eacf0b commit bd12664
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions pyomo/contrib/mindtpy/algorithm_base_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@

single_tree, single_tree_available = attempt_import('pyomo.contrib.mindtpy.single_tree')
tabu_list, tabu_list_available = attempt_import('pyomo.contrib.mindtpy.tabu_list')
egb = attempt_import('pyomo.contrib.pynumero.interfaces.external_grey_box')[0]
egb, egb_available = attempt_import('pyomo.contrib.pynumero.interfaces.external_grey_box')


class _MindtPyAlgorithm(object):
Expand Down Expand Up @@ -324,11 +324,12 @@ def build_ordered_component_lists(self, model):
ctype=Constraint, active=True, descend_into=(Block)
)
)
util_block.grey_box_list = list(
model.component_data_objects(
ctype=egb.ExternalGreyBoxBlock, active=True, descend_into=(Block)
if egb_available:
util_block.grey_box_list = list(
model.component_data_objects(
ctype=egb.ExternalGreyBoxBlock, active=True, descend_into=(Block)
)
)
)
util_block.linear_constraint_list = list(
c
for c in util_block.constraint_list
Expand Down Expand Up @@ -356,13 +357,22 @@ def build_ordered_component_lists(self, model):

# We use component_data_objects rather than list(var_set) in order to
# preserve a deterministic ordering.
util_block.variable_list = list(
v
for v in model.component_data_objects(
ctype=Var, descend_into=(Block, egb.ExternalGreyBoxBlock)
if egb_available:
util_block.variable_list = list(
v
for v in model.component_data_objects(
ctype=Var, descend_into=(Block, egb.ExternalGreyBoxBlock)
)
if v in var_set
)
else:
util_block.variable_list = list(
v
for v in model.component_data_objects(
ctype=Var, descend_into=(Block)
)
if v in var_set
)
if v in var_set
)
util_block.discrete_variable_list = list(
v for v in util_block.variable_list if v in var_set and v.is_integer()
)
Expand Down

0 comments on commit bd12664

Please sign in to comment.