Skip to content

Commit

Permalink
Switch to public Pyomo Data objects (#12)
Browse files Browse the repository at this point in the history
* Address defer_check -> defer_import deprecation

* Switch to non-underscore base class names

* Update pyomo requirement with minimum version

* Add test to verify that no deprecations are emitted

* Temporarily revert to deprecated name to ensure test fails

* Revert "Temporarily revert to deprecated name to ensure test fails"

This reverts commit 4596356.

* ExpressionData -> NamedExpressionData

---------

Co-authored-by: Ludovico Bianchi <[email protected]>
  • Loading branch information
bknueven and lbianchi-lbl authored Jun 14, 2024
1 parent 2bffbb0 commit 4bf6514
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ name = "parameter-sweep"
readme = "README.md"
dynamic = ["version"]
dependencies = [
"pyomo",
"pyomo>=6.7.3", # see watertap-org/parameter-sweep#10
"numpy",
"h5py",
"pyyaml",
Expand Down
4 changes: 2 additions & 2 deletions src/parameter_sweep/parallel/parallel_manager_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
)


MPI, mpi4py_available = attempt_import("mpi4py.MPI", defer_check=False)
ray, ray_avaialble = attempt_import("ray", defer_check=False)
MPI, mpi4py_available = attempt_import("mpi4py.MPI", defer_import=False)
ray, ray_avaialble = attempt_import("ray", defer_import=False)
if ray_avaialble:
from parameter_sweep.parallel.ray_io_parallel_manager import (
RayIoParallelManager,
Expand Down
2 changes: 1 addition & 1 deletion src/parameter_sweep/parallel/ray_io_parallel_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
)
from pyomo.common.dependencies import attempt_import

ray, ray_available = attempt_import("ray", defer_check=False)
ray, ray_available = attempt_import("ray", defer_import=False)
import os
import platform

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

from parameter_sweep.parallel.parallel_manager_factory import create_parallel_manager

ray, ray_available = attempt_import("ray", defer_check=False)
ray, ray_available = attempt_import("ray", defer_import=False)
if ray_available:
from parameter_sweep.parallel.ray_io_parallel_manager import (
RayIoParallelManager,
Expand Down
6 changes: 3 additions & 3 deletions src/parameter_sweep/parameter_sweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from pyomo.common.deprecation import deprecation_warning
from pyomo.common.config import ConfigValue
from pyomo.common.modeling import unique_component_name
from pyomo.core.base import _VarData, _ExpressionData
from pyomo.core.base.param import _ParamData
from pyomo.core.base import VarData, NamedExpressionData
from pyomo.core.base.param import ParamData
from pyomo.common.dependencies import attempt_import

requests, requests_available = attempt_import("requests")
Expand Down Expand Up @@ -304,7 +304,7 @@ def assign_variable_names(model, outputs):
unique_component_name(model, "_parameter_sweep_expressions"), exprs
)
for output_name, _pyo_obj in outputs.items():
if not isinstance(_pyo_obj, (_VarData, _ExpressionData, _ParamData)):
if not isinstance(_pyo_obj, (VarData, NamedExpressionData, ParamData)):
# Add this object as an expression and assign a name
exprs[output_name] = _pyo_obj
outputs[output_name] = exprs[output_name]
Expand Down
30 changes: 30 additions & 0 deletions src/parameter_sweep/tests/test_deprecations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import subprocess
import sys

import pytest


@pytest.mark.parametrize(
"statement",
[
"import parameter_sweep",
],
ids=repr,
)
@pytest.mark.parametrize(
"sentinel",
[
"DEPRECATED",
],
ids=repr,
)
def test_no_deprecation_warnings_emitted(sentinel: str, statement: str):
res = subprocess.run(
[sys.executable, "-c", statement],
text=True,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
)
assert res.returncode == 0
assert not sentinel in res.stdout
assert not sentinel in res.stderr

0 comments on commit 4bf6514

Please sign in to comment.