"""灯りの虫: 刻み幅 0.01・0.005・0.0025 秒で代表の設定を回し、姿勢量と裏返りが変わらないか見る（査読2回目の任意の指摘、2026-11-11）。
使い方（リポジトリ直下から）: uv run python ayumu-lab/research/insect-light/dt_check.py > ayumu-lab/research/insect-light/dt_check_20261111.json"""
import sys, os, json, subprocess
from concurrent.futures import ThreadPoolExecutor
here = os.path.dirname(os.path.abspath(__file__))
CONF = {"B_tube_01_02": ("tubew", dict(K1="6", K2="1", VT="2.0", PEXP="0.5", PEXP_GEOM="max", G2="5", RRANGE="0.1,0.2", ERANGE="0,35")),
        "B_tube_02_03": ("tubew", dict(K1="6", K2="1", VT="2.0", PEXP="0.5", PEXP_GEOM="max", G2="5", RRANGE="0.2,0.3", ERANGE="0,35")),
        "A_down_01_02": ("down", dict(K1="4", K2="3", VT="1.25", RRANGE="0.1,0.2", ERANGE="0,35")),
        "B_up_above": ("bup", dict(K1="6", K2="1", VT="1.3", PEXP="0.5", HALF="100", GLOW="0.3", G2="5", RRANGE="0.15,0.5"))}
CLEAR = ("K1", "K2", "K3", "VT", "PEXP", "PEXP_GEOM", "G2", "HALF", "GLOW", "ERANGE", "RRANGE", "DT", "DUMP")
def run(job):
    name, dt = job; shape, env = CONF[name]
    e = {k: v for k, v in os.environ.items() if k not in CLEAR}; e.update(env, DT=dt)
    o = json.loads(subprocess.run([sys.executable, os.path.join(here, "fabian_model.py"), "1000", "1", "1.0", shape], env=e, capture_output=True, text=True).stdout.strip().splitlines()[-1])
    return f"{name}|{dt}", {k: o[k] for k in ("azdiff", "theta", "dorsum_elev", "speed", "inverted_above", "n_insects")}
with ThreadPoolExecutor(2) as ex: res = dict(ex.map(run, [(n, d) for n in CONF for d in ("0.01", "0.005", "0.0025")]))
print(json.dumps(res, ensure_ascii=False, indent=0))
