"""Reconstruct regimes_e4b.pt from the exp4_e4b.log table (the scan's
torch.save crashed on a relative path; the printed table is complete).
Provenance note stored in the tensor dict: jbar from 150/256 prompts."""
import re

import torch

sensor, motor, persist, content = [], [], [], []
pat = re.compile(
    r"^L\s*(\d+) \| ([\d.]+)\s*#* *\| ([\d.]+)\s*#* *\| ([\d.]+) \| ([\d.]+)")
for line in open("results/exp4_e4b.log"):
    m = pat.match(line.strip())
    if m:
        _, s, mo, p, c = m.groups()
        sensor.append(float(s))
        motor.append(float(mo))
        persist.append(float(p))
        content.append(float(c))
assert len(sensor) == 42, len(sensor)
torch.save({"sensor": torch.tensor(sensor), "motor": torch.tensor(motor),
            "persist": torch.tensor(persist),
            "content": torch.tensor(content),
            "note": "reconstructed from exp4_e4b.log; jbar 150/256 prompts"},
           "results/regimes_e4b.pt")
print("saved 42 layers")
print("sensor peak: L%d = %.2f" % (sensor.index(max(sensor)), max(sensor)))
print("motor >=0.1 from: L%d" % next(
    i for i, v in enumerate(motor) if v >= 0.1))
