Skip to content

Commit

Permalink
fix import error
Browse files Browse the repository at this point in the history
  • Loading branch information
ZedongPeng committed Sep 21, 2023
1 parent ff401df commit d82dcde
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
7 changes: 3 additions & 4 deletions pyomo/contrib/mindtpy/algorithm_base_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
SolutionStatus,
SolverStatus,
)
from pyomo.contrib.pynumero.interfaces.external_grey_box import ExternalGreyBoxBlock
from pyomo.core import (
minimize,
maximize,
Expand Down Expand Up @@ -85,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]

class _MindtPyAlgorithm(object):
def __init__(self, **kwds):
Expand Down Expand Up @@ -326,7 +325,7 @@ def build_ordered_component_lists(self, model):
)
util_block.grey_box_list = list(
model.component_data_objects(
ctype=ExternalGreyBoxBlock, active=True, descend_into=(Block)
ctype=egb.ExternalGreyBoxBlock, active=True, descend_into=(Block)
)
)
util_block.linear_constraint_list = list(
Expand Down Expand Up @@ -359,7 +358,7 @@ def build_ordered_component_lists(self, model):
util_block.variable_list = list(
v
for v in model.component_data_objects(
ctype=Var, descend_into=(Block, ExternalGreyBoxBlock)
ctype=Var, descend_into=(Block, egb.ExternalGreyBoxBlock)
)
if v in var_set
)
Expand Down
5 changes: 3 additions & 2 deletions pyomo/contrib/mindtpy/tests/MINLP_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@
)
from pyomo.common.collections import ComponentMap
from pyomo.contrib.mindtpy.tests.MINLP_simple_grey_box import GreyBoxModel
from pyomo.contrib.pynumero.interfaces.external_grey_box import ExternalGreyBoxBlock
from pyomo.common.dependencies import attempt_import
egb = attempt_import('pyomo.contrib.pynumero.interfaces.external_grey_box')[0]


def build_model_external(m):
ex_model = GreyBoxModel(initial={"X1": 0, "X2": 0, "Y1": 0, "Y2": 1, "Y3": 1})
m.egb = ExternalGreyBoxBlock()
m.egb = egb.ExternalGreyBoxBlock()
m.egb.set_external_model(ex_model)


Expand Down
6 changes: 3 additions & 3 deletions pyomo/contrib/mindtpy/tests/MINLP_simple_grey_box.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from pyomo.common.dependencies import numpy as np
import pyomo.common.dependencies.scipy.sparse as scipy_sparse
from pyomo.contrib.pynumero.interfaces.external_grey_box import ExternalGreyBoxModel
from pyomo.contrib.pynumero.interfaces.external_grey_box import ExternalGreyBoxBlock
from pyomo.common.dependencies import attempt_import
egb = attempt_import('pyomo.contrib.pynumero.interfaces.external_grey_box')[0]


class GreyBoxModel(ExternalGreyBoxModel):
class GreyBoxModel(egb.ExternalGreyBoxModel):
"""Greybox model to compute the example OF."""

def __init__(self, initial, use_exact_derivatives=True, verbose=True):
Expand Down

0 comments on commit d82dcde

Please sign in to comment.