hone-python 0.13.0__py3-none-any.whl → 0.15.0__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.
- hone/__init__.py +2 -1
- hone/benchmarks/__init__.py +4 -0
- hone/benchmarks/__main__.py +138 -4
- hone/benchmarks/constrained.py +114 -7
- hone/benchmarks/cost.py +530 -0
- hone/benchmarks/engineering.py +92 -0
- hone/benchmarks/multi.py +127 -19
- hone/benchmarks/multi_outputs.py +312 -0
- hone/benchmarks/outputs.py +276 -0
- hone/benchmarks/problems.py +2 -1
- hone/benchmarks/runner.py +202 -32
- hone/benchmarks/sharded.py +150 -0
- hone/config/multi_objective_config.py +8 -4
- hone/config/optimizer_config.py +24 -4
- hone/objective_function/objective_function.py +8 -2
- hone/optimizers/_gp.py +41 -6
- hone/optimizers/_pool.py +37 -0
- hone/optimizers/base.py +165 -45
- hone/optimizers/bayesian.py +171 -24
- hone/optimizers/choice.py +16 -2
- hone/optimizers/cmaes.py +4 -2
- hone/optimizers/core.py +156 -9
- hone/optimizers/genetic/nsga2.py +23 -3
- hone/optimizers/genetic/optimizer.py +6 -3
- hone/optimizers/genetic/selection.py +30 -7
- hone/optimizers/multi.py +262 -12
- hone/optimizers/multi_bayesian.py +51 -10
- hone/parameters/__init__.py +1 -1
- hone/parameters/conditions.py +18 -2
- hone/parameters/constraints.py +189 -36
- hone/parameters/parameters.py +90 -10
- hone/pareto.py +10 -2
- hone/result.py +25 -3
- hone/sensitivity_analysis.py +27 -12
- {hone_python-0.13.0.dist-info → hone_python-0.15.0.dist-info}/METADATA +75 -11
- hone_python-0.15.0.dist-info/RECORD +51 -0
- hone_python-0.13.0.dist-info/RECORD +0 -46
- {hone_python-0.13.0.dist-info → hone_python-0.15.0.dist-info}/WHEEL +0 -0
- {hone_python-0.13.0.dist-info → hone_python-0.15.0.dist-info}/licenses/LICENSE +0 -0
hone/__init__.py
CHANGED
|
@@ -15,7 +15,7 @@ from hone.optimizers import (
|
|
|
15
15
|
choose_optimizer,
|
|
16
16
|
choose_pareto_optimizer,
|
|
17
17
|
)
|
|
18
|
-
from hone.parameters import ChoiceParameter, Condition, Constraint, FixedParameter, InfeasibleSearchSpace, RangeParameter, SearchSpace
|
|
18
|
+
from hone.parameters import ChoiceParameter, Condition, Constraint, FixedParameter, InfeasibleSearchSpace, Output, RangeParameter, SearchSpace
|
|
19
19
|
from hone.pareto import Front, ParetoGenerationStats, ParetoPoint, ParetoProgress, ParetoResult
|
|
20
20
|
from hone.result import GenerationStats, Progress, Result, RunInfo, print_progress
|
|
21
21
|
from hone.sensitivity_analysis import Interval, ParameterSensitivity, SensitivityReport, sensitivity
|
|
@@ -47,6 +47,7 @@ __all__ = [
|
|
|
47
47
|
"NSGA2Config",
|
|
48
48
|
"Optimizer",
|
|
49
49
|
"OptimizerConfig",
|
|
50
|
+
"Output",
|
|
50
51
|
"ParameterSensitivity",
|
|
51
52
|
"ParetoGenerationStats",
|
|
52
53
|
"ParetoPoint",
|
hone/benchmarks/__init__.py
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"""Benchmark problems and a runner for comparing optimizers. Run `python -m hone.benchmarks --help`."""
|
|
2
2
|
from .conditional import conditional_problems
|
|
3
3
|
from .constrained import constrained_problems
|
|
4
|
+
from .engineering import engineering_problems, engineering_table
|
|
4
5
|
from .ml import ml_problems
|
|
5
6
|
from .multi import MultiProblem, multi_problems, run_multi_benchmark, summarize_multi
|
|
7
|
+
from .multi_outputs import cantilever_outputs, noisy_multi_output_problems, osy, tnk
|
|
8
|
+
from .outputs import noisy_output_problems, output_problems
|
|
6
9
|
from .problems import Problem, noisy_problems, quick_problems, standard_problems
|
|
7
10
|
from .runner import (
|
|
8
11
|
BUDGETS,
|
|
@@ -10,6 +13,7 @@ from .runner import (
|
|
|
10
13
|
Run,
|
|
11
14
|
SkipBudget,
|
|
12
15
|
Summary,
|
|
16
|
+
batch_optimizers,
|
|
13
17
|
load_summaries,
|
|
14
18
|
regressions,
|
|
15
19
|
run_benchmark,
|
hone/benchmarks/__main__.py
CHANGED
|
@@ -4,22 +4,39 @@ import sys
|
|
|
4
4
|
import time
|
|
5
5
|
from collections.abc import Sequence
|
|
6
6
|
from importlib.metadata import version
|
|
7
|
+
from pathlib import Path
|
|
7
8
|
|
|
8
|
-
from . import ml
|
|
9
|
+
from . import cost, engineering, ml
|
|
9
10
|
from .conditional import conditional_problems
|
|
10
11
|
from .multi import multi_markdown, multi_problems, run_multi_benchmark, summarize_multi
|
|
11
12
|
from .constrained import constrained_problems
|
|
13
|
+
from .outputs import noisy_output_problems, output_problems
|
|
12
14
|
from .problems import noisy_problems, quick_problems, standard_problems
|
|
13
|
-
from .runner import
|
|
15
|
+
from .runner import (
|
|
16
|
+
BUDGETS,
|
|
17
|
+
DEFAULT_OPTIMIZERS,
|
|
18
|
+
batch_optimizers,
|
|
19
|
+
load_summaries,
|
|
20
|
+
regressions,
|
|
21
|
+
run_benchmark,
|
|
22
|
+
save_summaries,
|
|
23
|
+
summarize,
|
|
24
|
+
to_markdown,
|
|
25
|
+
)
|
|
14
26
|
|
|
15
27
|
|
|
16
28
|
QUICK_BUDGETS = (10, 50, 200)
|
|
17
29
|
NOISY_BUDGETS = (10, 40, 200)
|
|
30
|
+
OUTPUT_BATCH_SIZES = (4, 8) # Bayesian optimization's batch sizes run on the problems with constraints on outputs, besides 1
|
|
18
31
|
|
|
19
32
|
|
|
20
33
|
def _join(numbers: list[int]) -> str:
|
|
21
34
|
"""[10, 20, 50] -> "10, 20 and 50"."""
|
|
22
|
-
|
|
35
|
+
return _join_words([f"{n:,}" for n in numbers])
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _join_words(words: list[str]) -> str:
|
|
39
|
+
"""["a", "b", "c"] -> "a, b and c"."""
|
|
23
40
|
return words[0] if len(words) == 1 else ", ".join(words[:-1]) + " and " + words[-1]
|
|
24
41
|
|
|
25
42
|
|
|
@@ -30,12 +47,34 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
30
47
|
suite.add_argument("--ml", action="store_true", help="run the machine learning tuning problems instead (needs scikit-learn)")
|
|
31
48
|
suite.add_argument("--noisy", action="store_true", help="run the problems with noise added to every evaluation instead")
|
|
32
49
|
suite.add_argument("--constrained", action="store_true", help="run the problems with constraints instead")
|
|
50
|
+
suite.add_argument(
|
|
51
|
+
"--outputs", action="store_true", help="run the problems with constraints on outputs instead, the noisy engineering designs included, with Bayesian optimization at batch sizes 1, 4 and 8"
|
|
52
|
+
)
|
|
33
53
|
suite.add_argument(
|
|
34
54
|
"--multi", action="store_true", help="run the problems with several objectives instead, scored by hypervolume"
|
|
35
55
|
)
|
|
56
|
+
suite.add_argument(
|
|
57
|
+
"--cost",
|
|
58
|
+
action="store_true",
|
|
59
|
+
help="time Bayesian optimization's candidates against evaluations and limits on outputs instead, with one profiled run; "
|
|
60
|
+
"--baseline then checks the ceiling at 500 evaluations",
|
|
61
|
+
)
|
|
62
|
+
suite.add_argument(
|
|
63
|
+
"--cost-multi",
|
|
64
|
+
action="store_true",
|
|
65
|
+
help="time MultiObjectiveBayesian's candidates (parego and models, 0 and 8 limits) as --cost does, without the "
|
|
66
|
+
"single-objective table or the profile; --noise times the noisy problem; --baseline checks the ceiling at 500 evaluations",
|
|
67
|
+
)
|
|
36
68
|
suite.add_argument(
|
|
37
69
|
"--conditional", action="store_true", help="run the problems with conditional parameters, and their flat versions, instead"
|
|
38
70
|
)
|
|
71
|
+
suite.add_argument(
|
|
72
|
+
"--engineering",
|
|
73
|
+
action="store_true",
|
|
74
|
+
help="run nothing: tabulate the engineering designs and g06, g07 and g10 against their published optima, "
|
|
75
|
+
"from saved summaries (see --summaries)",
|
|
76
|
+
)
|
|
77
|
+
parser.add_argument("--noise", action="store_true", help="with --cost-multi, also time the noisy problem (noise=True, which needs noise with limits), after the noise-free cells")
|
|
39
78
|
parser.add_argument("--seeds", type=int, help="number of seeds per problem (default 10, or 5 with --quick)")
|
|
40
79
|
parser.add_argument(
|
|
41
80
|
"--budgets",
|
|
@@ -45,8 +84,23 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
45
84
|
f"{' '.join(map(str, QUICK_BUDGETS))} with --quick, {' '.join(map(str, ml.BUDGETS))} with --ml, "
|
|
46
85
|
f"or {' '.join(map(str, NOISY_BUDGETS))} with --noisy)",
|
|
47
86
|
)
|
|
87
|
+
parser.add_argument(
|
|
88
|
+
"--batch-sizes",
|
|
89
|
+
type=int,
|
|
90
|
+
nargs="+",
|
|
91
|
+
metavar="SIZE",
|
|
92
|
+
help="also run Bayesian optimization choosing this many candidates per batch, as bayesian-SIZE (default 4 8 with --outputs)",
|
|
93
|
+
)
|
|
48
94
|
parser.add_argument("--jobs", type=int, default=1, help="share the runs among this many processes (Linux only)")
|
|
49
95
|
parser.add_argument("--tolerance", type=float, default=1e-4, help="error at or below which a run counts as solved")
|
|
96
|
+
parser.add_argument(
|
|
97
|
+
"--summaries",
|
|
98
|
+
nargs="+",
|
|
99
|
+
metavar="FILE",
|
|
100
|
+
default=list(engineering.SOURCES),
|
|
101
|
+
help="with --engineering, the saved summaries to read, a later file's results replacing an earlier one's "
|
|
102
|
+
f"(default {' '.join(engineering.SOURCES)})",
|
|
103
|
+
)
|
|
50
104
|
parser.add_argument("--markdown", help="write the results table to this file")
|
|
51
105
|
parser.add_argument("--save", help="write the summaries as JSON to this file, for use as a baseline")
|
|
52
106
|
parser.add_argument("--baseline", help="compare against summaries saved with --save; exit 1 on a regression")
|
|
@@ -54,6 +108,12 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
54
108
|
|
|
55
109
|
if args.multi:
|
|
56
110
|
return _multi(args)
|
|
111
|
+
if args.cost:
|
|
112
|
+
return _cost(args)
|
|
113
|
+
if args.cost_multi:
|
|
114
|
+
return _cost_multi(args)
|
|
115
|
+
if args.engineering:
|
|
116
|
+
return _engineering(args)
|
|
57
117
|
default_budgets: Sequence[int]
|
|
58
118
|
if args.quick:
|
|
59
119
|
problems, default_budgets = quick_problems(), QUICK_BUDGETS
|
|
@@ -63,15 +123,20 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
63
123
|
problems, default_budgets = noisy_problems(), NOISY_BUDGETS
|
|
64
124
|
elif args.constrained:
|
|
65
125
|
problems, default_budgets = constrained_problems(), BUDGETS
|
|
126
|
+
elif args.outputs:
|
|
127
|
+
problems, default_budgets = output_problems() + noisy_output_problems(), BUDGETS
|
|
66
128
|
elif args.conditional:
|
|
67
129
|
problems, default_budgets = conditional_problems(), BUDGETS
|
|
68
130
|
else:
|
|
69
131
|
problems, default_budgets = standard_problems(), BUDGETS
|
|
70
132
|
seeds = args.seeds or (5 if args.quick else 10)
|
|
71
133
|
budgets = sorted(set(args.budgets or default_budgets))
|
|
134
|
+
batch_sizes = args.batch_sizes if args.batch_sizes is not None else OUTPUT_BATCH_SIZES if args.outputs else ()
|
|
135
|
+
optimizers = {**DEFAULT_OPTIMIZERS, **batch_optimizers(batch_sizes)}
|
|
72
136
|
|
|
73
137
|
start = time.perf_counter()
|
|
74
|
-
|
|
138
|
+
runs = run_benchmark(problems, optimizers, seeds=range(seeds), budgets_per_dimension=budgets, jobs=args.jobs)
|
|
139
|
+
summaries = summarize(runs, args.tolerance)
|
|
75
140
|
elapsed = time.perf_counter() - start
|
|
76
141
|
|
|
77
142
|
table = to_markdown(summaries, args.tolerance)
|
|
@@ -117,5 +182,74 @@ def _multi(args: argparse.Namespace) -> int:
|
|
|
117
182
|
return 0
|
|
118
183
|
|
|
119
184
|
|
|
185
|
+
def _engineering(args: argparse.Namespace) -> int:
|
|
186
|
+
"""The engineering designs against their published optima, from summaries already saved."""
|
|
187
|
+
summaries = [s for path in args.summaries for s in load_summaries(path)]
|
|
188
|
+
table = engineering.engineering_table(summaries)
|
|
189
|
+
print(table)
|
|
190
|
+
if args.markdown:
|
|
191
|
+
sources = _join_words([f"`{Path(path).name}`" for path in args.summaries])
|
|
192
|
+
with open(args.markdown, "w") as f:
|
|
193
|
+
f.write(
|
|
194
|
+
"# Engineering designs against their published optima\n\n"
|
|
195
|
+
f"Generated by `python -m hone.benchmarks --engineering` from {sources}, which the constrained and "
|
|
196
|
+
f"outputs suites save; nothing is run.\n\n{table}"
|
|
197
|
+
)
|
|
198
|
+
return 0
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def _cost(args: argparse.Namespace) -> int:
|
|
202
|
+
"""The cost of a Bayesian candidate: the table, one profiled run, and the ceiling against a saved table."""
|
|
203
|
+
print("Timing Bayesian candidates, one cell at a time:")
|
|
204
|
+
cells = cost.measure_cost(progress=True)
|
|
205
|
+
print("Profiling one run on g07:")
|
|
206
|
+
table = cost.CostTable(
|
|
207
|
+
hone=version("hone-python"),
|
|
208
|
+
machine=cost.machine(),
|
|
209
|
+
dimensions=cost.DIMENSIONS,
|
|
210
|
+
candidates=cost.CANDIDATES,
|
|
211
|
+
seeds=cost.SEEDS,
|
|
212
|
+
cells=cells,
|
|
213
|
+
profile=cost.profile_run(),
|
|
214
|
+
)
|
|
215
|
+
text = cost.cost_markdown(table)
|
|
216
|
+
print(text)
|
|
217
|
+
if args.markdown:
|
|
218
|
+
with open(args.markdown, "w") as f:
|
|
219
|
+
f.write(f"# The cost of a Bayesian candidate\n\nGenerated by `python -m hone.benchmarks --cost`.\n\n{text}")
|
|
220
|
+
if args.save:
|
|
221
|
+
cost.save_cost(table, args.save)
|
|
222
|
+
if args.baseline:
|
|
223
|
+
found = cost.ceiling_breaches(cells, cost.load_cost(args.baseline).cells)
|
|
224
|
+
if found:
|
|
225
|
+
print(f"\nOver the ceiling of ×{cost.CEILING} at {cost.CEILING_AT} evaluations:", *found, sep="\n ")
|
|
226
|
+
return 1
|
|
227
|
+
print(f"\nWithin the ceiling of ×{cost.CEILING} at {cost.CEILING_AT} evaluations.")
|
|
228
|
+
return 0
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def _cost_multi(args: argparse.Namespace) -> int:
|
|
232
|
+
"""The cost of a MultiObjectiveBayesian candidate: the table, and the ceiling against a saved table."""
|
|
233
|
+
print("Timing multi-objective Bayesian candidates, one cell at a time:")
|
|
234
|
+
table = cost.CostTable(
|
|
235
|
+
hone=version("hone-python"), machine=cost.machine(), dimensions=cost.DIMENSIONS, candidates=cost.CANDIDATES, seeds=cost.SEEDS,
|
|
236
|
+
cells=[], multi=cost.measure_multi_cost(progress=True) + (cost.measure_multi_cost(noise=True, progress=True) if args.noise else []),
|
|
237
|
+
)
|
|
238
|
+
text = cost.cost_markdown(table)
|
|
239
|
+
print(text)
|
|
240
|
+
if args.markdown:
|
|
241
|
+
with open(args.markdown, "w") as f:
|
|
242
|
+
f.write(f"# The cost of a multi-objective Bayesian candidate\n\nGenerated by `python -m hone.benchmarks --cost-multi`.\n\n{text}")
|
|
243
|
+
if args.save:
|
|
244
|
+
cost.save_cost(table, args.save)
|
|
245
|
+
if args.baseline:
|
|
246
|
+
found = cost.multi_ceiling_breaches(table.multi, cost.load_cost(args.baseline).multi)
|
|
247
|
+
if found:
|
|
248
|
+
print(f"\nOver the ceiling of ×{cost.CEILING} at {cost.CEILING_AT} evaluations:", *found, sep="\n ")
|
|
249
|
+
return 1
|
|
250
|
+
print(f"\nWithin the ceiling of ×{cost.CEILING} at {cost.CEILING_AT} evaluations.")
|
|
251
|
+
return 0
|
|
252
|
+
|
|
253
|
+
|
|
120
254
|
if __name__ == "__main__":
|
|
121
255
|
sys.exit(main())
|
hone/benchmarks/constrained.py
CHANGED
|
@@ -6,8 +6,16 @@
|
|
|
6
6
|
- rosenbrock-disk: Rosenbrock's function inside the disk x² + y² ≤ 2, whose optimum (1, 1) sits
|
|
7
7
|
on the disk's edge.
|
|
8
8
|
- pressure-vessel, tension-spring and welded-beam: three standard engineering design problems,
|
|
9
|
-
scored against the best designs published for them
|
|
10
|
-
|
|
9
|
+
scored against the best designs published for them, which Cagnina, Esquivel and Coello Coello
|
|
10
|
+
(2008), "Solving engineering optimization problems with the simple constrained particle swarm
|
|
11
|
+
optimizer", Informatica 32(3):319-326, list as problems E02, E04 and E01. The welded beam's
|
|
12
|
+
stress formulas need square roots, so its constraints are functions; the others are
|
|
13
|
+
expressions.
|
|
14
|
+
|
|
15
|
+
Each engineering problem also comes with its limits on outputs, as the -outputs version: the
|
|
16
|
+
objective reports the volume, stresses and so on that the limits apply to, as a simulation
|
|
17
|
+
would, and the optimizer only learns that a design breaks a limit after evaluating it. The
|
|
18
|
+
pairs show what is lost by not knowing a limit beforehand.
|
|
11
19
|
"""
|
|
12
20
|
import math
|
|
13
21
|
import zlib
|
|
@@ -15,7 +23,7 @@ from typing import Any
|
|
|
15
23
|
|
|
16
24
|
import numpy as np
|
|
17
25
|
|
|
18
|
-
from hone.parameters import Constraint, RangeParameter, SearchSpace
|
|
26
|
+
from hone.parameters import Constraint, Output, RangeParameter, SearchSpace
|
|
19
27
|
|
|
20
28
|
from .problems import BOUND, Problem, _shift
|
|
21
29
|
|
|
@@ -76,7 +84,8 @@ def pressure_vessel() -> Problem:
|
|
|
76
84
|
"""A cylindrical vessel with hemispherical heads, at least 1,296,000 cubic inches, of least cost.
|
|
77
85
|
|
|
78
86
|
Shell and head thicknesses come in sixteenths of an inch, so they are integers here. The best
|
|
79
|
-
published design costs 6059.714 (Ts = 13/16, Th = 7/16, R = 42.098, L = 176.637)
|
|
87
|
+
published design costs 6059.714 (Ts = 13/16, Th = 7/16, R = 42.098, L = 176.637)
|
|
88
|
+
(Cagnina et al., 2008, problem E02).
|
|
80
89
|
"""
|
|
81
90
|
shell, head = RangeParameter("shell", 1, 99, integer=True), RangeParameter("head", 1, 99, integer=True)
|
|
82
91
|
radius, length = RangeParameter("radius", 10, 200), RangeParameter("length", 10, 200)
|
|
@@ -99,7 +108,14 @@ def pressure_vessel() -> Problem:
|
|
|
99
108
|
def tension_spring() -> Problem:
|
|
100
109
|
"""A coil spring of least weight under limits on deflection, shear stress, surge frequency and diameter.
|
|
101
110
|
|
|
102
|
-
The best published design weighs 0.0126652 (d = 0.
|
|
111
|
+
The best published design weighs 0.0126652 (d = 0.051689, D = 0.356720, N = 11.288832).
|
|
112
|
+
Cagnina et al., 2008, problem E04, give the design (0.051690, 0.356750, 11.287126) with a
|
|
113
|
+
weight of 0.012665. Its rounded values break the shear stress limit by about 2e-5 (the stress
|
|
114
|
+
is 1.00002 times the limit), which is why they weigh 0.0126651, a little less than the optimum.
|
|
115
|
+
Celik and Kutucu, "Solving the tension/compression spring design problem by an improved
|
|
116
|
+
firefly algorithm", CEUR Workshop Proceedings 2255, paper 2, give the optimum as 0.0126652327883
|
|
117
|
+
at (0.051689156131, 0.356720026419, 11.288831695483), which satisfies every limit here. They
|
|
118
|
+
cite no source for it.
|
|
103
119
|
"""
|
|
104
120
|
d, coil, n = RangeParameter("wire", 0.05, 2.0), RangeParameter("coil", 0.25, 1.3), RangeParameter("turns", 2.0, 15.0)
|
|
105
121
|
|
|
@@ -139,6 +155,7 @@ def welded_beam() -> Problem:
|
|
|
139
155
|
"""A beam welded to a support, of least cost under limits on shear, bending, buckling and deflection.
|
|
140
156
|
|
|
141
157
|
The best published design costs 1.724852 (h = 0.205730, l = 3.470489, t = 9.036624, b = 0.205730).
|
|
158
|
+
Cagnina et al., 2008, problem E01, give the same cost and design with b = 0.205729.
|
|
142
159
|
"""
|
|
143
160
|
weld, length = RangeParameter("weld", 0.1, 2.0), RangeParameter("length", 0.1, 10.0)
|
|
144
161
|
thickness, width = RangeParameter("thickness", 0.1, 10.0), RangeParameter("width", 0.1, 2.0)
|
|
@@ -166,7 +183,97 @@ def welded_beam() -> Problem:
|
|
|
166
183
|
return Problem(name="welded-beam", function=welded_beam, search_space=space, optimum=1.724852, tags=frozenset({"constrained", "engineering"}))
|
|
167
184
|
|
|
168
185
|
|
|
186
|
+
def pressure_vessel_outputs() -> Problem:
|
|
187
|
+
"""The pressure vessel, with its limits on what it reports: the plate thicknesses its radius needs, and its volume."""
|
|
188
|
+
problem = pressure_vessel()
|
|
189
|
+
shell, head = RangeParameter("shell", 1, 99, integer=True), RangeParameter("head", 1, 99, integer=True)
|
|
190
|
+
radius, length = RangeParameter("radius", 10, 200), RangeParameter("length", 10, 200)
|
|
191
|
+
cost = problem.function
|
|
192
|
+
|
|
193
|
+
def pressure_vessel_outputs(shell: int, head: int, radius: float, length: float) -> dict[str, float]:
|
|
194
|
+
return {
|
|
195
|
+
"objective": cost(shell=shell, head=head, radius=radius, length=length),
|
|
196
|
+
"shell_needed": 0.0193 * radius,
|
|
197
|
+
"head_needed": 0.00954 * radius,
|
|
198
|
+
"volume": math.pi * radius**2 * length + 4 / 3 * math.pi * radius**3,
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
space = SearchSpace(
|
|
202
|
+
[shell, head, radius, length],
|
|
203
|
+
[shell / 16 >= Output("shell_needed"), head / 16 >= Output("head_needed"), Output("volume") >= 1_296_000],
|
|
204
|
+
)
|
|
205
|
+
return problem.model_copy(update={"name": "pressure-vessel-outputs", "function": pressure_vessel_outputs, "search_space": space, "tags": problem.tags | {"outputs"}})
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def tension_spring_outputs() -> Problem:
|
|
209
|
+
"""The tension spring, with its deflection, shear stress and surge frequency limits on what it reports."""
|
|
210
|
+
problem = tension_spring()
|
|
211
|
+
d, coil, n = RangeParameter("wire", 0.05, 2.0), RangeParameter("coil", 0.25, 1.3), RangeParameter("turns", 2.0, 15.0)
|
|
212
|
+
weight = problem.function
|
|
213
|
+
|
|
214
|
+
def tension_spring_outputs(wire: float, coil: float, turns: float) -> dict[str, float]:
|
|
215
|
+
if coil == wire:
|
|
216
|
+
return {"objective": math.nan, "deflection": math.nan, "shear": math.nan, "surge": math.nan} # the shear divides by zero: failed
|
|
217
|
+
return {
|
|
218
|
+
"objective": weight(wire=wire, coil=coil, turns=turns),
|
|
219
|
+
"deflection": coil**3 * turns / (71785 * wire**4),
|
|
220
|
+
"shear": (4 * coil**2 - wire * coil) / (12566 * (coil * wire**3 - wire**4)) + 1 / (5108 * wire**2),
|
|
221
|
+
"surge": 140.45 * wire / (coil**2 * turns),
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
space = SearchSpace(
|
|
225
|
+
[d, coil, n],
|
|
226
|
+
[Output("deflection") >= 1, Output("shear") <= 1, Output("surge") >= 1, d + coil <= 1.5],
|
|
227
|
+
)
|
|
228
|
+
return problem.model_copy(update={"name": "tension-spring-outputs", "function": tension_spring_outputs, "search_space": space, "tags": problem.tags | {"outputs"}})
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def welded_beam_outputs() -> Problem:
|
|
232
|
+
"""The welded beam, with its shear, bending, buckling and deflection limits on what it reports.
|
|
233
|
+
|
|
234
|
+
The geometric limits, weld <= width and the cost cap, stay on the parameters, as they would
|
|
235
|
+
in practice: they need no simulation.
|
|
236
|
+
"""
|
|
237
|
+
problem = welded_beam()
|
|
238
|
+
weld, length = RangeParameter("weld", 0.1, 2.0), RangeParameter("length", 0.1, 10.0)
|
|
239
|
+
thickness, width = RangeParameter("thickness", 0.1, 10.0), RangeParameter("width", 0.1, 2.0)
|
|
240
|
+
cost = problem.function
|
|
241
|
+
|
|
242
|
+
def welded_beam_outputs(weld: float, length: float, thickness: float, width: float) -> dict[str, float]:
|
|
243
|
+
return {
|
|
244
|
+
"objective": cost(weld=weld, length=length, thickness=thickness, width=width),
|
|
245
|
+
"shear": _shear(weld, length, thickness),
|
|
246
|
+
"bending": 6 * P * L / (width * thickness**2),
|
|
247
|
+
"buckling": _buckling(thickness, width),
|
|
248
|
+
"deflection": 4 * P * L**3 / (E * thickness**3 * width),
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
space = SearchSpace(
|
|
252
|
+
[weld, length, thickness, width],
|
|
253
|
+
[
|
|
254
|
+
Output("shear") <= 13600,
|
|
255
|
+
Output("bending") <= 30000,
|
|
256
|
+
weld <= width,
|
|
257
|
+
0.10471 * weld**2 + 0.04811 * thickness * width * (14 + length) <= 5,
|
|
258
|
+
Output("deflection") <= 0.25,
|
|
259
|
+
Output("buckling") >= P,
|
|
260
|
+
],
|
|
261
|
+
)
|
|
262
|
+
return problem.model_copy(update={"name": "welded-beam-outputs", "function": welded_beam_outputs, "search_space": space, "tags": problem.tags | {"outputs"}})
|
|
263
|
+
|
|
264
|
+
|
|
169
265
|
def constrained_problems(dimensions: tuple[int, ...] = (2, 5, 10)) -> list[Problem]:
|
|
170
|
-
"""The constrained suite: boundary sphere and ellipsoid in each dimension, Rosenbrock in a disk, and three engineering designs.
|
|
266
|
+
"""The constrained suite: boundary sphere and ellipsoid in each dimension, Rosenbrock in a disk, and three engineering designs.
|
|
267
|
+
|
|
268
|
+
Each engineering design comes twice: with its limits on the parameters, and on its outputs.
|
|
269
|
+
"""
|
|
171
270
|
problems = [factory(d) for d in dimensions for factory in (boundary_sphere, boundary_ellipsoid)]
|
|
172
|
-
return problems + [
|
|
271
|
+
return problems + [
|
|
272
|
+
rosenbrock_disk(),
|
|
273
|
+
pressure_vessel(),
|
|
274
|
+
tension_spring(),
|
|
275
|
+
welded_beam(),
|
|
276
|
+
pressure_vessel_outputs(),
|
|
277
|
+
tension_spring_outputs(),
|
|
278
|
+
welded_beam_outputs(),
|
|
279
|
+
]
|