diff --git a/research/fraction-contribution-table-feasibility/.gitignore b/research/fraction-contribution-table-feasibility/.gitignore new file mode 100644 index 0000000000..c18dd8d83c --- /dev/null +++ b/research/fraction-contribution-table-feasibility/.gitignore @@ -0,0 +1 @@ +__pycache__/ diff --git a/research/fraction-contribution-table-feasibility/NOTICE b/research/fraction-contribution-table-feasibility/NOTICE new file mode 100644 index 0000000000..0d0e087f7e --- /dev/null +++ b/research/fraction-contribution-table-feasibility/NOTICE @@ -0,0 +1,5 @@ +Fraction arithmetic primitive profile and bounded contribution-table feasibility +============================================================================ +Original Fraction/error arithmetic: Ali Romman, retaining Adam Gall/ywz65/PR2878, PR5826/5819, Mason Hale/PR5811 and all P104/native/compiler/precision notices. Full PR5848, PR5831 and nested source archives are unchanged. Apache-2.0. + +New primitive profiling, exact local table, finite/key/capacity/failure checks and complete-cost screen: Chris R / Clear1nsight, substantial OpenAI Codex assistance; no subagents or independent human/kernel acceptance. Memoization is a standard technique. PR5848/5839 supply the qualifier/Linux baseline; PR5816/5818/5832/5761 retain tooling and test-repair credit with original authorship. The prior zero/unit negative artifact71f22c77b393e5cc14925c771894dc1a92c8443c supplies source-binding and finite-fixture lineage. No complete performance or kappa improvement is claimed. diff --git a/research/fraction-contribution-table-feasibility/PROOF.md b/research/fraction-contribution-table-feasibility/PROOF.md new file mode 100644 index 0000000000..a7f3ef43f3 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/PROOF.md @@ -0,0 +1,15 @@ +# Exact local contribution tabulation + +For standard immutable Fraction values x,q,y,a,c, define + +`v = x + q*y; d = abs(v)-abs(x); H(x,q,y,a,c) = (v,d*a,d*c,d)`. + +This is exactly the original coefficient and score-increment arithmetic in the authenticated Fraction ADD/COPY loop. Each input Fraction has a unique reduced numerator/positive-denominator pair. The ten-integer key therefore determines every input value. A Python dictionary compares the complete tuple after hashing; hash collisions do not identify distinct tuples. On a miss, the table computes H with the original Fraction operators. On a hit, it returns the same immutable four-value tuple. FIFO eviction removes only an optional stored answer; a later miss recomputes H. Capacity zero bypasses storage. Exceptions are not stored. Nonstandard numeric types bypass the table; the proof does not extend to arbitrary user-defined numeric operator side effects. + +Assuming equal rows/scores at the start of a coefficient iteration, replacing the local arithmetic with H preserves the new coefficient and all three increments. The caller still performs every score addition, zero removal/insertion and index-specific row update in the same order. Event operations, rounded-site injections, prefix/tie/peak decisions, full witness copies, Pareto sorting, final scores and signed hash updates are untouched. Induction over coefficients/events proves exact returned values on the declared domain. Tests additionally compare numeric types and unchanged inputs. Mutable output containers remain fresh; standard Fraction values are immutable through their public API. + +The cache is newly constructed for every trace. Only a statistics dictionary survives for observation, cleared before a new call; no Fraction answer table is reused by another call or backend. Original integer arithmetic, literal execution and transpose oracles are unchanged. Full module/function hashes and unique setup/contribution/return seams bind the derivation. The live source callable must equal a fresh compilation's recursively compared executable structure, excluding only source locations. The installer restores it in `finally`. + +Finite checks cover 241 programs/10,164 events at four capacities, including disabled and repeated-eviction cases, sign flips/cancellation and all operations. Thirty-four controls include each key operand, canonical equal-value keys, actual integer-hash collisions, capacity rejection, FIFO recomputation, uncached exceptions, failed-call statistics clearing, returned/statistics mutation, source/live/nested-code drift and restoration. Both full actual audits compare every returned trace/witness value/type and input on the frozen 25,984-event/799-coordinate word. + +This correctness result does not imply profitable qualification. The complete-cost screen includes the new finite checks and remains below the requested 15% saving. No complete performance implementation or CPU/wall benchmark is admitted. Physical native/reset/owned-return/tape/compiler/outer obligations and the selected result are untouched; kappa work remains paused. diff --git a/research/fraction-contribution-table-feasibility/README.md b/research/fraction-contribution-table-feasibility/README.md new file mode 100644 index 0000000000..30496c67e9 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/README.md @@ -0,0 +1,52 @@ +# Fraction primitive profile and contribution-table feasibility + +**Scoped finding: correctness passes; stop before complete qualifier construction. No performance PR or kappa gain.** This follows [PR #5848](https://github.com/CrocSwap/integer-mult-bounds/pull/5848) and the [released zero/unit experiment](https://github.com/CrocSwap/integer-mult-bounds/pull/5848#issuecomment-6435104002). + +A complete unchanged qualification passes with cProfile enabled only around its actual Fraction error trace. That trace makes **26,030,845 `_from_coprime_ints` calls, 10,396,952 `_add` calls, 7,892,384 `_mul` calls and 2,579,750 coefficient updates**. The profiled trace costs 65.737 seconds and whole qualification 86.794 seconds; instrumentation inflates these times. They are not benchmark observations and cannot be directly compared to the unprofiled 39.015-second complete median. + +## Exact table and feasibility result + +The prototype tabulates the pure local result `(new coefficient, weighted increment A, weighted increment C, unweighted increment)` as a function of exact Fraction values `(old coefficient, scalar, source coefficient, weight A, weight C)`. Canonical numerator/denominator pairs form the complete key. Misses use the original Fraction arithmetic. Every score/row update, rounded site, peak/witness, signed hash and original independent integer operation remains active. Each trace creates a fresh bounded FIFO table; it shares no answers across backends or calls. See `PROOF.md`. + +All **241 finite programs / 10,164 events** compare complete values, witnesses, types and unchanged inputs at capacities **0,1,2,16384**: 964 complete differential comparisons. All **34** key/hash/capacity/eviction/source/exception/mutation/restoration controls pass normally and under optimization. The previous finite harness recompiled four unchanged functions per program; the final harness derives those same four functions once and explicitly checks fresh table lifetimes across repeated calls. No numerical case is removed. + +Two separately labelled full actual audits preserve every trace/witness value/type and input on **25,984 events / 799 coordinates**: + +| Table | Original trace | Derived trace | Hits | Misses | Evictions | +|---|---:|---:|---:|---:|---:| +| 2,048 entries, dictionary FIFO | 19.996 s | 16.578 s | 1,934,536 | 645,214 | 643,166 | +| 16,384 entries, OrderedDict FIFO | 20.251 s | 14.600 s | 2,252,966 | 326,784 | 310,400 | + +The first result had insufficient whole-stage headroom. The plan was reassessed before any complete construction, allowing one final bounded size/constant-time FIFO test under the unchanged resource cap. Both prototypes and the reassessment remain in evidence. These are single ordered within-process comparisons, not fresh-process wall/CPU benchmarks, medians or a causal separation of capacity and container effects. + +## Complete-cost decision + +The larger table removes 5.652 seconds in its observed trace comparison. Against PR #5848's complete wall median of 39.015 seconds, that is only **14.49% before new checks**. The new full finite/control stage takes about 1.621 seconds. A simple screen gives: + +`39.014916 - 5.651933 + 1.620956 = 34.983939 seconds`, about **10.33% modelled saving**. + +The required 15% target is at most 33.162678 seconds, alongside an independently passing complete CPU gate. The screen does not justify a complete candidate. No complete qualifier, complete B/C pair, six-process expansion or performance PR is constructed. This is a scoped engineering decision, not a universal obstruction or measured complete-stage/CPU result. + +## Reproduce and coverage boundary + +Python 3.12, standard library only: + +```sh +python3 -B scripts/research_package.py --package research/fraction-contribution-table-feasibility +``` + +This performs a **fresh full finite differential at all four capacities and all 34 controls**, about 1.6 seconds locally. It does not freshly replay the complete actual source, profile it, replace qualification, prove a mathematical theorem or certify performance. The manifest explicitly states finite-only coverage. + +`actual_audit.py` is separately opt-in: it repeats the fresh original/16k derived full actual trace comparison, about 38 seconds here. Run only with a separately available serial budget, the original 180-second cap, 1 GiB sampled process-group RSS and no automatic retries. No automatic rerun is justified by this handoff. + +The input is the complete official 97-file PR #5848 export at `66fb6c6b8683b37967e9d7f313b3df99a49d2406`, including unchanged PR #5831 and PR #5826 archives/notices. Exact module/function hashes, unique source edits and recursive executable-code binding are mandatory. Frozen files are never edited. The scoped installer restores the source callable on success and failure. `evidence/` retains all raw outputs/resource receipts, both table versions, cProfile statistics/data, runtime hashes and the screen. + +## Open next questions + +A separately assigned follow-up could examine whether source-bound type invariants allow moving the new table's repeated type validation out of the hot loop while preserving failure behaviour. The table currently checks five operand types per coefficient update, about 12.9 million checks. This overhead is visible in the implementation; its exact cost and any saving from relocation remain unmeasured. Such work needs an explicit well-formed-input contract, a proof of internal type preservation, malformed-input fallback and a new feasibility gate. No successor is dispatched here. + +Other table policies or exact arithmetic algorithms require a fresh bounded reuse/primitive census and complete memory/time bill. No further capacity trial is authorized by this completed round. Kappa research, Work 1/2, feeds, agents and automations remain paused. + +## Credit + +Ali Romman supplied the original Fraction/error arithmetic and integer backend. Preserve [PR #5831](https://github.com/CrocSwap/integer-mult-bounds/pull/5831), [PR #5826](https://github.com/CrocSwap/integer-mult-bounds/pull/5826), [PR #5819](https://github.com/CrocSwap/integer-mult-bounds/pull/5819), Adam Gall, ywz65, [PR #2878](https://github.com/CrocSwap/integer-mult-bounds/pull/2878), Mason Hale/[PR #5811](https://github.com/CrocSwap/integer-mult-bounds/pull/5811) and every retained P104/native/compiler/precision notice. [PR #5839](https://github.com/CrocSwap/integer-mult-bounds/pull/5839) supplies Linux observations; verification lineage includes [PR #5816](https://github.com/CrocSwap/integer-mult-bounds/pull/5816), [PR #5818](https://github.com/CrocSwap/integer-mult-bounds/pull/5818), [PR #5832](https://github.com/CrocSwap/integer-mult-bounds/pull/5832) and exact test-only [PR #5761](https://github.com/CrocSwap/integer-mult-bounds/pull/5761) authorship/cherry-pick credit. The previous negative artifact `71f22c77b393e5cc14925c771894dc1a92c8443c` supplies source-binding and fixture lineage. New profile/table/feasibility work: Chris R / Clear1nsight with substantial OpenAI Codex assistance; no subagents or independent human/kernel acceptance. Memoization is standard. Apache-2.0. diff --git a/research/fraction-contribution-table-feasibility/RESULT.json b/research/fraction-contribution-table-feasibility/RESULT.json new file mode 100644 index 0000000000..0980873646 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/RESULT.json @@ -0,0 +1,102 @@ +{ + "actual_16384": { + "all_values_types_and_inputs_preserved": true, + "baseline_trace_seconds": 20.251469953014748, + "coordinates": 799, + "derived_trace_seconds": 14.599537244997919, + "events": 25984, + "full_output_sha256": "954c7448ff74d78753828e9623ad44c46da9e5ce459420b6e50a5d47294250b9", + "observed_seconds_removed": 5.65193270801683, + "profile_whole_qualifier_seconds": 38.31372155799181, + "status": "PASS_FULL_ACTUAL_FRACTION_TRACE_EQUIVALENCE", + "table_statistics": { + "bypasses": 0, + "calls": 2579750, + "capacity": 16384, + "evictions": 310400, + "hits": 2252966, + "misses": 326784, + "resident": 16384 + }, + "weights_sha256": "cf98bf5da5df28ec1ca3ca7e8723d740b98e142f31e94ff7ec36815cc387c373" + }, + "actual_2048": { + "all_values_types_and_inputs_preserved": true, + "baseline_trace_seconds": 19.996063037018757, + "coordinates": 799, + "derived_trace_seconds": 16.578300290973857, + "events": 25984, + "full_output_sha256": "954c7448ff74d78753828e9623ad44c46da9e5ce459420b6e50a5d47294250b9", + "observed_seconds_removed": 3.4177627460449003, + "profile_whole_qualifier_seconds": 38.31372155799181, + "status": "PASS_FULL_ACTUAL_FRACTION_TRACE_EQUIVALENCE", + "table_statistics": { + "bypasses": 0, + "calls": 2579750, + "capacity": 2048, + "evictions": 643166, + "hits": 1934536, + "misses": 645214, + "resident": 2048 + }, + "weights_sha256": "cf98bf5da5df28ec1ca3ca7e8723d740b98e142f31e94ff7ec36815cc387c373" + }, + "complete_qualifier_constructed": false, + "complete_wall_CPU_benchmark_run": false, + "finite": { + "all_complete_values_and_types_equal": true, + "cases": 241, + "controls": [ + "returned-mutation-isolated", + "source-drift", + "Fraction-type-drift", + "module-byte-drift", + "live-code-drift", + "nested-live-code-drift", + "omitted-witness", + "omitted-rounded-sites", + "wrong-coefficient", + "wrong-weighted-increment", + "bad-role", + "bad-scalar", + "missing-weight", + "restore-success", + "restore-exception", + "fresh-derivation", + "key-field-0", + "key-field-1", + "key-field-2", + "key-field-3", + "key-field-4", + "FIFO-eviction", + "canonical-key", + "hash-collision", + "disabled", + "invalid-capacity--1", + "invalid-capacity-16385", + "invalid-capacity-True", + "invalid-capacity-1.5", + "uncached-exception-0", + "uncached-exception-1", + "fresh-call-table", + "stats-mutation", + "failed-call-clears-stats" + ], + "events": 10164, + "status": "PASS_FINITE_FRACTION_TABLE_FEASIBILITY" + }, + "performance_claim": null, + "screen": { + "decision": "STOP_BEFORE_COMPLETE_CONSTRUCTION", + "extra_new_finite_wall_observation": 1.6209555940004066, + "further_capacity_trials": 0, + "modeled_complete_wall": 34.983938607008895, + "modeled_fraction_saved": 0.10331887278290623, + "modeled_not_a_complete_wall_CPU_benchmark": true, + "optimistic_fraction_ignoring_new_checks": 0.14486594687095472, + "prior_complete_wall_median": 39.01491572102532, + "required_fraction": 0.15, + "within_process_trace_seconds_removed": 5.65193270801683 + }, + "status": "SCOPED_NEGATIVE_COMPLETE_COST_SCREEN" +} diff --git a/research/fraction-contribution-table-feasibility/SOURCES.json b/research/fraction-contribution-table-feasibility/SOURCES.json new file mode 100644 index 0000000000..c68ffab6bc --- /dev/null +++ b/research/fraction-contribution-table-feasibility/SOURCES.json @@ -0,0 +1,30 @@ +{ + "schema_version": 1, + "base_commit": "de5ec2e7a6074068452f45b1a191b5c72832df4a", + "files": [ + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "3404fbdd5e7529a0674eef26114b5071e4586cec", + "sha256": "ead6cdc9d0af6d58e8a49744d8ec8c7c15e13d2ba93c276c434bcf9b51b93a81" + }, + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "581f8d87008354eb5b869f7ed9de1317ad837ce8", + "sha256": "2a0220e866417774606e0f991e41b9c1d26b1f43b97857238cf478dbc7d330b5" + }, + { + "path": "research/fraction-contribution-table-feasibility/inputs/PR5848.tar", + "usage": "input", + "git_blob": "307d09d2a968e1bbec8025d9fbd0a884df790d12", + "sha256": "f899600acb6966a6b028ffbf1e33a94061615626b510feaca8cb073f03a34de6", + "pin": "head:0b2de67914ff659b0e1fca4ff4f275228aa246d6:research/fraction-contribution-table-feasibility/inputs/PR5848.tar" + } + ], + "external_origin": { + "pr": 5848, + "head": "66fb6c6b8683b37967e9d7f313b3df99a49d2406", + "export_files": 97 + } +} diff --git a/research/fraction-contribution-table-feasibility/TASK.json b/research/fraction-contribution-table-feasibility/TASK.json new file mode 100644 index 0000000000..4b5ff194a8 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/TASK.json @@ -0,0 +1,66 @@ +{ + "schema_version": 1, + "task_id": "replay-runtime", + "original_card": { + "id": "replay-runtime", + "question": "Can one measured replay bottleneck be sped up without dropping coverage?", + "starting_points": [ + "scripts/run_isolated_tests.py", + "scripts/verify_replay_coverage.py", + "certificates/selected-result.json" + ], + "methods": [ + "Profile one isolated replay and optimize the measured bottleneck.", + "Design source-bound reuse with explicit dependency invalidation and negative controls." + ], + "acceptance_gate": "Report before/after wall time on the same fixture, retained checks and invalidation behavior.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_selected_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Resolve the current selected review, separate complex/ordinary BIT/admitted BIT/outer budgets, and compare the card against live handoffs before starting. Historical ceilings require exact source/model equivalence.", + "scope": "Source-binding orientation only; not a scientific replay or all-size proof. Materialize selected inputs if this checkout is sparse." + }, + "first_experiment": "Measure one unchanged fixture, preserve check coverage, and test one optimization with invalidation controls.", + "bottleneck_link": "Faster trustworthy replays increase review throughput and let mechanism candidates be checked sooner.", + "allowed_variations": [ + "Profile one stage or design one source-bound cache boundary." + ], + "scope_change_triggers": [ + "Skipping coverage or comparing different fixtures to claim speedup." + ], + "overlap_terms": [ + "replay runtime", + "cache invalidation", + "isolated tests" + ] + }, + "scope_status": "refined", + "scope_change_reason": "Explicit donor asked for primitive profile and feasibility before construction. Exact bounded table passes correctness and speeds the trace; complete-cost screen remains below15% after new checks, so no complete qualifier or performance PR.", + "actual_scope": "PR5848/frozen-66fb6c6/Fraction-primitives-and-bounded-contribution-table", + "bottleneck_link": "Faster trustworthy replays increase review throughput and let mechanism candidates be checked sooner.", + "stop_rule": "Stopped at complete-cost screen after the one declared final16k FIFO feasibility step. No further capacity/algorithm trial, complete qualifier, B/C benchmark or performance PR. Original180s source cap,600s initial/1500s shared cumulative,1GiB sampled group RSS, serialized, no automatic retries.", + "time_budget_minutes": 90, + "outcome": "negative-result", + "evidence": "PRIMITIVES profile, PROOF.md, RESULT.json and all raw evidence. 241 finite programs at4 capacities,34 controls, both2048/16384-entry actual audits, complete-cost screen and preserved bounds. All source bytes unchanged.", + "author": "Chris R / Clear1nsight", + "ai_assistance": "Substantial OpenAI Codex assistance for source review, execution, tooling and report; no subagents, independent human or proof-kernel acceptance.", + "open_questions": [ + { + "question": "Can source-bound invariant validation be moved out of the new hot loop without losing failure coverage?", + "why_it_matters": "The pure table introduces five type checks per coefficient update, about12.9 million checks; whether moving them changes the complete-cost decision is unmeasured.", + "first_step": "Separately bind a well-formed immutable Fraction input contract, prove internal type preservation, retain malformed-input fallback and profile the new hot path before a finite gate.", + "blocked_by": "A separately assigned source/independence/coverage scope; no automatic permission from this artifact." + }, + { + "question": "Would a different bounded table or arithmetic algorithm clear the whole-stage gate?", + "why_it_matters": "The current16k table retains326784 misses; its measured trace benefit does not pay the complete15% target.", + "first_step": "Use a separately bounded reuse/primitive census and complete memory/time bill before construction.", + "blocked_by": "New overlap and feasibility gates; no extrapolated performance claim." + } + ], + "base_commit": "de5ec2e7a6074068452f45b1a191b5c72832df4a" +} diff --git a/research/fraction-contribution-table-feasibility/VALIDATION.json b/research/fraction-contribution-table-feasibility/VALIDATION.json new file mode 100644 index 0000000000..70507be53b --- /dev/null +++ b/research/fraction-contribution-table-feasibility/VALIDATION.json @@ -0,0 +1,28 @@ +{ + "all_pass": true, + "automatic_retries": 0, + "complete_qualifier_constructed": false, + "complete_wall_CPU_benchmark_run": false, + "guarded_attempts": 10, + "guarded_wall_seconds": 179.50205514702247, + "hosted_ci": "not run; no upstream performance PR", + "initial_stage_cap_seconds": 600, + "kappa_research": "PAUSED", + "per_source_command_seconds": 180, + "portable_finite_normal_and_O": true, + "sampled_group_rss_cap_bytes": 1073741824, + "screen": { + "decision": "STOP_BEFORE_COMPLETE_CONSTRUCTION", + "extra_new_finite_wall_observation": 1.6209555940004066, + "further_capacity_trials": 0, + "modeled_complete_wall": 34.983938607008895, + "modeled_fraction_saved": 0.10331887278290623, + "modeled_not_a_complete_wall_CPU_benchmark": true, + "optimistic_fraction_ignoring_new_checks": 0.14486594687095472, + "prior_complete_wall_median": 39.01491572102532, + "required_fraction": 0.15, + "within_process_trace_seconds_removed": 5.65193270801683 + }, + "shared_cap_seconds": 1500, + "source_unchanged": true +} diff --git a/research/fraction-contribution-table-feasibility/VERIFY.json b/research/fraction-contribution-table-feasibility/VERIFY.json new file mode 100644 index 0000000000..61c256f7a2 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/VERIFY.json @@ -0,0 +1,20 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "research/fraction-contribution-table-feasibility/inputs/PR5848.tar" + ], + "commands": [ + { + "argv": [ + "{python}", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 30, + "checks": "Fresh241-program/10164-event exact finite trace/type/input differential at four capacities (964 complete comparisons), plus34 key/hash/capacity/eviction/exception/source/restoration controls. Finite feasibility only; does not freshly replay actual source qualification or certify wall/CPU savings." + } + ] +} diff --git a/research/fraction-contribution-table-feasibility/actual_audit.py b/research/fraction-contribution-table-feasibility/actual_audit.py new file mode 100644 index 0000000000..8ab0936432 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/actual_audit.py @@ -0,0 +1,29 @@ +"""One fresh full actual original/derived trace comparison; not a speed benchmark.""" +from copy import deepcopy +import gzip +import importlib.util +import json +from pathlib import Path +import sys +import time +from frozen import baseline,require +from fraction_table import derive +from finite import types_of + +with baseline() as package: + sys.path.insert(0,str(package)) + import source + with source.baseline() as p: + spec=importlib.util.spec_from_file_location('actual_audit_source',p/'verify.py') + v=importlib.util.module_from_spec(spec);spec.loader.exec_module(v) + with v.source() as (original_path,original,reference): + word=json.loads(gzip.decompress((original_path/'inputs/WORD.json.gz').read_bytes())) + ideal,weights=reference.ideal(word);rounded=set(ideal['counts']) + fingerprint=reference.digest((word,weights,sorted(rounded))) + started=time.perf_counter();a=reference.error_trace(word,weights,rounded);baseline_seconds=time.perf_counter()-started + fast=derive(reference) + started=time.perf_counter();b=fast(word,weights,rounded);candidate_seconds=time.perf_counter()-started + require(a==b and types_of(a)==types_of(b),'all actual trace/witness values and types') + require(reference.digest((word,weights,sorted(rounded)))==fingerprint,'all actual inputs unchanged') + result=dict(status='PASS_FULL_ACTUAL_FRACTION_TRACE_EQUIVALENCE',events=len(word['program']),coordinates=ideal['n'],full_output_sha256=reference.digest(a),weights_sha256=reference.digest(weights),baseline_trace_seconds=baseline_seconds,derived_trace_seconds=candidate_seconds,observed_seconds_removed=baseline_seconds-candidate_seconds,profile_whole_qualifier_seconds=38.31372155799181,all_values_types_and_inputs_preserved=True,table_statistics=fast.statistics()) + print(json.dumps(result,sort_keys=True)) diff --git a/research/fraction-contribution-table-feasibility/evidence/CLAIM.md b/research/fraction-contribution-table-feasibility/evidence/CLAIM.md new file mode 100644 index 0000000000..2c73417cc0 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/CLAIM.md @@ -0,0 +1 @@ +CLAIM — bounded verification follow-up to [PR #5848](https://github.com/CrocSwap/integer-mult-bounds/pull/5848), exact source `66fb6c6b8683b37967e9d7f313b3df99a49d2406`. Following the [released zero/unit negative finding](https://github.com/CrocSwap/integer-mult-bounds/pull/5848#issuecomment-6435104002), one fresh full qualification with cProfile only inside its actual Fraction trace passes. It records about 26 million Fraction-result allocations, 10.4 million additions, 7.9 million multiplications and 2.58 million coefficient updates. Instrumented costs are not performance evidence. Nomination: at most one source-bound per-trace bounded FIFO table of pure exact Fraction coefficient transitions and weighted increments, complete canonical keys, original Fraction arithmetic on misses; no integer-engine, word, oracle-count, guard or frozen-source edits and no cross-run/backend answer reuse. First test finite values/types, all operation/sign/cancellation cases, invalidation, capacity/eviction, mutation, exceptions and restoration, then one full actual trace audit. Construct a complete qualifier only with credible 15% whole-stage headroom. A performance PR requires >=15% complete wall AND CPU savings in a fresh first pair before all six B,C,C,B,B,C medians, plus normal/optimized/sealed and exact-head CI gates. Preserve all 25,984 events/799 coordinates, full witnesses/weights/metadata,120-program/4,240-event differential, original 6 semantic/3 integer/4 custody/27 observation controls. Serial, no automatic retries; 180 s/source command, 1 GiB sampled group RSS, 600 s initial and 1,500 s shared local cap. Stop on source/coverage/control/receipt/resource failure, insufficient gain or active overlap. Canonical main freshly checked remains `de5ec2e7a6074068452f45b1a191b5c72832df4a`, priority 8. Targeted PR/source-comment/cache searches found no matching successor or external feedback; bounded coverage is not exhaustive/unpublished assurance. Expiry 27 October 2026 at 19:00 AEDT. Retain Ali Romman and all original precision/native/compiler/tooling credit, including PR5831/5826/5819/5839/5816/5818/5832/5761. Chris R / Clear1nsight with substantial OpenAI Codex assistance; no subagents. Kappa research, Work 1/2, feeds and automations remain paused. diff --git a/research/fraction-contribution-table-feasibility/evidence/COMPLETE-COST-SCREEN.json b/research/fraction-contribution-table-feasibility/evidence/COMPLETE-COST-SCREEN.json new file mode 100644 index 0000000000..9f21b1f8b4 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/COMPLETE-COST-SCREEN.json @@ -0,0 +1,12 @@ +{ + "decision": "STOP_BEFORE_COMPLETE_CONSTRUCTION", + "prior_complete_wall_median": 39.01491572102532, + "within_process_trace_seconds_removed": 5.65193270801683, + "extra_new_finite_wall_observation": 1.6209555940004066, + "optimistic_fraction_ignoring_new_checks": 0.14486594687095472, + "modeled_complete_wall": 34.983938607008895, + "modeled_fraction_saved": 0.10331887278290623, + "required_fraction": 0.15, + "modeled_not_a_complete_wall_CPU_benchmark": true, + "further_capacity_trials": 0 +} diff --git a/research/fraction-contribution-table-feasibility/evidence/PLAN.json b/research/fraction-contribution-table-feasibility/evidence/PLAN.json new file mode 100644 index 0000000000..d7167e1663 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/PLAN.json @@ -0,0 +1,122 @@ +{ + "task": "Profile Fraction primitives in frozen PR5848; nominate at most one feasible source-bound optimization.", + "source": "66fb6c6b8683b37967e9d7f313b3df99a49d2406", + "canonical_main": "de5ec2e7a6074068452f45b1a191b5c72832df4a", + "previous_negative": "71f22c77b393e5cc14925c771894dc1a92c8443c; zero/unit shortcuts did not show15% complete-stage headroom.", + "gates": [ + "One complete unchanged qualification, cProfile only the Fraction actual error_trace. Report primitive calls/self/cumulative costs and instrumentation overhead; profile is not a benchmark.", + "Declare mathematical domain, source/runtime bindings, independence and coverage before a small finite/actual feasibility test. Construct no complete candidate before this gate.", + "At most one complete candidate; first fresh complete B/C pair >=15% less wall AND CPU, then all six B,C,C,B,B,C medians.", + "All original25984 events/799 coordinates, actual full witnesses/metadata/weights, independent arithmetic/oracles,120 finite programs/4240 events,6 semantic/3 integer/4 custody/27 observation controls preserved.", + "Normal/O/sealed checks, portable finite failures, exact committed bytes/modes/input ancestry, fresh upstream overlap and hosted exact-head CI before performance PR handoff." + ], + "limits": { + "initial_profile_feasibility_seconds": 600, + "shared_all_local_seconds": 1500, + "per_complete_precision_seconds": 180, + "group_rss_bytes": 1073741824, + "serial_runs": true, + "automatic_retries": 0 + }, + "stop": [ + "Incomplete required source/fixture/runtime binding, numerical/typed/witness/control/receipt mismatch, stderr or resource failure. Preserve and diagnose any pre-target launcher error separately.", + "No credible full-stage15% headroom, first-pair/median threshold failure, lost coverage/independence or active duplicate upstream work. No construction expansion after a closed gate." + ], + "kappa_research": "PAUSED", + "agents": 0, + "profile_gate": { + "status": "PASS", + "whole_profiled_seconds": 86.79358924200642, + "trace_profiled_seconds": 65.73670392399072, + "counts": { + "Fraction_results": 26030845, + "add": 10396952, + "mul": 7892384, + "coefficient_updates": 2579750 + }, + "timing_not_benchmark": true + }, + "nomination": "Per-trace bounded FIFO tabulation of exact Fraction coefficient transition and weighted increments, keyed by canonical values of old,q,v,weightA,weightC. Original Fraction arithmetic on misses; no cross-backend/run cache.", + "finite_gate": { + "status": "PASS", + "cases": 241, + "events_per_capacity": 10164, + "capacities": [ + 0, + 1, + 2, + 16384 + ], + "complete_comparisons": 964, + "controls": 34, + "normal_and_optimized": true + }, + "initial_table_feasibility": { + "capacity": 2048, + "all_values_types_inputs_equal": true, + "baseline_trace_seconds": 19.996063037018757, + "derived_trace_seconds": 16.578300290973857, + "statistics": { + "bypasses": 0, + "calls": 2579750, + "capacity": 2048, + "evictions": 643166, + "hits": 1934536, + "misses": 645214, + "resident": 2048 + }, + "decision": "Insufficient whole-stage headroom after new controls; no complete construction." + }, + "bounded_feasibility_reassessment": { + "question": "Does one16,384-entry FIFO table with O(1) OrderedDict eviction remove enough recomputation to justify complete construction?", + "reason": "2048-entry table evicted643166 entries, with25% misses. Current iterator/pop eviction also does not guarantee O(1) oldest removal.", + "unchanged": [ + "exact local formula and complete keys", + "original Fraction misses and independent integer backend", + "full event/witness/typed/negative coverage", + "180s per source command,1GiB RSS,600s initial and1500s shared caps" + ], + "new_bounds": { + "entries": 16384, + "capacity_trials_remaining": 1 + }, + "stop": "No further capacity/algorithm trial if this actual screen lacks credible15% complete-stage headroom." + }, + "actual_gate": { + "status": "PASS_VALUES_TYPES_INPUTS", + "actual": { + "all_values_types_and_inputs_preserved": true, + "baseline_trace_seconds": 20.251469953014748, + "coordinates": 799, + "derived_trace_seconds": 14.599537244997919, + "events": 25984, + "full_output_sha256": "954c7448ff74d78753828e9623ad44c46da9e5ce459420b6e50a5d47294250b9", + "observed_seconds_removed": 5.65193270801683, + "profile_whole_qualifier_seconds": 38.31372155799181, + "status": "PASS_FULL_ACTUAL_FRACTION_TRACE_EQUIVALENCE", + "table_statistics": { + "bypasses": 0, + "calls": 2579750, + "capacity": 16384, + "evictions": 310400, + "hits": 2252966, + "misses": 326784, + "resident": 16384 + }, + "weights_sha256": "cf98bf5da5df28ec1ca3ca7e8723d740b98e142f31e94ff7ec36815cc387c373" + } + }, + "complete_cost_gate": { + "decision": "STOP_BEFORE_COMPLETE_CONSTRUCTION", + "prior_complete_wall_median": 39.01491572102532, + "within_process_trace_seconds_removed": 5.65193270801683, + "extra_new_finite_wall_observation": 1.6209555940004066, + "optimistic_fraction_ignoring_new_checks": 0.14486594687095472, + "modeled_complete_wall": 34.983938607008895, + "modeled_fraction_saved": 0.10331887278290623, + "required_fraction": 0.15, + "modeled_not_a_complete_wall_CPU_benchmark": true, + "further_capacity_trials": 0 + }, + "next": "Publish scoped primitive-profile/table feasibility artifact and seven-field handoff only; no complete candidate or performance PR." +} diff --git a/research/fraction-contribution-table-feasibility/evidence/PRIMITIVES.json b/research/fraction-contribution-table-feasibility/evidence/PRIMITIVES.json new file mode 100644 index 0000000000..a0d1f026a6 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/PRIMITIVES.json @@ -0,0 +1,377 @@ +{ + "functions": [ + { + "cumulative_seconds": 15.812900419000002, + "file": "/usr/lib/python3.12/fractions.py", + "function": "_from_coprime_ints", + "line": 317, + "primitive_calls": 26030845, + "self_seconds": 11.713773661000001, + "total_calls": 26030845 + }, + { + "cumulative_seconds": 65.705991368, + "file": "/tmp/p104-integer-error-5qs2zy09/research/p104-noisy-copy-reset/precision.py", + "function": "error_trace", + "line": 123, + "primitive_calls": 1, + "self_seconds": 10.434950722, + "total_calls": 1 + }, + { + "cumulative_seconds": 42.276408473000004, + "file": "/usr/lib/python3.12/fractions.py", + "function": "forward", + "line": 613, + "primitive_calls": 20869086, + "self_seconds": 8.990157252000001, + "total_calls": 20869086 + }, + { + "cumulative_seconds": 14.986647283000002, + "file": "/usr/lib/python3.12/fractions.py", + "function": "_add", + "line": 710, + "primitive_calls": 10396952, + "self_seconds": 7.27879753, + "total_calls": 10396952 + }, + { + "cumulative_seconds": 12.070233685000002, + "file": "/usr/lib/python3.12/fractions.py", + "function": "_mul", + "line": 742, + "primitive_calls": 7892384, + "self_seconds": 5.6414134350000005, + "total_calls": 7892384 + }, + { + "cumulative_seconds": 4.530817473, + "file": "~", + "function": "", + "line": 0, + "primitive_calls": 28685894, + "self_seconds": 4.530817473, + "total_calls": 28685894 + }, + { + "cumulative_seconds": 3.8257899620000004, + "file": "~", + "function": "", + "line": 0, + "primitive_calls": 33126402, + "self_seconds": 3.8257899620000004, + "total_calls": 33126402 + }, + { + "cumulative_seconds": 5.832970863000001, + "file": "/usr/lib/python3.12/fractions.py", + "function": "__abs__", + "line": 853, + "primitive_calls": 5161759, + "self_seconds": 2.4324906790000003, + "total_calls": 5161759 + }, + { + "cumulative_seconds": 2.5090920110000003, + "file": "~", + "function": "", + "line": 0, + "primitive_calls": 21672605, + "self_seconds": 2.203636216, + "total_calls": 21672605 + }, + { + "cumulative_seconds": 7.329944933, + "file": "~", + "function": "", + "line": 0, + "primitive_calls": 5161759, + "self_seconds": 2.029012335, + "total_calls": 10323518 + }, + { + "cumulative_seconds": 2.184894383, + "file": "/usr/lib/python3.12/fractions.py", + "function": "__new__", + "line": 186, + "primitive_calls": 2655049, + "self_seconds": 1.6123486360000001, + "total_calls": 2655049 + }, + { + "cumulative_seconds": 4.191139103, + "file": "/usr/lib/python3.12/fractions.py", + "function": "_sub", + "line": 726, + "primitive_calls": 2579750, + "self_seconds": 1.562701657, + "total_calls": 2579750 + }, + { + "cumulative_seconds": 0.567401469, + "file": "~", + "function": "", + "line": 0, + "primitive_calls": 2579750, + "self_seconds": 0.567401469, + "total_calls": 2579750 + }, + { + "cumulative_seconds": 0.75091821, + "file": "/tmp/p104-integer-error-5qs2zy09/research/p104-noisy-copy-reset/precision.py", + "function": "update_hash", + "line": 119, + "primitive_calls": 385830, + "self_seconds": 0.551897967, + "total_calls": 385830 + }, + { + "cumulative_seconds": 0.522914474, + "file": "/usr/lib/python3.12/fractions.py", + "function": "__bool__", + "line": 969, + "primitive_calls": 2579750, + "self_seconds": 0.522914474, + "total_calls": 2579750 + }, + { + "cumulative_seconds": 0.679060922, + "file": "/usr/lib/python3.12/fractions.py", + "function": "_richcmp", + "line": 931, + "primitive_calls": 390976, + "self_seconds": 0.29755512300000003, + "total_calls": 390976 + }, + { + "cumulative_seconds": 0.17329617900000002, + "file": "~", + "function": "", + "line": 0, + "primitive_calls": 849121, + "self_seconds": 0.17329617900000002, + "total_calls": 849121 + }, + { + "cumulative_seconds": 1.0426144320000001, + "file": "~", + "function": "", + "line": 0, + "primitive_calls": 801, + "self_seconds": 0.166359589, + "total_calls": 801 + }, + { + "cumulative_seconds": 0.15758518000000002, + "file": "~", + "function": "", + "line": 0, + "primitive_calls": 758587, + "self_seconds": 0.15758518000000002, + "total_calls": 758587 + }, + { + "cumulative_seconds": 0.373710888, + "file": "/usr/lib/python3.12/fractions.py", + "function": "__eq__", + "line": 910, + "primitive_calls": 319161, + "self_seconds": 0.152659912, + "total_calls": 319161 + }, + { + "cumulative_seconds": 0.30545579500000003, + "file": "", + "function": "__instancecheck__", + "line": 117, + "primitive_calls": 758587, + "self_seconds": 0.147870615, + "total_calls": 758587 + }, + { + "cumulative_seconds": 0.101872844, + "file": "~", + "function": "", + "line": 0, + "primitive_calls": 411814, + "self_seconds": 0.101872844, + "total_calls": 411814 + }, + { + "cumulative_seconds": 0.09183905, + "file": "/usr/lib/python3.12/fractions.py", + "function": "numerator", + "line": 397, + "primitive_calls": 1095967, + "self_seconds": 0.09183905, + "total_calls": 1095967 + }, + { + "cumulative_seconds": 0.505407649, + "file": "/usr/lib/python3.12/fractions.py", + "function": "__lt__", + "line": 953, + "primitive_calls": 284733, + "self_seconds": 0.07561146, + "total_calls": 284733 + }, + { + "cumulative_seconds": 0.074123193, + "file": "~", + "function": "", + "line": 0, + "primitive_calls": 411814, + "self_seconds": 0.074123193, + "total_calls": 411814 + }, + { + "cumulative_seconds": 0.065064019, + "file": "/usr/lib/python3.12/fractions.py", + "function": "denominator", + "line": 401, + "primitive_calls": 809015, + "self_seconds": 0.065064019, + "total_calls": 809015 + }, + { + "cumulative_seconds": 0.062322091, + "file": "~", + "function": "", + "line": 0, + "primitive_calls": 22466, + "self_seconds": 0.062322091, + "total_calls": 22466 + }, + { + "cumulative_seconds": 0.096953124, + "file": "~", + "function": "", + "line": 0, + "primitive_calls": 25984, + "self_seconds": 0.052744080000000006, + "total_calls": 25984 + }, + { + "cumulative_seconds": 0.044209044, + "file": "/usr/lib/python3.12/fractions.py", + "function": "__str__", + "line": 410, + "primitive_calls": 77952, + "self_seconds": 0.044209044, + "total_calls": 77952 + }, + { + "cumulative_seconds": 0.291541954, + "file": "/usr/lib/python3.12/fractions.py", + "function": "__gt__", + "line": 957, + "primitive_calls": 106243, + "self_seconds": 0.042277221000000004, + "total_calls": 106243 + }, + { + "cumulative_seconds": 0.036193269, + "file": "~", + "function": "", + "line": 0, + "primitive_calls": 87908, + "self_seconds": 0.036193269, + "total_calls": 87908 + }, + { + "cumulative_seconds": 0.029552753, + "file": "~", + "function": "", + "line": 0, + "primitive_calls": 284733, + "self_seconds": 0.029552753, + "total_calls": 284733 + }, + { + "cumulative_seconds": 0.017329772, + "file": "~", + "function": "", + "line": 0, + "primitive_calls": 106243, + "self_seconds": 0.017329772, + "total_calls": 106243 + }, + { + "cumulative_seconds": 0.008940519000000001, + "file": "~", + "function": "", + "line": 0, + "primitive_calls": 26787, + "self_seconds": 0.008940519000000001, + "total_calls": 26787 + }, + { + "cumulative_seconds": 0.006942796, + "file": "~", + "function": "", + "line": 0, + "primitive_calls": 22466, + "self_seconds": 0.006942796, + "total_calls": 22466 + }, + { + "cumulative_seconds": 0.009097874, + "file": "~", + "function": "", + "line": 0, + "primitive_calls": 3, + "self_seconds": 0.001226127, + "total_calls": 3 + }, + { + "cumulative_seconds": 0.001053539, + "file": "~", + "function": "", + "line": 0, + "primitive_calls": 800, + "self_seconds": 0.001053539, + "total_calls": 800 + }, + { + "cumulative_seconds": 0.0007139410000000001, + "file": "/tmp/p104-integer-error-5qs2zy09/research/p104-noisy-copy-reset/precision.py", + "function": "", + "line": 174, + "primitive_calls": 2313, + "self_seconds": 0.0007139410000000001, + "total_calls": 2313 + }, + { + "cumulative_seconds": 0.000544358, + "file": "~", + "function": "", + "line": 0, + "primitive_calls": 800, + "self_seconds": 0.000544358, + "total_calls": 800 + }, + { + "cumulative_seconds": 4.6447000000000004e-05, + "file": "~", + "function": "", + "line": 0, + "primitive_calls": 1, + "self_seconds": 4.6447000000000004e-05, + "total_calls": 1 + }, + { + "cumulative_seconds": 1.226e-06, + "file": "~", + "function": "", + "line": 0, + "primitive_calls": 3, + "self_seconds": 1.226e-06, + "total_calls": 3 + } + ], + "primitive_calls": 176633094, + "profiled_trace_seconds": 65.73670392399072, + "total_calls": 181794853, + "total_profile_self_seconds": 65.70603781499999 +} diff --git a/research/fraction-contribution-table-feasibility/evidence/RUNTIME-BINDINGS.json b/research/fraction-contribution-table-feasibility/evidence/RUNTIME-BINDINGS.json new file mode 100644 index 0000000000..300195f9af --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/RUNTIME-BINDINGS.json @@ -0,0 +1,8 @@ +{ + "python_fraction_path": "/usr/lib/python3.12/fractions.py", + "python_fraction_sha256": "cf33568f7b767f66896995a7a81cc662e8be226f2e58efb61d2028f64eb5d231", + "Fraction_slots": [ + "_numerator", + "_denominator" + ] +} diff --git a/research/fraction-contribution-table-feasibility/evidence/TABLE-2048-PROTOTYPE.py.txt b/research/fraction-contribution-table-feasibility/evidence/TABLE-2048-PROTOTYPE.py.txt new file mode 100644 index 0000000000..24d702475c --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/TABLE-2048-PROTOTYPE.py.txt @@ -0,0 +1,122 @@ +"""Per-trace bounded tabulation of pure exact Fraction contributions. + +Original arithmetic: Ali Romman and retained completed-error lineage. +New table/derivation: Chris R / Clear1nsight, substantial OpenAI Codex assistance. +Apache-2.0. No approximate or shared integer-backend arithmetic. +""" +from contextlib import contextmanager +from fractions import Fraction as F +from hashlib import sha256 +import inspect +from pathlib import Path +from types import CodeType + +MODULE_SHA256='a4c743e79c55e9c2ac26deb6d87cb948b1b0fbe942e4f7912ccbfba55db4b32a' +FUNCTION_SHA256='379c0e7c1c5ab7433ab5ad2669c1bda1234dbf0530fc61b21bfbe83528f37f53' +CAPACITY=2048 +BEFORE=''' value = old + q*v + change = abs(value)-abs(old) + scores[r][0] += change*weights[i][0] + scores[r][1] += change*weights[i][1] + scores[r][2] += change +''' +AFTER=''' value, increment_a, increment_c, change = contributions.step( + old, q, v, weights[i][0], weights[i][1]) + scores[r][0] += increment_a + scores[r][1] += increment_c + scores[r][2] += change +''' + + +def need(ok,message): + if not ok: + raise ValueError(message) + + +class Contributions: + def __init__(self,capacity=CAPACITY): + need(type(capacity) is int and 0<=capacity<=CAPACITY,'bounded integer table capacity') + self.capacity=capacity + self.table={} + self.calls=self.hits=self.misses=self.evictions=self.bypasses=0 + + @staticmethod + def compute(old,q,v,a,c): + value=old+q*v + change=abs(value)-abs(old) + return value,change*a,change*c,change + + def step(self,old,q,v,a,c): + self.calls+=1 + if not self.capacity or not all(type(x) is F for x in (old,q,v,a,c)): + self.bypasses+=1 + return self.compute(old,q,v,a,c) + key=(old.numerator,old.denominator,q.numerator,q.denominator, + v.numerator,v.denominator,a.numerator,a.denominator,c.numerator,c.denominator) + result=self.table.get(key) + if result is not None: + self.hits+=1 + return result + self.misses+=1 + result=self.compute(old,q,v,a,c) + if len(self.table)>=self.capacity: + self.table.pop(next(iter(self.table))) + self.evictions+=1 + self.table[key]=result + return result + + def statistics(self): + return dict(calls=self.calls,hits=self.hits,misses=self.misses, + evictions=self.evictions,bypasses=self.bypasses, + resident=len(self.table),capacity=self.capacity) + + +def code_shape(code): + constants=tuple(code_shape(c) if isinstance(c,CodeType) else c for c in code.co_consts) + return (code.co_code,constants,code.co_names,code.co_varnames,code.co_argcount, + code.co_posonlyargcount,code.co_kwonlyargcount,code.co_flags, + code.co_freevars,code.co_cellvars,code.co_name,code.co_stacksize, + code.co_nlocals,code.co_exceptiontable) + + +def transformed(raw): + need(sha256(raw.encode()).hexdigest()==FUNCTION_SHA256,'exact Fraction function source') + need(raw.count(BEFORE)==1,'one exact Fraction contribution block') + value=raw.replace(BEFORE,AFTER) + seam=" n = word['public'] + word['owned_fields']\n" + need(value.count(seam)==1,'one exact Fraction setup seam') + value=value.replace(seam,seam+' _contribution_report(None)\n contributions = _contribution_factory()\n') + seam=' return dict(rounded=sorted(rounded), sites=sites, peaks=peaks, pareto=pareto,\n' + need(value.count(seam)==1,'one exact Fraction return seam') + return value.replace(seam,' _contribution_report(contributions.statistics())\n'+seam) + + +def derive(reference,capacity=CAPACITY): + need(type(capacity) is int and 0<=capacity<=CAPACITY,'bounded integer table capacity') + need(reference.F is F,'exact standard Fraction type') + need(sha256(Path(reference.__file__).read_bytes()).hexdigest()==MODULE_SHA256,'exact Fraction module bytes') + original=reference.error_trace + raw=inspect.getsource(original) + text=transformed(raw) + namespace=dict(reference.__dict__) + exec(compile(raw,'','exec'),namespace) + need(code_shape(original.__code__)==code_shape(namespace['error_trace'].__code__),'live Fraction code agrees with source') + need(original.__defaults__ is None and original.__kwdefaults__ is None and original.__closure__ is None,'ordinary Fraction function') + last=[None] + def report(value):last[0]=None if value is None else dict(value) + namespace.update(_contribution_factory=lambda:Contributions(capacity),_contribution_report=report) + exec(compile(text,'','exec'),namespace) + result=namespace['error_trace'] + result.statistics=lambda:None if last[0] is None else dict(last[0]) + return result + + +@contextmanager +def installed(reference,capacity=CAPACITY): + original=reference.error_trace + derived=derive(reference,capacity) + reference.error_trace=derived + try: + yield derived + finally: + reference.error_trace=original diff --git a/research/fraction-contribution-table-feasibility/evidence/TABLE-REASSESSMENT.json b/research/fraction-contribution-table-feasibility/evidence/TABLE-REASSESSMENT.json new file mode 100644 index 0000000000..75590bb4c7 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/TABLE-REASSESSMENT.json @@ -0,0 +1,15 @@ +{ + "question": "Does one16,384-entry FIFO table with O(1) OrderedDict eviction remove enough recomputation to justify complete construction?", + "reason": "2048-entry table evicted643166 entries, with25% misses. Current iterator/pop eviction also does not guarantee O(1) oldest removal.", + "unchanged": [ + "exact local formula and complete keys", + "original Fraction misses and independent integer backend", + "full event/witness/typed/negative coverage", + "180s per source command,1GiB RSS,600s initial and1500s shared caps" + ], + "new_bounds": { + "entries": 16384, + "capacity_trials_remaining": 1 + }, + "stop": "No further capacity/algorithm trial if this actual screen lacks credible15% complete-stage headroom." +} diff --git a/research/fraction-contribution-table-feasibility/evidence/actual-table-audit/receipt.json b/research/fraction-contribution-table-feasibility/evidence/actual-table-audit/receipt.json new file mode 100644 index 0000000000..0749bf2076 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/actual-table-audit/receipt.json @@ -0,0 +1,26 @@ +{ + "exit": 0, + "label": "actual-table-audit", + "optimized": false, + "original_local_receipt_sha256": "a039fb6d77f5974849acf3d15bc55d4f85b8523548960aa6688021a5310eb796", + "platform": "Linux-7.0.0-38-generic-x86_64-with-glibc2.39", + "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", + "runner_sha256": "7540f8cc4ae4d12ed86c844ef0837a74184d3ada653979608c295c09f200a751", + "runtime_policy_sha256": "64a9c3344f850c4426fb1d565ea03cf91ea1c4f2f2cd444b4a04702584429b81", + "sampled_process_group_rss_bytes": 107495424, + "source_bytes_and_modes_unchanged": true, + "source_inventory_sha256": "d5587c8fce35504aa41226611db91d331639c3945a63b3c7b607c0b8fc3b886d", + "status": "PASS", + "stderr_bytes": 0, + "stderr_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "stdout_bytes": 658, + "stdout_sha256": "0061e352cd7b4f39a2da80d8355bbb78cc2b4b952399365855aa884292676dc7", + "termination": null, + "usage": { + "exit": 0, + "kernel_max_rss_kib": 103524, + "system_seconds": 0.07, + "user_seconds": 39.11 + }, + "wall_seconds": 39.225202494009864 +} diff --git a/research/fraction-contribution-table-feasibility/evidence/actual-table-audit/stderr.txt b/research/fraction-contribution-table-feasibility/evidence/actual-table-audit/stderr.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/research/fraction-contribution-table-feasibility/evidence/actual-table-audit/stdout.txt b/research/fraction-contribution-table-feasibility/evidence/actual-table-audit/stdout.txt new file mode 100644 index 0000000000..21f1867b25 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/actual-table-audit/stdout.txt @@ -0,0 +1 @@ +{"all_values_types_and_inputs_preserved": true, "baseline_trace_seconds": 19.996063037018757, "coordinates": 799, "derived_trace_seconds": 16.578300290973857, "events": 25984, "full_output_sha256": "954c7448ff74d78753828e9623ad44c46da9e5ce459420b6e50a5d47294250b9", "observed_seconds_removed": 3.4177627460449003, "profile_whole_qualifier_seconds": 38.31372155799181, "status": "PASS_FULL_ACTUAL_FRACTION_TRACE_EQUIVALENCE", "table_statistics": {"bypasses": 0, "calls": 2579750, "capacity": 2048, "evictions": 643166, "hits": 1934536, "misses": 645214, "resident": 2048}, "weights_sha256": "cf98bf5da5df28ec1ca3ca7e8723d740b98e142f31e94ff7ec36815cc387c373"} diff --git a/research/fraction-contribution-table-feasibility/evidence/actual-table-audit/usage.json b/research/fraction-contribution-table-feasibility/evidence/actual-table-audit/usage.json new file mode 100644 index 0000000000..260f83884b --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/actual-table-audit/usage.json @@ -0,0 +1 @@ +{"user_seconds":39.11,"system_seconds":0.07,"kernel_max_rss_kib":103524,"exit":0} diff --git a/research/fraction-contribution-table-feasibility/evidence/actual-table-audit16k/receipt.json b/research/fraction-contribution-table-feasibility/evidence/actual-table-audit16k/receipt.json new file mode 100644 index 0000000000..8fda82e0cf --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/actual-table-audit16k/receipt.json @@ -0,0 +1,26 @@ +{ + "exit": 0, + "label": "actual-table-audit16k", + "optimized": false, + "original_local_receipt_sha256": "dd124d23ee8fcaa966b61b848210f3afa4828037417070adfa60ce43cb2fe176", + "platform": "Linux-7.0.0-38-generic-x86_64-with-glibc2.39", + "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", + "runner_sha256": "7540f8cc4ae4d12ed86c844ef0837a74184d3ada653979608c295c09f200a751", + "runtime_policy_sha256": "64a9c3344f850c4426fb1d565ea03cf91ea1c4f2f2cd444b4a04702584429b81", + "sampled_process_group_rss_bytes": 110895104, + "source_bytes_and_modes_unchanged": true, + "source_inventory_sha256": "5a0244167b6b9e918918c7f11b0ac037821e7b3a37aacbb42549bffe98973e77", + "status": "PASS", + "stderr_bytes": 0, + "stderr_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "stdout_bytes": 658, + "stdout_sha256": "9f9d7616ddc913983eff7e27d40aad86facaf29a9adc0aeffccc06e68113b3f7", + "termination": null, + "usage": { + "exit": 0, + "kernel_max_rss_kib": 106844, + "system_seconds": 0.08, + "user_seconds": 37.32 + }, + "wall_seconds": 37.45972871899721 +} diff --git a/research/fraction-contribution-table-feasibility/evidence/actual-table-audit16k/stderr.txt b/research/fraction-contribution-table-feasibility/evidence/actual-table-audit16k/stderr.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/research/fraction-contribution-table-feasibility/evidence/actual-table-audit16k/stdout.txt b/research/fraction-contribution-table-feasibility/evidence/actual-table-audit16k/stdout.txt new file mode 100644 index 0000000000..94b31c3ab2 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/actual-table-audit16k/stdout.txt @@ -0,0 +1 @@ +{"all_values_types_and_inputs_preserved": true, "baseline_trace_seconds": 20.251469953014748, "coordinates": 799, "derived_trace_seconds": 14.599537244997919, "events": 25984, "full_output_sha256": "954c7448ff74d78753828e9623ad44c46da9e5ce459420b6e50a5d47294250b9", "observed_seconds_removed": 5.65193270801683, "profile_whole_qualifier_seconds": 38.31372155799181, "status": "PASS_FULL_ACTUAL_FRACTION_TRACE_EQUIVALENCE", "table_statistics": {"bypasses": 0, "calls": 2579750, "capacity": 16384, "evictions": 310400, "hits": 2252966, "misses": 326784, "resident": 16384}, "weights_sha256": "cf98bf5da5df28ec1ca3ca7e8723d740b98e142f31e94ff7ec36815cc387c373"} diff --git a/research/fraction-contribution-table-feasibility/evidence/actual-table-audit16k/usage.json b/research/fraction-contribution-table-feasibility/evidence/actual-table-audit16k/usage.json new file mode 100644 index 0000000000..eb389e25ec --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/actual-table-audit16k/usage.json @@ -0,0 +1 @@ +{"user_seconds":37.32,"system_seconds":0.08,"kernel_max_rss_kib":106844,"exit":0} diff --git a/research/fraction-contribution-table-feasibility/evidence/dispatch.py b/research/fraction-contribution-table-feasibility/evidence/dispatch.py new file mode 100644 index 0000000000..2422bf2e12 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/dispatch.py @@ -0,0 +1,6 @@ +import guard,sys +label=sys.argv[1] if sys.argv[1:] else 'primitive-profile' +script='../feasibility/finite.py' if label.startswith('finite') else '../feasibility/actual_audit.py' if label.startswith('actual-table-audit') else 'primitive_profile.py' +with (guard.HERE/'execution.lock').open('a') as lock: + guard.fcntl.flock(lock,guard.fcntl.LOCK_EX|guard.fcntl.LOCK_NB) + guard.run(label,script,optimized=label.endswith('-O')) diff --git a/research/fraction-contribution-table-feasibility/evidence/finite-fresh-lifetime-O/receipt.json b/research/fraction-contribution-table-feasibility/evidence/finite-fresh-lifetime-O/receipt.json new file mode 100644 index 0000000000..ffbdd70355 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/finite-fresh-lifetime-O/receipt.json @@ -0,0 +1,26 @@ +{ + "exit": 0, + "label": "finite-fresh-lifetime-O", + "optimized": true, + "original_local_receipt_sha256": "0fad8667ecc8eaf2cccb3b30f86ed0e69cd426771ef6b07a00e9dc67014bfa35", + "platform": "Linux-7.0.0-38-generic-x86_64-with-glibc2.39", + "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", + "runner_sha256": "7540f8cc4ae4d12ed86c844ef0837a74184d3ada653979608c295c09f200a751", + "runtime_policy_sha256": "64a9c3344f850c4426fb1d565ea03cf91ea1c4f2f2cd444b4a04702584429b81", + "sampled_process_group_rss_bytes": 29904896, + "source_bytes_and_modes_unchanged": true, + "source_inventory_sha256": "d5587c8fce35504aa41226611db91d331639c3945a63b3c7b607c0b8fc3b886d", + "status": "PASS", + "stderr_bytes": 0, + "stderr_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "stdout_bytes": 825, + "stdout_sha256": "803fe5ca16af6059e9dc6700e0e2026f907d7b6d01b3ed9ad44f675f846198c6", + "termination": null, + "usage": { + "exit": 0, + "kernel_max_rss_kib": 27896, + "system_seconds": 0.02, + "user_seconds": 1.54 + }, + "wall_seconds": 1.570529852004256 +} diff --git a/research/fraction-contribution-table-feasibility/evidence/finite-fresh-lifetime-O/stderr.txt b/research/fraction-contribution-table-feasibility/evidence/finite-fresh-lifetime-O/stderr.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/research/fraction-contribution-table-feasibility/evidence/finite-fresh-lifetime-O/stdout.txt b/research/fraction-contribution-table-feasibility/evidence/finite-fresh-lifetime-O/stdout.txt new file mode 100644 index 0000000000..0109f475ce --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/finite-fresh-lifetime-O/stdout.txt @@ -0,0 +1 @@ +{"all_complete_values_and_types_equal": true, "cases": 241, "controls": ["returned-mutation-isolated", "source-drift", "Fraction-type-drift", "module-byte-drift", "live-code-drift", "nested-live-code-drift", "omitted-witness", "omitted-rounded-sites", "wrong-coefficient", "wrong-weighted-increment", "bad-role", "bad-scalar", "missing-weight", "restore-success", "restore-exception", "fresh-derivation", "key-field-0", "key-field-1", "key-field-2", "key-field-3", "key-field-4", "FIFO-eviction", "canonical-key", "hash-collision", "disabled", "invalid-capacity--1", "invalid-capacity-2049", "invalid-capacity-True", "invalid-capacity-1.5", "uncached-exception-0", "uncached-exception-1", "fresh-call-table", "stats-mutation", "failed-call-clears-stats"], "events": 10164, "status": "PASS_FINITE_FRACTION_TABLE_FEASIBILITY"} diff --git a/research/fraction-contribution-table-feasibility/evidence/finite-fresh-lifetime-O/usage.json b/research/fraction-contribution-table-feasibility/evidence/finite-fresh-lifetime-O/usage.json new file mode 100644 index 0000000000..59e336cc6e --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/finite-fresh-lifetime-O/usage.json @@ -0,0 +1 @@ +{"user_seconds":1.54,"system_seconds":0.02,"kernel_max_rss_kib":27896,"exit":0} diff --git a/research/fraction-contribution-table-feasibility/evidence/finite-fresh-lifetime/receipt.json b/research/fraction-contribution-table-feasibility/evidence/finite-fresh-lifetime/receipt.json new file mode 100644 index 0000000000..78ad67d1a8 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/finite-fresh-lifetime/receipt.json @@ -0,0 +1,26 @@ +{ + "exit": 0, + "label": "finite-fresh-lifetime", + "optimized": false, + "original_local_receipt_sha256": "64cc88e1225d3733c07eeeca559b1dfca310ac7771f190fcee05cea90752fea4", + "platform": "Linux-7.0.0-38-generic-x86_64-with-glibc2.39", + "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", + "runner_sha256": "7540f8cc4ae4d12ed86c844ef0837a74184d3ada653979608c295c09f200a751", + "runtime_policy_sha256": "64a9c3344f850c4426fb1d565ea03cf91ea1c4f2f2cd444b4a04702584429b81", + "sampled_process_group_rss_bytes": 29913088, + "source_bytes_and_modes_unchanged": true, + "source_inventory_sha256": "d5587c8fce35504aa41226611db91d331639c3945a63b3c7b607c0b8fc3b886d", + "status": "PASS", + "stderr_bytes": 0, + "stderr_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "stdout_bytes": 825, + "stdout_sha256": "803fe5ca16af6059e9dc6700e0e2026f907d7b6d01b3ed9ad44f675f846198c6", + "termination": null, + "usage": { + "exit": 0, + "kernel_max_rss_kib": 27924, + "system_seconds": 0.03, + "user_seconds": 1.85 + }, + "wall_seconds": 2.003223514999263 +} diff --git a/research/fraction-contribution-table-feasibility/evidence/finite-fresh-lifetime/stderr.txt b/research/fraction-contribution-table-feasibility/evidence/finite-fresh-lifetime/stderr.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/research/fraction-contribution-table-feasibility/evidence/finite-fresh-lifetime/stdout.txt b/research/fraction-contribution-table-feasibility/evidence/finite-fresh-lifetime/stdout.txt new file mode 100644 index 0000000000..0109f475ce --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/finite-fresh-lifetime/stdout.txt @@ -0,0 +1 @@ +{"all_complete_values_and_types_equal": true, "cases": 241, "controls": ["returned-mutation-isolated", "source-drift", "Fraction-type-drift", "module-byte-drift", "live-code-drift", "nested-live-code-drift", "omitted-witness", "omitted-rounded-sites", "wrong-coefficient", "wrong-weighted-increment", "bad-role", "bad-scalar", "missing-weight", "restore-success", "restore-exception", "fresh-derivation", "key-field-0", "key-field-1", "key-field-2", "key-field-3", "key-field-4", "FIFO-eviction", "canonical-key", "hash-collision", "disabled", "invalid-capacity--1", "invalid-capacity-2049", "invalid-capacity-True", "invalid-capacity-1.5", "uncached-exception-0", "uncached-exception-1", "fresh-call-table", "stats-mutation", "failed-call-clears-stats"], "events": 10164, "status": "PASS_FINITE_FRACTION_TABLE_FEASIBILITY"} diff --git a/research/fraction-contribution-table-feasibility/evidence/finite-fresh-lifetime/usage.json b/research/fraction-contribution-table-feasibility/evidence/finite-fresh-lifetime/usage.json new file mode 100644 index 0000000000..21a614b6a3 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/finite-fresh-lifetime/usage.json @@ -0,0 +1 @@ +{"user_seconds":1.85,"system_seconds":0.03,"kernel_max_rss_kib":27924,"exit":0} diff --git a/research/fraction-contribution-table-feasibility/evidence/finite-table/receipt.json b/research/fraction-contribution-table-feasibility/evidence/finite-table/receipt.json new file mode 100644 index 0000000000..3dd47fec7d --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/finite-table/receipt.json @@ -0,0 +1,26 @@ +{ + "exit": 0, + "label": "finite-table", + "optimized": false, + "original_local_receipt_sha256": "d66ec75cdb7e1ca1531ee5a232b4588206886d67f1e894a6c0ebe19704a2de47", + "platform": "Linux-7.0.0-38-generic-x86_64-with-glibc2.39", + "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", + "runner_sha256": "3b8765731f5e446cdc0ca8c4b754e8a11d39373e4110058c0f212997246db28b", + "runtime_policy_sha256": "58f5d61296389ed74ed67b739ae7bcace49e47c3d7cc6213653f18ae1a2f4029", + "sampled_process_group_rss_bytes": 30367744, + "source_bytes_and_modes_unchanged": true, + "source_inventory_sha256": "90a9e130271936908dfef84a693846cdbce150cc5bcbb16ed066f946f5e24492", + "status": "PASS", + "stderr_bytes": 0, + "stderr_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "stdout_bytes": 825, + "stdout_sha256": "803fe5ca16af6059e9dc6700e0e2026f907d7b6d01b3ed9ad44f675f846198c6", + "termination": null, + "usage": { + "exit": 0, + "kernel_max_rss_kib": 28368, + "system_seconds": 0.04, + "user_seconds": 4.34 + }, + "wall_seconds": 4.405135999986669 +} diff --git a/research/fraction-contribution-table-feasibility/evidence/finite-table/stderr.txt b/research/fraction-contribution-table-feasibility/evidence/finite-table/stderr.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/research/fraction-contribution-table-feasibility/evidence/finite-table/stdout.txt b/research/fraction-contribution-table-feasibility/evidence/finite-table/stdout.txt new file mode 100644 index 0000000000..0109f475ce --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/finite-table/stdout.txt @@ -0,0 +1 @@ +{"all_complete_values_and_types_equal": true, "cases": 241, "controls": ["returned-mutation-isolated", "source-drift", "Fraction-type-drift", "module-byte-drift", "live-code-drift", "nested-live-code-drift", "omitted-witness", "omitted-rounded-sites", "wrong-coefficient", "wrong-weighted-increment", "bad-role", "bad-scalar", "missing-weight", "restore-success", "restore-exception", "fresh-derivation", "key-field-0", "key-field-1", "key-field-2", "key-field-3", "key-field-4", "FIFO-eviction", "canonical-key", "hash-collision", "disabled", "invalid-capacity--1", "invalid-capacity-2049", "invalid-capacity-True", "invalid-capacity-1.5", "uncached-exception-0", "uncached-exception-1", "fresh-call-table", "stats-mutation", "failed-call-clears-stats"], "events": 10164, "status": "PASS_FINITE_FRACTION_TABLE_FEASIBILITY"} diff --git a/research/fraction-contribution-table-feasibility/evidence/finite-table/usage.json b/research/fraction-contribution-table-feasibility/evidence/finite-table/usage.json new file mode 100644 index 0000000000..e0369f806b --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/finite-table/usage.json @@ -0,0 +1 @@ +{"user_seconds":4.34,"system_seconds":0.04,"kernel_max_rss_kib":28368,"exit":0} diff --git a/research/fraction-contribution-table-feasibility/evidence/finite-table16k-O/receipt.json b/research/fraction-contribution-table-feasibility/evidence/finite-table16k-O/receipt.json new file mode 100644 index 0000000000..540b9c589e --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/finite-table16k-O/receipt.json @@ -0,0 +1,26 @@ +{ + "exit": 0, + "label": "finite-table16k-O", + "optimized": true, + "original_local_receipt_sha256": "7d79a8dee49a0375e2bbf8d90d4facbdf9c9e4d8609df3ae9c468161b6816bba", + "platform": "Linux-7.0.0-38-generic-x86_64-with-glibc2.39", + "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", + "runner_sha256": "7540f8cc4ae4d12ed86c844ef0837a74184d3ada653979608c295c09f200a751", + "runtime_policy_sha256": "64a9c3344f850c4426fb1d565ea03cf91ea1c4f2f2cd444b4a04702584429b81", + "sampled_process_group_rss_bytes": 29790208, + "source_bytes_and_modes_unchanged": true, + "source_inventory_sha256": "5a0244167b6b9e918918c7f11b0ac037821e7b3a37aacbb42549bffe98973e77", + "status": "PASS", + "stderr_bytes": 0, + "stderr_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "stdout_bytes": 826, + "stdout_sha256": "bd820afc7a2ca3f8e9016dc3c308c2c173306ea9a479441d9da7f950ca1a27fa", + "termination": null, + "usage": { + "exit": 0, + "kernel_max_rss_kib": 27944, + "system_seconds": 0.01, + "user_seconds": 1.5 + }, + "wall_seconds": 1.569447460991796 +} diff --git a/research/fraction-contribution-table-feasibility/evidence/finite-table16k-O/stderr.txt b/research/fraction-contribution-table-feasibility/evidence/finite-table16k-O/stderr.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/research/fraction-contribution-table-feasibility/evidence/finite-table16k-O/stdout.txt b/research/fraction-contribution-table-feasibility/evidence/finite-table16k-O/stdout.txt new file mode 100644 index 0000000000..2412841a5e --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/finite-table16k-O/stdout.txt @@ -0,0 +1 @@ +{"all_complete_values_and_types_equal": true, "cases": 241, "controls": ["returned-mutation-isolated", "source-drift", "Fraction-type-drift", "module-byte-drift", "live-code-drift", "nested-live-code-drift", "omitted-witness", "omitted-rounded-sites", "wrong-coefficient", "wrong-weighted-increment", "bad-role", "bad-scalar", "missing-weight", "restore-success", "restore-exception", "fresh-derivation", "key-field-0", "key-field-1", "key-field-2", "key-field-3", "key-field-4", "FIFO-eviction", "canonical-key", "hash-collision", "disabled", "invalid-capacity--1", "invalid-capacity-16385", "invalid-capacity-True", "invalid-capacity-1.5", "uncached-exception-0", "uncached-exception-1", "fresh-call-table", "stats-mutation", "failed-call-clears-stats"], "events": 10164, "status": "PASS_FINITE_FRACTION_TABLE_FEASIBILITY"} diff --git a/research/fraction-contribution-table-feasibility/evidence/finite-table16k-O/usage.json b/research/fraction-contribution-table-feasibility/evidence/finite-table16k-O/usage.json new file mode 100644 index 0000000000..3b7bd81b7b --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/finite-table16k-O/usage.json @@ -0,0 +1 @@ +{"user_seconds":1.50,"system_seconds":0.01,"kernel_max_rss_kib":27944,"exit":0} diff --git a/research/fraction-contribution-table-feasibility/evidence/finite-table16k/receipt.json b/research/fraction-contribution-table-feasibility/evidence/finite-table16k/receipt.json new file mode 100644 index 0000000000..c8cbe5189f --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/finite-table16k/receipt.json @@ -0,0 +1,26 @@ +{ + "exit": 0, + "label": "finite-table16k", + "optimized": false, + "original_local_receipt_sha256": "dc16c6d9a86d9fe3cc6d941e9ae854219ef7a7da5167339aa5ccb11c8c848dd2", + "platform": "Linux-7.0.0-38-generic-x86_64-with-glibc2.39", + "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", + "runner_sha256": "7540f8cc4ae4d12ed86c844ef0837a74184d3ada653979608c295c09f200a751", + "runtime_policy_sha256": "64a9c3344f850c4426fb1d565ea03cf91ea1c4f2f2cd444b4a04702584429b81", + "sampled_process_group_rss_bytes": 30048256, + "source_bytes_and_modes_unchanged": true, + "source_inventory_sha256": "5a0244167b6b9e918918c7f11b0ac037821e7b3a37aacbb42549bffe98973e77", + "status": "PASS", + "stderr_bytes": 0, + "stderr_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "stdout_bytes": 826, + "stdout_sha256": "bd820afc7a2ca3f8e9016dc3c308c2c173306ea9a479441d9da7f950ca1a27fa", + "termination": null, + "usage": { + "exit": 0, + "kernel_max_rss_kib": 28036, + "system_seconds": 0.02, + "user_seconds": 1.54 + }, + "wall_seconds": 1.6209555940004066 +} diff --git a/research/fraction-contribution-table-feasibility/evidence/finite-table16k/stderr.txt b/research/fraction-contribution-table-feasibility/evidence/finite-table16k/stderr.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/research/fraction-contribution-table-feasibility/evidence/finite-table16k/stdout.txt b/research/fraction-contribution-table-feasibility/evidence/finite-table16k/stdout.txt new file mode 100644 index 0000000000..2412841a5e --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/finite-table16k/stdout.txt @@ -0,0 +1 @@ +{"all_complete_values_and_types_equal": true, "cases": 241, "controls": ["returned-mutation-isolated", "source-drift", "Fraction-type-drift", "module-byte-drift", "live-code-drift", "nested-live-code-drift", "omitted-witness", "omitted-rounded-sites", "wrong-coefficient", "wrong-weighted-increment", "bad-role", "bad-scalar", "missing-weight", "restore-success", "restore-exception", "fresh-derivation", "key-field-0", "key-field-1", "key-field-2", "key-field-3", "key-field-4", "FIFO-eviction", "canonical-key", "hash-collision", "disabled", "invalid-capacity--1", "invalid-capacity-16385", "invalid-capacity-True", "invalid-capacity-1.5", "uncached-exception-0", "uncached-exception-1", "fresh-call-table", "stats-mutation", "failed-call-clears-stats"], "events": 10164, "status": "PASS_FINITE_FRACTION_TABLE_FEASIBILITY"} diff --git a/research/fraction-contribution-table-feasibility/evidence/finite-table16k/usage.json b/research/fraction-contribution-table-feasibility/evidence/finite-table16k/usage.json new file mode 100644 index 0000000000..79951fd2e6 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/finite-table16k/usage.json @@ -0,0 +1 @@ +{"user_seconds":1.54,"system_seconds":0.02,"kernel_max_rss_kib":28036,"exit":0} diff --git a/research/fraction-contribution-table-feasibility/evidence/fraction-trace.pstats b/research/fraction-contribution-table-feasibility/evidence/fraction-trace.pstats new file mode 100644 index 0000000000..8c62cb8d49 Binary files /dev/null and b/research/fraction-contribution-table-feasibility/evidence/fraction-trace.pstats differ diff --git a/research/fraction-contribution-table-feasibility/evidence/guard.py b/research/fraction-contribution-table-feasibility/evidence/guard.py new file mode 100644 index 0000000000..bf4265b129 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/guard.py @@ -0,0 +1,120 @@ +"""Serial bounded Linux measurements; preserve the complete frozen precision contract.""" +import argparse +import fcntl +import hashlib +import json +import os +from pathlib import Path +import platform +import signal +import statistics +import subprocess +import sys +import tempfile +import time + +HERE = Path(__file__).resolve().parent +SOURCE = HERE +CLOSURE = ('frozen.py','primitive_profile.py','guard.py','dispatch.py','inputs/PR5848.tar','../feasibility/fraction_table.py','../feasibility/finite.py','/usr/lib/python3.12/fractions.py','../feasibility/actual_audit.py') +TIMEOUT = 180 +RSS_CAP = 1024**3 +OUTPUT_CAP = 2*1024**2 +AGGREGATE = 600 +PREVIOUS_WALL_SECONDS = 0 + +def sha(raw): + return hashlib.sha256(raw).hexdigest() + +def inventory(): + result = {} + for name in CLOSURE: + path = SOURCE / name + if path.is_symlink() or not path.is_file(): + raise ValueError('Regular complete runtime file: ' + name) + result[name] = [sha(path.read_bytes()), path.stat().st_mode & 0o777] + return result + +def group_rss(group): + total = 0 + count = 0 + for p in Path('/proc').iterdir(): + if not p.name.isdigit(): + continue + try: + raw = (p/'stat').read_text() + fields = raw[raw.rfind(')')+2:].split() + if int(fields[2]) == group: + total += int(fields[21])*os.sysconf('SC_PAGE_SIZE') + count += 1 + except (FileNotFoundError, ProcessLookupError, PermissionError): + pass + return total, count + +def run(label, script, optimized=False): + records = HERE/'runs' + records.mkdir(exist_ok=True) + prior = list(records.glob('*/receipt.json')) + spent = PREVIOUS_WALL_SECONDS + sum(json.loads(p.read_bytes())['wall_seconds'] for p in prior) + if spent >= AGGREGATE: + raise ValueError('Aggregate budget consumed') + folder = records/label + folder.mkdir() + before = inventory() + env = os.environ.copy() + for key in ('PYTHONPATH','PYTHONOPTIMIZE','PYTHONINSPECT','PYTHONSTARTUP','PYTHONPYCACHEPREFIX'): + env.pop(key,None) + env.update(PYTHONHASHSEED='0', LC_ALL='C.UTF-8', TZ='UTC') + usage = folder/'usage.json' + with tempfile.TemporaryDirectory(prefix='linux5757-bytecode-') as cache: + command = ['/usr/bin/python3.12', '-B', '-X', 'pycache_prefix='+cache] + if optimized: + command.append('-O') + command.append(str(SOURCE/script)) + timed = ['/usr/bin/time','-f','{"user_seconds":%U,"system_seconds":%S,"kernel_max_rss_kib":%M,"exit":%x}', '-o', str(usage),'--',*command] + start = time.monotonic() + peak = 0 + stop = None + with (folder/'stdout.txt').open('wb') as out, (folder/'stderr.txt').open('wb') as err: + p = subprocess.Popen(timed, cwd=SOURCE, env=env, stdout=out, stderr=err, start_new_session=True) + try: + while p.poll() is None: + rss, _ = group_rss(p.pid) + peak = max(peak,rss) + elapsed = time.monotonic()-start + if rss > RSS_CAP: + stop='sampled_group_rss_cap' + elif elapsed > min(TIMEOUT,AGGREGATE-spent): + stop='wall_or_aggregate_cap' + elif max((folder/'stdout.txt').stat().st_size,(folder/'stderr.txt').stat().st_size)>OUTPUT_CAP: + stop='output_cap' + if stop: + os.killpg(p.pid,signal.SIGKILL) + break + time.sleep(0.05) + code=p.wait() + finally: + try: os.killpg(p.pid,signal.SIGKILL) + except ProcessLookupError: pass + p.wait() + elapsed = time.monotonic()-start + stdout=(folder/'stdout.txt').read_bytes() + stderr=(folder/'stderr.txt').read_bytes() + after=inventory() + measurement=None + if usage.exists(): + try: measurement=json.loads(usage.read_bytes()) + except json.JSONDecodeError: measurement={'raw':usage.read_text()} + receipt={'label':label,'script':script,'optimized':optimized,'wall_seconds':elapsed, + 'exit':code,'termination':stop,'sampled_process_group_rss_bytes':peak, + 'usage':measurement,'stdout_sha256':sha(stdout),'stdout_bytes':len(stdout), + 'stderr_sha256':sha(stderr),'stderr_bytes':len(stderr), + 'source_inventory_sha256':sha(json.dumps(before,sort_keys=True,separators=(',',':')).encode()), + 'source_bytes_and_modes_unchanged':before==after, + 'python':sys.version,'platform':platform.platform(), + 'runner_sha256':sha(Path(__file__).read_bytes()),'runtime_policy_sha256':sha(json.dumps(CLOSURE).encode())} + receipt['status']='PASS' if code==0 and stop is None and not stderr and before==after else 'STOP' + (folder/'receipt.json').write_text(json.dumps(receipt,indent=2,sort_keys=True)+'\n') + print(json.dumps(receipt,sort_keys=True),flush=True) + if receipt['status']!='PASS': + raise SystemExit(1) + return receipt diff --git a/research/fraction-contribution-table-feasibility/evidence/packaged-finite-O/receipt.json b/research/fraction-contribution-table-feasibility/evidence/packaged-finite-O/receipt.json new file mode 100644 index 0000000000..30791e974e --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/packaged-finite-O/receipt.json @@ -0,0 +1,26 @@ +{ + "exit": 0, + "label": "packaged-finite-O", + "optimized": true, + "original_local_receipt_sha256": "5fd01a939fbd1d6adfa8b5429cc70d2ab0a2d9e2f7e6b19436f6b060c2cd710e", + "platform": "Linux-7.0.0-38-generic-x86_64-with-glibc2.39", + "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", + "runner_sha256": "7540f8cc4ae4d12ed86c844ef0837a74184d3ada653979608c295c09f200a751", + "runtime_policy_sha256": "d08ad47d585eb04e6f0cc88803410edaf178c6182b435ff39435ac5b64f97b75", + "sampled_process_group_rss_bytes": 29380608, + "source_bytes_and_modes_unchanged": true, + "source_inventory_sha256": "b49ec4110e8a3d580bcddc6507b94684223812b5d5c0d4db472e7fd41f347184", + "status": "PASS", + "stderr_bytes": 0, + "stderr_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "stdout_bytes": 868, + "stdout_sha256": "972e731672ee04850b3308adb2a6e84897a0a50b1a8da235f21d3fe002784c06", + "termination": null, + "usage": { + "exit": 0, + "kernel_max_rss_kib": 27392, + "system_seconds": 0.03, + "user_seconds": 2.51 + }, + "wall_seconds": 2.866858140012482 +} diff --git a/research/fraction-contribution-table-feasibility/evidence/packaged-finite-O/stderr.txt b/research/fraction-contribution-table-feasibility/evidence/packaged-finite-O/stderr.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/research/fraction-contribution-table-feasibility/evidence/packaged-finite-O/stdout.txt b/research/fraction-contribution-table-feasibility/evidence/packaged-finite-O/stdout.txt new file mode 100644 index 0000000000..b640d81dd1 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/packaged-finite-O/stdout.txt @@ -0,0 +1,2 @@ +{"all_complete_values_and_types_equal": true, "cases": 241, "controls": ["returned-mutation-isolated", "source-drift", "Fraction-type-drift", "module-byte-drift", "live-code-drift", "nested-live-code-drift", "omitted-witness", "omitted-rounded-sites", "wrong-coefficient", "wrong-weighted-increment", "bad-role", "bad-scalar", "missing-weight", "restore-success", "restore-exception", "fresh-derivation", "key-field-0", "key-field-1", "key-field-2", "key-field-3", "key-field-4", "FIFO-eviction", "canonical-key", "hash-collision", "disabled", "invalid-capacity--1", "invalid-capacity-16385", "invalid-capacity-True", "invalid-capacity-1.5", "uncached-exception-0", "uncached-exception-1", "fresh-call-table", "stats-mutation", "failed-call-clears-stats"], "events": 10164, "status": "PASS_FINITE_FRACTION_TABLE_FEASIBILITY"} +PASS_SCOPED_TABLE_FEASIBILITY_FINITE_ONLY diff --git a/research/fraction-contribution-table-feasibility/evidence/packaged-finite-O/usage.json b/research/fraction-contribution-table-feasibility/evidence/packaged-finite-O/usage.json new file mode 100644 index 0000000000..9542294a2e --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/packaged-finite-O/usage.json @@ -0,0 +1 @@ +{"user_seconds":2.51,"system_seconds":0.03,"kernel_max_rss_kib":27392,"exit":0} diff --git a/research/fraction-contribution-table-feasibility/evidence/packaged-finite/receipt.json b/research/fraction-contribution-table-feasibility/evidence/packaged-finite/receipt.json new file mode 100644 index 0000000000..26dd8e6141 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/packaged-finite/receipt.json @@ -0,0 +1,26 @@ +{ + "exit": 0, + "label": "packaged-finite", + "optimized": false, + "original_local_receipt_sha256": "d23dc76fa2a3397494c86443d2c2010ebba638a271440b9ce91c2ac36c8b057f", + "platform": "Linux-7.0.0-38-generic-x86_64-with-glibc2.39", + "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", + "runner_sha256": "7540f8cc4ae4d12ed86c844ef0837a74184d3ada653979608c295c09f200a751", + "runtime_policy_sha256": "d08ad47d585eb04e6f0cc88803410edaf178c6182b435ff39435ac5b64f97b75", + "sampled_process_group_rss_bytes": 29097984, + "source_bytes_and_modes_unchanged": true, + "source_inventory_sha256": "b49ec4110e8a3d580bcddc6507b94684223812b5d5c0d4db472e7fd41f347184", + "status": "PASS", + "stderr_bytes": 0, + "stderr_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "stdout_bytes": 868, + "stdout_sha256": "972e731672ee04850b3308adb2a6e84897a0a50b1a8da235f21d3fe002784c06", + "termination": null, + "usage": { + "exit": 0, + "kernel_max_rss_kib": 27100, + "system_seconds": 0.03, + "user_seconds": 1.87 + }, + "wall_seconds": 1.9873841300141066 +} diff --git a/research/fraction-contribution-table-feasibility/evidence/packaged-finite/stderr.txt b/research/fraction-contribution-table-feasibility/evidence/packaged-finite/stderr.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/research/fraction-contribution-table-feasibility/evidence/packaged-finite/stdout.txt b/research/fraction-contribution-table-feasibility/evidence/packaged-finite/stdout.txt new file mode 100644 index 0000000000..b640d81dd1 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/packaged-finite/stdout.txt @@ -0,0 +1,2 @@ +{"all_complete_values_and_types_equal": true, "cases": 241, "controls": ["returned-mutation-isolated", "source-drift", "Fraction-type-drift", "module-byte-drift", "live-code-drift", "nested-live-code-drift", "omitted-witness", "omitted-rounded-sites", "wrong-coefficient", "wrong-weighted-increment", "bad-role", "bad-scalar", "missing-weight", "restore-success", "restore-exception", "fresh-derivation", "key-field-0", "key-field-1", "key-field-2", "key-field-3", "key-field-4", "FIFO-eviction", "canonical-key", "hash-collision", "disabled", "invalid-capacity--1", "invalid-capacity-16385", "invalid-capacity-True", "invalid-capacity-1.5", "uncached-exception-0", "uncached-exception-1", "fresh-call-table", "stats-mutation", "failed-call-clears-stats"], "events": 10164, "status": "PASS_FINITE_FRACTION_TABLE_FEASIBILITY"} +PASS_SCOPED_TABLE_FEASIBILITY_FINITE_ONLY diff --git a/research/fraction-contribution-table-feasibility/evidence/packaged-finite/usage.json b/research/fraction-contribution-table-feasibility/evidence/packaged-finite/usage.json new file mode 100644 index 0000000000..4c977e5e46 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/packaged-finite/usage.json @@ -0,0 +1 @@ +{"user_seconds":1.87,"system_seconds":0.03,"kernel_max_rss_kib":27100,"exit":0} diff --git a/research/fraction-contribution-table-feasibility/evidence/primitive-profile/receipt.json b/research/fraction-contribution-table-feasibility/evidence/primitive-profile/receipt.json new file mode 100644 index 0000000000..a43a9b7f69 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/primitive-profile/receipt.json @@ -0,0 +1,26 @@ +{ + "exit": 0, + "label": "primitive-profile", + "optimized": false, + "original_local_receipt_sha256": "f71613519370688b2b68cad95b8418591c012f404e73d20d183c532c7e6177d0", + "platform": "Linux-7.0.0-38-generic-x86_64-with-glibc2.39", + "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", + "runner_sha256": "d68398d78684dbd26aa534b20d4dcb347f44e577191e1008708418054df9b33b", + "runtime_policy_sha256": "c9e7c7fb96103d9e7b30f0264345dd5e687b24752b95b6d70d76dafcdd71a0fd", + "sampled_process_group_rss_bytes": 123768832, + "source_bytes_and_modes_unchanged": true, + "source_inventory_sha256": "56293e69bc59f68e33dd4d440a0df64c91b8e33d975857e2ed7030a4eeb611c5", + "status": "PASS", + "stderr_bytes": 0, + "stderr_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "stdout_bytes": 5738, + "stdout_sha256": "9428053948f1a437640561be4faaccafc3420a443c3ee0fd519f3127f48d31b4", + "termination": null, + "usage": { + "exit": 0, + "kernel_max_rss_kib": 119416, + "system_seconds": 0.16, + "user_seconds": 85.92 + }, + "wall_seconds": 86.79358924200642 +} diff --git a/research/fraction-contribution-table-feasibility/evidence/primitive-profile/stderr.txt b/research/fraction-contribution-table-feasibility/evidence/primitive-profile/stderr.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/research/fraction-contribution-table-feasibility/evidence/primitive-profile/stdout.txt b/research/fraction-contribution-table-feasibility/evidence/primitive-profile/stdout.txt new file mode 100644 index 0000000000..c31ad82b24 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/primitive-profile/stdout.txt @@ -0,0 +1,5 @@ +PASS_PRECISION_LINUX_SOURCE_CONTROLS {"contract": "declared contract edits", "declared_edit": "unique backend seam", "inner_archive": "source hash", "official_export_byte": "Exact PR5831 bundle"} +{"backends": 2, "controls": ["one-use", "closed-call", "missing", "duplicate", "changed-weights", "changed-rounding", "changed-word", "original-malformed-rejection", "propagated-exception", "failed-finish", "failed-take", "fresh-context-not-previous-pass", "aborted-take", "one-use", "closed-call", "missing", "duplicate", "changed-weights", "changed-rounding", "changed-word", "original-malformed-rejection", "propagated-exception", "failed-finish", "failed-take", "fresh-context-not-previous-pass", "aborted-take", "input-mutation"], "events": 5, "status": "PASS_FINITE_FEASIBILITY_ONLY"} +PASS_P104_SINGLE_PASS_QUALIFICATION +{"mode": "qualify", "receipt": {"all_actual_witness_rows_equal": true, "coefficient_scale_bits": 55, "coordinates": 799, "events": 25984, "finite_fixtures": {"cases": 120, "controls": ["nondyadic scalar", "inexact scale division", "nondyadic weight"], "events": 4240}, "guards": {"owned": 22, "prefix": 26, "public": 23}, "source_controls": 6, "source_result_sha256": "cc7739703ed23532d187949c8507d09c13ac4c152e07a930f0087cde0d7a3d98"}, "seconds": 86.214536} +{"fraction_source_sha256": "cf33568f7b767f66896995a7a81cc662e8be226f2e58efb61d2028f64eb5d231", "profile_not_a_benchmark": true, "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", "status": "PASS_FULL_QUALIFICATION_PRIMITIVE_PROFILE", "top_self_functions": [{"cumulative_seconds": 15.812900419000002, "file": "/usr/lib/python3.12/fractions.py", "function": "_from_coprime_ints", "line": 317, "primitive_calls": 26030845, "self_seconds": 11.713773661000001, "total_calls": 26030845}, {"cumulative_seconds": 65.705991368, "file": "/tmp/p104-integer-error-5qs2zy09/research/p104-noisy-copy-reset/precision.py", "function": "error_trace", "line": 123, "primitive_calls": 1, "self_seconds": 10.434950722, "total_calls": 1}, {"cumulative_seconds": 42.276408473000004, "file": "/usr/lib/python3.12/fractions.py", "function": "forward", "line": 613, "primitive_calls": 20869086, "self_seconds": 8.990157252000001, "total_calls": 20869086}, {"cumulative_seconds": 14.986647283000002, "file": "/usr/lib/python3.12/fractions.py", "function": "_add", "line": 710, "primitive_calls": 10396952, "self_seconds": 7.27879753, "total_calls": 10396952}, {"cumulative_seconds": 12.070233685000002, "file": "/usr/lib/python3.12/fractions.py", "function": "_mul", "line": 742, "primitive_calls": 7892384, "self_seconds": 5.6414134350000005, "total_calls": 7892384}, {"cumulative_seconds": 4.530817473, "file": "~", "function": "", "line": 0, "primitive_calls": 28685894, "self_seconds": 4.530817473, "total_calls": 28685894}, {"cumulative_seconds": 3.8257899620000004, "file": "~", "function": "", "line": 0, "primitive_calls": 33126402, "self_seconds": 3.8257899620000004, "total_calls": 33126402}, {"cumulative_seconds": 5.832970863000001, "file": "/usr/lib/python3.12/fractions.py", "function": "__abs__", "line": 853, "primitive_calls": 5161759, "self_seconds": 2.4324906790000003, "total_calls": 5161759}, {"cumulative_seconds": 2.5090920110000003, "file": "~", "function": "", "line": 0, "primitive_calls": 21672605, "self_seconds": 2.203636216, "total_calls": 21672605}, {"cumulative_seconds": 7.329944933, "file": "~", "function": "", "line": 0, "primitive_calls": 5161759, "self_seconds": 2.029012335, "total_calls": 10323518}, {"cumulative_seconds": 2.184894383, "file": "/usr/lib/python3.12/fractions.py", "function": "__new__", "line": 186, "primitive_calls": 2655049, "self_seconds": 1.6123486360000001, "total_calls": 2655049}, {"cumulative_seconds": 4.191139103, "file": "/usr/lib/python3.12/fractions.py", "function": "_sub", "line": 726, "primitive_calls": 2579750, "self_seconds": 1.562701657, "total_calls": 2579750}, {"cumulative_seconds": 0.567401469, "file": "~", "function": "", "line": 0, "primitive_calls": 2579750, "self_seconds": 0.567401469, "total_calls": 2579750}, {"cumulative_seconds": 0.75091821, "file": "/tmp/p104-integer-error-5qs2zy09/research/p104-noisy-copy-reset/precision.py", "function": "update_hash", "line": 119, "primitive_calls": 385830, "self_seconds": 0.551897967, "total_calls": 385830}, {"cumulative_seconds": 0.522914474, "file": "/usr/lib/python3.12/fractions.py", "function": "__bool__", "line": 969, "primitive_calls": 2579750, "self_seconds": 0.522914474, "total_calls": 2579750}, {"cumulative_seconds": 0.679060922, "file": "/usr/lib/python3.12/fractions.py", "function": "_richcmp", "line": 931, "primitive_calls": 390976, "self_seconds": 0.29755512300000003, "total_calls": 390976}, {"cumulative_seconds": 0.17329617900000002, "file": "~", "function": "", "line": 0, "primitive_calls": 849121, "self_seconds": 0.17329617900000002, "total_calls": 849121}, {"cumulative_seconds": 1.0426144320000001, "file": "~", "function": "", "line": 0, "primitive_calls": 801, "self_seconds": 0.166359589, "total_calls": 801}, {"cumulative_seconds": 0.15758518000000002, "file": "~", "function": "", "line": 0, "primitive_calls": 758587, "self_seconds": 0.15758518000000002, "total_calls": 758587}, {"cumulative_seconds": 0.373710888, "file": "/usr/lib/python3.12/fractions.py", "function": "__eq__", "line": 910, "primitive_calls": 319161, "self_seconds": 0.152659912, "total_calls": 319161}], "whole_profiled_seconds": 86.30507170801866} diff --git a/research/fraction-contribution-table-feasibility/evidence/primitive-profile/usage.json b/research/fraction-contribution-table-feasibility/evidence/primitive-profile/usage.json new file mode 100644 index 0000000000..0a699d91e3 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/primitive-profile/usage.json @@ -0,0 +1 @@ +{"user_seconds":85.92,"system_seconds":0.16,"kernel_max_rss_kib":119416,"exit":0} diff --git a/research/fraction-contribution-table-feasibility/evidence/primitive_profile.py b/research/fraction-contribution-table-feasibility/evidence/primitive_profile.py new file mode 100644 index 0000000000..a45b31a64c --- /dev/null +++ b/research/fraction-contribution-table-feasibility/evidence/primitive_profile.py @@ -0,0 +1,62 @@ +"""Profile only one complete frozen Fraction trace inside unchanged qualification.""" +import cProfile +import fractions +from hashlib import sha256 +import importlib.util +import json +from pathlib import Path +import profile as profile_support +import pstats +import runpy +import sys +import time +from frozen import baseline, require + +require(Path(profile_support.__file__).name=='profile.py' and 'primitive-profile' not in str(profile_support.__file__),'stdlib profiling support') +rows=[] +with baseline() as package: + sys.path.insert(0,str(package)) + native_spec=importlib.util.spec_from_file_location + def spec(name,path,*args,**kwargs): + value=native_spec(name,path,*args,**kwargs) + if name=='single_pass_source': + execute=value.loader.exec_module + def observed_execute(module): + execute(module) + load=module.load + def observed_load(n,p): + m=load(n,p) + if n=='frozen_contract': + factory=m.module + def observed_factory(n2,p2): + a=factory(n2,p2) + if n2=='noisy_precision': + original=a.error_trace + def profiled(*args,**kwargs): + require(not rows,'one actual Fraction trace') + profiler=cProfile.Profile() + started=time.perf_counter() + result=profiler.runcall(original,*args,**kwargs) + elapsed=time.perf_counter()-started + profiler.dump_stats(str(Path(__file__).with_name('fraction-trace.pstats'))) + stats=pstats.Stats(profiler) + for (file,line,function),(primitive,total,self_seconds,cumulative,callers) in stats.stats.items(): + rows.append(dict(file=file,line=line,function=function,primitive_calls=primitive,total_calls=total,self_seconds=self_seconds,cumulative_seconds=cumulative)) + rows.sort(key=lambda x:x['self_seconds'],reverse=True) + Path(__file__).with_name('PRIMITIVES.json').write_text(json.dumps(dict(profiled_trace_seconds=elapsed,total_calls=stats.total_calls,primitive_calls=stats.prim_calls,total_profile_self_seconds=stats.total_tt,functions=rows),indent=2,sort_keys=True)+'\n') + return result + a.error_trace=profiled + return a + m.module=observed_factory + return m + module.load=observed_load + value.loader.exec_module=observed_execute + return value + started=time.perf_counter() + importlib.util.spec_from_file_location=spec + try: + sys.argv=[str(package/'verify.py')] + runpy.run_path(sys.argv[0],run_name='__main__') + finally: + importlib.util.spec_from_file_location=native_spec + print(json.dumps(dict(status='PASS_FULL_QUALIFICATION_PRIMITIVE_PROFILE',whole_profiled_seconds=time.perf_counter()-started,profile_not_a_benchmark=True,fraction_source_sha256=sha256(Path(fractions.__file__).read_bytes()).hexdigest(),python=sys.version,top_self_functions=rows[:20]),sort_keys=True)) diff --git a/research/fraction-contribution-table-feasibility/finite.py b/research/fraction-contribution-table-feasibility/finite.py new file mode 100644 index 0000000000..e00dd29385 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/finite.py @@ -0,0 +1,164 @@ +"""Finite gate before construction, using the actual frozen Fraction source.""" +from copy import deepcopy +from fractions import Fraction as F +import importlib.util +import inspect +import json +from pathlib import Path +import random +import sys +import tempfile +import types +from frozen import baseline, require +from fraction_table import derive, installed, transformed, Contributions, CAPACITY + + +def types_of(value): + if isinstance(value, dict): + return ('dict', {k:types_of(v) for k,v in value.items()}) + if isinstance(value, (list, tuple)): + return (type(value).__name__, [types_of(v) for v in value]) + return type(value).__name__ + + +def fixtures(): + rng = random.Random(5848) + special = [['ADD',0,1,1,0],['ADD',1,0,1,0],['ADD',1,0,-2,0], + ['ADD',1,0,1,0],['COPY',2,1,-1,0],['SCALE',1,'1/2',0], + ['MOVE',2,0,0,False],['INIT',2,0],['CLEAR',2,0]] + yield dict(public=2,owned_fields=1,program=special), [(F(1),F(1))]*len(special), {'ADD','COPY','SCALE','INIT','CLEAR','MOVE'} + scalars = ['1','-1','1/2','-3/8','2','-4','5/16'] + for case in range(240): + n = 3+case%6 + program = [] + for i in range(case%95): + op = rng.choice(['INIT','CLEAR','MOVE','ADD','COPY','SCALE']) + r = rng.randrange(n) + if op in ('INIT','CLEAR'):event=[op,r,0] + elif op=='MOVE':event=[op,r,0,0,False] + elif op=='SCALE':event=[op,r,rng.choice(scalars),0] + else:event=[op,r,rng.choice([s for s in range(n) if s!=r]),rng.choice(scalars),0] + program.append(event) + weights=[(F(rng.randrange(6),2**rng.randrange(7)),F(rng.randrange(5),2**rng.randrange(6))) for e in program] + rounded={op for op in ('INIT','CLEAR','MOVE','ADD','COPY','SCALE') if rng.randrange(2)} + yield dict(public=n-1,owned_fields=1,program=program),weights,rounded + + +def main(): + results=[] + def rejects(label, action, exception=ValueError): + try:action() + except exception:results.append(label) + else:raise ValueError('accepted '+label) + with baseline() as package: + sys.path.insert(0,str(package)) + import source + with source.baseline() as p: + spec=importlib.util.spec_from_file_location('finite_precision_entry',p/'verify.py') + v=importlib.util.module_from_spec(spec);spec.loader.exec_module(v) + with v.source() as (_,original,ref): + old=ref.error_trace + fast=derive(ref) + cases=list(fixtures());events=0 + engines={capacity:derive(ref,capacity) for capacity in (0,1,2,CAPACITY)} + for word,weights,rounded in cases: + before=deepcopy((word,weights,rounded)) + a=old(word,weights,rounded) + for capacity in (0,1,2,CAPACITY): + f=engines[capacity];b=f(word,weights,rounded) + require(a==b and types_of(a)==types_of(b),'complete finite output and numeric types') + require(f.statistics()['resident']<=capacity,'bounded per-trace table') + require((word,weights,rounded)==before,'inputs remain unchanged') + events+=len(word['program']) + word,weights,rounded=cases[0] + value=fast(word,weights,rounded);value[0]['final_scores'][0][0]=F(999) + require(fast(word,weights,rounded)==old(word,weights,rounded),'fresh mutable output') + results.append('returned-mutation-isolated') + raw=inspect.getsource(old) + rejects('source-drift',lambda:transformed(raw+'\n# drift\n')) + saved_F=ref.F;ref.F=int + try:rejects('Fraction-type-drift',lambda:derive(ref)) + finally:ref.F=saved_F + with tempfile.TemporaryDirectory() as td: + file=Path(td)/'precision.py';file.write_bytes(Path(ref.__file__).read_bytes()+b'\n# drift\n') + saved_file=ref.__file__;ref.__file__=str(file) + try:rejects('module-byte-drift',lambda:derive(ref)) + finally:ref.__file__=saved_file + code=old.__code__.replace(co_consts=('live-code-drift',)+old.__code__.co_consts[1:]) + ref.error_trace=types.FunctionType(code,old.__globals__) + try:rejects('live-code-drift',lambda:derive(ref)) + finally:ref.error_trace=old + constants=list(old.__code__.co_consts) + index=next(i for i,c in enumerate(constants) if isinstance(c,types.CodeType)) + constants[index]=constants[index].replace(co_consts=constants[index].co_consts+('nested-code-drift',)) + ref.error_trace=types.FunctionType(old.__code__.replace(co_consts=tuple(constants)),old.__globals__) + try:rejects('nested-live-code-drift',lambda:derive(ref)) + finally:ref.error_trace=old + for label,change in [ + ('omitted-witness',('witness[k] = dict(rows[r])','witness[k] = {}')), + ('omitted-rounded-sites',('if op in rounded:','if False:'))]: + text=transformed(raw);require(change[0] in text,'mutant site');text=text.replace(*change) + ns=dict(ref.__dict__);ns.update(_contribution_factory=Contributions,_contribution_report=lambda value:None) + exec(compile(text,'','exec'),ns) + require(any(ns['error_trace'](*c)!=old(*c) for c in cases),'mutant rejected '+label) + results.append(label) + correct_compute=Contributions.compute + for label,index in [('wrong-coefficient',0),('wrong-weighted-increment',1)]: + def corrupted(*args,**kwargs): + out=list(correct_compute(*args,**kwargs));out[index]+=F(1);return tuple(out) + Contributions.compute=staticmethod(corrupted) + try:require(any(fast(*c)!=old(*c) for c in cases),'arithmetic mutant rejected '+label) + finally:Contributions.compute=staticmethod(correct_compute) + results.append(label) + for label,bad_word,bad_weights in [('bad-role',dict(public=2,owned_fields=0,program=[['ADD',99,0,1,0]]),[(F(1),F(1))]),('bad-scalar',dict(public=2,owned_fields=0,program=[['ADD',0,1,'bad',0]]),[(F(1),F(1))]),('missing-weight',word,[])]: + errors=[] + for fn in (old,fast): + try:fn(bad_word,bad_weights,rounded) + except (IndexError,ValueError) as e:errors.append((type(e).__name__,str(e))) + else:raise ValueError('missing original exception '+label) + require(errors[0]==errors[1],'same original exception '+label);results.append(label) + with installed(ref) as f: + require(ref.error_trace is f and f(*cases[0])==old(*cases[0]),'scoped install') + require(ref.error_trace is old,'restore on success');results.append('restore-success') + try: + with installed(ref):raise RuntimeError('caller-failure') + except RuntimeError:pass + require(ref.error_trace is old,'restore on exception');results.append('restore-exception') + require(derive(ref)(*cases[0])==old(*cases[0]),'fresh derivation');results.append('fresh-derivation') + # Complete exact keys, collision safety, FIFO, exceptions and fresh lifetimes. + base=(F(0),F(1),F(1),F(2),F(3)) + for field in range(5): + c=Contributions(4);c.step(*base);c.step(*base) + changed=list(base);changed[field]+=F(1,2) + require(c.step(*changed)==correct_compute(*changed),'complete key value') + require(c.hits==1 and c.misses==2,'every key field bound') + results.append('key-field-'+str(field)) + c=Contributions(2);a=base;b=(F(1),*base[1:]);d=(F(2),*base[1:]) + c.step(*a);c.step(*b);c.step(*a);c.step(*d) + require(c.evictions==1 and len(c.table)==2,'capacity eviction') + prior=c.misses;c.step(*a);require(c.misses==prior+1,'FIFO eviction recomputes');results.append('FIFO-eviction') + c=Contributions(2);c.step(*base) + same=(F(0,2),F(2,2),F(3,3),F(4,2),F(9,3));c.step(*same) + require(c.hits==1,'canonical equal-value key');results.append('canonical-key') + modulus=sys.hash_info.modulus + one=base;two=(F(modulus),*base[1:]);keys=lambda values:tuple(t for x in values for t in (x.numerator,x.denominator)) + require(hash(keys(one))==hash(keys(two)) and keys(one)!=keys(two),'actual hash-collision fixture') + c=Contributions(2);require(c.step(*one)!=c.step(*two) and c.misses==2,'full equality after hash collision');results.append('hash-collision') + c=Contributions(0);c.step(*base);c.step(*base);require(not c.table and c.bypasses==2,'disabled table');results.append('disabled') + for cap in (-1,CAPACITY+1,True,1.5):rejects('invalid-capacity-'+str(cap),lambda cap=cap:Contributions(cap)) + class Explodes: + def __mul__(self,value):raise ArithmeticError('uncached failure') + c=Contributions(2) + for attempt in range(2):rejects('uncached-exception-'+str(attempt),lambda:c.step(F(0),Explodes(),F(1),F(1),F(1)),ArithmeticError) + require(not c.table,'exceptions not cached') + fast(*cases[0]);first=fast.statistics();fast(*cases[0]);require(first==fast.statistics(),'fresh per-call table counters');results.append('fresh-call-table') + first['hits']=-1;require(fast.statistics()['hits']>=0,'stats mutation isolated');results.append('stats-mutation') + try:fast(dict(public=1,owned_fields=0,program=[['ADD',99,0,1,0]]),[(F(1),F(1))],{'ADD'}) + except IndexError:pass + else:raise ValueError('missing original failed-call exception') + require(fast.statistics() is None,'failed call has no old accepted stats');results.append('failed-call-clears-stats') + require(len(results)==34,'finite control census') + result={'status':'PASS_FINITE_FRACTION_TABLE_FEASIBILITY','cases':len(cases),'events':events,'controls':results,'all_complete_values_and_types_equal':True} + print(json.dumps(result,sort_keys=True)) + return result +if __name__=='__main__':main() diff --git a/research/fraction-contribution-table-feasibility/fraction_table.py b/research/fraction-contribution-table-feasibility/fraction_table.py new file mode 100644 index 0000000000..7f44b25859 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/fraction_table.py @@ -0,0 +1,123 @@ +"""Per-trace bounded tabulation of pure exact Fraction contributions. + +Original arithmetic: Ali Romman and retained completed-error lineage. +New table/derivation: Chris R / Clear1nsight, substantial OpenAI Codex assistance. +Apache-2.0. No approximate or shared integer-backend arithmetic. +""" +from contextlib import contextmanager +from collections import OrderedDict +from fractions import Fraction as F +from hashlib import sha256 +import inspect +from pathlib import Path +from types import CodeType + +MODULE_SHA256='a4c743e79c55e9c2ac26deb6d87cb948b1b0fbe942e4f7912ccbfba55db4b32a' +FUNCTION_SHA256='379c0e7c1c5ab7433ab5ad2669c1bda1234dbf0530fc61b21bfbe83528f37f53' +CAPACITY=16384 +BEFORE=''' value = old + q*v + change = abs(value)-abs(old) + scores[r][0] += change*weights[i][0] + scores[r][1] += change*weights[i][1] + scores[r][2] += change +''' +AFTER=''' value, increment_a, increment_c, change = contributions.step( + old, q, v, weights[i][0], weights[i][1]) + scores[r][0] += increment_a + scores[r][1] += increment_c + scores[r][2] += change +''' + + +def need(ok,message): + if not ok: + raise ValueError(message) + + +class Contributions: + def __init__(self,capacity=CAPACITY): + need(type(capacity) is int and 0<=capacity<=CAPACITY,'bounded integer table capacity') + self.capacity=capacity + self.table=OrderedDict() + self.calls=self.hits=self.misses=self.evictions=self.bypasses=0 + + @staticmethod + def compute(old,q,v,a,c): + value=old+q*v + change=abs(value)-abs(old) + return value,change*a,change*c,change + + def step(self,old,q,v,a,c): + self.calls+=1 + if not self.capacity or not all(type(x) is F for x in (old,q,v,a,c)): + self.bypasses+=1 + return self.compute(old,q,v,a,c) + key=(old.numerator,old.denominator,q.numerator,q.denominator, + v.numerator,v.denominator,a.numerator,a.denominator,c.numerator,c.denominator) + result=self.table.get(key) + if result is not None: + self.hits+=1 + return result + self.misses+=1 + result=self.compute(old,q,v,a,c) + if len(self.table)>=self.capacity: + self.table.popitem(last=False) + self.evictions+=1 + self.table[key]=result + return result + + def statistics(self): + return dict(calls=self.calls,hits=self.hits,misses=self.misses, + evictions=self.evictions,bypasses=self.bypasses, + resident=len(self.table),capacity=self.capacity) + + +def code_shape(code): + constants=tuple(code_shape(c) if isinstance(c,CodeType) else c for c in code.co_consts) + return (code.co_code,constants,code.co_names,code.co_varnames,code.co_argcount, + code.co_posonlyargcount,code.co_kwonlyargcount,code.co_flags, + code.co_freevars,code.co_cellvars,code.co_name,code.co_stacksize, + code.co_nlocals,code.co_exceptiontable) + + +def transformed(raw): + need(sha256(raw.encode()).hexdigest()==FUNCTION_SHA256,'exact Fraction function source') + need(raw.count(BEFORE)==1,'one exact Fraction contribution block') + value=raw.replace(BEFORE,AFTER) + seam=" n = word['public'] + word['owned_fields']\n" + need(value.count(seam)==1,'one exact Fraction setup seam') + value=value.replace(seam,seam+' _contribution_report(None)\n contributions = _contribution_factory()\n') + seam=' return dict(rounded=sorted(rounded), sites=sites, peaks=peaks, pareto=pareto,\n' + need(value.count(seam)==1,'one exact Fraction return seam') + return value.replace(seam,' _contribution_report(contributions.statistics())\n'+seam) + + +def derive(reference,capacity=CAPACITY): + need(type(capacity) is int and 0<=capacity<=CAPACITY,'bounded integer table capacity') + need(reference.F is F,'exact standard Fraction type') + need(sha256(Path(reference.__file__).read_bytes()).hexdigest()==MODULE_SHA256,'exact Fraction module bytes') + original=reference.error_trace + raw=inspect.getsource(original) + text=transformed(raw) + namespace=dict(reference.__dict__) + exec(compile(raw,'','exec'),namespace) + need(code_shape(original.__code__)==code_shape(namespace['error_trace'].__code__),'live Fraction code agrees with source') + need(original.__defaults__ is None and original.__kwdefaults__ is None and original.__closure__ is None,'ordinary Fraction function') + last=[None] + def report(value):last[0]=None if value is None else dict(value) + namespace.update(_contribution_factory=lambda:Contributions(capacity),_contribution_report=report) + exec(compile(text,'','exec'),namespace) + result=namespace['error_trace'] + result.statistics=lambda:None if last[0] is None else dict(last[0]) + return result + + +@contextmanager +def installed(reference,capacity=CAPACITY): + original=reference.error_trace + derived=derive(reference,capacity) + reference.error_trace=derived + try: + yield derived + finally: + reference.error_trace=original diff --git a/research/fraction-contribution-table-feasibility/frozen.py b/research/fraction-contribution-table-feasibility/frozen.py new file mode 100644 index 0000000000..eb26be4a0f --- /dev/null +++ b/research/fraction-contribution-table-feasibility/frozen.py @@ -0,0 +1,67 @@ +"""Authenticate the unchanged complete PR5848 export before importing it.""" +from contextlib import contextmanager +from hashlib import sha256 +import json +from pathlib import Path +import tarfile +import tempfile + +HERE = Path(__file__).resolve().parent +BUNDLE_SHA256 = 'f899600acb6966a6b028ffbf1e33a94061615626b510feaca8cb073f03a34de6' +SOURCE_HEAD = '66fb6c6b8683b37967e9d7f313b3df99a49d2406' + + +def require(ok, why): + if not ok: + raise ValueError(why) + + +def payload(archive=None): + archive = HERE / 'inputs/PR5848.tar' if archive is None else archive + require(sha256(archive.read_bytes()).hexdigest() == BUNDLE_SHA256, 'Exact PR5848 bundle') + with tarfile.open(archive, 'r:') as stream: + members = stream.getmembers() + require(len(members) == 98 and len({m.name for m in members}) == 98, 'Complete unique baseline bundle') + require(all(m.isfile() and 0 <= m.size <= 8 * 1024**2 for m in members), 'Regular bounded baseline members') + receipt = json.loads(stream.extractfile('.research-export.json').read()) + require(receipt['commit'] == SOURCE_HEAD, 'Exact baseline export head') + rows = {r['path']: r for r in receipt['files']} + require(len(rows) == len(receipt['files']) == 97, 'Complete baseline file census') + require({m.name for m in members} == set(rows) | {'.research-export.json'}, 'Exact baseline member set') + contents = {} + for member in members: + path = Path(member.name) + require(not path.is_absolute() and '..' not in path.parts and path.parts, 'Safe baseline path') + raw = stream.extractfile(member).read() + if member.name in rows: + row = rows[member.name] + require(len(raw) == row['size'] and sha256(raw).hexdigest() == row['sha256'], 'Exact baseline file bytes') + require(row['mode'] in (0o644, 0o755), 'Regular baseline file mode') + contents[member.name] = raw + return contents + + +@contextmanager +def baseline(): + contents = payload() + with tempfile.TemporaryDirectory(prefix='precision-linux-source-') as temporary: + root = Path(temporary) + try: + for name, raw in contents.items(): + path = root / name + path.parent.mkdir(parents=True, exist_ok=True) + path.write_bytes(raw) + path.chmod(0o444) + for path in root.rglob('*'): + if path.is_dir(): + path.chmod(0o555) + before = {str(p.relative_to(root)): [sha256(p.read_bytes()).hexdigest(), p.stat().st_mode & 0o777] + for p in root.rglob('*') if p.is_file()} + yield root / 'research/p104-single-pass-qualification' + after = {str(p.relative_to(root)): [sha256(p.read_bytes()).hexdigest(), p.stat().st_mode & 0o777] + for p in root.rglob('*') if p.is_file() and not p.is_symlink()} + require(after == before and not any(p.is_symlink() for p in root.rglob('*')), 'Baseline export unchanged') + finally: + for path in [root, *root.rglob('*')]: + if path.is_dir(): + path.chmod(0o755) diff --git a/research/fraction-contribution-table-feasibility/inputs/PR5848.tar b/research/fraction-contribution-table-feasibility/inputs/PR5848.tar new file mode 100644 index 0000000000..307d09d2a9 Binary files /dev/null and b/research/fraction-contribution-table-feasibility/inputs/PR5848.tar differ diff --git a/research/fraction-contribution-table-feasibility/verify.py b/research/fraction-contribution-table-feasibility/verify.py new file mode 100644 index 0000000000..cb7a8958d0 --- /dev/null +++ b/research/fraction-contribution-table-feasibility/verify.py @@ -0,0 +1,9 @@ +"""Fresh finite coverage only; this is not a complete-qualifier performance check.""" +import json +from pathlib import Path +from frozen import require +from finite import main +if __name__=='__main__': + result=main() + require(result==json.loads(Path(__file__).with_name('RESULT.json').read_bytes())['finite'],'complete finite table receipt') + print('PASS_SCOPED_TABLE_FEASIBILITY_FINITE_ONLY') diff --git a/tests/fixtures/README.md b/tests/fixtures/README.md new file mode 100644 index 0000000000..472a6a502f --- /dev/null +++ b/tests/fixtures/README.md @@ -0,0 +1,41 @@ +# Frozen research routing fixture + +`research-routing-v7.json` retains two exact task cards from priority revision 7: +`portable-replay` and `centre-path-sharing`. They exercise the generic-baseline +and historical-ceiling routes in `choose_current_research_task.py`. The fixture +records the source commit, path and SHA256. The card objects are unchanged. + +The source is commit `553d26d796fde9871ff2661a49ac7732e945410f`, file +`docs/research/agent-task-catalog.json`. The test places these cards in a small +catalogue with one track of weight 100. This carrier is test data, not a change +to research priorities. Current cards are checked separately from the live +catalogue. Every live card must preserve its other fields; each distinct direct +command also passes through both real CLIs. + +The CLI fixture copies the two real scripts. It creates inert reference files +for path validation and copies the current selected record for receipt fields. +It does not execute those references or verify a mathematical claim. Missing +references, sparse omissions, deleted files and staged replacements have separate +negative tests. No Git history, network request or change to the live catalogue +is needed to run the fixture. + +```sh +python3 -B -m unittest discover -s tests -p test_research_current_assignment.py -v +python3 -B -m unittest discover -s tests -p test_research_assignment.py -v +``` + +This fixture repairs the CI handoff in +[Discussion 5722](https://github.com/CrocSwap/integer-mult-bounds/discussions/5722). +The [investigation](https://github.com/CrocSwap/integer-mult-bounds/discussions/5758) +records the failure, checks and publication status. The original scripts, task +catalogue and selected frontier are unchanged. + +On base `de5ec2e7a6074068452f45b1a191b5c72832df4a`, the old suite has eight +failures and two errors. After the repair, all 12 current-assignment tests pass +under Python 3.14.7 and Python 3.12.14, including an isolated optimized run. +All 16 related assignment tests pass under Python 3.12.14. This is test coverage, +not a mathematical replay. See the investigation for hosted-plan status. + +Retain the original catalogue, routing and test authors, including Douglas +Colkitt, Ali Romman and Mihir Srivastava. New fixture and test repair: Ali Romman +with substantial OpenAI Codex assistance. No subagents. Apache-2.0. diff --git a/tests/fixtures/research-routing-v7.json b/tests/fixtures/research-routing-v7.json new file mode 100644 index 0000000000..f5d52ac21d --- /dev/null +++ b/tests/fixtures/research-routing-v7.json @@ -0,0 +1,87 @@ +{ + "source_commit": "553d26d796fde9871ff2661a49ac7732e945410f", + "source_path": "docs/research/agent-task-catalog.json", + "source_sha256": "f7a48bfa2659b88378282a8eee7d9fe52cdf505594124c4d1686b58510fffd72", + "scope": "Two exact revision-7 cards. The test carrier is not a research allocation.", + "cards": [ + { + "id": "centre-path-sharing", + "question": "Can the 64-per-call centre path (eight rank-8 COPY/ERASE totals through the private temporary) be shared across calls or shrunk?", + "starting_points": [ + "docs/research/research-family-status.md", + "research/complex-local-word-ceiling/README.md", + "research/split-centres-global/proofs/PR386-BIT-GEOMETRY.txt", + "certificates/selected-result.json" + ], + "methods": [ + "Derive a fully charged favorable relaxation for sharing one centre path across k calls, including restoration, hosting and precision.", + "Prove a lower bound on copied information per call for the selected decoder contract." + ], + "acceptance_gate": "Show the changed centre charge and copy profile per call with every added restoration or hosting cost charged, and its ceiling via ceiling.ceiling(centre=...). A scoped local result may be retained without a complete supplier. Expanding it into further construction rounds requires the family-level budget and obligation gate in research-family-status.md; an optimistic passing relaxation alone is not acceptance.", + "first_step": { + "command": [ + "python3", + "-B", + "research/complex-local-word-ceiling/verify.py" + ], + "expected": "PASS_COMPLEX_LOCAL_WORD_CEILING", + "inspect": "Read the selected word's per-call local profile, its packing ceiling and the lever table; run levers.py for the ideal budget of the lever you target.", + "scope": "Positive control and planning budget only; this is not a new construction or full cold replay." + }, + "first_experiment": "Write the per-call centre charge and copy children for sharing across k = 2 calls, charge the sharing overhead, and screen it; stop this route if even the ideal sharing gains under 10%. Ideal budgets: free 2.80x, shared by two 1.90x (levers.py).", + "bottleneck_link": "The centre path consumes 64 of about 99.6 unpaid coordinates per call, i.e. about 64% of the raw deficit.", + "allowed_variations": [ + "One sharing pattern across a fixed number of calls.", + "One reduced copied-total contract for the existing decoder.", + "If the coverage law, template or guard changes, derive an applicable fully charged replacement bound instead of applying the incumbent ceiling outside its scope." + ], + "scope_change_triggers": [ + "Removing copies without a replacement contract for the decoder's copied totals.", + "Continuing a partial cost improvement while leaving the same unpriced consumer, restoration or central-readout obligation unresolved; refresh the family expansion decision first. Local product-retiming evidence has a narrow scope and is not a ban on changed graphs or contracts." + ], + "overlap_terms": [ + "centre path", + "copied totals", + "private temporary", + "shared centre", + "batching" + ] + }, + { + "id": "portable-replay", + "question": "Can one reproducible environment or artifact-comparison failure be repaired?", + "starting_points": [ + "research/gzip-container-reproducibility/README.md", + "docs/ci-verification.md" + ], + "methods": [ + "Reproduce one portability failure and add a minimal cross-environment fix.", + "Audit one canonical-payload comparison for omitted proof-relevant fields." + ], + "acceptance_gate": "Preserve immutable source hashes and proof-relevant content; a different compressed byte stream alone is not a mathematical mismatch.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Read the gzip-container reproducibility examples and distinguish frozen source bytes from regenerated payloads.", + "scope": "Positive control / source-bound orientation only; this is not a new construction or full cold replay." + }, + "first_experiment": "Reproduce one specific mismatch or audit one canonical comparison for omitted proof-relevant fields.", + "bottleneck_link": "Portable exact checks prevent environment failures from blocking valid contributions.", + "allowed_variations": [ + "One interpreter/version mismatch or one payload field comparison." + ], + "scope_change_triggers": [ + "Removing immutable-source pins because generated compressed bytes differ." + ], + "overlap_terms": [ + "gzip container", + "reproducibility", + "canonical payload" + ] + } + ] +} diff --git a/tests/test_research_current_assignment.py b/tests/test_research_current_assignment.py index 860f6b9b9e..c524c0037f 100644 --- a/tests/test_research_current_assignment.py +++ b/tests/test_research_current_assignment.py @@ -1,9 +1,15 @@ -"""Current orientation must preserve frozen task-selection evidence.""" +"""Current orientation must preserve frozen task-selection evidence. + +Frozen fixtures and live-catalog coverage: Ali Romman with OpenAI Codex +assistance. Retain the original routing and test authors. Apache-2.0. +""" import copy +from contextlib import contextmanager import importlib.util import json from pathlib import Path import subprocess +import shutil import sys import tempfile import unittest @@ -15,16 +21,49 @@ LEGACY = current.LEGACY legacy = current.runpy.run_path(str(LEGACY)) CATALOG = json.loads((ROOT / legacy["CATALOG"]).read_text(encoding="utf-8")) +FROZEN = json.loads((ROOT / "tests/fixtures/research-routing-v7.json").read_text()) +FROZEN_CATALOG = { + "schema_version": 1, "priority_revision": 7, + "priority_log": "docs/research/routing-fixture.md", + "tracks": [{"id": "routing-fixtures", "weight": 100, "tasks": FROZEN["cards"]}], +} + + +@contextmanager +def frozen_cli_tree(): + """Run the real scripts with exact old cards and inert reference files.""" + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + required = {FROZEN_CATALOG["priority_log"], + "scripts/research_selected_baseline.py", "scripts/research_package.py", + "research/historical-complex-ceiling-replay/VERIFY.json", + "research/historical-complex-ceiling-replay/verify.py"} + for card in FROZEN["cards"]: + required.update(card["starting_points"]) + required.add(card["first_step"]["command"][-1]) + for name in required: + path = root / name + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text("Inert reference for CLI validation only.\n") + for name in ("choose_research_task.py", "choose_current_research_task.py"): + shutil.copyfile(ROOT / "scripts" / name, root / "scripts" / name) + path = root / legacy["CATALOG"] + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(json.dumps(FROZEN_CATALOG)) + path = root / "certificates/selected-result.json" + path.parent.mkdir(parents=True, exist_ok=True) + shutil.copyfile(ROOT / "certificates/selected-result.json", path) + yield root class CurrentResearchAssignmentTests(unittest.TestCase): - def test_every_frozen_card_and_other_fields_stay_exact(self): - before = copy.deepcopy(CATALOG) + def check_card_round_trips(self, catalog): + before = copy.deepcopy(catalog) resolved = 0 historical = 0 - for track in CATALOG["tracks"]: + for track in catalog["tracks"]: for task in track["tasks"]: - result = legacy["select"](CATALOG, "a1" * 16, task_id=task["id"]) + result = legacy["select"](catalog, "a1" * 16, task_id=task["id"]) original = copy.deepcopy(result) current.resolve_current_first_steps(result, ROOT) card = result["suggestions"][0] @@ -55,19 +94,25 @@ def test_every_frozen_card_and_other_fields_stay_exact(self): self.assertTrue(card.pop("first_step_resolution")) card["first_step"] = card.pop("catalog_first_step") self.assertEqual(result, original) - self.assertEqual(resolved, 16) - self.assertEqual(historical, 4) - self.assertEqual(CATALOG, before) + self.assertEqual(catalog, before) + return resolved, historical + + def test_frozen_routes_and_other_fields_stay_exact(self): + self.assertEqual(self.check_card_round_trips(FROZEN_CATALOG), (1, 1)) + + def test_every_live_card_and_other_fields_stay_exact(self): + self.assertTrue(CATALOG["tracks"]) + self.check_card_round_trips(CATALOG) def test_only_exact_generic_command_is_resolved(self): - result = copy.deepcopy(legacy["select"](CATALOG, "0" * 32, task_id="portable-replay")) + result = copy.deepcopy(legacy["select"](FROZEN_CATALOG, "0" * 32, task_id="portable-replay")) result["suggestions"][0]["first_step"]["command"].append("--historical-fixture") original = copy.deepcopy(result) self.assertEqual(current.resolve_current_first_steps(result, ROOT), []) self.assertEqual(result, original) def test_missing_current_helper_does_not_change_receipt(self): - result = legacy["select"](CATALOG, "0" * 32, task_id="portable-replay") + result = legacy["select"](FROZEN_CATALOG, "0" * 32, task_id="portable-replay") original = copy.deepcopy(result) with tempfile.TemporaryDirectory() as directory: with self.assertRaisesRegex(ValueError, "missing current first-step script"): @@ -82,7 +127,7 @@ def test_nonexact_scientific_commands_are_not_reinterpreted(self): ): with self.subTest(command=command): result = copy.deepcopy(legacy["select"]( - CATALOG, "0" * 32, task_id="centre-path-sharing")) + FROZEN_CATALOG, "0" * 32, task_id="centre-path-sharing")) result["suggestions"][0]["first_step"]["command"] = command original = copy.deepcopy(result) self.assertEqual(current.resolve_current_first_steps(result, ROOT), []) @@ -102,34 +147,52 @@ def test_missing_historical_reference_leaves_all_cards_unchanged(self): path = root / name path.parent.mkdir(parents=True, exist_ok=True) path.write_text("fixture\n") - result = legacy["select"](CATALOG, "0" * 32, task_id="portable-replay") + result = legacy["select"](FROZEN_CATALOG, "0" * 32, task_id="portable-replay") result["suggestions"] += legacy["select"]( - CATALOG, "0" * 32, task_id="centre-path-sharing")["suggestions"] + FROZEN_CATALOG, "0" * 32, task_id="centre-path-sharing")["suggestions"] original = copy.deepcopy(result) with self.assertRaises(ValueError) as raised: current.resolve_current_first_steps(result, root) self.assertIn(absent, str(raised.exception)) self.assertEqual(result, original) - def cli(self, script, args): - return subprocess.run([sys.executable, "-B", str(script), *args], cwd=ROOT, + def cli(self, script, args, root=ROOT): + return subprocess.run([sys.executable, "-B", str(root / "scripts" / Path(script).name), *args], cwd=root, capture_output=True, text=True, encoding="utf-8") def test_cli_preserves_legacy_output_and_emits_both_commands(self): - args = ["--seed", "0" * 32, "--task", "portable-replay"] - original = self.cli(LEGACY, args) - output = self.cli(ROOT / "scripts/choose_current_research_task.py", args) - self.assertEqual(original.returncode, 0) - self.assertEqual(output.returncode, 0) - old, new = json.loads(original.stdout), json.loads(output.stdout) - card = new["suggestions"][0] - self.assertEqual(card["first_step"]["command"], - ["python3", "-B", "scripts/research_selected_baseline.py"]) - self.assertEqual(card.pop("catalog_first_step"), old["suggestions"][0]["first_step"]) - self.assertTrue(card.pop("first_step_resolution")) - card["first_step"] = old["suggestions"][0]["first_step"] - self.assertEqual(new, old) - self.assertEqual(self.cli(LEGACY, args).stdout, original.stdout) + with frozen_cli_tree() as root: + args = ["--seed", "0" * 32, "--task", "portable-replay"] + original = self.cli(LEGACY, args, root) + output = self.cli(ROOT / "scripts/choose_current_research_task.py", args, root) + self.assertEqual(original.returncode, 0) + self.assertEqual(output.returncode, 0) + old, new = json.loads(original.stdout), json.loads(output.stdout) + card = new["suggestions"][0] + self.assertEqual(card["first_step"]["command"], + ["python3", "-B", "scripts/research_selected_baseline.py"]) + self.assertEqual(card.pop("catalog_first_step"), old["suggestions"][0]["first_step"]) + self.assertTrue(card.pop("first_step_resolution")) + card["first_step"] = old["suggestions"][0]["first_step"] + self.assertEqual(new, old) + self.assertEqual(self.cli(LEGACY, args, root).stdout, original.stdout) + + def test_live_cli_preserves_each_unmapped_command(self): + checked = {tuple(card["first_step"]["command"]) for card in FROZEN["cards"]} + for track in CATALOG["tracks"]: + for task in track["tasks"]: + command = tuple(task["first_step"]["command"]) + if command in checked: + continue + checked.add(command) + with self.subTest(task=task["id"]): + args = ["--seed", "0" * 32, "--task", task["id"]] + original = self.cli(LEGACY, args) + output = self.cli(ROOT / "scripts/choose_current_research_task.py", args) + self.assertEqual(original.returncode, 0, original.stderr) + self.assertEqual(output.returncode, 0, output.stderr) + self.assertEqual(json.loads(output.stdout), json.loads(original.stdout)) + self.assertEqual(self.cli(LEGACY, args).stdout, original.stdout) def test_help_and_error_preserve_child_status_and_output(self): for args, code in ((["--help"], 0), (["--unknown-option"], 2), (["--seed", "bad"], 2)): @@ -139,23 +202,24 @@ def test_help_and_error_preserve_child_status_and_output(self): self.assertEqual((output.stdout, output.stderr), (original.stdout, original.stderr)) def test_cli_distinguishes_current_orientation_from_historical_control(self): - args = ["--seed", "0" * 32, "--task", "complex-new-helper-inventory"] - original = self.cli(LEGACY, args) - output = self.cli(ROOT / "scripts/choose_current_research_task.py", args) - self.assertEqual(original.returncode, 0, original.stderr) - self.assertEqual(output.returncode, 0, output.stderr) - old, new = json.loads(original.stdout), json.loads(output.stdout) - card = new["suggestions"][0] - self.assertEqual(card["first_step"]["command"][2], "scripts/research_selected_baseline.py") - self.assertEqual(card["first_step"]["expected"], "PASS_RESEARCH_BASELINE_BINDINGS_ONLY") - follow_up, = card.pop("follow_up_steps") - self.assertEqual(follow_up["command"][-1], "research/historical-complex-ceiling-replay") - self.assertIn("historical", follow_up["scope"].lower()) - self.assertIn("cost law", follow_up["inspect"]) - self.assertTrue(card.pop("first_step_resolution")) - card["first_step"] = card.pop("catalog_first_step") - self.assertEqual(new, old) - self.assertEqual(self.cli(LEGACY, args).stdout, original.stdout) + with frozen_cli_tree() as root: + args = ["--seed", "0" * 32, "--task", "centre-path-sharing"] + original = self.cli(LEGACY, args, root) + output = self.cli(ROOT / "scripts/choose_current_research_task.py", args, root) + self.assertEqual(original.returncode, 0, original.stderr) + self.assertEqual(output.returncode, 0, output.stderr) + old, new = json.loads(original.stdout), json.loads(output.stdout) + card = new["suggestions"][0] + self.assertEqual(card["first_step"]["command"][2], "scripts/research_selected_baseline.py") + self.assertEqual(card["first_step"]["expected"], "PASS_RESEARCH_BASELINE_BINDINGS_ONLY") + follow_up, = card.pop("follow_up_steps") + self.assertEqual(follow_up["command"][-1], "research/historical-complex-ceiling-replay") + self.assertIn("historical", follow_up["scope"].lower()) + self.assertIn("cost law", follow_up["inspect"]) + self.assertTrue(card.pop("first_step_resolution")) + card["first_step"] = card.pop("catalog_first_step") + self.assertEqual(new, old) + self.assertEqual(self.cli(LEGACY, args, root).stdout, original.stdout) def test_sparse_historical_references_require_unchanged_head_entries(self): with tempfile.TemporaryDirectory() as directory: @@ -178,12 +242,12 @@ def git(*args): git("update-index", "--skip-worktree", *omitted) for name in omitted: (root / name).unlink() - result = legacy["select"](CATALOG, "0" * 32, task_id="coverage-law-change") + result = legacy["select"](FROZEN_CATALOG, "0" * 32, task_id="centre-path-sharing") self.assertEqual(current.resolve_current_first_steps(result, root), sorted(omitted)) # Ordinary deletion must not acquire the deliberate-sparse exemption. changed = omitted[-1] git("update-index", "--no-skip-worktree", changed) - result = legacy["select"](CATALOG, "0" * 32, task_id="coverage-law-change") + result = legacy["select"](FROZEN_CATALOG, "0" * 32, task_id="centre-path-sharing") original = copy.deepcopy(result) with self.assertRaises(ValueError): current.resolve_current_first_steps(result, root) @@ -208,9 +272,9 @@ def git(*args): git("-c", "user.name=Fixture", "-c", "user.email=fixture@example.invalid", "-c", "core.hooksPath=/dev/null", "commit", "-qm", "helper") git("update-index", "--skip-worktree", name); path.unlink() - result = legacy["select"](CATALOG, "0" * 32, task_id="portable-replay") + result = legacy["select"](FROZEN_CATALOG, "0" * 32, task_id="portable-replay") self.assertEqual(current.resolve_current_first_steps(result, root), [name]) git("update-index", "--no-skip-worktree", name) - result = legacy["select"](CATALOG, "0" * 32, task_id="portable-replay") + result = legacy["select"](FROZEN_CATALOG, "0" * 32, task_id="portable-replay") with self.assertRaisesRegex(ValueError, "missing current first-step script"): current.resolve_current_first_steps(result, root)