Skip to content

Commit c911214

Browse files
authored
Merge pull request #576 from DLWoodruff/looseAMPL
Example of loose use of ampl
2 parents 888f458 + f6ee4a5 commit c911214

File tree

16 files changed

+1634
-78
lines changed

16 files changed

+1634
-78
lines changed

.github/workflows/test_pr_and_main.yml

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ concurrency:
1313
cancel-in-progress: true
1414

1515
defaults:
16-
run:
17-
shell: bash -l {0}
16+
run:
17+
shell: bash -l {0}
1818

1919
jobs:
2020
ruff:
@@ -33,7 +33,7 @@ jobs:
3333
- uses: conda-incubator/setup-miniconda@v2
3434
with:
3535
activate-environment: test_env
36-
python-version: 3.9
36+
python-version: 3.11
3737
auto-activate-base: false
3838
- name: Install dependencies
3939
run: |
@@ -49,12 +49,10 @@ jobs:
4949
cd mpisppy/tests
5050
python test_ef_ph.py
5151
52-
5352
regression:
5453
name: Basic regression tests
5554
runs-on: ubuntu-latest
5655
needs: [ruff]
57-
5856
steps:
5957
- uses: actions/checkout@v3
6058
- uses: conda-incubator/setup-miniconda@v2
@@ -98,11 +96,8 @@ jobs:
9896
runall_persistent:
9997
name: run_all.py persistent solver
10098
runs-on: ubuntu-latest
99+
needs: [ruff]
101100
timeout-minutes: 15
102-
# this takes the most time, so we'll start it
103-
# without waiting on the linting and other checks
104-
# needs: [ruff]
105-
106101
steps:
107102
- uses: actions/checkout@v3
108103
- uses: conda-incubator/setup-miniconda@v2
@@ -134,10 +129,6 @@ jobs:
134129
name: run_all.py direct solver
135130
runs-on: ubuntu-latest
136131
timeout-minutes: 15
137-
# this takes the most time, so we'll start it
138-
# without waiting on the linting and other checks
139-
# needs: [ruff]
140-
141132
steps:
142133
- uses: actions/checkout@v3
143134
- uses: conda-incubator/setup-miniconda@v2
@@ -168,51 +159,63 @@ jobs:
168159
schur-complement:
169160
name: schur-complement
170161
runs-on: ubuntu-latest
171-
needs: [ruff]
172162
strategy:
173163
matrix:
174-
python-version: [3.9]
164+
python-version: [3.11]
175165
steps:
176-
- uses: actions/checkout@v3
177-
- name: setup conda
178-
uses: conda-incubator/setup-miniconda@v2
179-
with:
180-
python-version: ${{ matrix.python-version }}
181-
channels: anaconda, conda-forge
182-
activate-environment: test_env
183-
auto-activate-base: false
184-
- name: Install dependencies
185-
run: |
186-
python -m pip install --upgrade pip
187-
pip install nose pybind11
188-
conda install conda-forge::libstdcxx-ng
189-
conda install openmpi pymumps --no-update-deps
190-
pip install mpi4py pandas
191-
pip install git+https://github.com/pyutilib/pyutilib.git
192-
git clone https://github.com/pyomo/pyomo.git
193-
cd pyomo/
194-
pip install -e .
195-
pyomo download-extensions
196-
pyomo build-extensions
197-
cd ../
198-
pip install git+https://github.com/parapint/parapint.git
199-
pip install -e .
200-
- name: Test with nose
201-
run: |
202-
nosetests -v mpisppy/tests/test_sc.py
203-
mpirun -np 3 -oversubscribe nosetests mpisppy/tests/test_sc.py
166+
- uses: actions/checkout@v3
167+
168+
- name: setup conda
169+
uses: conda-incubator/setup-miniconda@v2
170+
with:
171+
python-version: ${{ matrix.python-version }}
172+
channels: anaconda, conda-forge
173+
activate-environment: test_env
174+
auto-activate-base: false
175+
176+
- name: Install dependencies
177+
shell: bash -l {0}
178+
run: |
179+
python -m pip install --upgrade pip
180+
# Test tooling
181+
pip install pytest pytest-cov
182+
# Core build/test deps
183+
pip install pybind11
184+
conda install -y conda-forge::libstdcxx-ng
185+
conda install -y openmpi pymumps --no-update-deps
186+
pip install mpi4py pandas
187+
# pyutilib / pyomo / parapint
188+
pip install git+https://github.com/pyutilib/pyutilib.git
189+
git clone https://github.com/pyomo/pyomo.git
190+
cd pyomo/
191+
pip install -e .
192+
pyomo download-extensions
193+
pyomo build-extensions
194+
cd ../
195+
pip install git+https://github.com/parapint/parapint.git
196+
# Install this repo (editable)
197+
pip install -e .
198+
199+
- name: Test with pytest (serial)
200+
shell: bash -l {0}
201+
run: |
202+
pytest -q -vv mpisppy/tests/test_sc.py
203+
204+
- name: Test with pytest under MPI
205+
shell: bash -l {0}
206+
run: |
207+
mpirun -np 3 -oversubscribe python -m pytest -q -vv mpisppy/tests/test_sc.py
204208
205209
straight-tests:
206210
name: straight_tests.py
207211
runs-on: ubuntu-latest
208212
needs: [ruff]
209-
210213
steps:
211214
- uses: actions/checkout@v3
212215
- uses: conda-incubator/setup-miniconda@v2
213216
with:
214217
activate-environment: test_env
215-
python-version: 3.9
218+
python-version: 3.11
216219
auto-activate-base: false
217220
- name: Install dependencies
218221
run: |
@@ -232,13 +235,12 @@ jobs:
232235
name: admm wrapper tests
233236
runs-on: ubuntu-latest
234237
needs: [ruff]
235-
236238
steps:
237239
- uses: actions/checkout@v3
238240
- uses: conda-incubator/setup-miniconda@v2
239241
with:
240242
activate-environment: test_env
241-
python-version: 3.9
243+
python-version: 3.11
242244
auto-activate-base: false
243245
- name: Install dependencies
244246
run: |
@@ -262,13 +264,12 @@ jobs:
262264
name: aph tests
263265
runs-on: ubuntu-latest
264266
needs: [ruff]
265-
266267
steps:
267268
- uses: actions/checkout@v3
268269
- uses: conda-incubator/setup-miniconda@v2
269270
with:
270271
activate-environment: test_env
271-
python-version: 3.9
272+
python-version: 3.11
272273
auto-activate-base: false
273274
- name: Install dependencies
274275
run: |
@@ -290,13 +291,12 @@ jobs:
290291
name: pickled bundles tests
291292
runs-on: ubuntu-latest
292293
needs: [ruff]
293-
294294
steps:
295295
- uses: actions/checkout@v3
296296
- uses: conda-incubator/setup-miniconda@v2
297297
with:
298298
activate-environment: test_env
299-
python-version: 3.9
299+
python-version: 3.11
300300
auto-activate-base: false
301301
- name: Install dependencies
302302
run: |
@@ -313,12 +313,10 @@ jobs:
313313
cd mpisppy/tests
314314
python test_pickle_bundle.py
315315
316-
317316
mps:
318317
name: MPS tests
319318
runs-on: ubuntu-latest
320319
needs: [ruff]
321-
322320
steps:
323321
- uses: actions/checkout@v3
324322
- uses: conda-incubator/setup-miniconda@v2
@@ -341,18 +339,16 @@ jobs:
341339
cd mpisppy/tests
342340
python test_mps.py
343341
344-
345342
confidence-intervals:
346343
name: confidence intervals tests
347344
runs-on: ubuntu-latest
348345
needs: [ruff]
349-
350346
steps:
351347
- uses: actions/checkout@v3
352348
- uses: conda-incubator/setup-miniconda@v2
353349
with:
354350
activate-environment: test_env
355-
python-version: 3.9
351+
python-version: 3.11
356352
auto-activate-base: false
357353
- name: Install dependencies
358354
run: |
@@ -380,7 +376,6 @@ jobs:
380376
runs-on: ubuntu-latest
381377
needs: [ruff]
382378
timeout-minutes: 15
383-
384379
steps:
385380
- uses: actions/checkout@v3
386381
- uses: conda-incubator/setup-miniconda@v2
@@ -411,7 +406,6 @@ jobs:
411406
name: gradient and rho tests
412407
runs-on: ubuntu-latest
413408
needs: [ruff]
414-
415409
steps:
416410
- uses: actions/checkout@v3
417411
- uses: conda-incubator/setup-miniconda@v3
@@ -439,13 +433,12 @@ jobs:
439433
test-headers:
440434
name: header test
441435
runs-on: ubuntu-latest
442-
443436
steps:
444437
- uses: actions/checkout@v3
445438
- uses: conda-incubator/setup-miniconda@v2
446439
with:
447440
activate-environment: test_env
448-
python-version: 3.9
441+
python-version: 3.11
449442
auto-activate-base: false
450443
- name: Install dependencies
451444
run: |
@@ -466,13 +459,12 @@ jobs:
466459
name: pysp tests
467460
runs-on: ubuntu-latest
468461
needs: [ruff]
469-
470462
steps:
471463
- uses: actions/checkout@v3
472464
- uses: conda-incubator/setup-miniconda@v2
473465
with:
474466
activate-environment: test_env
475-
python-version: 3.9
467+
python-version: 3.11
476468
auto-activate-base: false
477469
- name: Install dependencies
478470
run: |
@@ -500,13 +492,12 @@ jobs:
500492
name: tests on some cylinders
501493
runs-on: ubuntu-latest
502494
needs: [ruff]
503-
504495
steps:
505496
- uses: actions/checkout@v3
506497
- uses: conda-incubator/setup-miniconda@v2
507498
with:
508499
activate-environment: test_env
509-
python-version: 3.9
500+
python-version: 3.11
510501
auto-activate-base: false
511502
- name: Install dependencies
512503
run: |
@@ -527,7 +518,6 @@ jobs:
527518
name: tests on agnostic
528519
runs-on: ubuntu-latest
529520
needs: [ruff]
530-
531521
steps:
532522
- uses: actions/checkout@v3
533523
- uses: conda-incubator/setup-miniconda@v2
@@ -543,6 +533,7 @@ jobs:
543533
python -m pip install amplpy --upgrade
544534
python -m amplpy.modules install highs cbc gurobi
545535
python -m pip install gamspy
536+
python -m pip install mip
546537
# license?
547538
548539
- name: setup the program
@@ -560,3 +551,12 @@ jobs:
560551
run: |
561552
cd mpisppy/agnostic/examples
562553
python afew_agnostic.py
554+
555+
- name: run loose AMPL
556+
timeout-minutes: 10
557+
run: |
558+
cd examples/loose_agnostic/AMPL
559+
bash farmer_example.bash
560+
# GAMS is not tested because I don't want to deal with the license
561+
#cd ../GAMS
562+
#bash farmer_example.bash

doc/src/agnostic.rst

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,38 @@ Code for creating a
1616
Pyomo model from an mps file is in ``mpisppy.utils.mps_reader.py``,
1717
but you can also just use ``generic_cylinders.py`` and give
1818
it the module ``mpisppy.utils.mps_module`` (you will need to specify
19-
that path to this module) and the ``--mps-files-directory``
19+
the path to this module) and the ``--mps-files-directory``
2020
option. Note
2121
that at the time of this writing, the number of scenarios is obtained
2222
by counting the mps files in the directory given.
2323

24-
The file ``examples.sizes.mps_demo.bash`` has two commands. The second illustrates
25-
how to instruction ``MPI-SPPY`` to read mps/json file pairs for each scenario from a
26-
directory. The first command illustrates how to use ``MPI-SPPY`` to write
27-
them in the first place (but if ``MPI-SPPY`` can get your scenarios, there
28-
is probably no reason to write them and then read them again!). This
29-
functionality is intended to be used by users of other AMLs or other
30-
scenario-based stochastic programming applications.
24+
The file ``examples.loose_agnostic.AMPL.farmer_example.bash`` has three
25+
commands. The second illustrates how to instruct ``MPI-SPPY`` to read
26+
mps/json file pairs for each scenario from a directory. The first runs
27+
an `AMPLpy` program that creates the scenario files. This program is
28+
in ``examples.loose_agnostic.AMPL.farmer_writer.py`` and, apart from
29+
the `scenario_creator` function, is pretty general for two-stage
30+
problems. You be able to copy the program and
31+
write a `scenario_creator` function for your two-stage problem.
32+
The third command runs a script that illustrates how to map column
33+
names created by the MPS writer back to AMPL variable names.
34+
35+
The file ``examples.loose_agnostic.GAMS.farmer_example.bash`` has
36+
three commands that mimic the commands for AMPL. The GAMS bash script
37+
is not part of the automated tests because I don't want to deal with
38+
the license.
39+
40+
A somewhat strange example is in the file
41+
``examples.sizes.mps_demo.bash`` has two commands. The second
42+
illustrates how to instruct ``MPI-SPPY`` to read mps/json file pairs
43+
for each scenario from a directory. The first command illustrates how
44+
to use ``MPI-SPPY`` to write them in the first place (but if
45+
``MPI-SPPY`` can get your scenarios, there is probably no reason to
46+
write them and then read them again!). This functionality is intended
47+
to be used by users of other AMLs or other scenario-based stochastic
48+
programming applications.
49+
50+
There is low-level support for `.lp` files instead of `.mps` files.
3151

3252
JSON file format
3353
----------------

0 commit comments

Comments
 (0)