simoptlib 1.3.0.dev0__py3-none-any.whl → 1.3.0.dev1__py3-none-any.whl

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 (37) hide show
  1. {simoptlib-1.3.0.dev0.dist-info → simoptlib-1.3.0.dev1.dist-info}/METADATA +4 -3
  2. {simoptlib-1.3.0.dev0.dist-info → simoptlib-1.3.0.dev1.dist-info}/RECORD +32 -36
  3. simoptlib-1.3.0.dev1.dist-info/top_level.txt +3 -0
  4. simopt-dsl/tests/test_model.py +0 -184
  5. simopt-solvers/tests/test_solve.py +0 -86
  6. simopt-solvers/tests/test_specifications.py +0 -55
  7. simopt-web/node_modules/flatted/python/flatted.py +0 -144
  8. simoptlib-1.3.0.dev0.dist-info/top_level.txt +0 -4
  9. {simopt-dsl/src/simopt_dsl → simopt_dsl}/__init__.py +0 -0
  10. {simopt-dsl/src/simopt_dsl → simopt_dsl}/expressions.py +0 -0
  11. {simopt-dsl/src/simopt_dsl → simopt_dsl}/model.py +0 -0
  12. {simopt-dsl/src/simopt_dsl → simopt_dsl}/py.typed +0 -0
  13. {simopt-dsl/src/simopt_dsl → simopt_dsl}/simulation.py +0 -0
  14. {simopt-dsl/src/simopt_dsl → simopt_dsl}/variables.py +0 -0
  15. {simopt-solvers/src/simopt_solvers → simopt_solvers}/__init__.py +0 -0
  16. {simopt-solvers/src/simopt_solvers → simopt_solvers}/_utils.py +0 -0
  17. {simopt-solvers/src/simopt_solvers → simopt_solvers}/base.py +0 -0
  18. {simopt-solvers/src/simopt_solvers → simopt_solvers}/problem_types.py +0 -0
  19. {simopt-solvers/src/simopt_solvers → simopt_solvers}/py.typed +0 -0
  20. {simopt-solvers/src/simopt_solvers → simopt_solvers}/solution.py +0 -0
  21. {simopt-solvers/src/simopt_solvers → simopt_solvers}/solver.py +0 -0
  22. {simopt-solvers/src/simopt_solvers → simopt_solvers}/solvers/__init__.py +0 -0
  23. {simopt-solvers/src/simopt_solvers → simopt_solvers}/solvers/_dasso.py +0 -0
  24. {simopt-solvers/src/simopt_solvers → simopt_solvers}/solvers/adam.py +0 -0
  25. {simopt-solvers/src/simopt_solvers → simopt_solvers}/solvers/aloe.py +0 -0
  26. {simopt-solvers/src/simopt_solvers → simopt_solvers}/solvers/astrodf.py +0 -0
  27. {simopt-solvers/src/simopt_solvers → simopt_solvers}/solvers/castrodf.py +0 -0
  28. {simopt-solvers/src/simopt_solvers → simopt_solvers}/solvers/dasso.py +0 -0
  29. {simopt-solvers/src/simopt_solvers → simopt_solvers}/solvers/fcsa.py +0 -0
  30. {simopt-solvers/src/simopt_solvers → simopt_solvers}/solvers/neldmd.py +0 -0
  31. {simopt-solvers/src/simopt_solvers → simopt_solvers}/solvers/randomsearch.py +0 -0
  32. {simopt-solvers/src/simopt_solvers → simopt_solvers}/solvers/spsa.py +0 -0
  33. {simopt-solvers/src/simopt_solvers → simopt_solvers}/solvers/strong.py +0 -0
  34. {simopt-solvers/src/simopt_solvers → simopt_solvers}/solvers/utils.py +0 -0
  35. {simoptlib-1.3.0.dev0.dist-info → simoptlib-1.3.0.dev1.dist-info}/WHEEL +0 -0
  36. {simoptlib-1.3.0.dev0.dist-info → simoptlib-1.3.0.dev1.dist-info}/entry_points.txt +0 -0
  37. {simoptlib-1.3.0.dev0.dist-info → simoptlib-1.3.0.dev1.dist-info}/licenses/LICENSE +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: simoptlib
3
- Version: 1.3.0.dev0
3
+ Version: 1.3.0.dev1
4
4
  Summary: A testbed for simulation-optimization experiments.
5
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
@@ -35,6 +35,7 @@ Description-Content-Type: text/markdown
35
35
  License-File: LICENSE
36
36
  Requires-Dist: boltons>=25.0.0
37
37
  Requires-Dist: colorama>=0.4.6
38
+ Requires-Dist: cvxpy>=1.7.3
38
39
  Requires-Dist: fastapi[standard]>=0.128.8
39
40
  Requires-Dist: joblib>=1.5.2
40
41
  Requires-Dist: matplotlib>=3.10.7
@@ -43,13 +44,13 @@ Requires-Dist: numpy<2.4,>=2.3.4
43
44
  Requires-Dist: pandas>=2.3.3
44
45
  Requires-Dist: pandera[pandas]>=0.27.0
45
46
  Requires-Dist: pillow>=12.0.0
47
+ Requires-Dist: pydoe>=0.9.7
46
48
  Requires-Dist: pydantic>=2.12.3
47
49
  Requires-Dist: scipy>=1.16.3
48
50
  Requires-Dist: seaborn>=0.13.2
49
51
  Requires-Dist: simpy>=4.1.2
50
- Requires-Dist: simopt-dsl>=0.1.0
51
- Requires-Dist: simopt-solvers[all]>=0.1.0
52
52
  Requires-Dist: structlog>=25.5.0
53
+ Requires-Dist: sympy>=1.14.0
53
54
  Provides-Extra: dev
54
55
  Requires-Dist: jupytext>=1.18.1; extra == "dev"
55
56
  Requires-Dist: pytest-xdist>=3.8.0; extra == "dev"
@@ -96,39 +96,35 @@ simopt/web/dist/icons.svg,sha256=tF-lBhlc_N70BrqfDHezbdwafCJAQJJuxwq8L96nuTo,503
96
96
  simopt/web/dist/index.html,sha256=S1VQx5NZaJ2nUWEmBMytS5u6MC8VDwpUKoWx50TyGMw,455
97
97
  simopt/web/dist/assets/index-BsdjTlAU.js,sha256=T8Wf0m6ggDq3O-AQDaSpDE9oC8KkIjiP613zigkaiPU,97930
98
98
  simopt/web/dist/assets/index-CdXZ_qpx.css,sha256=HMGinUHbIJVqqXR0BNjLC2aCUdfEOMDmbNcaTSPEMXM,22540
99
- simopt-dsl/src/simopt_dsl/__init__.py,sha256=lrUTzzohYj-zegn_JiX6ImJ1gn0Lr9zpivxqFmK2HaY,331
100
- simopt-dsl/src/simopt_dsl/expressions.py,sha256=m9PwnT5KvPzg09v1TjY5Y-art453MaB4sHXA4XMksuc,9119
101
- simopt-dsl/src/simopt_dsl/model.py,sha256=SckfipHJuFV7zRanezoWFi8ZVW-Ty7--r8YK6wXnIbg,31333
102
- simopt-dsl/src/simopt_dsl/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
103
- simopt-dsl/src/simopt_dsl/simulation.py,sha256=OGhA_ju9orU6IVNwxoBj2Mwz6E1EDY7JNyhvKBjAwu8,8243
104
- simopt-dsl/src/simopt_dsl/variables.py,sha256=g-9swls-lNm0NW4rKgxoFSHCp9tsEatgKbxHCA98AYs,2103
105
- simopt-dsl/tests/test_model.py,sha256=-bhqaeLRDs2t_nOIpVgZcwKBo5DoT30HRFI4GD19LqM,5677
106
- simopt-solvers/src/simopt_solvers/__init__.py,sha256=qjZQzAWC8CZbGjPZ61Dwybnz5StOLdzRyvMXB7frGo8,2023
107
- simopt-solvers/src/simopt_solvers/_utils.py,sha256=KYvEQGzHSi84beW05wR2sMwyR-sVpi16P55IJ0VQCK0,2421
108
- simopt-solvers/src/simopt_solvers/base.py,sha256=rFESFTqOS1Xas7RUoAQpRm5w921Jl9HU3kKAS-wkuhE,310
109
- simopt-solvers/src/simopt_solvers/problem_types.py,sha256=F4gnbMtzHRwMsTAfgNX7unEnOTKi0D1-zy-WyVuUq8E,1275
110
- simopt-solvers/src/simopt_solvers/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
111
- simopt-solvers/src/simopt_solvers/solution.py,sha256=UUCBge4RJxQTRCrz7NsWmx05Rpi4y6HvD4al1LtoN1I,10076
112
- simopt-solvers/src/simopt_solvers/solver.py,sha256=SZRSml4-PAoYf2pogGaflZ8YC-IyB-nBS6JVwm9_E4w,11379
113
- simopt-solvers/src/simopt_solvers/solvers/__init__.py,sha256=qWPxN1tMoPHGO51xfgT-YJZFChWdcykn5BtmcCyK65M,39
114
- simopt-solvers/src/simopt_solvers/solvers/_dasso.py,sha256=zTqKUPdzl3b6J-dbBh0galdJTq_dZrTH3Eqne2Zm9TI,4085
115
- simopt-solvers/src/simopt_solvers/solvers/adam.py,sha256=Mjbr13AGg2J48vEsbE8TGB4ZVm_g3PzHfK43932gnPI,5403
116
- simopt-solvers/src/simopt_solvers/solvers/aloe.py,sha256=j3lXcmiyn4kS1D_v6mN6UOTo05y_emBqATmvcVUe05k,5622
117
- simopt-solvers/src/simopt_solvers/solvers/astrodf.py,sha256=KmG47HF59IfbZ6WSecP97vbcPj7AtxG_EMhcNwQenUU,40669
118
- simopt-solvers/src/simopt_solvers/solvers/castrodf.py,sha256=KUnC3JgUwSutaODMPcnKMcCnKS14aXn1nbQbH_E1HEU,84212
119
- simopt-solvers/src/simopt_solvers/solvers/dasso.py,sha256=9fR996AzB5aXHkTlkAcdKlDy5ekNRoEuV55NEb8fx2U,64829
120
- simopt-solvers/src/simopt_solvers/solvers/fcsa.py,sha256=pBj1OLcwh8KPniP6ki-hag_MypbbLiroyZ7E4P6zRGw,11422
121
- simopt-solvers/src/simopt_solvers/solvers/neldmd.py,sha256=Xz6YXnCTlA0evSt4NkEMoV4zV0fcZlVUVa-8JRUsUUY,12990
122
- simopt-solvers/src/simopt_solvers/solvers/randomsearch.py,sha256=6qU7RMPL5QvIPQQVq2hh9EIZQ097FNyvgDGECNvTTZ8,2813
123
- simopt-solvers/src/simopt_solvers/solvers/spsa.py,sha256=ejDh3XgVlhwfjkqkhktp6iJw9BI0sBTFdHZKGGPGI6Y,11379
124
- simopt-solvers/src/simopt_solvers/solvers/strong.py,sha256=Xle4jzTLns9QYObtumY8LFFH4vj13zA_k3uns1k449I,18697
125
- simopt-solvers/src/simopt_solvers/solvers/utils.py,sha256=p1IfNQt9nsvNIinB3P7xB-aNn5VbYyI98zXwMIG8g9Y,12079
126
- simopt-solvers/tests/test_solve.py,sha256=efPty1W3mWFNu_jQz6x_BpSdOLi8l_ei-VeF2ffX_vU,2800
127
- simopt-solvers/tests/test_specifications.py,sha256=u2i_3RURoLzQHXQTQbntf3nQGCsDNsqXmvgV73HBVHg,1658
128
- simopt-web/node_modules/flatted/python/flatted.py,sha256=94TCVN52olQ166phxylCByczrktCYZuUO_N7CfpF5kQ,3773
129
- simoptlib-1.3.0.dev0.dist-info/licenses/LICENSE,sha256=3WAn8U4vCLx6JSFLUuPlykqEb0oQOH9OY2uhRXLo4sE,1090
130
- simoptlib-1.3.0.dev0.dist-info/METADATA,sha256=IJBdRQw-RuuYoKbaOnN2jQx35mDTUQ74-eM7QiYjuwg,16500
131
- simoptlib-1.3.0.dev0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
132
- simoptlib-1.3.0.dev0.dist-info/entry_points.txt,sha256=i8W853gNtgcn0vX3SrHV08-sHcRpmHMMnEfehQp6Jyo,43
133
- simoptlib-1.3.0.dev0.dist-info/top_level.txt,sha256=yNha7A8iFQG5JMjPy6QuR3iwkR6E4V3fNF5l-HrBxXo,44
134
- simoptlib-1.3.0.dev0.dist-info/RECORD,,
99
+ simopt_dsl/__init__.py,sha256=lrUTzzohYj-zegn_JiX6ImJ1gn0Lr9zpivxqFmK2HaY,331
100
+ simopt_dsl/expressions.py,sha256=m9PwnT5KvPzg09v1TjY5Y-art453MaB4sHXA4XMksuc,9119
101
+ simopt_dsl/model.py,sha256=SckfipHJuFV7zRanezoWFi8ZVW-Ty7--r8YK6wXnIbg,31333
102
+ simopt_dsl/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
103
+ simopt_dsl/simulation.py,sha256=OGhA_ju9orU6IVNwxoBj2Mwz6E1EDY7JNyhvKBjAwu8,8243
104
+ simopt_dsl/variables.py,sha256=g-9swls-lNm0NW4rKgxoFSHCp9tsEatgKbxHCA98AYs,2103
105
+ simopt_solvers/__init__.py,sha256=qjZQzAWC8CZbGjPZ61Dwybnz5StOLdzRyvMXB7frGo8,2023
106
+ simopt_solvers/_utils.py,sha256=KYvEQGzHSi84beW05wR2sMwyR-sVpi16P55IJ0VQCK0,2421
107
+ simopt_solvers/base.py,sha256=rFESFTqOS1Xas7RUoAQpRm5w921Jl9HU3kKAS-wkuhE,310
108
+ simopt_solvers/problem_types.py,sha256=F4gnbMtzHRwMsTAfgNX7unEnOTKi0D1-zy-WyVuUq8E,1275
109
+ simopt_solvers/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
110
+ simopt_solvers/solution.py,sha256=UUCBge4RJxQTRCrz7NsWmx05Rpi4y6HvD4al1LtoN1I,10076
111
+ simopt_solvers/solver.py,sha256=SZRSml4-PAoYf2pogGaflZ8YC-IyB-nBS6JVwm9_E4w,11379
112
+ simopt_solvers/solvers/__init__.py,sha256=qWPxN1tMoPHGO51xfgT-YJZFChWdcykn5BtmcCyK65M,39
113
+ simopt_solvers/solvers/_dasso.py,sha256=zTqKUPdzl3b6J-dbBh0galdJTq_dZrTH3Eqne2Zm9TI,4085
114
+ simopt_solvers/solvers/adam.py,sha256=Mjbr13AGg2J48vEsbE8TGB4ZVm_g3PzHfK43932gnPI,5403
115
+ simopt_solvers/solvers/aloe.py,sha256=j3lXcmiyn4kS1D_v6mN6UOTo05y_emBqATmvcVUe05k,5622
116
+ simopt_solvers/solvers/astrodf.py,sha256=KmG47HF59IfbZ6WSecP97vbcPj7AtxG_EMhcNwQenUU,40669
117
+ simopt_solvers/solvers/castrodf.py,sha256=KUnC3JgUwSutaODMPcnKMcCnKS14aXn1nbQbH_E1HEU,84212
118
+ simopt_solvers/solvers/dasso.py,sha256=9fR996AzB5aXHkTlkAcdKlDy5ekNRoEuV55NEb8fx2U,64829
119
+ simopt_solvers/solvers/fcsa.py,sha256=pBj1OLcwh8KPniP6ki-hag_MypbbLiroyZ7E4P6zRGw,11422
120
+ simopt_solvers/solvers/neldmd.py,sha256=Xz6YXnCTlA0evSt4NkEMoV4zV0fcZlVUVa-8JRUsUUY,12990
121
+ simopt_solvers/solvers/randomsearch.py,sha256=6qU7RMPL5QvIPQQVq2hh9EIZQ097FNyvgDGECNvTTZ8,2813
122
+ simopt_solvers/solvers/spsa.py,sha256=ejDh3XgVlhwfjkqkhktp6iJw9BI0sBTFdHZKGGPGI6Y,11379
123
+ simopt_solvers/solvers/strong.py,sha256=Xle4jzTLns9QYObtumY8LFFH4vj13zA_k3uns1k449I,18697
124
+ simopt_solvers/solvers/utils.py,sha256=p1IfNQt9nsvNIinB3P7xB-aNn5VbYyI98zXwMIG8g9Y,12079
125
+ simoptlib-1.3.0.dev1.dist-info/licenses/LICENSE,sha256=3WAn8U4vCLx6JSFLUuPlykqEb0oQOH9OY2uhRXLo4sE,1090
126
+ simoptlib-1.3.0.dev1.dist-info/METADATA,sha256=hKZkg5AYGPBLW5CUofXTybpqTZ7NpmFg3JAhcNsUKes,16510
127
+ simoptlib-1.3.0.dev1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
128
+ simoptlib-1.3.0.dev1.dist-info/entry_points.txt,sha256=i8W853gNtgcn0vX3SrHV08-sHcRpmHMMnEfehQp6Jyo,43
129
+ simoptlib-1.3.0.dev1.dist-info/top_level.txt,sha256=0UciL1jwZJr-og836d41isniDbNH2dsFiBqxXr2k7TU,33
130
+ simoptlib-1.3.0.dev1.dist-info/RECORD,,
@@ -0,0 +1,3 @@
1
+ simopt
2
+ simopt_dsl
3
+ simopt_solvers
@@ -1,184 +0,0 @@
1
- """Tests for model declarations and replication evaluation."""
2
-
3
- import math
4
- import random
5
- import warnings
6
-
7
- import pytest
8
-
9
- from simopt_dsl import Model
10
-
11
-
12
- def test_vector_component_does_not_alias_scalar_with_same_name() -> None:
13
- model = Model()
14
- vector = model.add_continuous_vector(0, 10, name="x", shape=1)
15
- scalar = model.add_continuous_variable(0, 10, name="x[0]")
16
- model.minimize(vector[0])
17
-
18
- assert vector[0] != scalar
19
-
20
- evaluation = model.run_replication((2, 7), [object()])
21
-
22
- assert evaluation.objective == 2
23
- assert evaluation.objective_gradient == (1, 0)
24
-
25
-
26
- def _gradient_model(*, gradients: bool) -> Model:
27
- model = Model()
28
- x = model.add_continuous_variable(0, 10, name="x")
29
-
30
- def run(decisions: dict, rngs: list) -> tuple[dict, dict]:
31
- return {"y": decisions["x"] ** 2}, {"y": {"x": 2 * decisions["x"]}}
32
-
33
- simulation = model.add_simulation(run=run, decisions={"x": x}, gradients=gradients)
34
- model.minimize(simulation.metric("y"))
35
- return model
36
-
37
-
38
- def test_gradient_available_follows_simulation_flag() -> None:
39
- assert _gradient_model(gradients=True).gradient_available
40
- assert not _gradient_model(gradients=False).gradient_available
41
-
42
-
43
- def test_gradient_available_without_simulation_metrics() -> None:
44
- model = Model()
45
- x = model.add_continuous_variable(0, 10)
46
- model.minimize(2 * x)
47
-
48
- assert model.gradient_available
49
-
50
-
51
- def test_gradient_available_ignores_simulations_outside_objective() -> None:
52
- model = Model()
53
- x = model.add_continuous_variable(0, 10, name="x")
54
-
55
- def run(decisions: dict, rngs: list) -> tuple[dict, dict]:
56
- return {"y": decisions["x"]}, {}
57
-
58
- used = model.add_simulation(
59
- name="used",
60
- run=lambda decisions, rngs: ({"y": decisions["x"]}, {"y": {"x": 1.0}}),
61
- decisions={"x": x},
62
- gradients=True,
63
- )
64
- unused = model.add_simulation(name="unused", run=run, decisions={"x": x})
65
- model.minimize(used.metric("y"))
66
- model.add_stochastic_constraint(unused.metric("y") <= 5)
67
-
68
- assert model.gradient_available
69
-
70
-
71
- def test_gradient_available_without_objective() -> None:
72
- assert not Model().gradient_available
73
-
74
-
75
- def test_random_solution_uses_sampler() -> None:
76
- model = Model()
77
- model.add_continuous_vector(0, 10, shape=2)
78
- model.set_random_solution(lambda rng: [rng.uniform(0, 1), 5])
79
-
80
- solution = model.random_solution(random.Random(0))
81
-
82
- assert isinstance(solution, tuple)
83
- assert solution[1] == 5
84
-
85
- model.set_random_solution(None)
86
- assert model._random_solution is None
87
-
88
-
89
- def test_random_solution_default_respects_bounds_and_integers() -> None:
90
- model = Model()
91
- model.add_continuous_variable(-1, 1)
92
- model.add_integer_vector(0, 3, shape=3)
93
- rng = random.Random(0)
94
-
95
- for _ in range(100):
96
- x, *ks = model.random_solution(rng)
97
- assert -1 <= x <= 1
98
- assert all(k in (0, 1, 2, 3) for k in ks)
99
-
100
-
101
- def test_random_solution_default_respects_deterministic_constraints() -> None:
102
- model = Model()
103
- x = model.add_continuous_variable(0, 10)
104
- y = model.add_continuous_variable(0, 10)
105
- model.add_linear_constraint(x + y <= 5)
106
- rng = random.Random(0)
107
-
108
- for _ in range(50):
109
- a, b = model.random_solution(rng)
110
- assert a + b <= 5
111
-
112
-
113
- def test_random_solution_default_rejects_infinite_bounds() -> None:
114
- model = Model()
115
- model.add_continuous_variable(0, math.inf)
116
-
117
- with pytest.raises(ValueError, match="infinite bound"):
118
- model.random_solution(random.Random(0))
119
-
120
-
121
- def test_derivatives_without_gradients_flag_warn() -> None:
122
- model = _gradient_model(gradients=False)
123
-
124
- with pytest.warns(UserWarning, match="gradients=False"):
125
- evaluation = model.run_replication((3,), [object()])
126
-
127
- assert evaluation.objective_gradient == (6,)
128
-
129
-
130
- def test_derivatives_with_gradients_flag_do_not_warn() -> None:
131
- model = _gradient_model(gradients=True)
132
-
133
- with warnings.catch_warnings():
134
- warnings.simplefilter("error")
135
- model.run_replication((3,), [object()])
136
-
137
-
138
- def test_dim_counts_scalar_components() -> None:
139
- model = Model()
140
- model.add_continuous_variable(0, 1, name="a")
141
- model.add_continuous_vector(0, 1, name="q", shape=3)
142
-
143
- assert model.dim == 4
144
-
145
-
146
- def test_n_stochastic_constraints() -> None:
147
- model = Model()
148
- x = model.add_continuous_variable(0, 1)
149
- model.add_stochastic_constraint(x <= 0.5)
150
- model.add_stochastic_constraint(x >= 0.1)
151
-
152
- assert model.n_stochastic_constraints == 2
153
-
154
-
155
- def test_integer_variables_store_ints_and_keep_infinite_bounds() -> None:
156
- model = Model()
157
- model.add_integer_variable(0, math.inf, initial=3)
158
- model.add_integer_vector(1, 5, shape=2, initial=[2, 4])
159
- model.add_continuous_variable(0, 1, initial=0)
160
-
161
- assert [type(b) for b in model.lower_bounds()] == [int, int, int, float]
162
- assert [type(b) for b in model.upper_bounds()] == [float, int, int, float]
163
- assert model.upper_bounds()[0] == math.inf
164
- assert [type(v) for v in model.initial_vector()] == [int, int, int, float]
165
-
166
-
167
- def test_integer_values_passed_to_simulation_as_ints() -> None:
168
- model = Model()
169
- n = model.add_integer_variable(0, 10, name="n")
170
- seen = {}
171
-
172
- def run(decisions: dict, rngs: list) -> tuple[dict, dict]:
173
- seen.update(decisions)
174
- return {"y": float(sum(range(decisions["n"])))}, {}
175
-
176
- simulation = model.add_simulation(run=run, decisions={"n": n})
177
- model.minimize(simulation.metric("y"))
178
-
179
- evaluation = model.run_replication((4.0,), [object()])
180
-
181
- assert type(seen["n"]) is int
182
- assert evaluation.objective == 6
183
- assert model.unpack_vector((4.0,)) == {"n": 4}
184
- assert type(model.unpack_vector((4.0,))["n"]) is int
@@ -1,86 +0,0 @@
1
- """Tests for running solvers on DSL models with ``solve``."""
2
-
3
- import subprocess
4
- import sys
5
- import textwrap
6
-
7
- import pandas as pd
8
- import pytest
9
- import simopt_dsl as dsl
10
-
11
- from simopt_solvers import ADAM, RandomSearch, solve
12
-
13
-
14
- def _noisy_quadratic() -> dsl.Model:
15
- model = dsl.Model()
16
- x = model.add_continuous_vector(-10, 10, name="x", shape=2, initial=[5, -5])
17
-
18
- def run(decisions: dict, rngs: list) -> tuple[dict, dict]:
19
- x1, x2 = decisions["x"]
20
- cost = (x1 - 3) ** 2 + (x2 + 1) ** 2 + rngs[0].normalvariate(0, 1)
21
- return {"cost": cost}, {}
22
-
23
- simulation = model.add_simulation(run=run, decisions={"x": x})
24
- model.minimize(dsl.mean(simulation.metric("cost")))
25
- return model
26
-
27
-
28
- def test_solve_dsl_model() -> None:
29
- model = _noisy_quadratic()
30
- model.set_random_solution(lambda rng: (rng.uniform(-10, 10), rng.uniform(-10, 10)))
31
-
32
- result = solve(model, RandomSearch(), budget=500, seed=0)
33
-
34
- assert isinstance(result.history, pd.DataFrame)
35
- assert result.x is not None
36
- assert result.x == result.history["solution"].iloc[-1]
37
- assert all(-10 <= value <= 10 for value in result.x)
38
- assert 0 < result.budget_used <= 500
39
-
40
-
41
- def test_solve_gradient_free_continuous_solver() -> None:
42
- result = solve(_noisy_quadratic(), ADAM(), budget=2000, seed=0)
43
-
44
- assert result.x is not None
45
- x1, x2 = result.x
46
- assert abs(x1 - 3) < abs(5 - 3)
47
- assert abs(x2 + 1) < abs(-5 + 1)
48
-
49
-
50
- def test_solve_is_reproducible_per_seed() -> None:
51
- first = solve(_noisy_quadratic(), ADAM(), budget=1000, seed=3)
52
- second = solve(_noisy_quadratic(), ADAM(), budget=1000, seed=3)
53
- other = solve(_noisy_quadratic(), ADAM(), budget=1000, seed=4)
54
-
55
- assert first.history.equals(second.history)
56
- assert not first.history.equals(other.history)
57
-
58
-
59
- @pytest.mark.parametrize(("budget", "seed"), [(0, 0), (100, -1)])
60
- def test_solve_rejects_invalid_arguments(budget: int, seed: int) -> None:
61
- with pytest.raises(ValueError):
62
- solve(_noisy_quadratic(), RandomSearch(), budget=budget, seed=seed)
63
-
64
-
65
- def test_solving_does_not_import_simopt_benchmark() -> None:
66
- code = textwrap.dedent(
67
- """
68
- import sys
69
-
70
- import simopt_dsl as dsl
71
- from simopt_solvers import ADAM, solve
72
-
73
- model = dsl.Model()
74
- x = model.add_continuous_variable(0, 10, initial=5)
75
- simulation = model.add_simulation(
76
- run=lambda decisions, rngs: ({"y": (decisions["x"] - 2) ** 2}, {}),
77
- decisions={"x": x},
78
- )
79
- model.minimize(dsl.mean(simulation.metric("y")))
80
- solve(model, ADAM(), budget=200)
81
-
82
- loaded = sorted(m for m in sys.modules if m == "simopt" or m.startswith("simopt."))
83
- assert not loaded, loaded
84
- """
85
- )
86
- subprocess.run([sys.executable, "-c", code], check=True)
@@ -1,55 +0,0 @@
1
- """Tests for deriving solver specifications from configuration fields."""
2
-
3
- import pytest
4
- from pydantic import BaseModel, Field
5
-
6
- from simopt_solvers._utils import get_specifications
7
-
8
-
9
- def test_specifications_preserve_defaults_aliases_and_metadata():
10
- class Config(BaseModel):
11
- count: int = Field(3, alias="n", description="Sample count")
12
- weights: tuple[float, ...] = Field(
13
- default_factory=lambda: (1.0, 2.0),
14
- json_schema_extra={"isDatafarmable": False},
15
- )
16
-
17
- specifications = get_specifications(Config)
18
-
19
- assert specifications["n"] == {
20
- "description": "Sample count",
21
- "datatype": int,
22
- "default": 3,
23
- }
24
- assert specifications["weights"] == {
25
- "description": None,
26
- "datatype": list,
27
- "default": [1.0, 2.0],
28
- "isDatafarmable": False,
29
- }
30
-
31
-
32
- def test_specifications_resolve_factories_using_prior_field_defaults():
33
- class Config(BaseModel):
34
- bounds: tuple[int, int] = (1, 5)
35
- upper: int = Field(default_factory=lambda data: data["bounds"][1])
36
-
37
- assert get_specifications(Config)["upper"]["default"] == 5
38
-
39
-
40
- def test_specifications_reject_required_fields():
41
- class Config(BaseModel):
42
- count: int
43
-
44
- with pytest.raises(ValueError, match="Configuration field 'count' must have a default"):
45
- get_specifications(Config)
46
-
47
-
48
- def test_specifications_allow_callable_schema_metadata():
49
- def add_title(schema: dict) -> None:
50
- schema["title"] = "Sample count"
51
-
52
- class Config(BaseModel):
53
- count: int = Field(3, json_schema_extra=add_title)
54
-
55
- assert get_specifications(Config)["count"]["default"] == 3
@@ -1,144 +0,0 @@
1
- # ISC License
2
- #
3
- # Copyright (c) 2018-2025, Andrea Giammarchi, @WebReflection
4
- #
5
- # Permission to use, copy, modify, and/or distribute this software for any
6
- # purpose with or without fee is hereby granted, provided that the above
7
- # copyright notice and this permission notice appear in all copies.
8
- #
9
- # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
- # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
- # AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
- # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
- # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14
- # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
- # PERFORMANCE OF THIS SOFTWARE.
16
-
17
- import json as _json
18
-
19
- class _Known:
20
- def __init__(self):
21
- self.key = []
22
- self.value = []
23
-
24
- class _String:
25
- def __init__(self, value):
26
- self.value = value
27
-
28
- def _array_keys(value):
29
- for i in range(len(value)):
30
- yield i
31
-
32
- def _object_keys(value):
33
- for key in value:
34
- yield key
35
-
36
- def _is_array(value):
37
- return isinstance(value, (list, tuple))
38
-
39
- def _is_object(value):
40
- return isinstance(value, dict)
41
-
42
- def _is_string(value):
43
- return isinstance(value, str)
44
-
45
- def _index(known, input, value):
46
- input.append(value)
47
- index = str(len(input) - 1)
48
- known.key.append(value)
49
- known.value.append(index)
50
- return index
51
-
52
- def _relate(known, input, value):
53
- if _is_string(value) or _is_array(value) or _is_object(value):
54
- try:
55
- return known.value[known.key.index(value)]
56
- except:
57
- return _index(known, input, value)
58
-
59
- return value
60
-
61
- def _resolver(input, lazy, parsed):
62
- def resolver(output):
63
- keys = _array_keys(output) if _is_array(output) else _object_keys(output) if _is_object(output) else []
64
- for key in keys:
65
- value = output[key]
66
- if isinstance(value, _String):
67
- tmp = input[int(value.value)]
68
- output[key] = tmp
69
- if (_is_array(tmp) or _is_object(tmp)) and tmp not in parsed:
70
- parsed.append(tmp)
71
- lazy.append([output, key])
72
-
73
- return output
74
-
75
- return resolver
76
-
77
- def _transform(known, input, value):
78
- if _is_array(value):
79
- output = []
80
- for val in value:
81
- output.append(_relate(known, input, val))
82
- return output
83
-
84
- if _is_object(value):
85
- obj = {}
86
- for key in value:
87
- obj[key] = _relate(known, input, value[key])
88
- return obj
89
-
90
- return value
91
-
92
- def _wrap(value):
93
- if _is_string(value):
94
- return _String(value)
95
-
96
- if _is_array(value):
97
- i = 0
98
- for val in value:
99
- value[i] = _wrap(val)
100
- i += 1
101
-
102
- elif _is_object(value):
103
- for key in value:
104
- value[key] = _wrap(value[key])
105
-
106
- return value
107
-
108
- def parse(value, *args, **kwargs):
109
- json = _json.loads(value, *args, **kwargs)
110
- wrapped = []
111
- for value in json:
112
- wrapped.append(_wrap(value))
113
-
114
- input = []
115
- for value in wrapped:
116
- if isinstance(value, _String):
117
- input.append(value.value)
118
- else:
119
- input.append(value)
120
-
121
- value = input[0]
122
- lazy = []
123
- revive = _resolver(input, lazy, [value])
124
-
125
- value = revive(value)
126
-
127
- i = 0
128
- while i < len(lazy):
129
- o, k = lazy[i]
130
- i += 1
131
- o[k] = revive(o[k])
132
-
133
- return value
134
-
135
-
136
- def stringify(value, *args, **kwargs):
137
- known = _Known()
138
- input = []
139
- output = []
140
- i = int(_index(known, input, value))
141
- while i < len(input):
142
- output.append(_transform(known, input, input[i]))
143
- i += 1
144
- return _json.dumps(output, *args, **kwargs)
@@ -1,4 +0,0 @@
1
- simopt
2
- simopt-dsl
3
- simopt-solvers
4
- simopt-web
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes