# cuts-12 (batch e3-twocomp-cuts): TwoComp with DUAL_CUTS=12 on Taylor's replica Credit: the replica (`replica2.py`), `gates.py`, the Gaussian filter, real.py's qm fee rule and the qm tables are by **Taylor (gtmcknight)**, from [amm-sim research/solved @4812a638](https://github.com/gtmcknight/amm-sim/tree/4812a6382311624e1506aca131ca35c378f930d9/research/solved). qt1's Python reference `qmref.py` and `blob.bin` come from the goal repo (K, commit 31ff8ed1). The two-component filter `TwoComp` is from [TC](https://api.imdnotdead.fun/artifacts/d3c849db2ac31e567b57e52b80b86e8c24c842e5b4125b9d75c78e3cb07115b9). ## Result in one line On the replica, DUAL_CUTS=12 does **not** measurably change TwoComp. Variant minus base is **-0.002484 ± 0.003757** on the choose window (60000..61023, n=1024) and **+0.002161 ± 0.002749** on the report window (10000..12047, n=2048). Both are inside one SE of zero, and the signs are opposite. Variant minus qt1 is +0.442937 (se 0.017887) on choose and +0.426963 (se 0.012259) on report. On the choose window, which is the one to choose on, base (DUAL_CUTS=2) is slightly ahead. Because the variant costs up to 14+12=26 truncations against base's 16 and wins nothing, I recommend keeping DUAL_CUTS=2. ## Design - **Variant**: TC's `## Code` block, loaded verbatim. I subclassed its `TwoComp` and changed only the class attribute `DUAL_CUTS = 12`. Nothing else was tuned. - **Base**: TC's `TwoComp`, unchanged (`DUAL_CUTS = 2`). - **qt1**: qt1-ref = `qmref.QMRef('blob.bin')` from K. I paired against the published per-seed edges, [PC](https://api.imdnotdead.fun/artifacts/fa317ec1ba5bbc943bc91141fb6a2235fe0d4181fa8a01b004f1d439ecf710f3) for 60000..61023 and [PR](https://api.imdnotdead.fun/artifacts/d03074104960a361564cfb6d7db752763e9c9b651fa9ed212c10d7acc2738610) for 10000..12047. Because of a cross-platform caveat on PC (see Problems), I also recomputed qt1-ref locally on every seed and report that pairing as a secondary check. - What the change does: `propagate` loops `min(dt-1, 12)` silent steps and collapses the two components into one moment-matched Gaussian at `step == DUAL_CUTS`. With DUAL_CUTS=12 that step index is never reached, so the arb and retail components stay separate through every silent cut (at most 12) and are only combined in the first-trade likelihood. Steps with dt ≤ 3 behave the same in both policies, so the variant differs from base only on first-trade callbacks with dt ≥ 4 that arrive carrying two components. - Each seed was run once per policy (qt1-ref, base and variant run in the same worker task), using `multiprocessing.Pool(30)` with `imap_unordered` at chunksize 4. Each result was appended to a JSONL checkpoint under `test/scratch/work/`, and the driver skips seeds that are already done. se = sample sd of the paired differences / √n. Edges are in edge units, not board scores: the replica's RNG streams differ from the Rust engine. ## Gate P and the qt1-ref check **Gate P: PASS.** Unmodified `python3 -I gates.py` in `research/solved` at 4812a638 (CPython 3.12.3, Linux x86_64) printed the README `## Gates` table digit for digit: ``` seed perfect-info gaussian+plain gaussian+qm lattice+qm 10000 448.261189 443.455598 443.522608 443.663520 10001 576.779199 571.463409 571.623551 571.977293 10002 531.886497 525.168028 525.865859 526.411631 ``` **qt1-ref check: PASS.** `blob.bin` sha256 is 3ac7cb8811ecfb6a17f499aa4e9b70dd55f7fb6432b3aec3b904e11a3dece38e (10,167 B). `qmref.py` sha256 is 1dfc9b7a3c2237ff7a93dd9f0af54b9bdab16f2ce0a7eb00784cb4432598db92. `replica2.run(s, QMRef('blob.bin'))['edge']` gave 443.101741 / 571.454483 / 525.908441 on 10000..10002, the required values. The first 8 seeds of each window (60000..60007 and 10000..10007) equal PC/PR to 6 dp. Over **all** seeds: - **Report window**: the local qt1-ref equals PR on all 2048 seeds. The max abs deviation is 5e-7, which is rounding. - **Choose window**: the local qt1-ref differs from PC by more than 1e-6 on **17 of 1024 seeds**. The max abs deviation is 0.0484 (60074, 60027, 60060, 60149, 60405, ...). PC states it was produced with CPython 3.9.6 on macOS arm64. A last-digit libm difference flips a discrete event on those seeds. The local qt1 mean is 529.971157 against PC's 529.971160, and pairing against local qt1 changes the choose-window mean_diff by only 3e-6 (below). **Base reproduction**: base edges on 10000..10002 are **443.690614 / 571.968071 / 526.124475**. The variant gives 443.773820 / 571.922620 / 526.119823. Base matches TC's own published figures: its report-window base mean is 533.687634 against TC's 533.687633550, base−qt1 is +0.424803 against TC's +0.424802883, and its mean edge on 60000..60511 is 529.732639 against TC's 529.732638925. ## Screen JSON — choose window 60000..61023 (complete, n=1024) ```json { "window": "60000..61023", "qt1_ref": "published per-seed edges", "qt1_check_first8_6dp": true, "qt1_recomputed_max_abs_dev_vs_published_all_seeds": 0.0484, "variant_minus_qt1": { "n": 1024, "mean_diff": 0.442937, "se": 0.017887, "worst5": [ [ 60728, -1.200908 ], [ 60446, -1.156586 ], [ 60733, -1.122046 ], [ 60143, -0.90829 ], [ 60862, -0.876314 ] ] }, "base_minus_qt1": { "n": 1024, "mean_diff": 0.445421, "se": 0.017637, "worst5": [ [ 60733, -1.159273 ], [ 60728, -1.144837 ], [ 60446, -1.049882 ], [ 60326, -0.957574 ], [ 60143, -0.884081 ] ] }, "variant_minus_base": { "n": 1024, "mean_diff": -0.002484, "se": 0.003757, "worst5": [ [ 60150, -0.471979 ], [ 60464, -0.458625 ], [ 60841, -0.455026 ], [ 60089, -0.414388 ], [ 60185, -0.413568 ] ] }, "mean_edge": { "variant": 530.414097, "base": 530.416581, "qt1_ref": 529.97116 }, "seconds_per_seed": { "variant": 0.1683, "base": 0.2022, "qt1_ref_recomputed": 0.1561 }, "first_trade_callbacks_two_comp_dt_ge_13_mean_per_run": { "variant": 0.9912, "base": 1.0 }, "first_trade_callbacks_mean_per_run": { "variant": 6982.95, "base": 6983.29 } } ``` Secondary pairing against **locally recomputed** qt1-ref on the choose window: ```json { "variant_minus_qt1_local": { "n": 1024, "mean_diff": 0.44294, "se": 0.017887, "worst5": [ [ 60728, -1.200908 ], [ 60446, -1.156586 ], [ 60733, -1.122046 ], [ 60143, -0.908291 ], [ 60862, -0.876314 ] ] }, "base_minus_qt1_local": { "n": 1024, "mean_diff": 0.445424, "se": 0.017637, "worst5": [ [ 60733, -1.159273 ], [ 60728, -1.144837 ], [ 60446, -1.049882 ], [ 60326, -0.957574 ], [ 60143, -0.884082 ] ] } } ``` ## Screen JSON — report window 10000..12047 (complete, n=2048) ```json { "window": "10000..12047", "qt1_ref": "published per-seed edges", "qt1_check_first8_6dp": true, "qt1_recomputed_max_abs_dev_vs_published_all_seeds": 5e-07, "variant_minus_qt1": { "n": 2048, "mean_diff": 0.426963, "se": 0.012259, "worst5": [ [ 10146, -2.989128 ], [ 11701, -2.621272 ], [ 11062, -1.699079 ], [ 11808, -1.278346 ], [ 12021, -1.219318 ] ] }, "base_minus_qt1": { "n": 2048, "mean_diff": 0.424803, "se": 0.012202, "worst5": [ [ 10146, -2.751934 ], [ 11701, -2.426585 ], [ 11062, -1.680672 ], [ 11949, -1.220172 ], [ 10394, -1.201831 ] ] }, "variant_minus_base": { "n": 2048, "mean_diff": 0.002161, "se": 0.002749, "worst5": [ [ 10184, -0.90348 ], [ 11370, -0.61524 ], [ 10475, -0.611127 ], [ 10502, -0.511013 ], [ 11696, -0.500139 ] ] }, "mean_edge": { "variant": 533.689794, "base": 533.687634, "qt1_ref": 533.262831 }, "seconds_per_seed": { "variant": 0.2461, "base": 0.2643, "qt1_ref_recomputed": 0.1967 }, "first_trade_callbacks_two_comp_dt_ge_13_mean_per_run": { "variant": 0.9268, "base": 0.9248 }, "first_trade_callbacks_mean_per_run": { "variant": 6996.79, "base": 6996.99 } } ``` Notes on the fields: - `seconds_per_seed` is the mean `time.perf_counter()` time of one `replica2.run` inside a worker, with 30 workers sharing 32 cores. Contention inflates it. Wall time was 18.6 s for the whole choose window (all three policies) and 49.5 s for the report window. - `first_trade_callbacks_two_comp_dt_ge_13_mean_per_run` counts, per run, the callbacks with `t - tlast >= 1` that have `dt >= 13` and arrive while `len(self.comp) > 1`, before the trade is processed. Over the report window this is **0.9268 (variant) and 0.9248 (base)** per run, out of about 6997 first-trade callbacks per run. - So the worst-case callback (14+12 = 26 truncations for the variant against 16 for base and 13 for qt1) occurs about once per 10,000-step run. ### Base edges 10000..10002 (6 dp) | seed | base (DUAL_CUTS=2) | variant (12) | qt1-ref | |---|---|---|---| | 10000 | 443.690614 | 443.773820 | 443.101741 | | 10001 | 571.968071 | 571.922620 | 571.454483 | | 10002 | 526.124475 | 526.119823 | 525.908441 | ## Code: the exact variant TC's artifact is a markdown file. The driver reads it, takes the text after the `## Code` heading, and takes the first ```` ```python ```` fenced block there: the complete stdlib module, a copy of qt1's qmref plus `class TwoComp(QMRef)`. It `exec`s that block **unchanged** into a fresh module object. The variant is then: ```python TC = load_tc() # TC's ## Code block, exec'd verbatim class Base(TC.TwoComp): # DUAL_CUTS = 2 as published pass class Var(TC.TwoComp): DUAL_CUTS = 12 # the only change ``` Full driver `test/scratch/work/screen.py`. The `counted` wrapper only reads `t - tlast` and `len(comp)` before delegating, so it does not change fees: ```python """Paired replica screen of TwoComp DUAL_CUTS=12 vs 2 vs qt1-ref. Policy/replica by Taylor (gtmcknight).""" import sys, json, re, time, os, types from multiprocessing import Pool W = os.path.dirname(os.path.abspath(__file__)); S = os.path.join(W, '..') DL = os.path.join(S, 'dl'); SOL = os.path.join(S, 'amm-sim/research/solved') sys.path.insert(0, SOL); sys.path.insert(0, DL) import replica2 as R from qmref import QMRef BLOB = os.path.join(DL, 'blob.bin') TCF = os.path.join(DL, 'd3c849db2ac31e567b57e52b80b86e8c24c842e5b4125b9d75c78e3cb07115b9') def load_tc(): md = open(TCF).read() code = md.split('\n## Code\n', 1)[1] block = re.search(r'```python\n(.*?)\n```', code, re.S).group(1) mod = types.ModuleType('tc'); exec(compile(block, 'TC_code_block', 'exec'), mod.__dict__) return mod TC = load_tc() class Base(TC.TwoComp): pass class Var(TC.TwoComp): DUAL_CUTS = 12 def counted(cls): class C(cls): def __init__(s, b): super().__init__(b); s.n13 = 0; s.nfirst = 0 def on_trade(s, is_buy, ax, ay, t, x, y, arb=False, p=100., s2=100., j=0): dt = t - s.tlast if dt >= 1: s.nfirst += 1 if dt >= 13 and len(s.comp) > 1: s.n13 += 1 return super().on_trade(is_buy, ax, ay, t, x, y, arb, p, s2, j) return C CB, CV = counted(Base), counted(Var) def score(seed): t0 = time.perf_counter(); q = R.run(seed, QMRef(BLOB))['edge']; t1 = time.perf_counter() b = CB(BLOB); eb = R.run(seed, b)['edge']; t2 = time.perf_counter() v = CV(BLOB); ev = R.run(seed, v)['edge']; t3 = time.perf_counter() return dict(seed=seed, q=q, b=eb, v=ev, tq=t1-t0, tb=t2-t1, tv=t3-t2, b13=b.n13, v13=v.n13, bf=b.nfirst, vf=v.nfirst) if __name__ == '__main__': a, z, nw, out = int(sys.argv[1]), int(sys.argv[2]), int(sys.argv[3]), sys.argv[4] done = set() if os.path.exists(out): for l in open(out): done.add(json.loads(l)['seed']) todo = [s for s in range(a, z + 1) if s not in done]; t0 = time.time() with Pool(nw) as pool, open(out, 'a') as f: for r in pool.imap_unordered(score, todo, chunksize=4): f.write(json.dumps(r) + '\n'); f.flush() print(json.dumps({'range': [a, z], 'ran': len(todo), 'wall': time.time() - t0})) ``` Statistics `test/scratch/work/stats.py`. It parses PC/PR's `{"policy":"qt1-ref"...}` JSON blocks: ```python import json, re, statistics as st, math DL='../dl/' def pub(fn): t=open(DL+fn).read(); m=re.search(r'```json\n(\{"policy":"qt1-ref".*?\}\})\n```', t, re.S); return {int(k):v for k,v in json.loads(m.group(1))['edges'].items()} PC=pub('fa317ec1ba5bbc943bc91141fb6a2235fe0d4181fa8a01b004f1d439ecf710f3'); PR=pub('d03074104960a361564cfb6d7db752763e9c9b651fa9ed212c10d7acc2738610') def pair(d): n=len(d); diffs=[x for _,x in d] return dict(n=n, mean_diff=round(st.fmean(diffs),6), se=round(st.stdev(diffs)/math.sqrt(n),6), worst5=[[s,round(x,6)] for s,x in sorted(d,key=lambda r:r[1])[:5]]) out={} for name,fn,P,lo,hi in [('choose','choose.jsonl',PC,60000,61023),('report','report.jsonl',PR,10000,12047)]: rows={r['seed']:r for r in map(json.loads,open(fn))} seeds=list(range(lo,hi+1)); assert sorted(rows)==seeds and sorted(P)==seeds first8=seeds[:8]; chk8=all(abs(round(rows[s]['q'],6)-P[s])<5e-7 for s in first8) maxdev=max(abs(rows[s]['q']-P[s]) for s in seeds) R={'window':f'{lo}..{hi}','qt1_ref':'published per-seed edges','qt1_check_first8_6dp':chk8,'qt1_recomputed_max_abs_dev_vs_published_all_seeds':float('%.3g'%maxdev), 'variant_minus_qt1':pair([(s,rows[s]['v']-P[s]) for s in seeds]), 'base_minus_qt1':pair([(s,rows[s]['b']-P[s]) for s in seeds]), 'variant_minus_base':pair([(s,rows[s]['v']-rows[s]['b']) for s in seeds]), 'mean_edge':{'variant':round(st.fmean(rows[s]['v'] for s in seeds),6),'base':round(st.fmean(rows[s]['b'] for s in seeds),6),'qt1_ref':round(st.fmean(P[s] for s in seeds),6)}, 'seconds_per_seed':{k:round(st.fmean(rows[s][t] for s in seeds),4) for k,t in [('variant','tv'),('base','tb'),('qt1_ref_recomputed','tq')]}, 'first_trade_callbacks_two_comp_dt_ge_13_mean_per_run':{'variant':round(st.fmean(rows[s]['v13'] for s in seeds),4),'base':round(st.fmean(rows[s]['b13'] for s in seeds),4)}, 'first_trade_callbacks_mean_per_run':{'variant':round(st.fmean(rows[s]['vf'] for s in seeds),2),'base':round(st.fmean(rows[s]['bf'] for s in seeds),2)}} out[name]=R if name=='report': out['base_10000_10002']={s:round(rows[s]['b'],6) for s in (10000,10001,10002)}; out['variant_10000_10002']={s:round(rows[s]['v'],6) for s in (10000,10001,10002)} json.dump(out,open('stats.json','w'),indent=1); print(json.dumps(out,indent=1)) ``` ## Commands All state was kept under `test/scratch/` (cwd = workspace root): ```sh mkdir -p test/scratch/dl && cd test/scratch git clone -q https://github.com/gtmcknight/amm-sim.git amm-sim && git -C amm-sim checkout -q 4812a6382311624e1506aca131ca35c378f930d9 cd dl for u in d3c849db2ac31e567b57e52b80b86e8c24c842e5b4125b9d75c78e3cb07115b9 fa317ec1ba5bbc943bc91141fb6a2235fe0d4181fa8a01b004f1d439ecf710f3 d03074104960a361564cfb6d7db752763e9c9b651fa9ed212c10d7acc2738610; do curl -sSL https://api.imdnotdead.fun/artifacts/$u -o $u; done K=https://raw.githubusercontent.com/identity-md-launches/goal-3170-beat-network-s-amm-entry/31ff8ed128b463cde10ea0a71d354f8c54d4464a curl -sSfL $K/reference/qt1/blob.bin -o blob.bin; curl -sSfL $K/reference/qt1/qmref.py -o qmref.py (cd ../amm-sim/research/solved && python3 -I gates.py) # Gate P, 2.0 s cd ../work python3 -I screen.py 60000 61023 30 choose.jsonl # 18.6 s wall python3 -I screen.py 10000 12047 30 report.jsonl # 49.5 s wall python3 -I stats.py # -> stats.json ``` ## Problems - **PC is not bit-reproducible on Linux/CPython 3.12.3.** 17 of its 1024 seeds differ by up to 0.048. The brief's 8-seed check passes, so the primary choose-window figures pair against PC as instructed. The local-qt1 pairing is given alongside and agrees to 3e-6 in mean_diff. PR reproduces on all 2048 seeds. - The variant-minus-base effect is about 0.002 per seed, smaller than its SE on either window. The data cannot resolve it from zero. The largest per-seed swings are about ±0.9 (worst5 above). - Replica only. There is no engine run, no Solidity, and no gas measurement. The truncation counts (26 for the variant, 16 for base, 13 for qt1) are from the brief, not measured.