Download code/case1/mpc_failures/first_tick.py from harryzhang1018/TestRandomization: direct link, hf CLI and curl.
- Browser
- Download file 1.16 kB
-
https://huggingface.co/datasets/harryzhang1018/TestRandomization/resolve/main/code/case1/mpc_failures/first_tick.py
- Command line
-
hf download hf://datasets/harryzhang1018/TestRandomization/code/case1/mpc_failures/first_tick.py
-
curl -L -o first_tick.py https://huggingface.co/datasets/harryzhang1018/TestRandomization/resolve/main/code/case1/mpc_failures/first_tick.py
1.16 kB
| #!/usr/bin/env python3 | |
| """First controller tick of every B01 MPC episode (input of d3_range.py). | |
| For each episode b01_<scenario_id>_mpc of the B01 logs, writes the first row of ticks.csv.gz with status 'ok' | |
| (the first tick at which the controller received a state): the controller's lookahead error e0 and the tracking | |
| error et0, et1, et2. Values are copied as logged (strings), so the downstream floats are exact. | |
| Usage: python first_tick.py <B01_main_tr run dir (contains episodes/)> <out.csv> | |
| """ | |
| import csv | |
| import glob | |
| import gzip | |
| import os | |
| import sys | |
| RUN, OUT = sys.argv[1:3] | |
| rows = [] | |
| for d in sorted(glob.glob(os.path.join(RUN, 'episodes', 'b01_*_mpc'))): | |
| sid = os.path.basename(d)[len('b01_'):-len('_mpc')] | |
| with gzip.open(os.path.join(d, 'ticks.csv.gz'), 'rt') as fh: | |
| t = next(x for x in csv.DictReader(fh) if x['status'] == 'ok') | |
| rows.append({'scenario_id': sid, 'tick': t['tick'], 'e0': t['e0'], 'et0': t['et0'], 'et1': t['et1'], 'et2': t['et2']}) | |
| with open(OUT, 'w', newline='') as f: | |
| w = csv.DictWriter(f, fieldnames=list(rows[0].keys())) | |
| w.writeheader() | |
| w.writerows(rows) | |
| print(f'{len(rows)} episodes -> {OUT}') | |