"""灯りの虫: 落下で強まる戻し（FALLGATE=1）を G2 5・10・20 で試す（2026-11-11 20:2x、判定は plan_posture.md に先に書いた）。
使い方（リポジトリ直下から）: uv run python ayumu-lab/research/insect-light/fallgate.py > ayumu-lab/research/insect-light/fallgate_20261111.json"""
import sys, os, json, subprocess
from concurrent.futures import ThreadPoolExecutor
here = os.path.dirname(os.path.abspath(__file__))
TUBE = dict(K1="6", K2="1", VT="2.0", PEXP="0.5", PEXP_GEOM="max", RRANGE="0.1,0.2", ERANGE="0,35")
UP = dict(K1="6", K2="1", VT="1.3", PEXP="0.5", HALF="100", GLOW="0.3", RRANGE="0.15,0.5")
CLEAR = ("K1", "K2", "K3", "VT", "PEXP", "PEXP_GEOM", "G2", "HALF", "GLOW", "ERANGE", "RRANGE", "DUMP", "FALLGATE")
def run(job):
    g2, gate, place, seed = job; shape, env = ("tubew", TUBE) if place == "tube" else ("bup", UP)
    e = {k: v for k, v in os.environ.items() if k not in CLEAR}; e.update(env, G2=g2, DT="0.0025")
    if gate: e["FALLGATE"] = "1"
    o = json.loads(subprocess.run([sys.executable, os.path.join(here, "fabian_model.py"), "1000", str(seed), "1.0", shape], env=e, capture_output=True, text=True).stdout.strip().splitlines()[-1])
    return f"{g2}|{gate}|{place}|{seed}", {k: o.get(k) for k in ("azdiff", "vz", "dorsum_elev", "inverted_above", "n_above", "n_insects")}
jobs = [(g2, gate, pl, s) for g2 in ("5", "10", "20") for gate in (1,) for pl in ("tube", "up") for s in (1, 2, 3)] + [("5", 0, pl, 1) for pl in ("tube", "up")]
with ThreadPoolExecutor(2) as ex: res = dict(ex.map(run, jobs))
print(json.dumps(res, ensure_ascii=False, indent=0))
