benchmarks-mv
Measurement harnesses and evidence bundles for AIEN on the NVIDIA DGX Spark GB10. Speed is reported against the machine's physical limit and my own previous run. Attachment of AienOS.
Brought by drakestapleton
benchmarks-mv / native / queueflow / proof / QueueFlow.lean
| 1 | /- SPDX-License-Identifier: Apache-2.0 |
| 2 | QueueFlow.lean (DRA-190, PREREG.md section 9). Model of the FCFS replay of flow.om for held |
| 3 | windows (fcfs, frontt; arms A and B) and of the in-system count. Model-to-system link: the |
| 4 | recursion below is hand-copied from flow.om `fcfs` / `frontt` at benchmarks-mv |
| 5 | hive/t_3fc453be-queue-flow @df77ac9a for windows that hold the slot; never-held windows and |
| 6 | parked windows are not in the model (see the counterexample at the end). -/ |
| 7 | import Mathlib.Data.List.Basic |
| 8 | import Mathlib.Order.Basic |
| 9 | |
| 10 | namespace QueueFlow |
| 11 | |
| 12 | /-- A held window: arrival (modeled), poll gap, external eligibility time, service. -/ |
| 13 | structure W where |
| 14 | arr : Nat |
| 15 | gp : Nat |
| 16 | el : Nat |
| 17 | s : Nat |
| 18 | |
| 19 | /-- Start of a window when the slot is free at d (flow.om: s = lmax (frontt i d) el). -/ |
| 20 | def start (d : Nat) (w : W) : Nat := max (max w.arr (d + w.gp)) w.el |
| 21 | |
| 22 | /-- FCFS replay: the starts of all windows, the slot is free at d before the first. -/ |
| 23 | def starts : Nat → List W → List Nat |
| 24 | | _, [] => [] |
| 25 | | d, w :: ws => start d w :: starts (start d w + w.s) ws |
| 26 | |
| 27 | /-- ws' is ws with every service capped (same arrival, gap and eligibility, s' <= s). -/ |
| 28 | def Capped (ws' ws : List W) : Prop := |
| 29 | List.Forall₂ (fun a b => a.arr = b.arr ∧ a.gp = b.gp ∧ a.el = b.el ∧ a.s ≤ b.s) ws' ws |
| 30 | |
| 31 | theorem start_mono {d' d : Nat} (w : W) (h : d' ≤ d) : start d' w ≤ start d w := by |
| 32 | unfold start; omega |
| 33 | |
| 34 | /-- L1: capping services never makes any window start later (arm B vs arm A), from any |
| 35 | earlier-or-equal slot-free time. -/ |
| 36 | theorem starts_capped_le : |
| 37 | ∀ (ws' ws : List W) (d' d : Nat), Capped ws' ws → d' ≤ d → |
| 38 | List.Forall₂ (· ≤ ·) (starts d' ws') (starts d ws) |
| 39 | | [], [], _, _, _, _ => by simp [starts] |
| 40 | | w' :: ws', w :: ws, d', d, h, hd => by |
| 41 | cases h with |
| 42 | | cons hw hr => |
| 43 | obtain ⟨ha, hg, he, hs⟩ := hw |
| 44 | have h1 : start d' w' ≤ start d w := by |
| 45 | unfold start; rw [ha, hg, he]; omega |
| 46 | simp only [starts] |
| 47 | exact List.Forall₂.cons h1 (starts_capped_le ws' ws _ _ hr (by omega)) |
| 48 | | [], _ :: _, _, _, h, _ => by cases h |
| 49 | | _ :: _, [], _, _, h, _ => by cases h |
| 50 | |
| 51 | /-- In-system count at time t for (arrival, departure) pairs. -/ |
| 52 | def inSys (t : Nat) (l : List (Nat × Nat)) : Nat := |
| 53 | l.countP (fun p => decide (p.1 ≤ t) && decide (t < p.2)) |
| 54 | |
| 55 | /-- L2: when every departure is at or after its arrival, arrivals minus departures up to t |
| 56 | equals the number in the system (so it is never negative). -/ |
| 57 | theorem conservation (t : Nat) : |
| 58 | ∀ l : List (Nat × Nat), (∀ p ∈ l, p.1 ≤ p.2) → |
| 59 | (l.countP (fun p => decide (p.1 ≤ t)) : Int) - (l.countP (fun p => decide (p.2 ≤ t)) : Int) |
| 60 | = (inSys t l : Int) |
| 61 | | [], _ => by simp [inSys] |
| 62 | | p :: l, h => by |
| 63 | have hp : p.1 ≤ p.2 := h p (by simp) |
| 64 | have ih := conservation t l (fun q hq => h q (by simp [hq])) |
| 65 | unfold inSys at ih ⊢ |
| 66 | rw [List.countP_cons, List.countP_cons, List.countP_cons] |
| 67 | by_cases h1 : p.1 ≤ t <;> by_cases h2 : p.2 ≤ t |
| 68 | · have h3 : ¬ t < p.2 := by omega |
| 69 | simp only [h1, h2, h3, decide_true, decide_false, Bool.and_false, ite_true] |
| 70 | push_cast; omega |
| 71 | · have h3 : t < p.2 := by omega |
| 72 | simp only [h1, h2, h3, decide_true, decide_false, Bool.and_true, ite_true] |
| 73 | push_cast; omega |
| 74 | · omega |
| 75 | · simp only [h1, h2, decide_false, Bool.false_and] |
| 76 | push_cast; omega |
| 77 | |
| 78 | /-- Negative control for L2: a window that departs before it arrives makes the difference -1. -/ |
| 79 | theorem conservation_needs_order : |
| 80 | (((([(5, 3)] : List (Nat × Nat)).countP (fun p => decide (p.1 ≤ 4))) : Int) - |
| 81 | ((([(5, 3)] : List (Nat × Nat)).countP (fun p => decide (p.2 ≤ 4))) : Int)) = -1 := by decide |
| 82 | |
| 83 | /-- Negative control for L1: lengthening a service (not a cap) makes the next window start later. -/ |
| 84 | theorem uncapped_can_delay : |
| 85 | starts 0 [⟨0, 0, 0, 10⟩, ⟨1, 0, 0, 1⟩] = [0, 10] ∧ |
| 86 | starts 0 [⟨0, 0, 0, 20⟩, ⟨1, 0, 0, 1⟩] = [0, 20] := by decide |
| 87 | |
| 88 | /-- Limit of the model: a never-held window that abandons at an absolute time e blocks the slot |
| 89 | until e only if e > its front time d + gp (flow.om `fcfs`, held = 0). An earlier slot-free time |
| 90 | can then turn a queue-leaver into a front-abandoner: free at 9 (A) with gap 2 and e = 11 the |
| 91 | front is 11, not > 11, so the slot stays free at 9; free at 8 (B) the front is 10 < 11, so the |
| 92 | slot is blocked until 11. It needs d < e <= d + gp, so the later slot time is at most the poll |
| 93 | gap (<= 3 s in the trace model); L1 is therefore stated for held windows only. -/ |
| 94 | def abandonD (d gp e : Nat) : Nat := if e > d + gp then e else d |
| 95 | |
| 96 | theorem abandon_not_monotone : abandonD 9 2 11 = 9 ∧ abandonD 8 2 11 = 11 := by decide |
| 97 | |
| 98 | #print axioms starts_capped_le |
| 99 | #print axioms conservation |
| 100 | #print axioms conservation_needs_order |
| 101 | #print axioms uncapped_can_delay |
| 102 | #print axioms abandon_not_monotone |
| 103 | |
| 104 | end QueueFlow |