Skip to content

Commit a8aba60

Browse files
committed
tests are ready to run?
1 parent 79072bd commit a8aba60

File tree

3 files changed

+43
-9
lines changed

3 files changed

+43
-9
lines changed

Diff for: .github/workflows/test_pr_and_main.yml

+29-1
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,34 @@ jobs:
310310
python test_pickle_bundle.py
311311
312312
313+
mps:
314+
name: MPS tests
315+
runs-on: ubuntu-latest
316+
needs: [ruff]
317+
318+
steps:
319+
- uses: actions/checkout@v3
320+
- uses: conda-incubator/setup-miniconda@v2
321+
with:
322+
activate-environment: test_env
323+
python-version: 3.11
324+
auto-activate-base: false
325+
- name: Install dependencies
326+
run: |
327+
conda install mpi4py pandas setuptools
328+
pip install pyomo xpress cplex mip
329+
330+
- name: setup the program
331+
run: |
332+
pip install -e .
333+
334+
- name: run MPS tests
335+
timeout-minutes: 2
336+
run: |
337+
cd mpisppy/tests
338+
python test_mps.py
339+
340+
313341
confidence-intervals:
314342
name: confidence intervals tests
315343
runs-on: ubuntu-latest
@@ -494,7 +522,7 @@ jobs:
494522
timeout-minutes: 10
495523
run: |
496524
cd mpisppy/tests
497-
mpiexec -np 2 python -m mpi4py test_with_cylinders.py
525+
mpiexec -np 2 python -m mpi4py test_with_cylinders.py
498526
499527
test-agnostic:
500528
name: tests on agnostic

Diff for: mpisppy/extensions/scenario_lp_mps_files.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@ def pre_iter0(self):
3030
for k, s in self.ph.local_subproblems.items():
3131
s.write(f"{k}.lp", io_options={'symbolic_solver_labels': True})
3232
s.write(f"{k}.mps", io_options={'symbolic_solver_labels': True})
33-
scenDict = {"scenProb": s._mpisppy_probability} # to be added to
34-
nodeDict = dict()
33+
scenData = {"name": s.name, "scenProb": s._mpisppy_probability}
34+
scenDict = {"scenarioData": scenData}
3535
for nd in s._mpisppy_node_list:
36-
nodeDict[nd.name] = {"condProb": nd.cond_prob}
37-
nodeDict[nd.name].update({"nonAnts": [lpize(var.name) for var in nd.nonant_vardata_list]})
38-
scenDict.update(nodeDict)
36+
scenDict[nd.name] = {"condProb": nd.cond_prob}
37+
scenDict[nd.name].update({"nonAnts": [lpize(var.name) for var in nd.nonant_vardata_list]})
3938
with open(f"{k}_nonants.json", "w") as jfile:
4039
json.dump(scenDict, jfile, indent=2)
4140

Diff for: mpisppy/utils/mps_module.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ def scenario_creator(sname, cfg=None):
5353
with open(jsonPath) as f:
5454
nonantDict = json.load(f)
5555
try:
56-
scenProb = nonantDict["scenProb"]
56+
scenProb = nonantDict["scenarioData"]["scenProb"]
5757
except Exception as e:
5858
raise RuntimeError(f'Error getting scenProb from {jsonPath}: {e}')
5959
assert "ROOT" in nonantDict, f'"ROOT" must be top node in {jsonPath}'
6060
treeNodes = list()
6161
parent_ndn = None # counting on the json file to have ordered nodes
6262
stage = 1
6363
for ndn in nonantDict:
64-
if ndn == "scenProb": # non-nodename at top level of json
64+
if ndn == "scenarioData": # non-nodename at top level of json
6565
continue
6666
cp = nonantDict[ndn]["condProb"]
6767
nonants = [model.\
@@ -94,13 +94,20 @@ def scenario_names_creator(num_scens, start=None):
9494
# IMPORTANT: start is zero-based even if the names are one-based!
9595
mps_files = [os.path.basename(f)
9696
for f in glob.glob(os.path.join(mps_files_directory, "*.mps"))]
97+
mps_files.sort()
9798
if start == None:
9899
start = 0
99100
if num_scens == None:
100101
num_scens = len(mps_files) - start
101102
first = re.search(r"\d+$",mps_files[0][:-4]) # first scenario number
103+
try:
104+
first = int(first.group())
105+
except Exception as e:
106+
raise RuntimeError(f'mps files in {mps_files_directory} must end with an integer'
107+
f'found file {mps_files[0]} (error was: {e})')
108+
102109
print("WARNING: one-based senario names might cause trouble"
103-
f" found {first} for file {os.path.join(mps_files_directory, mps_files[0])}")
110+
f" found {first} for dir {mps_files_directory}")
104111
assert start+num_scens <= len(mps_files),\
105112
f"Trying to create scenarios names with {start=}, {num_scens=} but {len(mps_files)=}"
106113
retval = [fn[:-4] for fn in mps_files[start:start+num_scens]]

0 commit comments

Comments
 (0)