{
  "format": 1,
  "method": "spectral-onsagernet",
  "version": "0.1.0",
  "interface": "Double precision, real length-n arrays, periodic sites j*length/n without duplicated endpoint. Normalized forward DFT c_k=sum_j u_j exp(-2*pi*i*j*k/n)/n, inverse unscaled. energy_force(u,length,alpha,beta,local,spectral) returns [V,mu in physical coordinates]. V=length/2*sum_k (alpha+beta*(2*pi*k/length)^2)*abs(c_k)^2 + length/n*sum_j local*(1-cos(u_j)) + length*spectral*tanh(P). P=sum_k e_k*abs(c_k)^2/2, e_k=k^2/(1+k^2) for signed integer k. mu=(n/length)*dV/du. transport(mu,real_head,imag_head) returns inverse DFT of -(real_head[abs(k)]^2+i*sign(k)*imag_head[abs(k)])*DFT(mu). Zero the imaginary multiplier at DC and at even-grid Nyquist. rollout_loss(states,horizon,dt,length,alpha,beta,local,spectral,real_head,imag_head) sums squared field errors (no averaging) at offsets 1..horizon for every start that has a complete window. Reevaluate mu on the predicted state at each forward Euler step. wave_loss_gradient(amplitudes,horizon,dt,length,weights) maps each [a,b] to the field [a,b,-a,-b]. For weights [beta,r,w] use alpha=1, local=spectral=0 and transport heads [0,r,0] and [0,w,0]. Return [rollout_loss,[d/dbeta,d/dr,d/dw]], differentiating through every Euler step. Export all four functions from port_adapter.py.",
  "cases": [
    {
      "name": "nonunit length and nonlinear spectral residual",
      "operation": "energy_force",
      "tol": 1e-11,
      "inputs": {
        "u": [
          0.1,
          -0.6,
          0.7,
          0.2,
          -0.3
        ],
        "length": 2.3,
        "alpha": 0.4,
        "beta": 0.025,
        "local": 0.3,
        "spectral": 0.6
      },
      "expected": [
        0.37985370169646737,
        [
          0.435698395851234,
          -1.0879155900893032,
          1.0874131945728502,
          0.1447312789500703,
          -0.5151599528978897
        ]
      ]
    },
    {
      "name": "pure even-grid Nyquist force",
      "operation": "energy_force",
      "tol": 1e-10,
      "inputs": {
        "u": [
          0.2,
          -0.2,
          0.2,
          -0.2
        ],
        "length": 1.7,
        "alpha": 0.5,
        "beta": 0.03,
        "local": 0.0,
        "spectral": 0.0
      },
      "expected": [
        0.07273423661791638,
        [
          0.42784845069362576,
          -0.42784845069362576,
          0.42784845069362576,
          -0.42784845069362576
        ]
      ]
    },
    {
      "name": "coexisting damping and signed transport",
      "operation": "transport",
      "tol": 1e-11,
      "inputs": {
        "mu": [
          0.6,
          -0.1,
          0.8,
          -0.7,
          0.15
        ],
        "real_head": [
          0.4,
          -0.5,
          0.2
        ],
        "imag_head": [
          0.7,
          0.3,
          -0.4
        ]
      },
      "expected": [
        -0.41593675254995155,
        0.10596456995363217,
        0.06679917041783638,
        -0.06472039137239316,
        0.18789340355087616
      ]
    },
    {
      "name": "all starts and accumulated two-step loss",
      "operation": "rollout_loss",
      "tol": 1e-11,
      "inputs": {
        "states": [
          [
            0.3,
            -0.1,
            0.7,
            0.15
          ],
          [
            0.25,
            -0.05,
            0.72,
            0.16
          ],
          [
            0.23,
            -0.06,
            0.69,
            0.17
          ],
          [
            0.19,
            -0.04,
            0.65,
            0.18
          ]
        ],
        "horizon": 2,
        "dt": 0.04,
        "length": 2.8,
        "alpha": 0.4,
        "beta": 0.012,
        "local": 0.7,
        "spectral": 0.3,
        "real_head": [
          0.7,
          -0.6,
          0.4
        ],
        "imag_head": [
          0.3,
          0.65,
          -0.2
        ]
      },
      "expected": 0.022560270095379004
    },
    {
      "name": "two-step wave loss and three weight derivatives",
      "operation": "wave_loss_gradient",
      "tol": 1e-10,
      "inputs": {
        "amplitudes": [
          [
            0.6,
            -0.1
          ],
          [
            0.49,
            -0.19
          ],
          [
            0.38,
            -0.24
          ],
          [
            0.28,
            -0.26
          ]
        ],
        "horizon": 2,
        "dt": 0.07,
        "length": 3.4,
        "weights": [
          0.13,
          0.82,
          0.68
        ]
      },
      "expected": [
        0.3429807431319012,
        [
          0.20507345408465766,
          -0.21002896791873768,
          0.254148043854361
        ]
      ]
    }
  ]
}
