Skip to content

Commit

Permalink
Deprecating RBF options in ALMAOpy
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewlee94 committed Jul 21, 2023
1 parent a03ea47 commit a111ba2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
17 changes: 13 additions & 4 deletions idaes/core/surrogate/alamopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ class Screener(Enum):
"sinfcns",
"cosfcns",
"constant",
"grbfcns",
"rbfparam",
# "grbfcns", # TODO: deprecated
# "rbfparam", # TODO: deprecated
"modeler",
"builder",
"backstepper",
Expand Down Expand Up @@ -282,15 +282,15 @@ class AlamoTrainer(SurrogateTrainer):
description="Include cosine basis functions if True.",
),
)
CONFIG.declare(
CONFIG.declare( # TODO: deprecated option
"grbfcns",
ConfigValue(
default=None,
domain=Bool,
description="Include Gaussian radial basis functions if True.",
),
)
CONFIG.declare(
CONFIG.declare( # TODO: deprecated option
"rbfparam",
ConfigValue(
default=None,
Expand Down Expand Up @@ -669,6 +669,15 @@ class AlamoTrainer(SurrogateTrainer):
def __init__(self, **settings):
super().__init__(**settings)

# TODO: Deprecation warnings for RBF options
if self.config.grbfcns is not None or self.config.rbfparam is not None:
raise ConfigurationError(
"Support for radial basis functions in the ALAMOpy wrapper have been "
"deprecated due to limitations in the current implementation. "
"Pull requests are welcome to address this, otherwise we recommend using "
"Pysmo which includes support for radial basis functions."
)

self._temp_context = None
self._almfile = None
self._trcfile = None
Expand Down
41 changes: 39 additions & 2 deletions idaes/core/surrogate/tests/test_alamopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,45 @@ def alamo_trainer(self):
training_dataframe=data,
)

@pytest.mark.unit
def test_rbf_deprecation(self):
data = {"x1": [1, 2, 3, 4], "x2": [5, 6, 7, 8], "z1": [10, 20, 30, 40]}
data = pd.DataFrame(data)

input_labels = ["x1", "x2"]
output_labels = ["z1"]
bnds = {"x1": (0, 5), "x2": (0, 10)}

with pytest.raises(
ConfigurationError,
match="Support for radial basis functions in the ALAMOpy wrapper have been "
"deprecated due to limitations in the current implementation. "
"Pull requests are welcome to address this, otherwise we recommend using "
"Pysmo which includes support for radial basis functions.",
):
AlamoTrainer(
input_labels=input_labels,
output_labels=output_labels,
input_bounds=bnds,
training_dataframe=data,
grbfcns=True,
)

with pytest.raises(
ConfigurationError,
match="Support for radial basis functions in the ALAMOpy wrapper have been "
"deprecated due to limitations in the current implementation. "
"Pull requests are welcome to address this, otherwise we recommend using "
"Pysmo which includes support for radial basis functions.",
):
AlamoTrainer(
input_labels=input_labels,
output_labels=output_labels,
input_bounds=bnds,
training_dataframe=data,
rbfparam=1.0,
)

@pytest.mark.unit
def test_get_files(self, alamo_trainer):
alamo_trainer.config.filename = "foo.alm"
Expand Down Expand Up @@ -486,8 +525,6 @@ def test_writer_full_config(self, alamo_trainer):
"sinfcns 1\n"
"cosfcns 0\n"
"constant 1\n"
"grbfcns 1\n"
"rbfparam 7.0\n"
"modeler 3\n"
"builder 1\n"
"backstepper 0\n"
Expand Down

0 comments on commit a111ba2

Please sign in to comment.