From 26d235164840d78215727345cebdbc5a0847a26e Mon Sep 17 00:00:00 2001 From: Dave Woodruff Date: Fri, 16 Dec 2022 13:14:10 -0800 Subject: [PATCH 1/9] adding some code to make it easier to avoid spurious warnings --- mpisppy/confidence_intervals/ciutils.py | 23 +++++++++++++++++++++-- mpisppy/tests/test_conf_int_farmer.py | 11 ++++++++++- mpisppy/utils/sputils.py | 3 +-- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/mpisppy/confidence_intervals/ciutils.py b/mpisppy/confidence_intervals/ciutils.py index fc3ec3ea7..1b9cc0638 100644 --- a/mpisppy/confidence_intervals/ciutils.py +++ b/mpisppy/confidence_intervals/ciutils.py @@ -163,6 +163,25 @@ def read_xhat(path="xhat.npy",num_stages=2,delete_file=False): os.remove(path) return(xhat) +def _fct_check(module, fct): + if not hasattr(module, fct): + raise RuntimeError(f"pyomo_opt_sense needs the module to have the {fct} function") + +def pyomo_opt_sense(module_name, cfg): + """ update cfg to have the optimization sense""" + module = importlib.import_module(module_name) + _fct_check(module, "scenario_names_creator") + sn = module.scenario_names_creator(1) # an arbitrary scenario name + _fct_check(module, "kw_creator") + kw = module.kw_creator(cfg) + m = module.scenario_creator(sn[0], **kw) + objs = sputils.get_objs(m) + if objs[0].is_minimizing: + cfg.quick_assign("pyomo_opt_sense", int, pyo.minimize) + else: + cfg.quick_assign("pyomo_opt_sense", int, pyo.maximize) + + def correcting_numeric(G, cfg, relative_error=True, threshold=1e-4, objfct=None): #Correcting small negative G due to numerical error while solving EF sense = cfg.get("pyo_opt_sense", pyo.minimize) # 1 is minimize, -1 max @@ -173,10 +192,10 @@ def correcting_numeric(G, cfg, relative_error=True, threshold=1e-4, objfct=None) crit = threshold if objfct is None: raise RuntimeError("We need a value of the objective function to remove numerically small G") - elif sense == 1 and G <= -crit: + elif sense == pyo.minimize and G <= -crit: print(f"WARNING: The gap estimator is the wrong sign: {G}") return G - elif sense == -1 and G >= crit: + elif sense == pyo.maximize and G >= crit: print(f"WARNING: The gap estimator is the wrong sign: {G}") return G else: diff --git a/mpisppy/tests/test_conf_int_farmer.py b/mpisppy/tests/test_conf_int_farmer.py index 182e0c1d6..1c171efb6 100644 --- a/mpisppy/tests/test_conf_int_farmer.py +++ b/mpisppy/tests/test_conf_int_farmer.py @@ -12,6 +12,7 @@ import subprocess import importlib +import pyomo.environ as pyo import mpisppy.MPI as mpi from mpisppy.tests.utils import get_solver, round_pos_sig @@ -29,7 +30,7 @@ fullcomm = mpi.COMM_WORLD global_rank = fullcomm.Get_rank() -__version__ = 0.5 +__version__ = 0.6 solver_available, solver_name, persistent_available, persistent_solver_name= get_solver() module_dir = os.path.dirname(os.path.abspath(__file__)) @@ -126,6 +127,14 @@ def test_seqsampling_creator(self): solving_type="EF_2stage", ) + + def test_pyomo_opt_sense(self): + cfg = self._get_base_options() + module = self.refmodelname + ciutils.pyomo_opt_sense(module, cfg) + assert cfg.pyomo_opt_sense == pyo.minimize # minimize is 1 + + @unittest.skipIf(not solver_available, "no solver is available") def test_ama_running(self): diff --git a/mpisppy/utils/sputils.py b/mpisppy/utils/sputils.py index 2486966c2..eb30fab41 100644 --- a/mpisppy/utils/sputils.py +++ b/mpisppy/utils/sputils.py @@ -89,8 +89,7 @@ def get_objs(scenario_instance, allow_none=False): "objective functions.") if (len(scenario_objs) > 1): print("WARNING: Scenario", sname, "has multiple active " - "objectives. Selecting the first objective for " - "inclusion in the extensive form.") + "objectives. Selecting the first objective.") return scenario_objs From 0291e5526bd6dbe3bd88312e8dcbfb7dd18c4512 Mon Sep 17 00:00:00 2001 From: David L Woodruff Date: Wed, 5 Apr 2023 10:30:12 -0700 Subject: [PATCH 2/9] trying to get pyotracker.yml to work --- .github/workflows/pyotracker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pyotracker.yml b/.github/workflows/pyotracker.yml index 51af463f3..caf798154 100644 --- a/.github/workflows/pyotracker.yml +++ b/.github/workflows/pyotracker.yml @@ -17,7 +17,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - pyomo-version: [6.4.2, main] + pyomo-version: [6.5.0, main] steps: - uses: actions/checkout@v3 - uses: conda-incubator/setup-miniconda@v2 From 05ec95b96314e28ec5bcda262c0374a5da09f5b9 Mon Sep 17 00:00:00 2001 From: David L Woodruff Date: Wed, 5 Apr 2023 10:46:32 -0700 Subject: [PATCH 3/9] trying to get straight.yml to work correctly --- .github/workflows/straight.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/straight.yml b/.github/workflows/straight.yml index a0d4d576e..7e095f680 100644 --- a/.github/workflows/straight.yml +++ b/.github/workflows/straight.yml @@ -1,5 +1,7 @@ name: straight (Pyomo released) +# april 2023, dropped pip install: sphinx sphinx_rtd_theme cplex + on: push: branches: [ main ] @@ -26,7 +28,7 @@ jobs: - name: Install dependencies run: | conda install mpi4py pandas setuptools - pip install pyomo pandas sphinx sphinx_rtd_theme cplex + pip install pyomo cplex pip install xpress numpy scipy dill - name: setup the program From dd05388848fed410ca4d8e2c9ba005960b7e70c9 Mon Sep 17 00:00:00 2001 From: David L Woodruff Date: Wed, 5 Apr 2023 10:56:33 -0700 Subject: [PATCH 4/9] still trying to get straight.yml to work --- .github/workflows/straight.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/straight.yml b/.github/workflows/straight.yml index 7e095f680..684b43bb2 100644 --- a/.github/workflows/straight.yml +++ b/.github/workflows/straight.yml @@ -1,6 +1,6 @@ name: straight (Pyomo released) -# april 2023, dropped pip install: sphinx sphinx_rtd_theme cplex +# april 2023: matched the testaph.yml dependencies on: push: @@ -28,8 +28,7 @@ jobs: - name: Install dependencies run: | conda install mpi4py pandas setuptools - pip install pyomo cplex - pip install xpress numpy scipy dill + pip install pyomo xpress cplex - name: setup the program run: | From 865e16f75d8974d192a3ea34674d2398a99ee10c Mon Sep 17 00:00:00 2001 From: David L Woodruff Date: Wed, 5 Apr 2023 11:00:58 -0700 Subject: [PATCH 5/9] splitting up the pip and trying python 3.9 --- .github/workflows/straight.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/straight.yml b/.github/workflows/straight.yml index 684b43bb2..d7b2f149f 100644 --- a/.github/workflows/straight.yml +++ b/.github/workflows/straight.yml @@ -23,12 +23,14 @@ jobs: - uses: mpi4py/setup-mpi@v1 with: activate-environment: test_env - python-version: 3.8 + python-version: 3.9 auto-activate-base: false - name: Install dependencies run: | conda install mpi4py pandas setuptools - pip install pyomo xpress cplex + pip install pyomo + pip install xpress + pip install cplex - name: setup the program run: | From 12834bf3ce44ae37e7a8f017a4fe0e0cadc10890 Mon Sep 17 00:00:00 2001 From: bknueven <30801372+bknueven@users.noreply.github.com> Date: Wed, 5 Apr 2023 16:12:03 -0600 Subject: [PATCH 6/9] try removing conda --- .github/workflows/straight.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/straight.yml b/.github/workflows/straight.yml index d7b2f149f..0c77d5658 100644 --- a/.github/workflows/straight.yml +++ b/.github/workflows/straight.yml @@ -27,10 +27,10 @@ jobs: auto-activate-base: false - name: Install dependencies run: | - conda install mpi4py pandas setuptools pip install pyomo pip install xpress pip install cplex + pip install mpi4py - name: setup the program run: | From 1d58b852e1e0b84021407c2800b2855adf5c7e1a Mon Sep 17 00:00:00 2001 From: Bernard Knueven Date: Wed, 5 Apr 2023 16:20:15 -0600 Subject: [PATCH 7/9] mirror aph --- .github/workflows/straight.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/straight.yml b/.github/workflows/straight.yml index 0c77d5658..44c863085 100644 --- a/.github/workflows/straight.yml +++ b/.github/workflows/straight.yml @@ -20,17 +20,14 @@ jobs: steps: - uses: actions/checkout@v3 - uses: conda-incubator/setup-miniconda@v2 - - uses: mpi4py/setup-mpi@v1 with: activate-environment: test_env - python-version: 3.9 + python-version: 3.8 auto-activate-base: false - name: Install dependencies run: | - pip install pyomo - pip install xpress - pip install cplex - pip install mpi4py + conda install mpi4py pandas setuptools + pip install pyomo xpress cplex - name: setup the program run: | From 963f39e824614d32d960c7ba713c0516badc9df8 Mon Sep 17 00:00:00 2001 From: Bernard Knueven Date: Wed, 5 Apr 2023 16:23:14 -0600 Subject: [PATCH 8/9] add dill back --- .github/workflows/straight.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/straight.yml b/.github/workflows/straight.yml index 44c863085..09811e1bf 100644 --- a/.github/workflows/straight.yml +++ b/.github/workflows/straight.yml @@ -27,7 +27,7 @@ jobs: - name: Install dependencies run: | conda install mpi4py pandas setuptools - pip install pyomo xpress cplex + pip install pyomo xpress cplex dill - name: setup the program run: | From 26076886189c8b5246f84c2fb97aba3c66f64a82 Mon Sep 17 00:00:00 2001 From: bknueven <30801372+bknueven@users.noreply.github.com> Date: Wed, 5 Apr 2023 16:29:21 -0600 Subject: [PATCH 9/9] Keep Pyomo 6.4.2 --- .github/workflows/pyotracker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pyotracker.yml b/.github/workflows/pyotracker.yml index caf798154..51af463f3 100644 --- a/.github/workflows/pyotracker.yml +++ b/.github/workflows/pyotracker.yml @@ -17,7 +17,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - pyomo-version: [6.5.0, main] + pyomo-version: [6.4.2, main] steps: - uses: actions/checkout@v3 - uses: conda-incubator/setup-miniconda@v2