The batch planner: how each row reaches the model (contract Execution, "Request layout").
A row with two or more distinct questions is sent as the state, each
question a branch. A row with exactly one would be sent in that
question's instructions, beside other rows' questions, but that layout
has no accuracy measurement against row as state, so it waits on the
layout-parity release gate (Testing). Until the gate passes it is
unreachable: [LayoutParity] has no values, so no [Planner] can hold
one, and every row is sent as the state.
Evidence that row in instructions passed the layout-parity release gate: jev-orderby-bench's mean |Δp|, Spearman and position effect against row as state, recorded against the pinned model version.
It has not been run, so the type is uninhabited. Giving it a value is the change that enables row in instructions, and it belongs with the recorded result.
Chooses each row's layout, and builds its state.
A row's layout as the [Planner] chose it. Only a planner makes one,
and row in instructions carries the [LayoutParity] evidence, so a
layout the gate has not passed cannot be written down, let alone
handed to [Planner::place].
Where a row goes in its request: its layout and the request's
state. Only a [Planner] makes one, so a layout the gate has not
passed never reaches a request or a cache key.
Under row as state, the row's canonical JSON.
The layout for a row with questions distinct questions.
Each row's layout, from the questions asked about it: asks pairs
a row with one question's serialized bytes, and a question asked
twice about the same row counts once.
98 pub fn layouts<'q, R: Hash + Eq>(&self, asks: impl IntoIterator<Item = (R, &'q [u8])>) -> HashMap<R, Planned> { 99 let mut questions: HashMap<R, HashSet<&'q [u8]>> = HashMap::new(); 100 for (row, question) in asks { 101 questions.entry(row).or_default().insert(question); 102 } 103 questions.into_iter().map(|(row, q)| (row, self.layout(q.len()))).collect() 104 }
row, a JSON text, placed as planned. Refused when the row is
not JSON.
116#[cfg(test)] 117mod tests { 118 use super::*; 119 120 #[test] 121 fn two_or_more_questions_are_row_as_state() { 122 let p = Planner::new(); 123 assert_eq!(p.layout(2).layout(), Layout::RowAsState); 124 assert_eq!(p.layout(255).layout(), Layout::RowAsState); 125 } 126 127 #[test] 128 fn one_question_is_row_as_state_until_the_gate_passes() { 129 assert_eq!(Planner::new().layout(1).layout(), Layout::RowAsState); 130 assert_eq!(Planner::default().layout(1).layout(), Layout::RowAsState); 131 } 132 133 #[test] 134 fn layouts_count_distinct_questions_per_row() { 135 let (a, b): (&[u8], &[u8]) = (b"{\"noul\":1}", b"{\"noul\":2}"); 136 let layouts = Planner::new().layouts([("r1", a), ("r1", b), ("r2", a), ("r2", a)]); 137 assert_eq!(layouts.len(), 2); 138 assert_eq!(layouts["r1"].layout(), Layout::RowAsState); 139 assert_eq!(layouts["r2"].layout(), Layout::RowAsState); 140 } 141 142 #[test] 143 fn row_as_state_sends_the_canonical_row() { 144 let p = Planner::new(); 145 let placed = p.place(p.layout(1), r#"{ "b": 1, "a": "x" }"#).unwrap(); 146 assert_eq!(placed.layout(), Layout::RowAsState); 147 assert_eq!(placed.state().as_str(), r#"{"a":"x","b":1}"#); 148 } 149 150 #[test] 151 fn a_row_that_is_not_json_is_refused() { 152 let p = Planner::new(); 153 assert!(p.place(p.layout(2), "{").is_err()); 154 } 155}