Skip to content

Commit 5e159da

Browse files
committed
[script] Add option to run benchmarks with SofaPython3 files
1 parent 30c3c99 commit 5e159da

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

scripts/runBenchmarks_script.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def stats(self) -> Optional[Dict[str, float]]:
5454

5555
DEFAULTS: Dict[str, Any] = {
5656
'sofa_exe': 'runSofa',
57+
'python': False,
5758
'warmup': 1,
5859
'output': 'log.benchmark',
5960
}
@@ -62,6 +63,7 @@ def stats(self) -> Optional[Dict[str, float]]:
6263
REQUIRED_KEYS = ('iterations', 'n_tests', 'timeout')
6364

6465
# All keys overrideable via CLI — must match build_parser arguments exactly.
66+
# 'python' uses store_true with default=None so it only overrides when explicitly passed.
6567
OVERRIDE_KEYS = (*DEFAULTS.keys(), *REQUIRED_KEYS)
6668

6769

@@ -132,12 +134,13 @@ def _parse_timing_line(line: str) -> Optional[RunResult]:
132134

133135

134136
def run_single(
135-
sofa_exe: str, scene: str, iterations: int, timeout: int
137+
sofa_exe: str, scene: str, iterations: int, timeout: int, python: bool = False
136138
) -> Tuple[Optional[RunResult], Optional[str]]:
137139
"""Returns (RunResult, None) on success, (None, error_message) on failure. Never raises."""
140+
python_args = ['-l', 'SofaPython3'] if python else []
138141
try:
139142
proc = subprocess.run(
140-
[sofa_exe, '-g', 'batch', '-n', str(iterations), scene],
143+
[sofa_exe, *python_args, '-g', 'batch', '-n', str(iterations), scene],
141144
capture_output=True,
142145
text=True,
143146
timeout=timeout,
@@ -170,14 +173,15 @@ def run_case(config: Dict[str, Any], case: Dict[str, str]) -> CaseResults:
170173
scene = case['scene']
171174
name = case['name']
172175

176+
python = config.get('python', False)
173177
cr = CaseResults(name=name, scene=scene)
174178

175179
for i in range(warmup + n_tests):
176180
is_warmup = i < warmup
177181
label = f'warmup {i + 1}/{warmup}' if is_warmup else f'test {i - warmup + 1}/{n_tests}'
178182
print(f' [{name}] {label} ... ', end='', flush=True)
179183

180-
result, error = run_single(sofa_exe, scene, iterations, timeout)
184+
result, error = run_single(sofa_exe, scene, iterations, timeout, python)
181185

182186
if result is not None:
183187
suffix = ' [warmup, discarded]' if is_warmup else ''
@@ -250,6 +254,7 @@ def build_parser() -> argparse.ArgumentParser:
250254
)
251255
p.add_argument('-config', required=True, help='Path to JSON config file')
252256
p.add_argument('-sofa_exe', default=None, help='Override: path to runSofa executable')
257+
p.add_argument('-python', action='store_true', default=None, help='Override: load SofaPython3 (-l SofaPython3)')
253258
p.add_argument('-iterations', default=None, type=int, help='Override: ODE iterations per run')
254259
p.add_argument('-n_tests', default=None, type=int, help='Override: timed test runs per case')
255260
p.add_argument('-warmup', default=None, type=int, help='Override: warmup runs (discarded from stats)')

0 commit comments

Comments
 (0)