import torch
from .field import QWANField
from .dynamics import evolve
from .observables import classify_regime, risk_score

def run_qwan(timeseries):
    field = QWANField(timeseries)
    x = field.get()

    x_final, history = evolve(x)

    last = history[-1]

    regime = classify_regime(last["H"], last["I"])
    risk = risk_score(last["H"], last["I"])

    return {
        "regime": regime,
        "risk": risk,
        "history": history
    }
