metafold 0.13.dev0__tar.gz → 0.13.dev2__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.
- {metafold-0.13.dev0 → metafold-0.13.dev2}/PKG-INFO +1 -1
- {metafold-0.13.dev0 → metafold-0.13.dev2}/metafold/simulation/compression_experiment.py +96 -4
- {metafold-0.13.dev0 → metafold-0.13.dev2}/metafold/simulation/run_experiment.py +30 -2
- {metafold-0.13.dev0 → metafold-0.13.dev2}/metafold.egg-info/PKG-INFO +1 -1
- {metafold-0.13.dev0 → metafold-0.13.dev2}/pyproject.toml +1 -1
- {metafold-0.13.dev0 → metafold-0.13.dev2}/tests/test_compession_experiment.py +133 -1
- {metafold-0.13.dev0 → metafold-0.13.dev2}/tests/test_run_experiment.py +47 -0
- {metafold-0.13.dev0 → metafold-0.13.dev2}/LICENSE +0 -0
- {metafold-0.13.dev0 → metafold-0.13.dev2}/README.md +0 -0
- {metafold-0.13.dev0 → metafold-0.13.dev2}/metafold/__init__.py +0 -0
- {metafold-0.13.dev0 → metafold-0.13.dev2}/metafold/api.py +0 -0
- {metafold-0.13.dev0 → metafold-0.13.dev2}/metafold/assets.py +0 -0
- {metafold-0.13.dev0 → metafold-0.13.dev2}/metafold/auth.py +0 -0
- {metafold-0.13.dev0 → metafold-0.13.dev2}/metafold/client.py +0 -0
- {metafold-0.13.dev0 → metafold-0.13.dev2}/metafold/exceptions.py +0 -0
- {metafold-0.13.dev0 → metafold-0.13.dev2}/metafold/jobs.py +0 -0
- {metafold-0.13.dev0 → metafold-0.13.dev2}/metafold/materials.py +0 -0
- {metafold-0.13.dev0 → metafold-0.13.dev2}/metafold/projects.py +0 -0
- {metafold-0.13.dev0 → metafold-0.13.dev2}/metafold/simulation/__init__.py +0 -0
- {metafold-0.13.dev0 → metafold-0.13.dev2}/metafold/simulation/compression_simulation.py +0 -0
- {metafold-0.13.dev0 → metafold-0.13.dev2}/metafold/utils.py +0 -0
- {metafold-0.13.dev0 → metafold-0.13.dev2}/metafold/workflows.py +0 -0
- {metafold-0.13.dev0 → metafold-0.13.dev2}/metafold.egg-info/SOURCES.txt +0 -0
- {metafold-0.13.dev0 → metafold-0.13.dev2}/metafold.egg-info/dependency_links.txt +0 -0
- {metafold-0.13.dev0 → metafold-0.13.dev2}/metafold.egg-info/requires.txt +0 -0
- {metafold-0.13.dev0 → metafold-0.13.dev2}/metafold.egg-info/top_level.txt +0 -0
- {metafold-0.13.dev0 → metafold-0.13.dev2}/setup.cfg +0 -0
- {metafold-0.13.dev0 → metafold-0.13.dev2}/tests/test_assets.py +0 -0
- {metafold-0.13.dev0 → metafold-0.13.dev2}/tests/test_compression_simulation.py +0 -0
- {metafold-0.13.dev0 → metafold-0.13.dev2}/tests/test_jobs.py +0 -0
- {metafold-0.13.dev0 → metafold-0.13.dev2}/tests/test_materials.py +0 -0
- {metafold-0.13.dev0 → metafold-0.13.dev2}/tests/test_projects.py +0 -0
- {metafold-0.13.dev0 → metafold-0.13.dev2}/tests/test_shear_simulation.py +0 -0
- {metafold-0.13.dev0 → metafold-0.13.dev2}/tests/test_utils.py +0 -0
- {metafold-0.13.dev0 → metafold-0.13.dev2}/tests/test_workflows.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import copy
|
|
2
2
|
import json
|
|
3
|
-
from typing import Any, List, Union, cast
|
|
3
|
+
from typing import Any, List, Optional, Union, cast
|
|
4
4
|
import glob
|
|
5
5
|
from pathlib import Path
|
|
6
6
|
from metafold.simulation.compression_simulation import (
|
|
@@ -106,6 +106,41 @@ class VarySimulationParameter(ExperimentVarying):
|
|
|
106
106
|
setattr(obj, parts[-1], self.values[sim_index])
|
|
107
107
|
|
|
108
108
|
|
|
109
|
+
class VaryVelocity(ExperimentVarying):
|
|
110
|
+
"""Vary a rigid part's velocity keyframes (e.g. a piston's motion profile).
|
|
111
|
+
Each value is a full velocity profile: a list of [t, vx, vy, vz] rows."""
|
|
112
|
+
|
|
113
|
+
part_name: str
|
|
114
|
+
velocities: List[list]
|
|
115
|
+
|
|
116
|
+
def __init__(self, part_name: str, velocities: List[list]):
|
|
117
|
+
# Each element is one profile: a list of [t,vx,vy,vz] rows.
|
|
118
|
+
for i, profile in enumerate(velocities):
|
|
119
|
+
if (
|
|
120
|
+
not isinstance(profile, list)
|
|
121
|
+
or not profile
|
|
122
|
+
or not all(isinstance(row, list) and len(row) == 4 for row in profile)
|
|
123
|
+
):
|
|
124
|
+
raise ValueError(
|
|
125
|
+
f"velocity profile {i} for part {part_name!r} must be a list "
|
|
126
|
+
f"of [t, vx, vy, vz] rows, got: {profile!r}"
|
|
127
|
+
)
|
|
128
|
+
self.part_name = part_name
|
|
129
|
+
self.velocities = velocities
|
|
130
|
+
|
|
131
|
+
def resolve(self, _base_dir: Path) -> None:
|
|
132
|
+
self.sim_count = len(self.velocities)
|
|
133
|
+
|
|
134
|
+
def apply_to(self, sim_index: int, sim: CompressionSimulation):
|
|
135
|
+
part_info: CompressionSimulation.PartInfo = sim.get_part_info(self.part_name)
|
|
136
|
+
if not hasattr(part_info.part, "velocity"):
|
|
137
|
+
# Only rigid (piston/support) parts consume a velocity profile.
|
|
138
|
+
raise ValueError(
|
|
139
|
+
f"Part {self.part_name!r} is not a rigid (piston/support) part "
|
|
140
|
+
)
|
|
141
|
+
part_info.part.velocity = self.velocities[sim_index]
|
|
142
|
+
|
|
143
|
+
|
|
109
144
|
class CompressionExperiment:
|
|
110
145
|
base_simulation: CompressionSimulation
|
|
111
146
|
varying: List[ExperimentVarying] = []
|
|
@@ -124,12 +159,16 @@ class CompressionExperiment:
|
|
|
124
159
|
auto_upload_server_manifest: bool = True,
|
|
125
160
|
use_legacy_results_format: bool = False,
|
|
126
161
|
write_ups: bool = True,
|
|
162
|
+
simulation_names: Optional[List[str]] = None,
|
|
127
163
|
):
|
|
128
164
|
simulation.use_legacy_results_format = use_legacy_results_format
|
|
129
165
|
simulation.write_ups = write_ups
|
|
130
166
|
self.use_legacy_results_format = use_legacy_results_format
|
|
131
167
|
self.base_simulation = simulation
|
|
132
168
|
self.varying = varying
|
|
169
|
+
# Optional per-simulation display names (index-aligned). A blank/missing
|
|
170
|
+
# entry falls back to the auto "<base>_sim<index>" name.
|
|
171
|
+
self.simulation_names = simulation_names or []
|
|
133
172
|
self.verbose = verbose
|
|
134
173
|
self.force_rerun = force_rerun
|
|
135
174
|
self.varying_part_names = []
|
|
@@ -139,12 +178,59 @@ class CompressionExperiment:
|
|
|
139
178
|
if hasattr(v, "part_name"):
|
|
140
179
|
self.varying_part_names.append(v.part_name)
|
|
141
180
|
|
|
181
|
+
# Every varying must produce the same number of variants — prepare()
|
|
182
|
+
# sizes the sim loop from one of them and indexes into all of them.
|
|
183
|
+
counts = {v.sim_count for v in self.varying}
|
|
184
|
+
if len(counts) > 1:
|
|
185
|
+
raise ValueError(
|
|
186
|
+
"All varying entries must have the same number of values, got "
|
|
187
|
+
f"counts: {sorted(counts)}"
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
self._validate_simulation_names()
|
|
191
|
+
|
|
142
192
|
if auto_run:
|
|
143
193
|
self.prepare()
|
|
144
194
|
self.run(auto_upload_server_manifest)
|
|
145
195
|
if auto_download_results:
|
|
146
196
|
self.download_results()
|
|
147
197
|
|
|
198
|
+
def _sim_name(self, sim_index: int) -> str:
|
|
199
|
+
"""Name for the sim at sim_index: the caller-supplied name when present,
|
|
200
|
+
otherwise the auto "<base>_sim<index>" name."""
|
|
201
|
+
custom = (
|
|
202
|
+
self.simulation_names[sim_index]
|
|
203
|
+
if sim_index < len(self.simulation_names)
|
|
204
|
+
else None
|
|
205
|
+
)
|
|
206
|
+
return custom or f"{self.base_simulation.simulation_name}_sim{sim_index}"
|
|
207
|
+
|
|
208
|
+
def _validate_simulation_names(self):
|
|
209
|
+
"""Names must be a list of path-safe strings (None or "" = use the
|
|
210
|
+
auto name) and resolve to a unique name per sim (they become filenames
|
|
211
|
+
and zip member paths)."""
|
|
212
|
+
if not isinstance(self.simulation_names, list) or not all(
|
|
213
|
+
n is None or isinstance(n, str) for n in self.simulation_names
|
|
214
|
+
):
|
|
215
|
+
raise ValueError(
|
|
216
|
+
f"simulation_names must be a list of strings, got: "
|
|
217
|
+
f"{self.simulation_names!r}"
|
|
218
|
+
)
|
|
219
|
+
self.simulation_names = [n or "" for n in self.simulation_names]
|
|
220
|
+
for name in self.simulation_names:
|
|
221
|
+
if any(c in name for c in "/\\:"):
|
|
222
|
+
raise ValueError(
|
|
223
|
+
f"simulation name {name!r} contains a path separator"
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
sim_count = self.varying[0].sim_count if self.varying else 1
|
|
227
|
+
resolved = [self._sim_name(i) for i in range(sim_count)]
|
|
228
|
+
duplicates = {n for n in resolved if resolved.count(n) > 1}
|
|
229
|
+
if duplicates:
|
|
230
|
+
raise ValueError(
|
|
231
|
+
f"simulation names must be unique, duplicated: {sorted(duplicates)}"
|
|
232
|
+
)
|
|
233
|
+
|
|
148
234
|
@property
|
|
149
235
|
def _experiment_state_filename(self) -> Path:
|
|
150
236
|
assert self.base_simulation.out_dir is not None
|
|
@@ -157,12 +243,18 @@ class CompressionExperiment:
|
|
|
157
243
|
"""Delete the experiment state file and all per-sim results files."""
|
|
158
244
|
if self._experiment_state_filename.is_file():
|
|
159
245
|
self._experiment_state_filename.unlink()
|
|
160
|
-
# delete per-sim results
|
|
161
|
-
#
|
|
246
|
+
# delete per-sim results: auto-named sims match the glob pattern,
|
|
247
|
+
# custom-named sims are deleted by name
|
|
162
248
|
for f in self.base_simulation.out_dir.glob(
|
|
163
249
|
f"{self.base_simulation.simulation_name}_sim*_results.json"
|
|
164
250
|
):
|
|
165
251
|
f.unlink()
|
|
252
|
+
for name in self.simulation_names:
|
|
253
|
+
if not name:
|
|
254
|
+
continue
|
|
255
|
+
f = self.base_simulation.out_dir / f"{name}_results.json"
|
|
256
|
+
if f.is_file():
|
|
257
|
+
f.unlink()
|
|
166
258
|
# delete out.zip if it exists
|
|
167
259
|
out_zip = self.base_simulation.out_dir / "out.zip"
|
|
168
260
|
if out_zip.is_file():
|
|
@@ -193,7 +285,7 @@ class CompressionExperiment:
|
|
|
193
285
|
self.base_simulation.part_infos = base_part_infos
|
|
194
286
|
|
|
195
287
|
# give each sim a unique name so zip paths don't collide
|
|
196
|
-
clone.simulation_name =
|
|
288
|
+
clone.simulation_name = self._sim_name(sim_index)
|
|
197
289
|
|
|
198
290
|
# ok now for the part infos we want to do something different, we want to keep shared elements the same but fork
|
|
199
291
|
# the part infos which we are varying, that way we dont mess up other copies when experiments vary things
|
|
@@ -55,7 +55,14 @@ JSON manifest format
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
]},
|
|
58
|
-
|
|
58
|
+
# A rigid part's velocity keyframes; each value is a full [t,vx,vy,vz] profile:
|
|
59
|
+
{"part": "piston", "velocity": [
|
|
60
|
+
[[0.0, 0, 0, 0.0], [0.04, 0, 0, -1.25]],
|
|
61
|
+
[[0.0, 0, 0, 0.0], [0.04, 0, 0, -2.50]],
|
|
62
|
+
[[0.0, 0, 0, 0.0], [0.04, 0, 0, -5.00]]
|
|
63
|
+
]},
|
|
64
|
+
# Every varying entry must have the same number of values (one per variant).
|
|
65
|
+
{"field": "max_time", "values": [0.02, 0.04, 0.06]}
|
|
59
66
|
],
|
|
60
67
|
|
|
61
68
|
"simulation": {
|
|
@@ -82,7 +89,12 @@ JSON manifest format
|
|
|
82
89
|
"compress",
|
|
83
90
|
"force_displacement",
|
|
84
91
|
{"step": "metrics", "parts": ["midsole", "outsole"]}
|
|
85
|
-
]
|
|
92
|
+
],
|
|
93
|
+
|
|
94
|
+
# Optional display name per simulation variant, index-aligned with the variants
|
|
95
|
+
# the varying entries produce. A null/blank/missing entry falls back to
|
|
96
|
+
# "<name>_sim<i>". Names must be unique and must not contain path separators.
|
|
97
|
+
"simulation_names": ["slow piston", null, "fastest piston"]
|
|
86
98
|
}
|
|
87
99
|
|
|
88
100
|
Available material presets
|
|
@@ -137,6 +149,7 @@ from metafold.simulation.compression_experiment import (
|
|
|
137
149
|
VaryMaterial,
|
|
138
150
|
VaryMesh,
|
|
139
151
|
VarySimulationParameter,
|
|
152
|
+
VaryVelocity,
|
|
140
153
|
)
|
|
141
154
|
from metafold.simulation.compression_simulation import (
|
|
142
155
|
CompressionSimulation,
|
|
@@ -180,6 +193,8 @@ def _build_parts(parts_config: list[dict]) -> list[ExperimentPart]:
|
|
|
180
193
|
|
|
181
194
|
if part_type == "piston_cylinder":
|
|
182
195
|
kwargs = {}
|
|
196
|
+
if "name" in entry:
|
|
197
|
+
kwargs["name"] = entry["name"]
|
|
183
198
|
if "velocity" in entry:
|
|
184
199
|
kwargs["velocity"] = entry["velocity"]
|
|
185
200
|
if "shape_parameters" in entry:
|
|
@@ -190,6 +205,8 @@ def _build_parts(parts_config: list[dict]) -> list[ExperimentPart]:
|
|
|
190
205
|
|
|
191
206
|
elif part_type == "piston_box":
|
|
192
207
|
kwargs = {}
|
|
208
|
+
if "name" in entry:
|
|
209
|
+
kwargs["name"] = entry["name"]
|
|
193
210
|
if "velocity" in entry:
|
|
194
211
|
kwargs["velocity"] = entry["velocity"]
|
|
195
212
|
if "shape_parameters" in entry:
|
|
@@ -200,6 +217,8 @@ def _build_parts(parts_config: list[dict]) -> list[ExperimentPart]:
|
|
|
200
217
|
|
|
201
218
|
elif part_type == "piston_mesh":
|
|
202
219
|
kwargs = {"filename": entry["file"]}
|
|
220
|
+
if "name" in entry:
|
|
221
|
+
kwargs["name"] = entry["name"]
|
|
203
222
|
if "velocity" in entry:
|
|
204
223
|
kwargs["velocity"] = entry["velocity"]
|
|
205
224
|
if "material" in entry:
|
|
@@ -243,6 +262,14 @@ def _build_varying(varying_config: list[dict]) -> list[ExperimentVarying]:
|
|
|
243
262
|
VaryMaterial(entry["part"], [_resolve_material(m) for m in materials])
|
|
244
263
|
)
|
|
245
264
|
|
|
265
|
+
elif "part" in entry and "velocity" in entry:
|
|
266
|
+
velocities = entry["velocity"]
|
|
267
|
+
if not isinstance(velocities, list):
|
|
268
|
+
raise ValueError(
|
|
269
|
+
f"varying 'velocity' must be a list of velocity profiles, got: {velocities!r}"
|
|
270
|
+
)
|
|
271
|
+
varying.append(VaryVelocity(entry["part"], velocities))
|
|
272
|
+
|
|
246
273
|
elif "field" in entry and "values" in entry:
|
|
247
274
|
varying.append(VarySimulationParameter(entry["field"], entry["values"]))
|
|
248
275
|
|
|
@@ -366,6 +393,7 @@ def run_experiment(
|
|
|
366
393
|
CompressionExperiment(
|
|
367
394
|
simulation=sim,
|
|
368
395
|
varying=varying,
|
|
396
|
+
simulation_names=config.get("simulation_names"),
|
|
369
397
|
auto_download_results=wait_for_results,
|
|
370
398
|
)
|
|
371
399
|
|
|
@@ -4,7 +4,13 @@ import copy
|
|
|
4
4
|
from pathlib import Path
|
|
5
5
|
from unittest.mock import MagicMock
|
|
6
6
|
|
|
7
|
-
from metafold.simulation.compression_experiment import
|
|
7
|
+
from metafold.simulation.compression_experiment import (
|
|
8
|
+
CompressionExperiment,
|
|
9
|
+
VaryMesh,
|
|
10
|
+
VaryMaterial,
|
|
11
|
+
VarySimulationParameter,
|
|
12
|
+
VaryVelocity,
|
|
13
|
+
)
|
|
8
14
|
from metafold.materials import Material, ConstitutiveModel, RigidParams
|
|
9
15
|
|
|
10
16
|
|
|
@@ -246,6 +252,132 @@ class TestVaryMaterialSweep:
|
|
|
246
252
|
assert v.materials[1].constitutive_model.params.shear_modulus == 20.0
|
|
247
253
|
|
|
248
254
|
|
|
255
|
+
PROFILES = [
|
|
256
|
+
[[0.0, 0, 0, 0.0], [0.04, 0, 0, -1.25]],
|
|
257
|
+
[[0.0, 0, 0, 0.0], [0.04, 0, 0, -2.50]],
|
|
258
|
+
]
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
class TestVaryVelocity:
|
|
262
|
+
def test_resolve_sets_sim_count(self, tmp_path):
|
|
263
|
+
v = VaryVelocity("piston", PROFILES)
|
|
264
|
+
v.resolve(tmp_path)
|
|
265
|
+
assert v.sim_count == 2
|
|
266
|
+
|
|
267
|
+
def test_apply_to_sets_velocity(self, mock_sim):
|
|
268
|
+
v = VaryVelocity("piston", PROFILES)
|
|
269
|
+
v.apply_to(0, mock_sim)
|
|
270
|
+
assert mock_sim.get_part_info("piston").part.velocity == PROFILES[0]
|
|
271
|
+
v.apply_to(1, mock_sim)
|
|
272
|
+
assert mock_sim.get_part_info("piston").part.velocity == PROFILES[1]
|
|
273
|
+
|
|
274
|
+
def test_single_flat_profile_rejected(self):
|
|
275
|
+
# one profile passed where a list of profiles is expected
|
|
276
|
+
with pytest.raises(ValueError, match="list of \\[t, vx, vy, vz\\] rows"):
|
|
277
|
+
VaryVelocity("piston", [[0.0, 0, 0, 0.0], [0.04, 0, 0, -1.25]])
|
|
278
|
+
|
|
279
|
+
def test_malformed_row_rejected(self):
|
|
280
|
+
with pytest.raises(ValueError, match="rows"):
|
|
281
|
+
VaryVelocity("piston", [[[0.0, 0, 0]]]) # 3 floats, not 4
|
|
282
|
+
|
|
283
|
+
def test_non_rigid_part_rejected(self, mock_sim):
|
|
284
|
+
class PlainPart: # no velocity attribute, unlike piston/support parts
|
|
285
|
+
name = "midsole"
|
|
286
|
+
|
|
287
|
+
info = MagicMock()
|
|
288
|
+
info.part = PlainPart()
|
|
289
|
+
mock_sim.get_part_info.side_effect = lambda n: info
|
|
290
|
+
|
|
291
|
+
v = VaryVelocity("midsole", PROFILES)
|
|
292
|
+
with pytest.raises(ValueError, match="not a rigid"):
|
|
293
|
+
v.apply_to(0, mock_sim)
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
class TestSimulationNames:
|
|
297
|
+
def _experiment(self, mock_sim, names, varying=None):
|
|
298
|
+
return CompressionExperiment(
|
|
299
|
+
mock_sim,
|
|
300
|
+
varying if varying is not None else [VaryMesh("midsole", "mid-*.ply")],
|
|
301
|
+
simulation_names=names,
|
|
302
|
+
auto_run=False,
|
|
303
|
+
)
|
|
304
|
+
|
|
305
|
+
def test_custom_names_used(self, mock_sim):
|
|
306
|
+
exp = self._experiment(mock_sim, ["a", "b", "c"])
|
|
307
|
+
exp.prepare()
|
|
308
|
+
assert [s.simulation_name for s in exp.sims] == ["a", "b", "c"]
|
|
309
|
+
|
|
310
|
+
def test_blank_name_falls_back_to_auto(self, mock_sim):
|
|
311
|
+
exp = self._experiment(mock_sim, ["a", "", "c"])
|
|
312
|
+
exp.prepare()
|
|
313
|
+
assert [s.simulation_name for s in exp.sims] == ["a", "base_sim_sim1", "c"]
|
|
314
|
+
|
|
315
|
+
def test_short_list_falls_back_to_auto(self, mock_sim):
|
|
316
|
+
exp = self._experiment(mock_sim, ["a"])
|
|
317
|
+
exp.prepare()
|
|
318
|
+
assert [s.simulation_name for s in exp.sims] == [
|
|
319
|
+
"a", "base_sim_sim1", "base_sim_sim2"]
|
|
320
|
+
|
|
321
|
+
def test_duplicate_names_rejected(self, mock_sim):
|
|
322
|
+
with pytest.raises(ValueError, match="unique"):
|
|
323
|
+
self._experiment(mock_sim, ["a", "a", "c"])
|
|
324
|
+
|
|
325
|
+
def test_name_colliding_with_auto_name_rejected(self, mock_sim):
|
|
326
|
+
# sim1's fallback name is base_sim_sim1; naming sim0 the same collides
|
|
327
|
+
with pytest.raises(ValueError, match="unique"):
|
|
328
|
+
self._experiment(mock_sim, ["base_sim_sim1"])
|
|
329
|
+
|
|
330
|
+
def test_path_separator_rejected(self, mock_sim):
|
|
331
|
+
with pytest.raises(ValueError, match="path separator"):
|
|
332
|
+
self._experiment(mock_sim, ["run/1"])
|
|
333
|
+
|
|
334
|
+
def test_none_entry_falls_back_to_auto(self, mock_sim):
|
|
335
|
+
exp = self._experiment(mock_sim, [None, "custom2", None])
|
|
336
|
+
exp.prepare()
|
|
337
|
+
assert [s.simulation_name for s in exp.sims] == [
|
|
338
|
+
"base_sim_sim0", "custom2", "base_sim_sim2"]
|
|
339
|
+
|
|
340
|
+
def test_non_list_rejected(self, mock_sim):
|
|
341
|
+
with pytest.raises(ValueError, match="list of strings"):
|
|
342
|
+
self._experiment(mock_sim, "baseline")
|
|
343
|
+
|
|
344
|
+
def test_non_string_entry_rejected(self, mock_sim):
|
|
345
|
+
with pytest.raises(ValueError, match="list of strings"):
|
|
346
|
+
self._experiment(mock_sim, ["a", 2])
|
|
347
|
+
|
|
348
|
+
def test_force_rerun_clears_custom_named_results(self, mock_sim):
|
|
349
|
+
stale = mock_sim.out_dir / "custom_a_results.json"
|
|
350
|
+
stale.write_text("{}")
|
|
351
|
+
exp = self._experiment(mock_sim, ["custom_a", "b", "c"])
|
|
352
|
+
exp.force_rerun = True
|
|
353
|
+
exp._clear_saved_state()
|
|
354
|
+
assert not stale.exists()
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
class TestVaryingCountMismatch:
|
|
358
|
+
def test_mismatched_counts_rejected(self, mock_sim):
|
|
359
|
+
with pytest.raises(ValueError, match="same number"):
|
|
360
|
+
CompressionExperiment(
|
|
361
|
+
mock_sim,
|
|
362
|
+
[
|
|
363
|
+
VaryMesh("midsole", "mid-*.ply"), # 3 files
|
|
364
|
+
VaryVelocity("piston", PROFILES), # 2 profiles
|
|
365
|
+
],
|
|
366
|
+
auto_run=False,
|
|
367
|
+
)
|
|
368
|
+
|
|
369
|
+
def test_matching_counts_accepted(self, mock_sim):
|
|
370
|
+
exp = CompressionExperiment(
|
|
371
|
+
mock_sim,
|
|
372
|
+
[
|
|
373
|
+
VarySimulationParameter("max_time", [0.02, 0.04]),
|
|
374
|
+
VaryVelocity("piston", PROFILES),
|
|
375
|
+
],
|
|
376
|
+
auto_run=False,
|
|
377
|
+
)
|
|
378
|
+
assert exp.varying[0].sim_count == exp.varying[1].sim_count == 2
|
|
379
|
+
|
|
380
|
+
|
|
249
381
|
class TestVarySimulationParameter:
|
|
250
382
|
def test_resolve_sets_sim_count(self, tmp_path):
|
|
251
383
|
v = VarySimulationParameter("max_time", [0.02, 0.04, 0.06])
|
|
@@ -36,6 +36,7 @@ from metafold.simulation.compression_experiment import (
|
|
|
36
36
|
VaryMaterial,
|
|
37
37
|
VaryMesh,
|
|
38
38
|
VarySimulationParameter,
|
|
39
|
+
VaryVelocity,
|
|
39
40
|
)
|
|
40
41
|
|
|
41
42
|
|
|
@@ -109,6 +110,18 @@ class TestBuildParts:
|
|
|
109
110
|
assert isinstance(parts[0], ExperimentPistonMesh)
|
|
110
111
|
assert parts[0].filename == "piston.ply"
|
|
111
112
|
|
|
113
|
+
def test_piston_parts_custom_name(self):
|
|
114
|
+
parts = _build_parts([
|
|
115
|
+
{"type": "piston_mesh", "name": "last", "file": "last.ply"},
|
|
116
|
+
{"type": "piston_cylinder", "name": "press"},
|
|
117
|
+
{"type": "piston_box", "name": "anvil"},
|
|
118
|
+
])
|
|
119
|
+
assert [p.name for p in parts] == ["last", "press", "anvil"]
|
|
120
|
+
|
|
121
|
+
def test_piston_parts_default_name_when_omitted(self):
|
|
122
|
+
parts = _build_parts([{"type": "piston_mesh", "file": "piston.ply"}])
|
|
123
|
+
assert parts[0].name == "piston"
|
|
124
|
+
|
|
112
125
|
def test_piston_mesh_with_velocity(self):
|
|
113
126
|
velocity = [[0.0, 0, 0, 0.0], [0.02, 0, 0, -1.25], [0.04, 0, 0, 0.0]]
|
|
114
127
|
parts = _build_parts([{"type": "piston_mesh", "file": "piston.ply", "velocity": velocity}])
|
|
@@ -220,6 +233,20 @@ class TestBuildVarying:
|
|
|
220
233
|
assert varying[0].field_path == "max_time"
|
|
221
234
|
assert varying[0].values == [0.02, 0.04, 0.06]
|
|
222
235
|
|
|
236
|
+
def test_vary_velocity(self):
|
|
237
|
+
profiles = [
|
|
238
|
+
[[0.0, 0, 0, 0.0], [0.04, 0, 0, -1.25]],
|
|
239
|
+
[[0.0, 0, 0, 0.0], [0.04, 0, 0, -2.50]],
|
|
240
|
+
]
|
|
241
|
+
varying = _build_varying([{"part": "piston", "velocity": profiles}])
|
|
242
|
+
assert isinstance(varying[0], VaryVelocity)
|
|
243
|
+
assert varying[0].part_name == "piston"
|
|
244
|
+
assert varying[0].velocities == profiles
|
|
245
|
+
|
|
246
|
+
def test_vary_velocity_non_list_rejected(self):
|
|
247
|
+
with pytest.raises(ValueError, match="velocity"):
|
|
248
|
+
_build_varying([{"part": "piston", "velocity": "nope"}])
|
|
249
|
+
|
|
223
250
|
def test_unrecognised_entry_raises(self):
|
|
224
251
|
with pytest.raises(ValueError, match="Unrecognised varying"):
|
|
225
252
|
_build_varying([{"unknown_key": "foo"}])
|
|
@@ -394,6 +421,26 @@ class TestRunExperiment:
|
|
|
394
421
|
assert params.max_time == 0.02
|
|
395
422
|
assert params.max_resolution == 128
|
|
396
423
|
|
|
424
|
+
def test_simulation_names_passed_to_experiment(self, ply_folder, tmp_path):
|
|
425
|
+
fake_sim = self._fake_sim(ply_folder)
|
|
426
|
+
captured = {}
|
|
427
|
+
|
|
428
|
+
def capture_experiment(*args, **kwargs):
|
|
429
|
+
captured.update(kwargs)
|
|
430
|
+
|
|
431
|
+
with (
|
|
432
|
+
patch("metafold.simulation.run_experiment.CompressionSimulation", return_value=fake_sim),
|
|
433
|
+
patch("metafold.simulation.run_experiment.CompressionExperiment", side_effect=capture_experiment),
|
|
434
|
+
):
|
|
435
|
+
run_experiment({
|
|
436
|
+
"project_name": "t",
|
|
437
|
+
"output_path": str(tmp_path / "out"),
|
|
438
|
+
"parts": [],
|
|
439
|
+
"simulation_names": ["baseline", "stiff outsole"],
|
|
440
|
+
})
|
|
441
|
+
|
|
442
|
+
assert captured["simulation_names"] == ["baseline", "stiff outsole"]
|
|
443
|
+
|
|
397
444
|
def test_workflow_steps_config_passed_to_simulation(self, ply_folder, tmp_path):
|
|
398
445
|
fake_sim = self._fake_sim(ply_folder)
|
|
399
446
|
captured = {}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|