{
  "blocked": null,
  "replica_source": "\"\"\"AMM challenge replica, pinned engine 6b6921f8; CH d34a5199.\nExtract this string to replica.py. Python 3.10+, no required third-party packages.\nOptional NumPy+Numba accelerates the scalar loop (no fastmath). Pure Python\nfallback preserves configurations and random streams. Set AMM_REPLICA_PURE=1\nbefore import to force it. run_many returns rows (edge, retail_edge, arb_edge,\nretail_volume), in seed order. Defaults: 10,000 steps, 100 X, 10,000 Y.\n\nMarket distributions match Rust, paths deliberately differ: xoshiro128** with\nBox-Muller normals and inverse-product Poisson, separate seed/seed+1 streams.\nCH arithmetic is float64, not Solidity's truncated uint256 WAD arithmetic.\nFee hooks are within markers; TH is the ordered constants below. Flat fees are\nselected by TH[FLAT_FEE]>=0. Fee fractions are clamped to [0,0.1].\n\"\"\"\nimport math\nimport os\nimport multiprocessing as mp\ntry:\n    if os.environ.get('AMM_REPLICA_PURE') == '1':\n        raise ImportError\n    import numpy as np\n    from numba import njit\n    JITTED = True\nexcept ImportError:\n    np = None\n    JITTED = False\n    def njit(*args, **kwargs):\n        return lambda f: f\n\nif JITTED:\n    @njit(cache=True)\n    def zeros(n):\n        return np.zeros(n, dtype=np.float64)\nelse:\n    def zeros(n):\n        return [0.0] * n\n\nTH_NAMES = ['ELAPSED_CAP', 'SIGNAL_THRESHOLD', 'DIR_DECAY', 'ACT_DECAY', 'SIZE_DECAY', 'TOX_DECAY', 'SIGMA_DECAY', 'LAMBDA_DECAY', 'SIZE_BLEND_DECAY', 'TOX_BLEND_DECAY', 'ACT_BLEND_DECAY', 'PHAT_ALPHA', 'PHAT_ALPHA_RETAIL', 'DIR_IMPACT_MULT', 'GATE_SIGMA_MULT', 'MIN_GATE', 'TRADE_TOX_BOOST', 'STALE_ATTRACT_FRAC', 'RET_CAP', 'TOX_CAP', 'TRADE_RATIO_CAP', 'LAMBDA_CAP', 'STEP_COUNT_CAP', 'BASE_FEE', 'SIGMA_COEF', 'LAMBDA_COEF', 'FLOW_SIZE_COEF', 'TOX_COEF', 'TOX_QUAD_COEF', 'ACT_COEF', 'DIR_COEF', 'DIR_TOX_COEF', 'STALE_DIR_COEF', 'SIGMA_TOX_COEF', 'TAIL_KNEE', 'TAIL_SLOPE_PROTECT', 'TAIL_SLOPE_ATTRACT', 'INIT_SIGMA', 'INIT_LAMBDA', 'INIT_SIZE', 'FLAT_FEE']\nTH_VALUES = [8, 0.0015384615384615385, 0.75, 0.53, 0.53, 0.91, 0.69, 0.99, 0.828, 0.051, 0.985, 0.27, 0.06, 4, 7.2, 0.03, 0.35, 1.05, 0.02857142857142857, 0.2, 0.2, 1.82, 64, 0.0004, 0.2, 0.0012, 0.4842, 0.03, 1.5, 9.1843, 0.002, 0.01, 0.685, 0.05, 0.06, 0.93, 0.85, 0.00095, 0.8, 0.002, -1.0]\nTH = np.array(TH_VALUES, dtype=np.float64) if JITTED else TH_VALUES.copy()\nELAPSED_CAP = 0\nSIGNAL_THRESHOLD = 1\nDIR_DECAY = 2\nACT_DECAY = 3\nSIZE_DECAY = 4\nTOX_DECAY = 5\nSIGMA_DECAY = 6\nLAMBDA_DECAY = 7\nSIZE_BLEND_DECAY = 8\nTOX_BLEND_DECAY = 9\nACT_BLEND_DECAY = 10\nPHAT_ALPHA = 11\nPHAT_ALPHA_RETAIL = 12\nDIR_IMPACT_MULT = 13\nGATE_SIGMA_MULT = 14\nMIN_GATE = 15\nTRADE_TOX_BOOST = 16\nSTALE_ATTRACT_FRAC = 17\nRET_CAP = 18\nTOX_CAP = 19\nTRADE_RATIO_CAP = 20\nLAMBDA_CAP = 21\nSTEP_COUNT_CAP = 22\nBASE_FEE = 23\nSIGMA_COEF = 24\nLAMBDA_COEF = 25\nFLOW_SIZE_COEF = 26\nTOX_COEF = 27\nTOX_QUAD_COEF = 28\nACT_COEF = 29\nDIR_COEF = 30\nDIR_TOX_COEF = 31\nSTALE_DIR_COEF = 32\nSIGMA_TOX_COEF = 33\nTAIL_KNEE = 34\nTAIL_SLOPE_PROTECT = 35\nTAIL_SLOPE_ATTRACT = 36\nINIT_SIGMA = 37\nINIT_LAMBDA = 38\nINIT_SIZE = 39\nFLAT_FEE = 40\n\n# STRATEGY BEGIN\n@njit(cache=True)\ndef strat_init(S, TH, x0, y0):\n    for i in range(40):\n        S[i] = 0.0\n    fee = TH[BASE_FEE] if TH[FLAT_FEE] < 0 else TH[FLAT_FEE]\n    S[0] = fee\n    S[1] = fee\n    S[3] = 1.0\n    S[5] = y0 / x0 if x0 > 0 else 100.0\n    S[6] = TH[INIT_SIGMA]\n    S[7] = TH[INIT_LAMBDA]\n    S[8] = TH[INIT_SIZE]\n    return fee, fee\n\n@njit(cache=True)\ndef strat_after(S, TH, is_buy, amount_x, amount_y, timestamp, reserve_x, reserve_y):\n    if TH[FLAT_FEE] >= 0:\n        return TH[FLAT_FEE], TH[FLAT_FEE]\n    direction, act, phat = S[3], S[4], S[5]\n    sigma, lam, size, toxema, count = S[6], S[7], S[8], S[9], S[10]\n    if timestamp > S[2]:\n        raw = timestamp - S[2]\n        elapsed = min(raw, TH[ELAPSED_CAP])\n        direction = 1.0 + (direction - 1.0) * TH[DIR_DECAY] ** elapsed\n        act *= TH[ACT_DECAY] ** elapsed\n        size *= TH[SIZE_DECAY] ** elapsed\n        toxema *= TH[TOX_DECAY] ** elapsed\n        if count > 0:\n            inst = min(count / raw, TH[LAMBDA_CAP])\n            lam = lam * TH[LAMBDA_DECAY] + inst * (1.0 - TH[LAMBDA_DECAY])\n        count = 0.0\n    first = count == 0\n    spot = reserve_y / reserve_x if reserve_x > 0 else phat\n    if phat == 0:\n        phat = spot\n    fee_used = S[0] if is_buy else S[1]\n    gamma = max(1.0 - fee_used, 0.0)\n    implied = spot if gamma == 0 else (spot * gamma if is_buy else spot / gamma)\n    ret = abs(implied - phat) / phat if phat > 0 else 0.0\n    alpha = TH[PHAT_ALPHA] if first else TH[PHAT_ALPHA_RETAIL]\n    gate = max(sigma * TH[GATE_SIGMA_MULT], TH[MIN_GATE])\n    if ret <= gate:\n        phat = phat * (1.0 - alpha) + implied * alpha\n    if first:\n        ret = min(ret, TH[RET_CAP])\n        sigma = sigma * TH[SIGMA_DECAY] + ret * (1.0 - TH[SIGMA_DECAY])\n    ratio = min(amount_y / reserve_y, TH[TRADE_RATIO_CAP]) if reserve_y > 0 else 0.0\n    if ratio > TH[SIGNAL_THRESHOLD]:\n        push = min(ratio * TH[DIR_IMPACT_MULT], 0.25)\n        direction = min(direction + push, 2.0) if is_buy else max(direction - push, 0.0)\n        act = act * TH[ACT_BLEND_DECAY] + ratio * (1.0 - TH[ACT_BLEND_DECAY])\n        size = min(size * TH[SIZE_BLEND_DECAY] + ratio * (1.0 - TH[SIZE_BLEND_DECAY]), 1.0)\n    tox = min(abs(spot - phat) / phat, TH[TOX_CAP]) if phat > 0 else 0.0\n    toxema = toxema * TH[TOX_BLEND_DECAY] + tox * (1.0 - TH[TOX_BLEND_DECAY])\n    count = min(count + 1.0, TH[STEP_COUNT_CAP])\n    flow = lam * size\n    base = TH[BASE_FEE] + TH[SIGMA_COEF] * sigma + TH[LAMBDA_COEF] * lam + TH[FLOW_SIZE_COEF] * flow\n    mid = base + TH[TOX_COEF] * toxema + TH[TOX_QUAD_COEF] * toxema * toxema + TH[ACT_COEF] * act\n    mid += TH[SIGMA_TOX_COEF] * sigma * toxema\n    dev = abs(direction - 1.0)\n    sell_pressure = direction >= 1.0\n    skew = TH[DIR_COEF] * dev + TH[DIR_TOX_COEF] * dev * toxema\n    if sell_pressure:\n        bid, ask = mid + skew, max(mid - skew, 0.0)\n    else:\n        bid, ask = max(mid - skew, 0.0), mid + skew\n    shift = TH[STALE_DIR_COEF] * toxema\n    attract = shift * TH[STALE_ATTRACT_FRAC]\n    if spot >= phat:\n        bid += shift\n        ask = max(ask - attract, 0.0)\n    else:\n        ask += shift\n        bid = max(bid - attract, 0.0)\n    aligned = (is_buy and spot >= phat) or (not is_buy and spot < phat)\n    if aligned:\n        boost = TH[TRADE_TOX_BOOST] * ratio\n        if is_buy:\n            bid += boost\n        else:\n            ask += boost\n    bid_slope = TH[TAIL_SLOPE_PROTECT] if sell_pressure else TH[TAIL_SLOPE_ATTRACT]\n    ask_slope = TH[TAIL_SLOPE_ATTRACT] if sell_pressure else TH[TAIL_SLOPE_PROTECT]\n    knee = TH[TAIL_KNEE]\n    if bid > knee:\n        bid = knee + (bid - knee) * bid_slope\n    if ask > knee:\n        ask = knee + (ask - knee) * ask_slope\n    bid, ask = min(bid, 0.1), min(ask, 0.1)\n    S[0], S[1], S[2], S[3], S[4], S[5] = bid, ask, timestamp, direction, act, phat\n    S[6], S[7], S[8], S[9], S[10] = sigma, lam, size, toxema, count\n    return bid, ask\n# STRATEGY END\n\n@njit(cache=True)\ndef _rot32(x, k):\n    return ((x << k) | (x >> (32 - k))) & 0xffffffff\n\n@njit(cache=True)\ndef _rng_init(seed):\n    r = zeros(4)\n    z = (int(seed) ^ (int(seed) >> 32)) & 0xffffffff\n    for i in range(4):\n        z = (z + 0x9e3779b9) & 0xffffffff\n        x = z\n        x = ((x ^ (x >> 16)) * 0x21f0aaad) & 0xffffffff\n        x = ((x ^ (x >> 15)) * 0x735a2d97) & 0xffffffff\n        r[i] = x ^ (x >> 15)\n    return r\n\n@njit(cache=True)\ndef _u32(r):\n    a, b, c, d = int(r[0]), int(r[1]), int(r[2]), int(r[3])\n    result = (_rot32((b * 5) & 0xffffffff, 7) * 9) & 0xffffffff\n    t = (b << 9) & 0xffffffff\n    c ^= a\n    d ^= b\n    b ^= c\n    a ^= d\n    c ^= t\n    d = _rot32(d, 11)\n    r[0], r[1], r[2], r[3] = a, b, c, d\n    return result\n\n@njit(cache=True)\ndef _uniform(r):\n    a = _u32(r) >> 5\n    b = _u32(r) >> 6\n    return (a * 67108864.0 + b) / 9007199254740992.0\n\n@njit(cache=True)\ndef _normal(r):\n    # Open at zero; one normal per Box-Muller pair, no hidden cache/state.\n    u = 1.0 - _uniform(r)\n    return math.sqrt(-2.0 * math.log(u)) * math.cos(2.0 * math.pi * _uniform(r))\n\n@njit(cache=True)\ndef _poisson(r, rate):\n    limit = math.exp(-max(rate, 0.01))\n    prod = 1.0\n    k = 0\n    while prod > limit:\n        prod *= _uniform(r)\n        k += 1\n    return k - 1\n\n@njit(cache=True)\ndef _hook(S, TH, is_buy, ax, ay, t, x, y):\n    bid, ask = strat_after(S, TH, is_buy, ax, ay, t, x, y)\n    return min(max(bid, 0.0), 0.1), min(max(ask, 0.0), 0.1)\n\n@njit(cache=True)\ndef run_market(TH, seed, mean_size, rate, sigma, n_steps):\n    \"\"\"One strategy vs Vanilla; returns edge, retail_edge, arb_edge, retail Y volume.\n\n    Inputs use normalized units (WAD/1e18); timestamp is an integer step.\n    TH must be float64 contiguous when Numba is available. S is float64[40].\n    Both random streams are independent of strategy execution and therefore\n    identical across paired fee variants at the same seed/config.\n    \"\"\"\n    S = zeros(40)\n    xs, ys, bids, asks = zeros(2), zeros(2), zeros(2), zeros(2)\n    xs[0], xs[1], ys[0], ys[1] = 100.0, 100.0, 10000.0, 10000.0\n    bid, ask = strat_init(S, TH, 100.0, 10000.0)\n    bids[0], asks[0] = min(max(bid, 0.0), 0.1), min(max(ask, 0.0), 0.1)\n    bids[1], asks[1] = 0.003, 0.003\n    prng, rrng = _rng_init(seed), _rng_init(seed + 1)\n    p = 100.0\n    retail_edge, arb_edge, retail_volume, edge = 0.0, 0.0, 0.0, 0.0\n    mu_size = math.log(max(mean_size, 0.01)) - 0.5 * 1.2 * 1.2\n    drift = -0.5 * sigma * sigma\n    for t in range(n_steps):\n        p *= math.exp(drift + sigma * _normal(prng))\n        # One arb attempt per pool, submission then normalizer. No iteration.\n        for i in range(2):\n            x, y = xs[i], ys[i]\n            k, spot = x * y, y / x\n            if spot < p:\n                gamma = 1.0 - asks[i]\n                ax = min(x - math.sqrt(k / (gamma * p)), x * 0.99)\n                if ax <= 0.0:\n                    continue\n                nx = x - ax\n                ny = k / nx\n                net_y = ny - y\n                ay = net_y / gamma\n                profit = ax * p - ay\n                if ay <= 0.0 or profit <= 0.0:\n                    continue\n                # Rust executes amount-fee for reserve accounting.\n                fee_y = ay - net_y\n                xs[i], ys[i] = nx, y + (ay - fee_y)\n                is_buy = False\n            elif spot > p:\n                gamma = 1.0 - bids[i]\n                ax = (math.sqrt(k * gamma / p) - x) / gamma\n                if ax <= 0.0:\n                    continue\n                ay = y - k / (x + ax * gamma)\n                profit = ay - ax * p\n                if ay <= 0.0 or profit <= 0.0:\n                    continue\n                xs[i], ys[i] = x + (ax - ax * bids[i]), y - ay\n                is_buy = True\n            else:\n                continue\n            if i == 0:\n                arb_edge -= profit\n                edge -= profit\n                bids[0], asks[0] = _hook(S, TH, is_buy, ax, ay, t, xs[0], ys[0])\n        # All retail random draws are independent of hooks and routing.\n        count = _poisson(rrng, rate)\n        for order in range(count):\n            size = math.exp(mu_size + 1.2 * _normal(rrng))\n            trader_buy = _uniform(rrng) < 0.5\n            total = size if trader_buy else size / p\n            g0 = 1.0 - (asks[0] if trader_buy else bids[0])\n            g1 = 1.0 - (asks[1] if trader_buy else bids[1])\n            a0 = math.sqrt(xs[0] * g0 * ys[0])\n            a1 = math.sqrt(xs[1] * g1 * ys[1])\n            if a1 == 0:\n                split = total\n            else:\n                r = a0 / a1\n                reserve0 = ys[0] if trader_buy else xs[0]\n                reserve1 = ys[1] if trader_buy else xs[1]\n                denom = g0 + r * g1\n                split = total / 2 if denom == 0 else (r * (reserve1 + g1 * total) - reserve0) / denom\n                split = min(max(split, 0.0), total)\n            # Both allocations are fixed before first pool's hook.\n            for i in range(2):\n                amount = split if i == 0 else total - split\n                if amount <= 0.0001:\n                    continue\n                x, y = xs[i], ys[i]\n                if trader_buy:\n                    ay = amount\n                    ax = x - x * y / (y + ay * (1.0 - asks[i]))\n                    if ax <= 0:\n                        continue\n                    xs[i], ys[i] = x - ax, y + (ay - ay * asks[i])\n                    trade_edge = ay - ax * p\n                else:\n                    ax = amount\n                    ay = y - x * y / (x + ax * (1.0 - bids[i]))\n                    if ay <= 0:\n                        continue\n                    xs[i], ys[i] = x + (ax - ax * bids[i]), y - ay\n                    trade_edge = ax * p - ay\n                if i == 0:\n                    retail_edge += trade_edge\n                    edge += trade_edge\n                    retail_volume += ay\n                    bids[0], asks[0] = _hook(S, TH, not trader_buy, ax, ay, t, xs[0], ys[0])\n    return edge, retail_edge, arb_edge, retail_volume\n\n\ndef _config_uniforms(seed):\n    \"\"\"Pure-Python NumPy SeedSequence(integer)->PCG64, first three doubles.\n\n    Implements only the nonnegative integer entropy/no spawn-key case used by\n    MatchRunner. Python integers make uint32/uint128 truncation explicit.\n    \"\"\"\n    seed = int(seed)\n    if seed < 0:\n        raise ValueError('seed must be nonnegative')\n    mask = (1 << 32) - 1\n    entropy = []\n    while seed:\n        entropy.append(seed & mask)\n        seed >>= 32\n    if not entropy:\n        entropy = [0]\n    hc = 0x43b0d7e5\n    def hashed(v):\n        nonlocal hc\n        v ^= hc\n        hc = (hc * 0x931e8875) & mask\n        v = (v * hc) & mask\n        return v ^ (v >> 16)\n    def mix(x, y):\n        v = (0xca01f9dd * x - 0x4973f715 * y) & mask\n        return v ^ (v >> 16)\n    pool = [hashed(entropy[i] if i < len(entropy) else 0) for i in range(4)]\n    for src in range(4):\n        for dst in range(4):\n            if src != dst:\n                pool[dst] = mix(pool[dst], hashed(pool[src]))\n    for v in entropy[4:]:\n        for dst in range(4):\n            pool[dst] = mix(pool[dst], hashed(v))\n    hc = 0x8b51f9dd\n    words = []\n    for i in range(8):\n        v = pool[i % 4] ^ hc\n        hc = (hc * 0x58f38ded) & mask\n        v = (v * hc) & mask\n        words.append(v ^ (v >> 16))\n    words64 = [words[2*i] | (words[2*i+1] << 32) for i in range(4)]\n    initial = (words64[0] << 64) | words64[1]\n    mask128 = (1 << 128) - 1\n    mask64 = (1 << 64) - 1\n    inc = ((((words64[2] << 64) | words64[3]) << 1) | 1) & mask128\n    mult = (2549297995355413924 << 64) | 4865540595714422341\n    state = ((inc + initial) * mult + inc) & mask128\n    out = []\n    for i in range(3):\n        state = (state * mult + inc) & mask128\n        v = ((state >> 64) ^ state) & mask64\n        rot = state >> 122\n        raw = ((v >> rot) | (v << ((-rot) & 63))) & mask64\n        out.append((raw >> 11) / 9007199254740992.0)\n    return out\n\n\ndef config_for_seed(seed):\n    \"\"\"Exact MatchRunner draw order: size, arrival rate, volatility.\"\"\"\n    if JITTED:\n        r = np.random.default_rng(int(seed))\n        return r.uniform(19.0, 21.0), r.uniform(0.6, 1.0), r.uniform(0.000882, 0.001008)\n    a, b, c = _config_uniforms(seed)\n    return 19.0 + 2.0*a, 0.6 + 0.4*b, 0.000882 + (0.001008 - 0.000882)*c\n\n\n_WORKER_TH = None\n_WORKER_STEPS = 10000\n\ndef _worker_init(theta, n_steps):\n    global _WORKER_TH, _WORKER_STEPS\n    _WORKER_TH = np.asarray(theta, dtype=np.float64) if JITTED else list(theta)\n    _WORKER_STEPS = n_steps\n\n\ndef _worker(seed):\n    size, rate, sigma = config_for_seed(seed)\n    return run_market(_WORKER_TH, int(seed), size, rate, sigma, _WORKER_STEPS)\n\n\ndef run_many(TH, seeds, procs=8, n_steps=10000):\n    \"\"\"Ordered N x 4 array (list of tuples without NumPy), spawn-safe workers.\n\n    Call under if __name__ == '__main__' when using procs>1. Time the full call\n    after warming run_market for throughput including process startup and IPC.\n    n_steps is optional; challenge validation uses the default 10000.\n    \"\"\"\n    seeds = list(seeds)\n    if procs < 1:\n        raise ValueError('procs must be positive')\n    if not seeds:\n        return np.empty((0,4), dtype=np.float64) if JITTED else []\n    if procs == 1:\n        _worker_init(TH, n_steps)\n        rows = [_worker(seed) for seed in seeds]\n    else:\n        with mp.get_context('spawn').Pool(procs, initializer=_worker_init,\n                                         initargs=(TH, n_steps)) as pool:\n            rows = pool.map(_worker, seeds, chunksize=max(1, len(seeds)//(procs*8)))\n    return np.asarray(rows, dtype=np.float64) if JITTED else rows\n\n\nif __name__ == '__main__':\n    import argparse\n    import json\n    import time\n    ap = argparse.ArgumentParser()\n    ap.add_argument('--n', type=int, default=256)\n    ap.add_argument('--start', type=int, default=0)\n    ap.add_argument('--procs', type=int, default=8)\n    ap.add_argument('--steps', type=int, default=10000)\n    args = ap.parse_args()\n    run_market(TH, 0, 20.0, 0.8, 0.000945, 1)\n    start = time.perf_counter()\n    rows = run_many(TH, range(args.start, args.start+args.n), args.procs, args.steps)\n    elapsed = time.perf_counter() - start\n    print(json.dumps({'n':len(rows), 'jitted':JITTED,\n          'means':[sum(float(row[i]) for row in rows)/len(rows) for i in range(4)],\n          'seconds':elapsed, 'markets_per_second':len(rows)/elapsed}))\n",
  "sha256": "25a8eb8af92964ce7171daf6df48f4c4b8dbcbd913de8d0a33054e0ed204f7a8",
  "th_names": [
    "ELAPSED_CAP",
    "SIGNAL_THRESHOLD",
    "DIR_DECAY",
    "ACT_DECAY",
    "SIZE_DECAY",
    "TOX_DECAY",
    "SIGMA_DECAY",
    "LAMBDA_DECAY",
    "SIZE_BLEND_DECAY",
    "TOX_BLEND_DECAY",
    "ACT_BLEND_DECAY",
    "PHAT_ALPHA",
    "PHAT_ALPHA_RETAIL",
    "DIR_IMPACT_MULT",
    "GATE_SIGMA_MULT",
    "MIN_GATE",
    "TRADE_TOX_BOOST",
    "STALE_ATTRACT_FRAC",
    "RET_CAP",
    "TOX_CAP",
    "TRADE_RATIO_CAP",
    "LAMBDA_CAP",
    "STEP_COUNT_CAP",
    "BASE_FEE",
    "SIGMA_COEF",
    "LAMBDA_COEF",
    "FLOW_SIZE_COEF",
    "TOX_COEF",
    "TOX_QUAD_COEF",
    "ACT_COEF",
    "DIR_COEF",
    "DIR_TOX_COEF",
    "STALE_DIR_COEF",
    "SIGMA_TOX_COEF",
    "TAIL_KNEE",
    "TAIL_SLOPE_PROTECT",
    "TAIL_SLOPE_ATTRACT",
    "INIT_SIGMA",
    "INIT_LAMBDA",
    "INIT_SIZE",
    "FLAT_FEE"
  ],
  "th_default": [
    8,
    0.0015384615384615385,
    0.75,
    0.53,
    0.53,
    0.91,
    0.69,
    0.99,
    0.828,
    0.051,
    0.985,
    0.27,
    0.06,
    4,
    7.2,
    0.03,
    0.35,
    1.05,
    0.02857142857142857,
    0.2,
    0.2,
    1.82,
    64,
    0.0004,
    0.2,
    0.0012,
    0.4842,
    0.03,
    1.5,
    9.1843,
    0.002,
    0.01,
    0.685,
    0.05,
    0.06,
    0.93,
    0.85,
    0.00095,
    0.8,
    0.002,
    -1.0
  ],
  "method": {
    "engine_commit": "6b6921f8d463314aa7c96234e1be25a25245f704",
    "engine_source": "https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_sim_rs/src/simulation/engine.rs",
    "strategy_source": "https://raw.githubusercontent.com/ChengHua926/amm-challenge/d34a5199c59a4c44d5336a25f1436b4ae1f21104/contracts/src/Strategy.sol",
    "config_source": "https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_competition/competition/match.py",
    "settings_source": "https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_competition/competition/config.py",
    "real_engine": "amm_sim_rs 0.1.0.post1, wheel SHA256 aedb68280aca34c110968f00148387c95885207913fb2cf19a1ab4c5cfd6887a",
    "real_calls": "amm_sim_rs.run_batch(submission_bytecode, vanilla_bytecode, configs, 8); 32-config chunks, one submission and one Vanilla per market; gas_stats_reset before each complete strategy run",
    "compiler": "Solidity 0.8.24, optimizer 200, viaIR, EVM paris; upstream SolidityCompiler",
    "n_steps": 10000,
    "initial_x": 100.0,
    "initial_y": 10000.0,
    "initial_price": 100.0,
    "mu": 0.0,
    "dt": 1.0,
    "retail_size_sigma": 1.2,
    "retail_buy_prob": 0.5,
    "config_generation": "default_rng(seed) draws uniform(19,21), uniform(0.6,1.0), uniform(0.000882,0.001008), in that order; exact stdlib SeedSequence/PCG64 fallback included",
    "streams": "Rust: Pcg64 seed / seed+1; replica: independent xoshiro128** seed / seed+1. Identical stream per fee variant within each engine.",
    "validation_se": "sqrt(sample_var(real)/n_real + sample_var(replica)/n_replica), ddof=1; diff = replica mean - real mean; two-sample SE requested despite same configuration seeds",
    "transfer_se": "For each engine, sample_sd(variant edge - CH edge)/sqrt(n), ddof=1. Combined se = sqrt(real_se^2 + replica_se^2). Worst = smallest per-market paired edge difference.",
    "units": "Y-token edge; fees fractions; amounts/reserves WAD/1e18; timestamp integer step",
    "perturbations": "Three independent one-at-a-time changes; stale shift means STALE_DIR_COEF, scaling both protective shift and the derived attraction shift."
  },
  "validation": {
    "CH": {
      "seeds": {
        "start": 0,
        "stop_exclusive": 1000
      },
      "real_mean": 525.5258821780834,
      "replica_mean": 526.6481241447553,
      "diff": 1.122241966671936,
      "se": 3.983886406108961,
      "z": 0.2816952724733995,
      "real": {
        "n": 1000,
        "mean": 525.5258821780834,
        "sd": 88.20940976057928,
        "se": 2.7894264590251843,
        "min": 335.2599069447382,
        "max": 799.7496034177782
      },
      "replica": {
        "n": 1000,
        "mean": 526.6481241447553,
        "sd": 89.94693394702233,
        "se": 2.8443717982130954,
        "min": 314.6057227760197,
        "max": 829.866032311195
      },
      "gas": {
        "max_ok": 151647,
        "oog": 0,
        "afterSwap_submission_calls": 10445223,
        "afterSwap_submission_ok": 10445223,
        "max_ok_initialize_submission": 185532,
        "all_roles_other_errors": 0
      },
      "replica_retail_edge_mean": 556.1860068088107,
      "replica_arb_edge_mean": -29.537882664055374,
      "replica_retail_volume_mean": 76923.21780557383,
      "real_retail_volume_mean": 76855.64867581258,
      "evidence": "Local measured run; reproduction.real_checks and reproduction.replica_checks; rules from method.engine_source and method.config_source.",
      "expected_real_mean": 525.5258821780834,
      "reference_error": 0.0
    },
    "flat30": {
      "seeds": {
        "start": 0,
        "stop_exclusive": 256
      },
      "real_mean": 347.9224335871958,
      "replica_mean": 347.09377738416623,
      "diff": -0.8286562030295954,
      "se": 4.435551180095908,
      "z": -0.18682147254846412,
      "real": {
        "n": 256,
        "mean": 347.9224335871958,
        "sd": 50.22855477671973,
        "se": 3.1392846735449833,
        "min": 248.6869669631139,
        "max": 460.4780415087
      },
      "replica": {
        "n": 256,
        "mean": 347.09377738416623,
        "sd": 50.1364691465416,
        "se": 3.13352932165885,
        "min": 236.38301745915348,
        "max": 462.5342312154702
      },
      "gas": {
        "max_ok": 22592,
        "oog": 0,
        "afterSwap_submission_calls": 2971306,
        "afterSwap_submission_ok": 2971306,
        "max_ok_initialize_submission": 21796,
        "all_roles_other_errors": 0
      },
      "replica_retail_edge_mean": 576.3879379677558,
      "replica_arb_edge_mean": -229.29416058358953,
      "replica_retail_volume_mean": 80740.64072601273,
      "real_retail_volume_mean": 80891.47110120568,
      "evidence": "Local measured run; reproduction.real_checks and reproduction.replica_checks; rules from method.engine_source and method.config_source."
    }
  },
  "transfer": {
    "base_plus3": {
      "change": {
        "constant": "BASE_FEE",
        "original": 0.0004,
        "variant": 0.0007
      },
      "real_seeds": {
        "start": 676100,
        "stop_exclusive": 676228
      },
      "replica_seeds": {
        "start": 676100,
        "stop_exclusive": 680196
      },
      "real_delta": -1.0552259184310975,
      "replica_delta": -0.9222213214113749,
      "real_se": 0.08048985801417369,
      "replica_se": 0.01509991812430501,
      "diff": 0.13300459701972256,
      "se": 0.08189398494701888,
      "z": 1.6241070343050172,
      "real_paired": {
        "n": 128,
        "mean_diff": -1.0552259184310975,
        "se": 0.08048985801417369,
        "worst": -3.778599656806364
      },
      "replica_paired": {
        "n": 4096,
        "mean_diff": -0.9222213214113749,
        "se": 0.01509991812430501,
        "worst": -13.249261313513898
      },
      "replica_retail_edge_delta": {
        "n": 4096,
        "mean": -3.9340595076476705,
        "sd": 1.044685113854049,
        "se": 0.016323204903969515,
        "min": -18.512290465867977,
        "max": 0.1003729984081474
      },
      "replica_arb_edge_delta": {
        "n": 4096,
        "mean": 3.0118381862362806,
        "sd": 0.3705265742139352,
        "se": 0.0057894777220927375,
        "min": -0.45060055892179207,
        "max": 7.0416540120235425
      },
      "replica_retail_volume_delta": {
        "n": 4096,
        "mean": -4154.824654013553,
        "sd": 488.0658093342171,
        "se": 7.626028270847142,
        "min": -7394.22075676758,
        "max": -3014.0875596098995
      },
      "real_retail_edge_delta": null,
      "real_arb_edge_delta": null,
      "gas": {
        "max_ok": 150982,
        "oog": 0,
        "afterSwap_submission_calls": 1261068,
        "afterSwap_submission_ok": 1261068,
        "max_ok_initialize_submission": 185532,
        "all_roles_other_errors": 0
      },
      "evidence": "Local measured paired arrays, each strategy alone against Vanilla. Real and replica random paths differ. No rescaling or fitting."
    },
    "stale_x08": {
      "change": {
        "constant": "STALE_DIR_COEF",
        "original": 0.685,
        "variant": 0.548
      },
      "real_seeds": {
        "start": 676100,
        "stop_exclusive": 676228
      },
      "replica_seeds": {
        "start": 676100,
        "stop_exclusive": 680196
      },
      "real_delta": -6.858314321978259,
      "replica_delta": -6.754375511814141,
      "real_se": 0.17948026265614378,
      "replica_se": 0.03468420109446881,
      "diff": 0.10393881016411832,
      "se": 0.18280087113763957,
      "z": 0.5685903437837437,
      "real_paired": {
        "n": 128,
        "mean_diff": -6.858314321978259,
        "se": 0.17948026265614378,
        "worst": -14.873395287649146
      },
      "replica_paired": {
        "n": 4096,
        "mean_diff": -6.754375511814141,
        "se": 0.03468420109446881,
        "worst": -20.873797144120886
      },
      "replica_retail_edge_delta": {
        "n": 4096,
        "mean": 9.354721880042248,
        "sd": 2.283125739879183,
        "se": 0.03567383968561223,
        "min": 3.370398639729842,
        "max": 29.36512283901817
      },
      "replica_arb_edge_delta": {
        "n": 4096,
        "mean": -16.10909739185641,
        "sd": 2.840047881321279,
        "se": 0.04437574814564498,
        "min": -29.111280209498574,
        "max": -9.34497939872642
      },
      "replica_retail_volume_delta": {
        "n": 4096,
        "mean": 3802.2575563724067,
        "sd": 619.1535402622592,
        "se": 9.6742740665978,
        "min": 2314.085002318927,
        "max": 8071.074129970031
      },
      "real_retail_edge_delta": null,
      "real_arb_edge_delta": null,
      "gas": {
        "max_ok": 150899,
        "oog": 0,
        "afterSwap_submission_calls": 1443496,
        "afterSwap_submission_ok": 1443496,
        "max_ok_initialize_submission": 185532,
        "all_roles_other_errors": 0
      },
      "evidence": "Local measured paired arrays, each strategy alone against Vanilla. Real and replica random paths differ. No rescaling or fitting."
    },
    "lambda_x15": {
      "change": {
        "constant": "LAMBDA_COEF",
        "original": 0.0012,
        "variant": 0.0018
      },
      "real_seeds": {
        "start": 676100,
        "stop_exclusive": 676228
      },
      "replica_seeds": {
        "start": 676100,
        "stop_exclusive": 680196
      },
      "real_delta": -4.242972174634329,
      "replica_delta": -3.924723006182335,
      "real_se": 0.15237986188242605,
      "replica_se": 0.029044758228203082,
      "diff": 0.31824916845199436,
      "se": 0.1551232422554467,
      "z": 2.051589199817798,
      "real_paired": {
        "n": 128,
        "mean_diff": -4.242972174634329,
        "se": 0.15237986188242605,
        "worst": -9.284612845821357
      },
      "replica_paired": {
        "n": 4096,
        "mean_diff": -3.924723006182335,
        "se": 0.029044758228203082,
        "worst": -13.967675825691401
      },
      "replica_retail_edge_delta": {
        "n": 4096,
        "mean": -9.808124009794632,
        "sd": 2.0818380151138243,
        "se": 0.032528718986153504,
        "min": -20.580715205715364,
        "max": -3.2112699005169816
      },
      "replica_arb_edge_delta": {
        "n": 4096,
        "mean": 5.883401003612254,
        "sd": 0.7691525889150074,
        "se": 0.01201800920179699,
        "min": 3.8465589878211404,
        "max": 26.37276134563899
      },
      "replica_retail_volume_delta": {
        "n": 4096,
        "mean": -8623.621093217747,
        "sd": 1190.018294017279,
        "se": 18.594035844019984,
        "min": -12149.876775212862,
        "max": -6032.840335513436
      },
      "real_retail_edge_delta": null,
      "real_arb_edge_delta": null,
      "gas": {
        "max_ok": 150899,
        "oog": 0,
        "afterSwap_submission_calls": 1153407,
        "afterSwap_submission_ok": 1153407,
        "max_ok_initialize_submission": 185532,
        "all_roles_other_errors": 0
      },
      "evidence": "Local measured paired arrays, each strategy alone against Vanilla. Real and replica random paths differ. No rescaling or fitting."
    }
  },
  "transfer_baseline": {
    "real": {
      "n": 128,
      "mean": 531.3011528329869,
      "sd": 85.23640085679935,
      "se": 7.533904631222208,
      "min": 361.92613691694464,
      "max": 749.6252288949235
    },
    "replica": {
      "n": 4096,
      "mean": 521.0440922590817,
      "sd": 90.24239352942746,
      "se": 1.410037398897304,
      "min": 315.0500084853589,
      "max": 975.7387497764842
    },
    "gas": {
      "max_ok": 150899,
      "oog": 0,
      "afterSwap_submission_calls": 1347829,
      "afterSwap_submission_ok": 1347829,
      "max_ok_initialize_submission": 185532,
      "all_roles_other_errors": 0
    }
  },
  "speed": {
    "processes": 8,
    "n": 4096,
    "n_steps": 10000,
    "seconds": 5.746815843973309,
    "markets_per_second": 712.7425188498913,
    "includes": "process spawn, worker cache loading, per-seed configuration, simulation, IPC, result collection; parent JIT warmup excluded",
    "backend": "Numba 0.68.1; NumPy 2.5.4; Python 3.12.3",
    "concurrent_simulations": false,
    "mean_edge": 522.0851384912567
  },
  "checks": {
    "CH": {
      "calls": 3000,
      "max_abs_fee_error": 8.951173136040325e-16
    },
    "base_plus3": {
      "calls": 3000,
      "max_abs_fee_error": 8.673617379884035e-16
    },
    "stale_x08": {
      "calls": 3000,
      "max_abs_fee_error": 6.522560269672795e-16
    },
    "lambda_x15": {
      "calls": 3000,
      "max_abs_fee_error": 8.049116928532385e-16
    },
    "pure_vs_jit": {
      "markets": 8,
      "steps_each": 1000,
      "max_abs_output_error": 0.0
    },
    "config_exactness": {
      "seeds": 5099,
      "all_equal": true
    },
    "offline_smoke": {
      "command": "python -S scratch/replica.py --n 2 --steps 100 --procs 2",
      "exit_code": 0,
      "jitted": false
    }
  },
  "deviations": [
    {
      "rule": "Random-number paths",
      "detail": "The Rust Pcg64 seed expansion and rand_distr samplers are not ported. The replica uses xoshiro128** with a custom 32-bit seed mixer, Box-Muller StandardNormal, and product-inversion Poisson. Both streams and all target distributions/parameters are preserved, but same-seed paths are not identical. Market seed initialization folds high and low 32-bit halves, so different 64-bit seeds can collide; requested seeds are below 2^32.",
      "impact": "Use population comparisons and within-engine paired deltas, not same-seed real-minus-replica path comparisons."
    },
    {
      "rule": "Fixed-point and EVM execution",
      "detail": "Float64 CH arithmetic replaces uint256 WAD floors and omits float->WAD->float trade/fee quantization. Synthetic callback tests bound observed fee discrepancies, not all possible paths. No EVM, gas estimator, revert, overflow or OOG behavior is modeled; a hook exception propagates. The real CFMM keeps old fees on callback error. All measured real runs had zero callback failures.",
      "impact": "Not a replacement for real gas/validity checks; rerun any selected new strategy in the real engine."
    },
    {
      "rule": "Configured market scope",
      "detail": "Only the requested two-pool/default-config market is implemented. n_steps, size, arrival rate and price volatility are arguments; initial reserves/price, zero drift, dt=1, retail log-sigma=1.2, buy probability=0.5 and Vanilla 30 bps are fixed. No multi-pool router, PnL chart, fee bucket balances or per-step output is returned. Edge, arb edge, retail edge and retail Y volume do not need fee bucket balances."
    },
    {
      "rule": "Statistical transfer limit",
      "detail": "The lambda x1.5 transfer difference is about 2.05 combined SE (exact value in transfer.lambda_x15.z). Results support coarse family screening, not a claim of exact transfer at sub-unit gains. No parameter fitting was done to force agreement."
    }
  ],
  "notes": [
    "Extract replica_source verbatim to replica.py; its SHA256 is supplied. With NumPy and Numba it uses a jitted scalar loop and float64[40] strategy state. Without them it runs entirely offline using only the Python standard library; the optional accelerators and simulator are measurement tools, not required shipped dependencies.",
    "run_many(TH, seeds, procs) returns an N-by-4 array, or list of 4-tuples in the standard-library fallback, in seed order. Columns: edge, retail_edge, arb_edge, retail_volume. Call multiprocessing under a __main__ guard. TH can be copied and modified by index from th_names.",
    "Flat30 uses TH[FLAT_FEE]=0.003; CH uses -1. All CH tunable constants and initialization estimates are in TH. Other structural literals (clamp, centered state, impact cap) follow CH source.",
    "Sources below establish the model and port; numerical results are this run's observations, not values claimed by those URLs. Reproduction scripts are embedded to make the measurements reviewable.",
    "The real result API exposes total edge and retail volume but not separate retail/arb edge. Those real decomposition fields are null, not inferred from volume. Replica decompositions are returned and reported.",
    "All requested validation and transfer blocks were measured once. Additional 3000-call tests per CH variant used synthetic trades to exercise branch behavior, including repeated timestamps, gaps, clipping and large trades; they are not performance markets.",
    "The standard-library fallback was additionally run using python -S, 2 spawned workers, 2 markets of 100 steps, without site-packages; it completed successfully.",
    "About 713 markets/second is rounded; use speed.markets_per_second for the measured value. The benchmark has 8 spawned processes and includes startup and result collection, after a parent warmup. It ran without other simulation jobs."
  ],
  "reproduction": {
    "layout": "At the pinned checkout root after the requested scratch/setup.sh, save replica_source as scratch/replica.py. Save each following script under scratch/<name>.py. Prefix execution with . scratch/env.sh && . The scripts recreate scratch JSON/log data; real_checks expects the CH URL downloaded as scratch/CH.sol. Install optional numba for measured accelerated timing.",
    "real_checks": "import json,time\nfrom pathlib import Path\nimport numpy as np\nimport amm_sim_rs as rs\nfrom amm_competition.evm.compiler import SolidityCompiler\nfrom amm_competition.competition.config import build_config\nC=SolidityCompiler()\ndef compile(s,name='Strategy'):\n r=C.compile(s,name); assert r.success,r.errors\n return list(r.bytecode)\ndef configs(seeds):\n out=[]\n for seed in seeds:\n  r=np.random.default_rng(seed); size=r.uniform(19,21); rate=r.uniform(.6,1); sigma=r.uniform(.000882,.001008)\n  out.append(build_config(seed=seed,gbm_sigma=sigma,retail_arrival_rate=rate,retail_mean_size=size))\n return out\nch=Path('scratch/CH.sol').read_text()\nvan=compile(Path('contracts/src/VanillaStrategy.sol').read_text(),'VanillaStrategy')\nsources={'CH':ch,'flat30':Path('contracts/src/VanillaStrategy.sol').read_text().replace('contract VanillaStrategy','contract Strategy'),'base_plus3':ch.replace('BASE_FEE = 4 * BPS','BASE_FEE = 7 * BPS'),'stale_x08':ch.replace('STALE_DIR_COEF = 6850 * BPS','STALE_DIR_COEF = 5480 * BPS'),'lambda_x15':ch.replace('LAMBDA_COEF = 12 * BPS','LAMBDA_COEF = 18 * BPS')}\nout={}\nfor name,seeds in [('CH',range(1000)),('flat30',range(256)),('CH_transfer',range(676100,676228)),('base_plus3',range(676100,676228)),('stale_x08',range(676100,676228)),('lambda_x15',range(676100,676228))]:\n code=compile(sources['CH' if name=='CH_transfer' else name]); rs.gas_stats_reset(); start=time.perf_counter(); vals=[]\n for start_i in range(0,len(seeds),32):\n  results=rs.run_batch(code,van,configs(seeds[start_i:start_i+32]),8).results\n  for r in results:\n   vals.append({'seed':r.seed,'edge':r.edges['submission'],'retail_volume':r.retail_volume_y['submission']})\n  print(name,len(vals),flush=True)\n out[name]={'results':vals,'gas':rs.gas_stats(),'seconds':time.perf_counter()-start}\n Path('scratch/real_results.json').write_text(json.dumps(out))\n print(name,'mean',np.mean([v['edge'] for v in vals]),'gas',rs.gas_stats(),flush=True)\n",
    "replica_checks": "import json,time\nfrom pathlib import Path\nimport numpy as np\nimport replica as r\n\ndef measure(theta,seeds):\n start=time.perf_counter(); a=r.run_many(theta,seeds,8); elapsed=time.perf_counter()-start\n return {'rows':a.tolist(),'seconds':elapsed,'markets_per_second':len(seeds)/elapsed}\nif __name__=='__main__':\n r.run_market(r.TH,0,20.,.8,.000945,1)\n out={}\n for name,seeds in [('CH',range(1000)),('flat30',range(256)),('CH_transfer',range(676100,680196)),('base_plus3',range(676100,680196)),('stale_x08',range(676100,680196)),('lambda_x15',range(676100,680196))]:\n  theta=r.TH.copy()\n  if name=='flat30':theta[r.FLAT_FEE]=.003\n  if name=='base_plus3':theta[r.BASE_FEE]+=.0003\n  if name=='stale_x08':theta[r.STALE_DIR_COEF]*=.8\n  if name=='lambda_x15':theta[r.LAMBDA_COEF]*=1.5\n  out[name]=measure(theta,seeds)\n  Path('scratch/replica_results.json').write_text(json.dumps(out))\n  print(name,np.mean(out[name]['rows'],axis=0).tolist(),out[name]['markets_per_second'],flush=True)\n",
    "check_hooks": "import json,sys,os,importlib.util\nfrom pathlib import Path\nimport numpy as np\nfrom decimal import Decimal\nfrom amm_competition.evm.executor import EVMStrategyExecutor\nfrom amm_competition.evm.compiler import SolidityCompiler\nfrom amm_competition.core.trade import TradeInfo\nimport replica as r\n\ndef check():\n src=Path('scratch/CH.sol').read_text(); C=SolidityCompiler(); out={}\n variants=[('CH',src,r.TH.copy()),('base_plus3',src.replace('BASE_FEE = 4 * BPS','BASE_FEE = 7 * BPS'),r.TH.copy()),('stale_x08',src.replace('STALE_DIR_COEF = 6850 * BPS','STALE_DIR_COEF = 5480 * BPS'),r.TH.copy()),('lambda_x15',src.replace('LAMBDA_COEF = 12 * BPS','LAMBDA_COEF = 18 * BPS'),r.TH.copy())]\n variants[1][2][r.BASE_FEE]+=.0003; variants[2][2][r.STALE_DIR_COEF]*=.8; variants[3][2][r.LAMBDA_COEF]*=1.5\n for name,source,theta in variants:\n  c=C.compile(source); assert c.success,c.errors; evm=EVMStrategyExecutor(c.bytecode,c.abi)\n  assert evm.after_initialize(Decimal(100),Decimal(10000)).success\n  S=np.zeros(40); r.strat_init(S,theta,100.,10000.)\n  rng=np.random.default_rng(81254); t=0; maxerr=0.; p=100.\n  for i in range(3000):\n   t+=int(rng.choice([0,0,0,1,1,2,8,15])); p*=np.exp(rng.normal(0,.008)); x=np.sqrt(1e6/p); y=x*p\n   buy=bool(rng.integers(2)); ay=float(np.exp(rng.uniform(-4,8))); ax=ay/p\n   trade=TradeInfo('buy' if buy else 'sell',Decimal(str(ax)),Decimal(str(ay)),t,Decimal(str(x)),Decimal(str(y)))\n   evm_fees=np.array(evm.after_swap_fast(trade),dtype=float)/1e18\n   py_fees=np.array(r.strat_after(S,theta,buy,ax,ay,t,x,y))\n   err=float(np.max(np.abs(evm_fees-py_fees))); maxerr=max(err,maxerr)\n   assert err<1e-12,(name,i,err,evm_fees,py_fees)\n  out[name]={'calls':3000,'max_abs_fee_error':maxerr}\n # Pure Python vs JIT identical streams and loops, across CH and flat fee.\n os.environ['AMM_REPLICA_PURE']='1'\n spec=importlib.util.spec_from_file_location('replica_pure','scratch/replica.py'); pure=importlib.util.module_from_spec(spec); spec.loader.exec_module(pure)\n del os.environ['AMM_REPLICA_PURE']\n errs=[]\n for seed in [0,1,255,676100]:\n  for flat in [False,True]:\n   theta=r.TH.copy()\n   if flat:theta[r.FLAT_FEE]=.003\n   args=(seed,*r.config_for_seed(seed),1000)\n   a=np.array(r.run_market(theta,*args)); b=np.array(pure.run_market(theta.tolist(),*args))\n   errs.append(float(np.max(np.abs(a-b)))); assert np.allclose(a,b,rtol=1e-12,atol=1e-10),(a,b)\n   assert abs(a[0]-(a[1]+a[2]))<1e-8\n # Config exactness over all validation seeds plus large seeds.\n for seed in list(range(1000))+list(range(676100,680196))+[2**32,2**64+17,2**160+123]:\n  assert np.array_equal(r._config_uniforms(seed),np.random.default_rng(seed).random(3)),seed\n out['pure_vs_jit']={'markets':8,'steps_each':1000,'max_abs_output_error':max(errs)}\n out['config_exactness']={'seeds':5099,'all_equal':True}\n Path('scratch/hook_results.json').write_text(json.dumps(out,indent=2)); print(json.dumps(out,indent=2))\nif __name__=='__main__':check()\n",
    "speed_check": "import time,json\nfrom pathlib import Path\nimport replica as r\nif __name__=='__main__':\n r.run_market(r.TH,0,20.,.8,.000945,1)\n start=time.perf_counter()\n rows=r.run_many(r.TH,range(700000,704096),8)\n elapsed=time.perf_counter()-start\n out={'processes':8,'n':4096,'n_steps':10000,'seconds':elapsed,'markets_per_second':4096/elapsed,'includes':'process spawn, worker cache loading, per-seed configuration, simulation, IPC, result collection; parent JIT warmup excluded','backend':'Numba 0.68.1; NumPy 2.5.4; Python 3.12.3','concurrent_simulations':False,'mean_edge':float(rows[:,0].mean())}\n Path('scratch/speed_results.json').write_text(json.dumps(out));print(json.dumps(out))\n"
  },
  "measurement_digests": {
    "real_raw_json_sha256": "f7b50e3e3dd7e8f1ed576c87abf08d7e8e8aad9b9612a2f6b0472a3a6e9314d3",
    "replica_raw_json_sha256": "2a34cc5cf26fb136d9d8d807725cd9b0250cbfb7e68b684657d3f8a7268ca181",
    "note": "Raw timing-containing files are scratch-only; digests identify this run, not a reproducibility assertion across machines."
  }
}
