{
 "format": 1,
 "method": "processed-dkd-meal",
 "version": "0.1.0",
 "interface": "Training: modified_gradient(q, h, mass, theta) -> g~(q) = grad V + (h^2/12) (grad^2 V) M^-1 grad V for the potential V_theta of the case's problem; loss_and_derivative(qs, forces, h, mass, theta) -> (L, dL/dtheta) with L = mean over configurations i of |g~(q_i) + F_i|^2 (squared Euclidean norm) and dL/dtheta its derivative with respect to theta, both copies of grad V depending on theta. Simulation: process(q, p, h, mass, grad, post) -> (q, p) applies the postprocessor (post=true: shears D(s), K(s), D(-s), K(-s), D(-s), K(-s), D(s), K(s) in this order, s = |h|/sqrt(48)) or its exact inverse, the preprocessor (post=false: reverse order, negated durations), where D(t): q += t M^-1 p and K(t): p -= t grad V(q); rollout(q0, p0, h, n_steps, every, mass, grad) -> list of (step, q, p): preprocess once, n_steps drift-kick-drift steps of size h with the ordinary grad V, and a postprocessed copy of the state at step 0 (the input itself), at every step divisible by every, and at the final step. p is canonical momentum, p_i = mass_i * v_i; grad(q) returns +grad V(q).",
 "comparison": "Pass when every number differs from expected by at most tol (absolute); rollout must emit exactly the listed steps. gradient_evaluations is the number of grad calls rollout should make: n_steps + 4 + 4 * ceil(n_steps / every).",
 "problems": {
  "poly2": {
   "description": "Two coupled coordinates with a polynomial potential and different masses",
   "potential": "V_theta(q) = theta * (0.6*x^2 + 0.4*y^2 + 0.18*x*y + 0.05*x^4 + 0.025*y^4), q = (x, y)",
   "gradient": "grad V_theta = theta * (1.2*x + 0.18*y + 0.2*x^3, 0.8*y + 0.18*x + 0.1*y^3)",
   "hessian": "grad^2 V_theta = theta * [[1.2 + 0.6*x^2, 0.18], [0.18, 0.8 + 0.3*y^2]]",
   "mass": [
    1.3,
    0.7
   ]
  }
 },
 "cases": [
  {
   "kind": "modified_gradient",
   "problem": "poly2",
   "q": [
    0.4,
    -0.35
   ],
   "h": 0.12,
   "theta": 1.07,
   "expected": [
    0.46039967906469864,
    -0.2274144992806276
   ],
   "tol": 1e-12
  },
  {
   "kind": "modified_gradient",
   "problem": "poly2",
   "q": [
    -0.6,
    0.5
   ],
   "h": 0.12,
   "theta": 1.07,
   "expected": [
    -0.7212238503949663,
    0.3262098705497078
   ],
   "tol": 1e-12
  },
  {
   "kind": "modified_gradient",
   "problem": "poly2",
   "q": [
    0.2,
    0.7
   ],
   "h": 0.12,
   "theta": 1.07,
   "expected": [
    0.3940301875177301,
    0.6756624439013499
   ],
   "tol": 1e-12
  },
  {
   "kind": "loss",
   "problem": "poly2",
   "q": [
    [
     0.4,
     -0.35
    ],
    [
     -0.6,
     0.5
    ],
    [
     0.2,
     0.7
    ]
   ],
   "forces": [
    [
     -0.48,
     0.27
    ],
    [
     0.61,
     -0.28
    ],
    [
     -0.4,
     -0.5
    ]
   ],
   "h": 0.12,
   "theta": 1.07,
   "expected": {
    "loss": 0.015865575781219145,
    "dloss_dtheta": 0.12039246297041373
   },
   "tol": 1e-12
  },
  {
   "kind": "process",
   "problem": "poly2",
   "q": [
    0.4,
    -0.35
   ],
   "p": [
    0.1,
    0.3
   ],
   "h": 0.12,
   "theta": 1.07,
   "post": false,
   "expected": {
    "q": [
     0.39978783286032765,
     -0.34980538480755125
    ],
    "p": [
     0.10011355379465975,
     0.30023915564963194
    ]
   },
   "tol": 1e-14
  },
  {
   "kind": "process",
   "problem": "poly2",
   "q": [
    0.4,
    -0.35
   ],
   "p": [
    0.1,
    0.3
   ],
   "h": 0.12,
   "theta": 1.07,
   "post": true,
   "expected": {
    "q": [
     0.400212285644832,
     -0.3501947295296062
    ],
    "p": [
     0.09988655325941956,
     0.29976102662415166
    ]
   },
   "tol": 1e-14
  },
  {
   "kind": "rollout",
   "problem": "poly2",
   "q0": [
    0.4,
    -0.35
   ],
   "p0": [
    0.1,
    0.3
   ],
   "h": 0.12,
   "n_steps": 26,
   "every": 6,
   "theta": 1.07,
   "expected": {
    "outputs": [
     {
      "step": 0,
      "q": [
       0.4,
       -0.35
      ],
      "p": [
       0.1,
       0.3
      ]
     },
     {
      "step": 6,
      "q": [
       0.35852749369292497,
       0.0056636058709751465
      ],
      "p": [
       -0.25122106092399976,
       0.35503762765246727
      ]
     },
     {
      "step": 12,
      "q": [
       0.137304167163746,
       0.31147555988498593
      ],
      "p": [
       -0.5192540563654772,
       0.21262827589248315
      ]
     },
     {
      "step": 18,
      "q": [
       -0.17354780469750433,
       0.4098376825080673
      ],
      "p": [
       -0.5570807321165635,
       -0.02479466016187816
      ]
     },
     {
      "step": 24,
      "q": [
       -0.4269141003443347,
       0.27981893481984776
      ],
      "p": [
       -0.31339476325244725,
       -0.207854335673517
      ]
     },
     {
      "step": 26,
      "q": [
       -0.472791762339827,
       0.20301357059657593
      ],
      "p": [
       -0.18041833033618465,
       -0.2371286979033453
      ]
     }
    ],
    "gradient_evaluations": 50
   },
   "tol": 1e-12
  },
  {
   "kind": "rollout",
   "problem": "poly2",
   "q0": [
    0.4,
    -0.35
   ],
   "p0": [
    0.1,
    0.3
   ],
   "h": -0.12,
   "n_steps": 10,
   "every": 10,
   "theta": 1.07,
   "expected": {
    "outputs": [
     {
      "step": 0,
      "q": [
       0.4,
       -0.35
      ],
      "p": [
       0.1,
       0.3
      ]
     },
     {
      "step": 10,
      "q": [
       0.11623136460989367,
       -0.5054011400365997
      ],
      "p": [
       0.43058433774520916,
       -0.16018321720228573
      ]
     }
    ],
    "gradient_evaluations": 18
   },
   "tol": 1e-12
  }
 ]
}
