Files
VSAG_SENTRY_SIM_27RMUL/tools/run_lio_matrix.py
T

51 lines
2.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""Run three cold starts per route/launcher, plus a blocked-goal check."""
import argparse
import json
from pathlib import Path
import signal
import subprocess
import sys
def main():
parser=argparse.ArgumentParser(description=__doc__)
parser.add_argument('--launcher',choices=['shell','python'],required=True)
parser.add_argument('--output',type=Path,required=True)
parser.add_argument('--map',type=Path,required=True)
parser.add_argument('--domain', type=int, choices=range(1, 233), metavar='[1–232]')
parser.add_argument('--scenario', action='append', choices=['clear', 'cylinder', 'blocked', 'lidar_loss'])
parser.add_argument('--repeats', type=int)
args=parser.parse_args()
if args.repeats is not None and args.repeats < 1:
parser.error('repeats must be positive')
if args.output.exists():parser.error('output must be new')
args.output.mkdir(parents=True)
root=Path(__file__).resolve().parents[1]
results=[]
for scenario in args.scenario or ['clear', 'cylinder', 'blocked']:
count = args.repeats if args.repeats is not None else (3 if scenario in ('clear', 'cylinder') else 1)
for index in range(1, count+1):
name=f'{scenario}_{index}';folder=args.output/name
with open(args.output/(name+'.log'),'w') as log:
command=[sys.executable,str(root/'tools/validate_lio_navigation.py'),
'--launcher',args.launcher,'--map',str(args.map.resolve()),'--output',str(folder.resolve()),
'--scenario',scenario,'--goal','0','0']
if args.domain is not None:
command.extend(['--domain', str(args.domain)])
child=subprocess.Popen(command,cwd=root,stdout=log,stderr=subprocess.STDOUT,start_new_session=True)
try:code=child.wait()
except KeyboardInterrupt:
child.send_signal(signal.SIGINT)
child.wait(timeout=30)
raise
file=folder/'result.json'
result=json.loads(file.read_text()) if file.exists() else {'passed':False,'error':'no result'}
results.append({'name':name,'exit_code':code,**result})
(args.output/'summary.json').write_text(json.dumps(results,indent=2))
print(f'{args.launcher} {name}: passed={result.get("passed")} goal={result.get("goal_succeeded")} metrics={result.get("trajectory_metrics")}',flush=True)
return 0 if all(r['passed'] and r['exit_code']==0 for r in results) else 1
if __name__=='__main__':sys.exit(main())