"""Small synthetic CSR/record tests only; no brain, GPU or artifact writes.""" import ast import copy import hashlib import json from pathlib import Path import struct import unittest import numpy as np import engineering_queue_audit as audit def digest(array): return hashlib.sha256(np.ascontiguousarray(array).tobytes()).hexdigest() def queue_row(tick, edges, accepted): # Independent simple whole-payload construction, unlike the chunked audit. edge_bytes = np.asarray(edges, dtype='= 22) request_rows.append([tick, neuron, 1, accepted, 1 - accepted]) for when, neuron in events: if when == tick: last[neuron] = tick ref = np.maximum(22 - (tick - last), 0).astype(np.int32) refs.append(ref) edges = [j for when, neuron in events if when == tick - 18 for j in range(int(ptr[neuron]), int(ptr[neuron + 1]))] expanded.append(np.asarray(edges, np.int64)) masks.append((ref[dst[edges]] == 0).astype(np.uint8)) def record(start, stop): selected = (ticks >= start) & (ticks < stop) ev_t, ev_n = (ticks[selected] - start).copy(), nodes[selected].copy() rows = np.array([row for row in request_rows if start <= row[0] < stop], np.int64).reshape(-1, 5) rows[:, 0] -= start return {'steps': stop - start, 'global_tick_offset': start, 'summary': {'pass_all': False}, # Never treated as authority. 'state': {'step': ev_t, 'neuron_idx': ev_n, 'counts': np.bincount(ev_n, minlength=n).astype(np.int32), 'v': np.zeros(n, np.float64), 'g': np.zeros(n, np.float64), 'ref': refs[stop - 1].copy()}, 'requests': rows, 'queues': [queue_row(t - start, edge_id[expanded[t]], masks[t]) for t in range(start, stop)], 'state_hashes': [{'tick': t - start, 'v_sha256': digest(np.zeros(n, np.float64)), 'g_sha256': digest(np.zeros(n, np.float64)), 'ref_sha256': digest(refs[t])} for t in range(start, stop)]} intervals = list(zip([0, *cuts], [*cuts, total])) return {'mono': record(0, total), 'parts': [record(a, b) for a, b in intervals], 'ptr': ptr, 'dst': dst, 'edge_id': edge_id, 'effective_weights': weights, 'requests': requests, 'cuts': list(cuts)} def run(data): return audit.audit_queues(data['mono'], data['parts'], **{k: data[k] for k in ('ptr', 'dst', 'edge_id', 'effective_weights', 'requests', 'cuts')}) class QueueAudit(unittest.TestCase): def test_real_edge_witness_and_local_headers_cross_18_19(self): data = fixture() result = run(data) self.assertTrue(result['pass_all'], result['differences']) witness = result['first_witness'] self.assertEqual((witness['boundary_tick'], witness['source_spike_tick'], witness['arrival_tick']), (37, 22, 40)) self.assertEqual((witness['source_neuron_idx'], witness['target_neuron_idx'], witness['global_edge_id']), (0, 2, 10)) self.assertEqual(witness['effective_weight_float64_le_hex'], np.asarray(.001, dtype='