simoptlib 1.2.2__tar.gz → 1.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {simoptlib-1.2.2 → simoptlib-1.2.3}/PKG-INFO +10 -4
- {simoptlib-1.2.2 → simoptlib-1.2.3}/README.md +4 -1
- {simoptlib-1.2.2 → simoptlib-1.2.3}/pyproject.toml +7 -4
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/GUI.py +1 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/bootstrap.py +38 -34
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/experiment/post_normalize.py +3 -3
- simoptlib-1.2.3/simopt/experiment/run_solver.py +149 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/experiment/single.py +31 -386
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/experiment_base.py +16 -6
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/gui/main_menu.py +1 -1
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/gui/new_experiment_window.py +8 -1
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/models/amusementpark.py +3 -2
- simoptlib-1.2.3/simopt/models/ermexample.py +203 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/models/example.py +123 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/solver.py +12 -2
- simoptlib-1.2.3/simopt/solvers/_dasso.py +103 -0
- simoptlib-1.2.3/simopt/solvers/dasso.py +1524 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/solvers/fcsa.py +7 -3
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/solvers/neldmd.py +1 -2
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simoptlib.egg-info/PKG-INFO +10 -4
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simoptlib.egg-info/SOURCES.txt +4 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simoptlib.egg-info/requires.txt +4 -1
- simoptlib-1.2.3/simoptlib.egg-info/top_level.txt +2 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/test/test_experiments.py +2 -2
- simoptlib-1.2.2/simoptlib.egg-info/top_level.txt +0 -1
- {simoptlib-1.2.2 → simoptlib-1.2.3}/LICENSE +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/setup.cfg +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/__init__.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/__main__.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/base.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/curve.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/curve_utils.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/data_farming/data_farming_core.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/data_farming/nolhs.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/data_farming/nolhs_design_table.npz +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/data_farming_base.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/directory.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/experiment/__init__.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/experiment/multiple.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/experimental.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/feasibility.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/gui/data_farming_window.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/gui/df_object.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/gui/plot_window.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/gui/toplevel_custom.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/input_models.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/model.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/models/__init__.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/models/_ext.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/models/chessmm.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/models/cntnv.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/models/contam.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/models/dualsourcing.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/models/dynamnews.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/models/facilitysizing.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/models/fixedsan.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/models/hotel.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/models/ironore.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/models/mm1queue.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/models/network.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/models/paramesti.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/models/rmitd.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/models/san.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/models/sscont.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/models/tableallocation.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/plot_type.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/plots/__init__.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/plots/area_scatterplot.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/plots/feasibility_progress.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/plots/progress_curve.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/plots/solvability_cdf.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/plots/solvability_profile.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/plots/terminal_feasibility.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/plots/terminal_progress.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/plots/terminal_scatterplot.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/plots/utils.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/problem.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/problem_types.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/solvers/__init__.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/solvers/adam.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/solvers/aloe.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/solvers/astrodf.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/solvers/randomsearch.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/solvers/spsa.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/solvers/strong.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/solvers/utils.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/utils.py +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simopt/utils.pyi +0 -0
- {simoptlib-1.2.2 → simoptlib-1.2.3}/simoptlib.egg-info/dependency_links.txt +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: simoptlib
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.3
|
|
4
4
|
Summary: A testbed for simulation-optimization experiments.
|
|
5
|
-
Author-email: David Eckman <eckman@tamu.edu>, Shane Henderson <sgh9@cornell.edu>, Sara Shashaani <sshasha2@ncsu.edu>,
|
|
5
|
+
Author-email: David Eckman <eckman@tamu.edu>, Shane Henderson <sgh9@cornell.edu>, Sara Shashaani <sshasha2@ncsu.edu>, Cen Wang <cenwang@tamu.edu>
|
|
6
6
|
License: MIT License
|
|
7
7
|
|
|
8
8
|
Copyright (c) 2025 simopt-admin
|
|
@@ -34,14 +34,16 @@ Requires-Python: <3.14,>=3.11
|
|
|
34
34
|
Description-Content-Type: text/markdown
|
|
35
35
|
License-File: LICENSE
|
|
36
36
|
Requires-Dist: boltons>=25.0.0
|
|
37
|
+
Requires-Dist: colorama>=0.4.6
|
|
37
38
|
Requires-Dist: cvxpy>=1.7.3
|
|
38
39
|
Requires-Dist: joblib>=1.5.2
|
|
39
40
|
Requires-Dist: matplotlib>=3.10.7
|
|
40
41
|
Requires-Dist: mrg32k3a[rust]>=2.0.0
|
|
41
|
-
Requires-Dist: numpy
|
|
42
|
+
Requires-Dist: numpy<2.4,>=2.3.4
|
|
42
43
|
Requires-Dist: pandas>=2.3.3
|
|
43
44
|
Requires-Dist: pillow>=12.0.0
|
|
44
45
|
Requires-Dist: pydantic>=2.12.3
|
|
46
|
+
Requires-Dist: pydoe>=0.9.7
|
|
45
47
|
Requires-Dist: scipy>=1.16.3
|
|
46
48
|
Requires-Dist: seaborn>=0.13.2
|
|
47
49
|
Provides-Extra: dev
|
|
@@ -50,6 +52,7 @@ Requires-Dist: pytest-xdist>=3.8.0; extra == "dev"
|
|
|
50
52
|
Requires-Dist: pytest>=9.0.1; extra == "dev"
|
|
51
53
|
Requires-Dist: ruff>=0.14.2; extra == "dev"
|
|
52
54
|
Requires-Dist: ty>=0.0.1a26; extra == "dev"
|
|
55
|
+
Requires-Dist: zstandard>=0.25.0; extra == "dev"
|
|
53
56
|
Provides-Extra: docs
|
|
54
57
|
Requires-Dist: sphinx>=8.2.3; extra == "docs"
|
|
55
58
|
Requires-Dist: sphinx-autoapi>=3.6.1; extra == "docs"
|
|
@@ -295,9 +298,12 @@ The core development team currently consists of
|
|
|
295
298
|
- [**David Eckman**](https://eckman.engr.tamu.edu) (Texas A&M University)
|
|
296
299
|
- [**Sara Shashaani**](https://shashaani.wordpress.ncsu.edu) (North Carolina State University)
|
|
297
300
|
- [**Shane Henderson**](https://people.orie.cornell.edu/shane/) (Cornell University)
|
|
298
|
-
- [**William Grochocinski**](https://github.com/Grochocinski) (North Carolina State University)
|
|
299
301
|
- [**Cen Wang**](https://cenwangumass.github.io/) (Texas A&M University)
|
|
300
302
|
|
|
303
|
+
Previous maintainer:
|
|
304
|
+
|
|
305
|
+
- [**William Grochocinski**](https://github.com/Grochocinski) (North Carolina State University)
|
|
306
|
+
|
|
301
307
|
## Citation
|
|
302
308
|
To cite this work, please use the `CITATION.cff` file or use the built-in citation generator:
|
|
303
309
|

|
|
@@ -233,9 +233,12 @@ The core development team currently consists of
|
|
|
233
233
|
- [**David Eckman**](https://eckman.engr.tamu.edu) (Texas A&M University)
|
|
234
234
|
- [**Sara Shashaani**](https://shashaani.wordpress.ncsu.edu) (North Carolina State University)
|
|
235
235
|
- [**Shane Henderson**](https://people.orie.cornell.edu/shane/) (Cornell University)
|
|
236
|
-
- [**William Grochocinski**](https://github.com/Grochocinski) (North Carolina State University)
|
|
237
236
|
- [**Cen Wang**](https://cenwangumass.github.io/) (Texas A&M University)
|
|
238
237
|
|
|
238
|
+
Previous maintainer:
|
|
239
|
+
|
|
240
|
+
- [**William Grochocinski**](https://github.com/Grochocinski) (North Carolina State University)
|
|
241
|
+
|
|
239
242
|
## Citation
|
|
240
243
|
To cite this work, please use the `CITATION.cff` file or use the built-in citation generator:
|
|
241
244
|

|
|
@@ -12,16 +12,16 @@ exclude = ["build*"]
|
|
|
12
12
|
"simopt.data_farming" = ["*.npz"]
|
|
13
13
|
|
|
14
14
|
[tool.uv.sources]
|
|
15
|
-
simopt-extensions = { git = "https://github.com/cenwangumass/simopt-extensions", rev = "
|
|
15
|
+
simopt-extensions = { git = "https://github.com/cenwangumass/simopt-extensions", rev = "b40a9c8" }
|
|
16
16
|
|
|
17
17
|
[project]
|
|
18
18
|
name = "simoptlib"
|
|
19
|
-
version = "1.2.
|
|
19
|
+
version = "1.2.3"
|
|
20
20
|
authors = [
|
|
21
21
|
{ name = "David Eckman", email = "eckman@tamu.edu" },
|
|
22
22
|
{ name = "Shane Henderson", email = "sgh9@cornell.edu" },
|
|
23
23
|
{ name = "Sara Shashaani", email = "sshasha2@ncsu.edu" },
|
|
24
|
-
{ name = "
|
|
24
|
+
{ name = "Cen Wang", email = "cenwang@tamu.edu" }
|
|
25
25
|
]
|
|
26
26
|
description = "A testbed for simulation-optimization experiments."
|
|
27
27
|
readme = "README.md"
|
|
@@ -34,14 +34,16 @@ classifiers = [
|
|
|
34
34
|
]
|
|
35
35
|
dependencies = [
|
|
36
36
|
"boltons>=25.0.0",
|
|
37
|
+
"colorama>=0.4.6",
|
|
37
38
|
"cvxpy>=1.7.3",
|
|
38
39
|
"joblib>=1.5.2",
|
|
39
40
|
"matplotlib>=3.10.7",
|
|
40
41
|
"mrg32k3a[rust]>=2.0.0",
|
|
41
|
-
"numpy>=2.3.4",
|
|
42
|
+
"numpy>=2.3.4,<2.4",
|
|
42
43
|
"pandas>=2.3.3",
|
|
43
44
|
"pillow>=12.0.0",
|
|
44
45
|
"pydantic>=2.12.3",
|
|
46
|
+
"pydoe>=0.9.7",
|
|
45
47
|
"scipy>=1.16.3",
|
|
46
48
|
"seaborn>=0.13.2",
|
|
47
49
|
]
|
|
@@ -53,6 +55,7 @@ dev = [
|
|
|
53
55
|
"pytest>=9.0.1",
|
|
54
56
|
"ruff>=0.14.2",
|
|
55
57
|
"ty>=0.0.1a26",
|
|
58
|
+
"zstandard>=0.25.0",
|
|
56
59
|
]
|
|
57
60
|
docs = ["sphinx>=8.2.3", "sphinx-autoapi>=3.6.1", "sphinx-rtd-theme>=3.0.2"]
|
|
58
61
|
notebooks = ["ipykernel>=7.1.0"]
|
|
@@ -321,41 +321,45 @@ def functional_of_curves(
|
|
|
321
321
|
for curves in solver_1_curves
|
|
322
322
|
]
|
|
323
323
|
),
|
|
324
|
-
PlotType.DIFFERENCE_OF_CDF_SOLVABILITY: lambda:
|
|
325
|
-
curve_utils.
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
324
|
+
PlotType.DIFFERENCE_OF_CDF_SOLVABILITY: lambda: (
|
|
325
|
+
curve_utils.difference_of_curves(
|
|
326
|
+
curve_utils.mean_of_curves(
|
|
327
|
+
[
|
|
328
|
+
curve_utils.cdf_of_curves_crossing_times(
|
|
329
|
+
curves, threshold=solve_tol
|
|
330
|
+
)
|
|
331
|
+
for curves in solver_1_curves
|
|
332
|
+
]
|
|
333
|
+
),
|
|
334
|
+
curve_utils.mean_of_curves(
|
|
335
|
+
[
|
|
336
|
+
curve_utils.cdf_of_curves_crossing_times(
|
|
337
|
+
curves, threshold=solve_tol
|
|
338
|
+
)
|
|
339
|
+
for curves in solver_2_curves # type: ignore
|
|
340
|
+
]
|
|
341
|
+
),
|
|
342
|
+
)
|
|
341
343
|
),
|
|
342
|
-
PlotType.DIFFERENCE_OF_QUANTILE_SOLVABILITY: lambda:
|
|
343
|
-
curve_utils.
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
344
|
+
PlotType.DIFFERENCE_OF_QUANTILE_SOLVABILITY: lambda: (
|
|
345
|
+
curve_utils.difference_of_curves(
|
|
346
|
+
curve_utils.mean_of_curves(
|
|
347
|
+
[
|
|
348
|
+
curve_utils.quantile_cross_jump(
|
|
349
|
+
curves, threshold=solve_tol, beta=beta
|
|
350
|
+
)
|
|
351
|
+
for curves in solver_1_curves
|
|
352
|
+
]
|
|
353
|
+
),
|
|
354
|
+
curve_utils.mean_of_curves(
|
|
355
|
+
[
|
|
356
|
+
curve_utils.quantile_cross_jump(
|
|
357
|
+
curves, threshold=solve_tol, beta=beta
|
|
358
|
+
)
|
|
359
|
+
for curves in solver_2_curves # type: ignore
|
|
360
|
+
]
|
|
361
|
+
),
|
|
362
|
+
)
|
|
359
363
|
),
|
|
360
364
|
PlotType.MEAN_FEASIBILITY_PROGRESS: lambda: curve_utils.mean_of_curves(
|
|
361
365
|
single_curves
|
|
@@ -18,7 +18,7 @@ def _best_with_feasibility(
|
|
|
18
18
|
baseline_rngs: list[MRG32k3a],
|
|
19
19
|
n_postreps_init_opt: int,
|
|
20
20
|
) -> tuple:
|
|
21
|
-
|
|
21
|
+
infeasible_penalty = np.inf
|
|
22
22
|
best_est_objectives = np.zeros(len(experiments))
|
|
23
23
|
|
|
24
24
|
for experiment_idx in range(len(experiments)):
|
|
@@ -43,7 +43,7 @@ def _best_with_feasibility(
|
|
|
43
43
|
)
|
|
44
44
|
else:
|
|
45
45
|
exp_best_est_objectives[mrep] = (
|
|
46
|
-
experiment.problem.minmax[0] *
|
|
46
|
+
experiment.problem.minmax[0] * infeasible_penalty
|
|
47
47
|
)
|
|
48
48
|
|
|
49
49
|
best_est_objectives[experiment_idx] = np.max(exp_best_est_objectives)
|
|
@@ -52,7 +52,7 @@ def _best_with_feasibility(
|
|
|
52
52
|
best_experiment = experiments[best_index]
|
|
53
53
|
best_objective = best_experiment.problem.minmax[0] * best_est_objectives[best_index]
|
|
54
54
|
|
|
55
|
-
if abs(best_objective) ==
|
|
55
|
+
if abs(best_objective) == infeasible_penalty:
|
|
56
56
|
raise RuntimeError(
|
|
57
57
|
"No feasible solutions found for which to estimate proxy for x*."
|
|
58
58
|
)
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"""Functions for running solvers and collecting their outputs."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import time
|
|
5
|
+
from copy import deepcopy
|
|
6
|
+
|
|
7
|
+
import pandas as pd
|
|
8
|
+
from joblib import Parallel, delayed
|
|
9
|
+
|
|
10
|
+
from mrg32k3a.mrg32k3a import MRG32k3a
|
|
11
|
+
from simopt.problem import Problem
|
|
12
|
+
from simopt.solver import Solver
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _trim(df: pd.DataFrame, budget: int) -> pd.DataFrame:
|
|
16
|
+
"""Trim solution history beyond the problem's budget."""
|
|
17
|
+
df = df.loc[df["budget"] <= budget].copy()
|
|
18
|
+
|
|
19
|
+
# Add the latest solution as the final row
|
|
20
|
+
if df["budget"].iloc[-1] < budget:
|
|
21
|
+
row = pd.DataFrame.from_records(
|
|
22
|
+
[{"step": len(df), "solution": df["solution"].iloc[-1], "budget": budget}]
|
|
23
|
+
)
|
|
24
|
+
df = pd.concat([df, row], ignore_index=True)
|
|
25
|
+
|
|
26
|
+
return df
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _set_up_rngs(solver: Solver, problem: Problem, mrep: int) -> None:
|
|
30
|
+
# Stream 0: reserved for taking post-replications
|
|
31
|
+
# Stream 1: reserved for bootstrapping
|
|
32
|
+
# Stream 2: reserved for overhead ...
|
|
33
|
+
# Substream 0: rng for random problem instance
|
|
34
|
+
# Substream 1: rng for random initial solution x0 and restart solutions
|
|
35
|
+
# Substream 2: rng for selecting random feasible solutions
|
|
36
|
+
# Substream 3: rng for solver's internal randomness
|
|
37
|
+
# Streams 3, 4, ..., n_macroreps + 2: reserved for
|
|
38
|
+
# macroreplications
|
|
39
|
+
# FIXME: the following rngs seem to be overriden by the solver rngs below
|
|
40
|
+
rng_list = [MRG32k3a(s_ss_sss_index=[2, i + 1, 0]) for i in range(3)]
|
|
41
|
+
solver.attach_rngs(rng_list)
|
|
42
|
+
|
|
43
|
+
# Create RNGs for simulation
|
|
44
|
+
simulation_rngs = [
|
|
45
|
+
MRG32k3a(s_ss_sss_index=[mrep + 3, i, 0]) for i in range(problem.model.n_rngs)
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
# Create RNGs for the solver
|
|
49
|
+
solver_rngs = [
|
|
50
|
+
MRG32k3a(
|
|
51
|
+
s_ss_sss_index=[
|
|
52
|
+
mrep + 3,
|
|
53
|
+
problem.model.n_rngs + i,
|
|
54
|
+
0,
|
|
55
|
+
]
|
|
56
|
+
)
|
|
57
|
+
for i in range(len(solver.rng_list))
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
solver.solution_progenitor_rngs = simulation_rngs
|
|
61
|
+
solver.rng_list = solver_rngs
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _run_mrep(
|
|
65
|
+
solver: Solver, problem: Problem, mrep: int
|
|
66
|
+
) -> tuple[pd.DataFrame, float]:
|
|
67
|
+
"""Run one macroreplication of the solver on the problem."""
|
|
68
|
+
logging.debug(
|
|
69
|
+
f"Macroreplication {mrep}: "
|
|
70
|
+
f"starting solver {solver.name} on problem {problem.name}."
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
# Set up RNGs
|
|
74
|
+
_set_up_rngs(solver, problem, mrep)
|
|
75
|
+
|
|
76
|
+
# Run solver
|
|
77
|
+
start = time.perf_counter()
|
|
78
|
+
df = solver.run(problem)
|
|
79
|
+
elapsed = time.perf_counter() - start
|
|
80
|
+
logging.debug(
|
|
81
|
+
f"Macroreplication {mrep}: "
|
|
82
|
+
f"finished solver {solver.name} on problem {problem.name} "
|
|
83
|
+
f"in {elapsed:0.4f} seconds."
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
# Trim results to the problem budget and add macroreplication index
|
|
87
|
+
df = _trim(df, problem.factors["budget"])
|
|
88
|
+
df["mrep"] = mrep
|
|
89
|
+
|
|
90
|
+
return df, elapsed
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def run_solver(
|
|
94
|
+
solver: Solver, problem: Problem, n_macroreps: int, n_jobs: int = -1
|
|
95
|
+
) -> tuple[pd.DataFrame, list[float]]:
|
|
96
|
+
"""Runs the solver on the problem for a given number of macroreplications.
|
|
97
|
+
|
|
98
|
+
Args:
|
|
99
|
+
solver (Solver): The solver to run.
|
|
100
|
+
problem (Problem): The problem to solve.
|
|
101
|
+
n_macroreps (int): Number of macroreplications to run.
|
|
102
|
+
n_jobs (int, optional): Number of jobs to run in parallel. Defaults to -1.
|
|
103
|
+
-1: use all available cores
|
|
104
|
+
1: run sequentially
|
|
105
|
+
|
|
106
|
+
Raises:
|
|
107
|
+
ValueError: If `n_macroreps` is not positive.
|
|
108
|
+
"""
|
|
109
|
+
if n_macroreps <= 0:
|
|
110
|
+
raise ValueError("number of macroreplications must be positive.")
|
|
111
|
+
|
|
112
|
+
logging.info(f"Running solver {solver.name} on problem {problem.name}.")
|
|
113
|
+
logging.debug("Starting macroreplications")
|
|
114
|
+
|
|
115
|
+
# TODO: Long-term fix is to make Solver/Problem immutable (stateless)
|
|
116
|
+
# so macroreps can share instances safely without deepcopy.
|
|
117
|
+
if n_jobs == 1:
|
|
118
|
+
results: list[tuple] = [
|
|
119
|
+
_run_mrep(deepcopy(solver), deepcopy(problem), i)
|
|
120
|
+
for i in range(n_macroreps)
|
|
121
|
+
]
|
|
122
|
+
else:
|
|
123
|
+
results: list[tuple] = Parallel(n_jobs=n_jobs)(
|
|
124
|
+
delayed(_run_mrep)(deepcopy(solver), deepcopy(problem), i)
|
|
125
|
+
for i in range(n_macroreps)
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
dfs = []
|
|
129
|
+
elapsed_times = []
|
|
130
|
+
for df, elapsed in results:
|
|
131
|
+
dfs.append(df)
|
|
132
|
+
elapsed_times.append(elapsed)
|
|
133
|
+
df = pd.concat(dfs, ignore_index=True)
|
|
134
|
+
|
|
135
|
+
return df, elapsed_times
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def _to_list(df: pd.DataFrame, column: str) -> list[list]:
|
|
139
|
+
df = df.sort_values(["mrep", "step"])
|
|
140
|
+
return [group[column].tolist() for _, group in df.groupby("mrep")]
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def _from_list(data: list[list], column: str) -> pd.DataFrame:
|
|
144
|
+
records = [
|
|
145
|
+
{"mrep": mrep, "step": step, column: value}
|
|
146
|
+
for mrep, steps in enumerate(data)
|
|
147
|
+
for step, value in enumerate(steps)
|
|
148
|
+
]
|
|
149
|
+
return pd.DataFrame.from_records(records, columns=["mrep", "step", column])
|