f150696Output with the area mean of the acceleration removed; experiment harnessJeremy Magland 1"""Run the modal solver on a variant of a challenge for listening experiments (not submissions): overrides of the
2parameters, the strikes and the duration are applied to a copy of challenge.json written beside the outputs.
3Usage: python experiment.py <challenge.json> <experiments-dir> <name> [--set key=value ...] [--strikes t:x,t:x,...]
4 [--seconds S] [--spacing 0.008] [--fmax 20000] [--m 4] [--device cuda]
5Example: python experiment.py crash.json ../../experiments thickbell --set thickness_center=0.002 --strikes 0:0.04,1.2:0.12,2.4:0.185 --seconds 3.6"""
6import json
7import subprocess
8import sys
9from pathlib import Path
11ch = json.load(open(sys.argv[1]))
12exp_dir = Path(sys.argv[2])
13name = sys.argv[3]
14args = sys.argv[4:]
15passthrough = []
16i = 0
17while i < len(args):
18 if args[i] == "--set":
19 k, v = args[i + 1].split("=", 1)
20 ch["parameters"][k] = json.loads(v)
21 i += 2
22 elif args[i] == "--strikes":
23 ch["strikes"] = [{"t": float(t), "x": float(x), "y": 0.0} for t, x in (s.split(":") for s in args[i + 1].split(","))]
24 i += 2
25 elif args[i] == "--seconds":
26 ch["output"]["num_samples"] = int(round(ch["output"]["sample_rate_hz"] * float(args[i + 1])))
27 ch["fields"]["shape"][0] = int(round(ch["fields"]["frame_rate_hz"] * float(args[i + 1]))) + 1
28 i += 2
29 else:
30 passthrough.append(args[i])
31 i += 1
32ch["challenge_id"] = f"{ch['challenge_id']}-{name}"
33out = exp_dir / name
34out.mkdir(parents=True, exist_ok=True)
35cj = out / "challenge.json"
36json.dump(ch, open(cj, "w"), indent=1)
37here = Path(__file__).resolve().parent
38cmd = [sys.executable, str(here / "modal_shell.py"), str(cj), str(out), "--tag", name, *passthrough]
39print(" ".join(cmd), flush=True)
40sys.exit(subprocess.call(cmd))