Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Agnostic #402

Draft
wants to merge 173 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
173 commits
Select commit Hold shift + click to select a range
f943763
add some notes about agnostic
DLWoodruff Dec 19, 2022
7ac63b3
minor edits to txt file
DLWoodruff Jan 7, 2023
62ff84e
Merge branch 'main' into agnostic
DLWoodruff Aug 23, 2023
191027d
just getting started; more questions than answers
DLWoodruff Aug 24, 2023
6ef0c0b
[WIP] scenario creator for agnostic object is roughed in but totally …
DLWoodruff Aug 25, 2023
43fe36c
starting to make agnostic work
DLWoodruff Aug 25, 2023
537e3ba
scenario creation executes
DLWoodruff Aug 25, 2023
4423e00
starting to modify phbase for agnostic
DLWoodruff Aug 26, 2023
ea5f306
a bash script to be deleted later
DLWoodruff Aug 26, 2023
3fcf43d
WIP; early work on ph callback; starting attach to obj
DLWoodruff Aug 26, 2023
159d6e3
WIP; still working on attach_PH_to_objective (need xbars)
DLWoodruff Aug 26, 2023
1dd7c46
ready to start work on solve_one
DLWoodruff Aug 27, 2023
bfca106
starting on solve_one
DLWoodruff Aug 27, 2023
1d4b156
solve_one executes; need to debug _reenable_W
DLWoodruff Aug 27, 2023
440156b
PH is executing; need to write a solution and start working on spokes
DLWoodruff Aug 27, 2023
8c0e510
move the example to the examples dir
DLWoodruff Aug 27, 2023
06754dc
ready to try xhatter
DLWoodruff Aug 27, 2023
c24c3be
xhatshuffle seems to be working
DLWoodruff Aug 27, 2023
6492b8f
WIP: debugging W's in lagrangian
DLWoodruff Aug 27, 2023
23e41c1
debugging output
DLWoodruff Aug 28, 2023
64efddb
the ampl version of farmer (stochastic)
DLWoodruff Aug 28, 2023
1ebdba4
single scenario farmer works
DLWoodruff Aug 29, 2023
3b88743
examples of amplpy from AMPL
DLWoodruff Aug 30, 2023
26bd8bf
lshaped did not yet have the uniform probabiity option
DLWoodruff Aug 30, 2023
370fba9
draft of ampl create scenario written
DLWoodruff Aug 30, 2023
c94cccc
[WIP] almost done with draft of AMPL agnostic; one copy function left
DLWoodruff Aug 30, 2023
2ae66d7
w_ and prox_ disabled do not need a callout
DLWoodruff Aug 31, 2023
c4ea3c4
farmer_ampl_agnostic.py is sort of done, but totally untested
DLWoodruff Aug 31, 2023
c1d8c7e
[WIP] working on solving
DLWoodruff Aug 31, 2023
a7ec164
solve executes; now we need actual scenarios
DLWoodruff Sep 1, 2023
0f2f17e
The ampl guest module seems to be working
DLWoodruff Sep 2, 2023
e715e1a
reoranize files
DLWoodruff Sep 4, 2023
fb7f4c3
try to create a simple test
DLWoodruff Sep 4, 2023
76d41ad
have the ampl farmer in the test dir for now; a few months from now, …
DLWoodruff Sep 4, 2023
a076f12
decent tests added; the ampl example does not yet copy W values corre…
DLWoodruff Sep 4, 2023
b612e45
attach a better obj; but still doesn't seem to work right
DLWoodruff Sep 5, 2023
8878ab8
correct errors in objective function for PH
DLWoodruff Sep 5, 2023
e396e0a
drop a debugging print statement
DLWoodruff Sep 5, 2023
5efca81
not cool, but we have farmer.mod in two places
DLWoodruff Sep 7, 2023
1bf1e0b
ampl is almost working with PH, but is returning the wrong the object…
DLWoodruff Sep 7, 2023
d408982
giving up on getting data processing related to objs in the hub to ma…
DLWoodruff Sep 7, 2023
0450a6f
during merge from main, deal with bundling and persistent solvers; co…
DLWoodruff Sep 11, 2023
3b3472c
merge from main
DLWoodruff Nov 16, 2023
5cbd94e
finish merge
DLWoodruff Nov 16, 2023
acf8119
single scenario farmer for GAMS
DLWoodruff Nov 16, 2023
cd5f701
adding basic GAMS example
bknueven Nov 16, 2023
2424686
no gamspy
bknueven Nov 16, 2023
d7f9aea
some installation instructions for AMPL
DLWoodruff Nov 16, 2023
68620aa
update asl instructions
DLWoodruff Nov 16, 2023
a9bad1c
with padding
bknueven Nov 16, 2023
250850a
better GAMS installation instructions
bknueven Nov 16, 2023
211a866
adding seemingly working modifications
bknueven Nov 17, 2023
51af113
modifying records
bknueven Nov 17, 2023
ca40b86
really working
bknueven Nov 17, 2023
4b31cc7
quasi-working gams
bknueven Nov 17, 2023
741b674
adding farmer_gams_agnostic
bknueven Nov 17, 2023
7b068cd
now giving a rho a value in ampl and gams guests
DLWoodruff Nov 27, 2023
82a2a4b
[WIP] working on copying xbars and rho (ampl and gams are just pasted…
DLWoodruff Nov 27, 2023
aa03985
Merge branch 'main' into agnostic
DLWoodruff Nov 29, 2023
96f6a4f
[WIP] adding rho and xbar to the things that need to come from the ho…
DLWoodruff Nov 29, 2023
a591c3d
[WIP] Pyomo as a guest seems to be getting xbar, W, and rho; AMPL exe…
DLWoodruff Dec 12, 2023
bccc513
[WIP] AMPL does not match Pyomo at iter 2 (after iter 1)
DLWoodruff Dec 13, 2023
2cf5a66
GAMS now tries to copy W xbar and rho before solve; gams executes, bu…
DLWoodruff Dec 14, 2023
d64336e
GAMS is at a roadblock: non-determinstic trouble loading the solution…
DLWoodruff Dec 16, 2023
f51678f
AMPL now matches Pyomo
DLWoodruff Dec 16, 2023
1baa4d5
Linearized prox term for gams farmer
DLWoodruff Dec 28, 2023
032ed2c
at least the iter zero solves do not fail!
DLWoodruff Dec 28, 2023
aceac81
cleanup and comments for ampl
DLWoodruff Dec 28, 2023
0f3a777
The last commit message was misleading: some levels are somehow bad e…
DLWoodruff Dec 29, 2023
de715b4
added sync_db to debug code; ready to make it work for mpisppy
DLWoodruff Dec 29, 2023
fcd6e28
Now iter 0 really works, but iter 1 solves fail (with linearized prox…
DLWoodruff Dec 30, 2023
879d885
farmer_linear_augmented.py and farmer_line_augmented.gms show the bad…
DLWoodruff Dec 31, 2023
4230b31
gams linear is working with PH; bounds are not working yet; not sure …
DLWoodruff Dec 31, 2023
1c04d6b
gams linearized seems to work for hub and one other cylinder, but not…
DLWoodruff Dec 31, 2023
bdc863c
update notes
DLWoodruff Jan 3, 2024
bbb4b85
add serial PH example
bknueven Mar 29, 2024
3cfcda9
barely starting work on general agnostic with pyomo as guest
DLWoodruff Apr 26, 2024
7e071be
[WIP] working on pyomo.py for agnostic
DLWoodruff Apr 26, 2024
aa6fd8a
[WIP] done with my first pass at the general Pyomo; ready to develop …
DLWoodruff Apr 29, 2024
de71dec
[WIP] working on agnostic general cylinders; --help executes
DLWoodruff May 1, 2024
37d253b
move agnostic.py from utils to agnostic
DLWoodruff May 1, 2024
8bf335b
[WIP] about to support a class instead of a module in agnostic.py
DLWoodruff May 1, 2024
7d09b5a
update example
DLWoodruff May 1, 2024
179a844
[WIP] able to execute object creation
DLWoodruff May 1, 2024
75706e6
ready to test pyomo as guest
DLWoodruff Jun 5, 2024
8a34323
agnostic for general pyomo as guest seems to execute
DLWoodruff Jun 5, 2024
4678ebc
Just getting started with generic AMPL
DLWoodruff Jun 6, 2024
dde7e96
a rough version of generic ampl needs a lot of work to make it go
DLWoodruff Jun 6, 2024
3c7d974
ampl is starting to run, but still needs work
DLWoodruff Jun 7, 2024
601ab69
Just started working on callbacks for generic AMPL
DLWoodruff Jun 7, 2024
bfad1dc
ready to work on attach PH
DLWoodruff Jun 8, 2024
9747e0c
generic, agnostic farmer is starting to run, but solve_one still need…
DLWoodruff Jun 10, 2024
a161c7a
generic, agnostic ampl seems to be working at least for a hub; have n…
DLWoodruff Jun 10, 2024
ae2c4fb
set go.bash to run pyomo for now
DLWoodruff Jun 10, 2024
e217d37
add a little agnostic doc
DLWoodruff Jun 10, 2024
e656377
deal with merge conflicts
DLWoodruff Jun 10, 2024
fce36a9
trying to use a new pyotracker badge
DLWoodruff Jun 12, 2024
d58990b
Merge pull request #1 from DLWoodruff/badgerepair
DLWoodruff Jun 12, 2024
731c280
a little more agnostic doc; fix bug in ampl guest
DLWoodruff Jun 14, 2024
54310d2
typos
AymericPCLegros Jun 14, 2024
0a69744
WIP, doesn't work yet, trying to geeralize step by step the farmer ex…
AymericPCLegros Jun 25, 2024
460ce38
WIP easier to test things, but name not adapted
AymericPCLegros Jun 25, 2024
a6b3c12
Merge branch 'Pyomo:main' into main
DLWoodruff Jun 29, 2024
4567d99
we don't need or want the callouts in the thin wrapper
DLWoodruff Jul 10, 2024
5f90ae1
remove 'area' paste error; give an error with empty nonants list
DLWoodruff Jul 11, 2024
66d4244
Merge commit 'refs/pull/402/head' of https://github.com/Pyomo/mpi-spp…
AymericPCLegros Jul 11, 2024
3e46869
[WIP] GAMS does not work, but the doc is modified
AymericPCLegros Jul 12, 2024
ca54a68
completing the doc
AymericPCLegros Jul 12, 2024
a5e6d6d
Merge branch 'agnostic' into agnostic_local
AymericPCLegros Jul 12, 2024
154ff09
Merge pull request #2 from AymericPCLegros/agnostic_local
DLWoodruff Jul 12, 2024
0f5135e
created a bundle example for farmer called by go.bash
DLWoodruff Jul 15, 2024
405a329
[WIP] bundles not yet working due, presumably, to objective function …
DLWoodruff Jul 15, 2024
30a4b40
[WIP] making progress, but still need to get the names right
DLWoodruff Jul 15, 2024
ae539d4
[WIP] things seem to be working apart from the xhatter
DLWoodruff Jul 15, 2024
602a24c
The generic Pyomo farmer example seems to be working with proper bundles
DLWoodruff Jul 15, 2024
1512aec
edit the archicture png directly
DLWoodruff Jul 15, 2024
92e981b
fix warning message
DLWoodruff Jul 15, 2024
3cfd82b
trying to add the quadratic progamming nothing works yet
AymericPCLegros Jul 16, 2024
5769ad1
adding the powerpoint to modify the image
AymericPCLegros Jul 16, 2024
25d0793
Merge pull request #4 from AymericPCLegros/agnostic_local
DLWoodruff Jul 16, 2024
b23617f
cleaning the file, gams for specific linearized farmer seem to work
AymericPCLegros Jul 16, 2024
b9ac52c
implemented farmer problem in gurobipy
keeks05 Jul 16, 2024
2701329
added scenario creator
keeks05 Jul 16, 2024
2031248
implemented solve_one for gurobipy
keeks05 Jul 17, 2024
8874867
[WIP] The Best Bound print is not correct
AymericPCLegros Jul 19, 2024
a08c87b
[WIP] restauring the good values of prox_on...
AymericPCLegros Jul 22, 2024
6751cd9
adding print statements
AymericPCLegros Jul 22, 2024
f45a077
the incumbent is not absurd anymore, but does not get better
AymericPCLegros Jul 23, 2024
c1de5c6
gams farmer seems to work!
AymericPCLegros Jul 24, 2024
ee87cdf
deleting prints
AymericPCLegros Jul 24, 2024
a2c5cb9
Merge branch 'main' into agnostic
DLWoodruff Jul 25, 2024
406ebfd
Merge branch 'main' into agnostic
DLWoodruff Jul 25, 2024
9cc57c6
pip install -e . for testagnsotic.yml
DLWoodruff Jul 26, 2024
d3151ba
update test for agnostic.py now in agnostic, not utils
DLWoodruff Jul 26, 2024
6e7b251
starting generalizing gams for other problems than farmer
AymericPCLegros Jul 26, 2024
dc679ba
specifying which parts are generic in scenario creator
AymericPCLegros Jul 29, 2024
761ead1
starting the generic gams file, should be changed
AymericPCLegros Jul 29, 2024
3670298
[WIP] the cylinders need to be modified
AymericPCLegros Jul 30, 2024
7f3fb23
[WIP] problem with the kwargs in generic gams
AymericPCLegros Jul 31, 2024
ed5360e
Agnostic generic GAMS seems to be working, at least with farmer
AymericPCLegros Jul 31, 2024
9686a62
starting to implement the transport example
AymericPCLegros Aug 2, 2024
8512713
trying to adapt for sets defined as cartesian products
AymericPCLegros Aug 5, 2024
c66868d
The files in the agnostic directory execute. Yet, the lagrangian does…
AymericPCLegros Aug 9, 2024
d33f1f1
merge conflicts
AymericPCLegros Aug 9, 2024
b4a65de
Merge pull request #6 from AymericPCLegros/agnostic_gams
DLWoodruff Aug 9, 2024
45c467f
images for agnostic architecture
AymericPCLegros Aug 9, 2024
0fde762
Merge pull request #7 from AymericPCLegros/agnostic_gams
DLWoodruff Aug 9, 2024
abf3ffc
Merge branch 'main' into agnostic
DLWoodruff Aug 9, 2024
567fc8f
Merge branch 'main' of https://github.com/DLWoodruff/mpi-sppy-1
DLWoodruff Aug 12, 2024
51782e9
Merge branch 'main' into agnostic
DLWoodruff Aug 12, 2024
a01c2d6
up to date agnostic figure
DLWoodruff Aug 12, 2024
4431309
minor improvements to agnostic picture
DLWoodruff Aug 12, 2024
1401c09
Update agnostic_cylinders.py
DLWoodruff Aug 13, 2024
7dfc81a
Update agnostic_cylinders.py
DLWoodruff Aug 13, 2024
2f6d1df
fix error where the wrong obj was being used
DLWoodruff Aug 15, 2024
f9287a1
fix the objective function bug in the ampl_guest
DLWoodruff Aug 15, 2024
744fe5f
solution output file names now given as a string on command line
DLWoodruff Aug 15, 2024
f339c4c
try to add mpigap (untested)
DLWoodruff Aug 15, 2024
e2aff6c
implement farmer agnostic for gurobipy
keeks05 Aug 20, 2024
8c1a457
delete old gurobipy files
keeks05 Aug 21, 2024
dc9de39
pasted in contents of farmer.py
keeks05 Aug 29, 2024
c7b619f
fix coefficient bug
keeks05 Aug 30, 2024
df43f4b
Update farmer_gurobipy_agnostic.py
DLWoodruff Sep 4, 2024
bd25b6e
Merge branch 'main' of https://github.com/DLWoodruff/mpi-sppy-1
DLWoodruff Sep 12, 2024
f070a86
Merge branch 'main' of https://github.com/DLWoodruff/mpi-sppy-1
DLWoodruff Sep 17, 2024
1e2f26a
Merge remote-tracking branch 'david-fork/agnostic' into pr-402
keeks05 Sep 17, 2024
4bcba82
Merge branch 'main' of https://github.com/DLWoodruff/mpi-sppy-1
DLWoodruff Sep 18, 2024
4a9784a
merge conflicts
DLWoodruff Sep 18, 2024
7441080
Merge branch 'Pyomo:main' into agnostic
DLWoodruff Sep 24, 2024
b211318
add unit test for gurobipy
keeks05 Sep 24, 2024
d5d6afd
Merge pull request #8 from keeks05/pr-402
DLWoodruff Sep 27, 2024
c6d7f05
Merge branch 'main' of https://github.com/DLWoodruff/mpi-sppy-1
DLWoodruff Sep 27, 2024
b10b63d
Merge branch 'main' into agnostic
DLWoodruff Sep 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/testagnostic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# agnostic (pyomo released)

name: agnostic tests

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

defaults:
run:
shell: bash -l {0}

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: test_env
python-version: 3.9
auto-activate-base: false
- name: Install dependencies
run: |
conda install mpi4py pandas setuptools
pip install pyomo xpress
pip install numpy
python -m pip install amplpy --upgrade
python -m amplpy.modules install highs cbc gurobi
# license?

- name: setup the program
run: |
pip install -e .

- name: run tests
timeout-minutes: 100
run: |
cd mpisppy/tests
python test_agnostic.py
138 changes: 138 additions & 0 deletions agnostic.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
newest notes on top
----------------------------------------

host means mpisppy
guest means whatever the guest language is (which can even be Pyomo, of course)


Jan 3 2024: We are going to require that the guest takes care of
bundling and presents the host with "proper" bundles
that look to the host like regular scenarios.
We have AMPL and Pyomo working as guests and GAMS seems to work OK,
except that there are file contention issues that can probably be solved
easily (I think they have an example with parallel execution)

-------------------------


Aug 27


The example is now farmer_agnostic.py and agnostic_cylinders.py (ag.bash)
in the farmer example directory.

HEY::: who updates W? Let's do it right before the solve so we don't have to care...
this is a little dangerous at present because we are being silent when
they are not there because of xhatters


== nonant communication needs to be on the host side, of course, but
then callouts need to get values copied to/from the guest

== we need to enforce the assumption that the nonants match in every way possible
between host and guest at all times (e.g. _restore_nonants needs to callout,
but _save_nonants does not.

== bundling is left hanging in dangerous ways: e.g. Eobjective in two places

Aug 26

Work proceeds on three fronts:

- Addiing callouts to mpisppy
- creating the example guest language functions (in Pyomo)
- creating examples of the guest language funtions in other languages

= note: the callouts are almost always inside the local scenario loop in mpisspy

= note: after the solve we are going update the host model x values so
it can update the xbars

= The host will update the w's then a callout will send the new values to
the guest

= I am not even thinking about extensions...

= For bundling, we need to be able to solve EFs (to state the obvious)

circa Aug 25

- no changes needed in spbase so long as agnostic scenario creator is passed in

- EF will be basically a rewrite because we use blocks

- ? for the phbase constructor: pass cfg that contains Ag or pass Ag?; use the options dict for now

- working on an example, which is farmer_agnostic.py run from the __main__ of agnostic.py
(farmer_agnostic is presently run from the utils directory and I have a copy of farmer.py there as well)


===============================================================
Thoughts about AML-agnostic extensions to mpi-sppy
(started by DLW 18 Dec 2022)
Just thinking about support for straight PH for now. Bundles are probably the first thing to add.

-1. BTW: both GAMS and AMPL have python APIs.

0. On the Python side each scenario is still a Pyomo "model" (that perhaps has only the nonant Vars)
with _mpisppy_data and _mpisppy_model attached.
- it might result in a little speed-up to cut Pyomo out some day, but we should start with Pyomo, I think

1. Some functions in spbase, most functions in phbase, and maybe some functions in spopt will call this function:

def callout_agnostic(cfg, name, **kwargs):
""" callout for AML-agnostic support
Args:
cfg (Config): the field "AML_agnostic" might contain a module with callouts
name (str): the function name to call
kwargs (dict): the keywords args for the callout function
Calls:
a callout function that presumably has side-effects
Returns:
True if the callout was done and False if not
"""

if cfg.get(AML_agnostic, ifmissing=None) is not None:
if not hasattr(cfg.AML_agnostic, name):
raise RuntimeError(f"AML-agnostic module is missing function {name}")
fct = getattr(cfg.AML_agnostic, name)
fct(**kwargs)
return True
else:
return False

The function that is called by fct(**kwargs) will do the work of
interacting with the AML and updating mpi-sppy structures that are
passed in as kwargs. Note that cfg is going to need to be attached
some some objects that don't presently have it (e.g. SPOpt). Some
functions in mpi-sppy will want to return immediately if
callout_agnostic returns True (i.e., have the callout function do
all the work).


2 in spbase:
- don't support variable_prob
- _set_scense needs a callout

3 The scenario_creator function will be in Python and needs to call an AML scenario creator function

4. In solve_one it might be easiest to just do everything in the callout function. Maybe that will be the
case for many callouts. But from a maintenance perspective, it would best to have mpi-sppy code
do as much as possible and the callout Python do as little as possible.

5. Think about Compute_Xbar and Update_W. They probably need to do all their processing then do
a callout at the end so the AML model can be updated.

=======================================
Notes about callouts

- There are going to be a lot of them!

- Maybe it would be better to drop the name argument and use
inspect.stack()[1][3] in callout_agnostic so the name of the cfg field
is the name of the calling function in mpi-sppy.
This would
o standardize names,
o eliminate some cut-and-paste errors,
o make it a little wierd if there were ever two callouts from one function,
but not that wierd (just handled with kwarg flag) and two callouts should be rare.
161 changes: 161 additions & 0 deletions doc/src/agnostic.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
AML Agnosticism
===============

The mpi-sppy package provides callouts so that algebraic modeling languages
(AMLs) other than Pyomo can be used. A growing number of AMLs are supported
as `guest` languages (we refer to mpi-sppy as the `host`).

From the end-user's perspective
-------------------------------

When mpi-sppy is used for a model developed in an AML for which support
has been added, the end-user runs the ``mpisppy.agnostic.agnostic_cylinders.py``
program which serves as a driver that takes command line arguments and
launches the requested cylinders. The file
``mpisppy.agnostic.go.bash`` provides examples of a few command lines.


From the modeler's perspective
------------------------------

Assuming support has been added for the desired AML, the modeler supplies
two files:

- a model file with the model written in the guest AML (AMPL example: ``mpisppy.agnostic.examples.farmer.mod``)
- a thin model wrapper for the model file written in Python (AMPL example: ``mpisppy.agnostic.examples.farmer_ampl_model.py``). This thin python wrapper is model specific.

There can be a little confusion if there are error messages because
both files are sometimes refered to as the `model file.`

Most modelers will probably want to import the deterministic guest model into their
python wrapper for the model and the scenario_creator function in the wrapper
modifies the stochastic paramaters to have values that depend on the scenario
name argument to the scenario_creator function.

(An exception is when the guest is in Pyomo, then the wrapper
file might as well contain the model specification as well so
there typically is only one file.)


From the developers perspective
-------------------------------

If support has not yet been added for an AML, it is almost easier to
add support than to write a guest interface for a particular model. To
add support for a language, you need to write a general guest
interface in Python for it (see, e.g., ampl_guest.py or
pyomo_guest.py) and you need to add/edit a few lines in
``mpisppy.agnostic.agnostic_cylinders.py`` to allow end-users to
access it.


Special Note for developers
^^^^^^^^^^^^^^^^^^^^^^^^^^^

The general-purpose guest interfaces might not be the fastest possible
for many guest languages because they don't use indexes from the
original model when updating the objective function. If this is an issue,
you might want to write a problem-specific module to replace the guest
interface and the model wrapper with a single module. For an example, see
``examples.farmer.farmer_xxxx_agnostic``, where xxxx is replaced,
e.g., by ampl.

Architecture
^^^^^^^^^^^^
The following picture presents the architecture of the files.

.. image:: images/agnostic_architecture.png
:alt: Architecture of the agnostic files
:width: 700px
:align: center

We note "xxxx" the specific problem, for instance farmer. We note "yyyy" the guest language, for instance "ampl".
Two methods are presented. Either a method specific to the problem, or a generic method.
Regardless of the method, the file ``agnostic.py`` and ``xxxx.yyyy`` need to be used.
``agnostic.py`` is already implemented and must not be modified as all the files presented above the line "developer".
``xxxx.yyyy`` is the model in the guest language and must be given by the modeler such as all the files under the line "modeler".

The files ``agnostic_yyyy_cylinders.py`` and ``agnostic_cylinders.py`` are equivalent.
The file ``xxxx_yyyy_agnostic.py`` for the specific case is split into ``yyyy_guest.py`` and ``xxxx_yyyy_model.py`` for the generic case.


It is worth noting that the scenario creator is defined in 3 files.
It is first defined in the file specific to the problem and the guest language ``xxxx_yyyy_model.py``. At this point it may not return a scenario.
It is then wrapped in a file only specific to the language ``yyyy_guest.py``. At chich point it returns the dictionary ``gd`` which indludes the scenario.
Finally the tree structure is attached in ``agnostic.py``.


Bundles
-------

The use of scenario bundles can dramatically improve the performance
of scenario decomposition algorithms such as PH and APH. Although mpi-sppy
has facitilites for forming bundles, the mpi-sppy
``agnostic`` package assumes that bundles will be completely handled
by the guest. Bundles will be returned by the scenario creator function
as if they are a scenario. Although it seems sort of like a trick, it is
really the way bundles are intended to operate so we sometimes refer to
`true` bundles, which are used in non-agnostic way as briefly
described in section :ref:`Pickled-Bundles`.

Overview of Recommended Bundle Practices
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Modify the scenario creator function so that if the scenario name
starts with the string "scen" it returns a single scenario, but if the
name starts with "bundle" it returns the full extensive formulation for
a group of scenarios (i.e. a bundle). We typically number scenarios
and the scenario or bundle number is at the end of the first
positional argument for the scenario creator function (i.e. at
the end of the scenario name).

If the name starts with bundle, the scenario creator function can call
itself with the proper list of scenario names to get the scenarios
to form the EF that will be returned. We recommend names for
bundles such as "bundle_xxx_yyy" where xxx and yyy give the
first and last scenario number in the bundle.
You could also pass in a dictionary that maps bundle numbers to lists of
scenario numbers as a keyword argument to the scenario_creator function
and then append the bundle number to "bundle" and pass it as the positional
scenario name argument to the scenario creator function.

Some notes
^^^^^^^^^^

- The helper function called ``scenario_names_creator`` needs to be co-opted
to instead create bundle names and the code in the scenario_creator function
then needs to create its own scenario names for bundles. At the time
of this writing this results in a major hack being needed in order to
get bundle information to the names creator in the Pyomo example described
below. You need to supply a function called ``bundle_hack`` in your python model file that
does whatever needs to be done to alert the names creator that there
bundles. The function takes the config object as an argument.
See ``mpisppy.agnostic.farmer4agnostic.py``
- There is a heavy bias toward uniform probabilities in the examples and in
the mpi-sppy utilities. Scenario probabilities are attached to the scenario
as ``_mpisppy_probability`` so if your probabilities are not uniform, you will
need to calculate them for each bundle (your EF maker code can do that for you). Note that even if probabilities are uniform for the scenarios, they won't
be uniform for the bundles unless you require that the bundle size divides
the number of scenarios.
- There is a similar bias toward two stage problems, which is
extreme for the agnostic package. If you have a multi-stage
problem, you can make things a lot easier for yourself if you require
that the bundles contain all scenarios emanating from each second stage node
(e.g., on bundle per some integer number of second stage nodes). This
is what is done in (non-agnostic) :ref:`Pickled-Bundles`. The result of this
is that your multi-stage problem will look like a two-stage problem to
mpi-sppy.

Example
^^^^^^^

The example ``mpisppy.agnostic.farmer4agnostic.py`` contains example code.

.. Note::
In order to get information from the command line about bundles into the
``scenario_names_creator`` the ``bundle_hack`` function is called
called by the cylinders driver program very early. For this example,
function sets global variables called ``bunsize`` and ``numbuns``.

The script ``mpisppy.agnostic.examples.go.bash`` runs the example (and maybe some
other examples).
Binary file added doc/src/images/agnostic_architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/src/images/agnostic_architecture.pptx
Binary file not shown.
1 change: 1 addition & 0 deletions doc/src/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ MPI is used.
pickledbundles.rst
grad_rho.rst
w_rho.rst
agnostic.rst
admmWrapper.rst
stoch_admmWrapper.rst
helper_functions.rst
Expand Down
7 changes: 6 additions & 1 deletion doc/src/pickledbundles.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _Pickled-Bundles:

Pickled Bundles
===============

Expand All @@ -6,7 +8,10 @@ the bleeding edge. The idea is that bundles are formed and then saved
as dill pickle files for rapid retrieval. The file
``aircond_cylinders.py`` in the aircond example directory provides an
example. The latter part of the ``allways.bash`` script demonstrates
how to run it.
how to run it. (The directory is mpi-sppy.examples.aircond assuming you installed
into the directory mpi-sppy, but the important file aircondB.py is
mpisppy.tests.examples.aircondB.py, which contains the scenario creator
function.)

In the future, we plan to support this concept with higher levels of abstraction.

Expand Down
1 change: 1 addition & 0 deletions examples/farmer/AMPL/AMPLpy_examples/AAAreadme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Examples from AMPL
Loading
Loading