simoptlib 1.2.2.post0__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.
Files changed (89) hide show
  1. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/PKG-INFO +10 -4
  2. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/README.md +4 -1
  3. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/pyproject.toml +6 -3
  4. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/bootstrap.py +38 -34
  5. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/experiment/post_normalize.py +3 -3
  6. simoptlib-1.2.3/simopt/experiment/run_solver.py +149 -0
  7. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/experiment/single.py +31 -386
  8. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/models/amusementpark.py +3 -2
  9. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/models/example.py +123 -0
  10. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/solver.py +12 -2
  11. simoptlib-1.2.3/simopt/solvers/_dasso.py +103 -0
  12. simoptlib-1.2.3/simopt/solvers/dasso.py +1524 -0
  13. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/solvers/neldmd.py +1 -2
  14. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simoptlib.egg-info/PKG-INFO +10 -4
  15. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simoptlib.egg-info/SOURCES.txt +3 -0
  16. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simoptlib.egg-info/requires.txt +4 -1
  17. simoptlib-1.2.3/simoptlib.egg-info/top_level.txt +2 -0
  18. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/test/test_experiments.py +2 -2
  19. simoptlib-1.2.2.post0/simoptlib.egg-info/top_level.txt +0 -1
  20. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/LICENSE +0 -0
  21. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/setup.cfg +0 -0
  22. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/GUI.py +0 -0
  23. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/__init__.py +0 -0
  24. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/__main__.py +0 -0
  25. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/base.py +0 -0
  26. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/curve.py +0 -0
  27. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/curve_utils.py +0 -0
  28. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/data_farming/data_farming_core.py +0 -0
  29. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/data_farming/nolhs.py +0 -0
  30. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/data_farming/nolhs_design_table.npz +0 -0
  31. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/data_farming_base.py +0 -0
  32. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/directory.py +0 -0
  33. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/experiment/__init__.py +0 -0
  34. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/experiment/multiple.py +0 -0
  35. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/experiment_base.py +0 -0
  36. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/experimental.py +0 -0
  37. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/feasibility.py +0 -0
  38. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/gui/data_farming_window.py +0 -0
  39. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/gui/df_object.py +0 -0
  40. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/gui/main_menu.py +0 -0
  41. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/gui/new_experiment_window.py +0 -0
  42. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/gui/plot_window.py +0 -0
  43. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/gui/toplevel_custom.py +0 -0
  44. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/input_models.py +0 -0
  45. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/model.py +0 -0
  46. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/models/__init__.py +0 -0
  47. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/models/_ext.py +0 -0
  48. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/models/chessmm.py +0 -0
  49. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/models/cntnv.py +0 -0
  50. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/models/contam.py +0 -0
  51. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/models/dualsourcing.py +0 -0
  52. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/models/dynamnews.py +0 -0
  53. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/models/ermexample.py +0 -0
  54. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/models/facilitysizing.py +0 -0
  55. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/models/fixedsan.py +0 -0
  56. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/models/hotel.py +0 -0
  57. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/models/ironore.py +0 -0
  58. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/models/mm1queue.py +0 -0
  59. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/models/network.py +0 -0
  60. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/models/paramesti.py +0 -0
  61. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/models/rmitd.py +0 -0
  62. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/models/san.py +0 -0
  63. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/models/sscont.py +0 -0
  64. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/models/tableallocation.py +0 -0
  65. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/plot_type.py +0 -0
  66. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/plots/__init__.py +0 -0
  67. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/plots/area_scatterplot.py +0 -0
  68. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/plots/feasibility_progress.py +0 -0
  69. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/plots/progress_curve.py +0 -0
  70. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/plots/solvability_cdf.py +0 -0
  71. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/plots/solvability_profile.py +0 -0
  72. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/plots/terminal_feasibility.py +0 -0
  73. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/plots/terminal_progress.py +0 -0
  74. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/plots/terminal_scatterplot.py +0 -0
  75. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/plots/utils.py +0 -0
  76. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/problem.py +0 -0
  77. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/problem_types.py +0 -0
  78. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/solvers/__init__.py +0 -0
  79. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/solvers/adam.py +0 -0
  80. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/solvers/aloe.py +0 -0
  81. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/solvers/astrodf.py +0 -0
  82. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/solvers/fcsa.py +0 -0
  83. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/solvers/randomsearch.py +0 -0
  84. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/solvers/spsa.py +0 -0
  85. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/solvers/strong.py +0 -0
  86. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/solvers/utils.py +0 -0
  87. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/utils.py +0 -0
  88. {simoptlib-1.2.2.post0 → simoptlib-1.2.3}/simopt/utils.pyi +0 -0
  89. {simoptlib-1.2.2.post0 → 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.2.post0
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>, William Grochocinski <williamgrochocinski@gmail.com>
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>=2.3.4
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
  ![GitHub's built-in citation generator](https://github.com/user-attachments/assets/b8b49544-eb74-469e-aa37-68c2c0c3708b)
@@ -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
  ![GitHub's built-in citation generator](https://github.com/user-attachments/assets/b8b49544-eb74-469e-aa37-68c2c0c3708b)
@@ -16,12 +16,12 @@ simopt-extensions = { git = "https://github.com/cenwangumass/simopt-extensions",
16
16
 
17
17
  [project]
18
18
  name = "simoptlib"
19
- version = "1.2.2.post0"
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 = "William Grochocinski", email = "williamgrochocinski@gmail.com" },
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: curve_utils.difference_of_curves( # noqa: E501
325
- curve_utils.mean_of_curves(
326
- [
327
- curve_utils.cdf_of_curves_crossing_times(
328
- curves, threshold=solve_tol
329
- )
330
- for curves in solver_1_curves
331
- ]
332
- ),
333
- curve_utils.mean_of_curves(
334
- [
335
- curve_utils.cdf_of_curves_crossing_times(
336
- curves, threshold=solve_tol
337
- )
338
- for curves in solver_2_curves # type: ignore
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: curve_utils.difference_of_curves( # noqa: E501
343
- curve_utils.mean_of_curves(
344
- [
345
- curve_utils.quantile_cross_jump(
346
- curves, threshold=solve_tol, beta=beta
347
- )
348
- for curves in solver_1_curves
349
- ]
350
- ),
351
- curve_utils.mean_of_curves(
352
- [
353
- curve_utils.quantile_cross_jump(
354
- curves, threshold=solve_tol, beta=beta
355
- )
356
- for curves in solver_2_curves # type: ignore
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
- infeasible_pentalty = np.inf
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] * infeasible_pentalty
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) == infeasible_pentalty:
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])