rns-engine 0.11.0__tar.gz → 0.11.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. {rns_engine-0.11.0 → rns_engine-0.11.2}/PKG-INFO +1 -1
  2. {rns_engine-0.11.0 → rns_engine-0.11.2}/pyproject.toml +2 -2
  3. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/__init__.py +2 -2
  4. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/g4_results.py +19 -14
  5. rns_engine-0.11.2/src/rns_engine/g4_trust.py +356 -0
  6. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine.egg-info/PKG-INFO +1 -1
  7. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine.egg-info/SOURCES.txt +3 -0
  8. {rns_engine-0.11.0 → rns_engine-0.11.2}/tests/test_g4_results.py +8 -4
  9. rns_engine-0.11.2/tests/test_g4_species_labels.py +109 -0
  10. rns_engine-0.11.2/tests/test_g4_trust.py +119 -0
  11. {rns_engine-0.11.0 → rns_engine-0.11.2}/CAPACITY_PLANNING.md +0 -0
  12. {rns_engine-0.11.0 → rns_engine-0.11.2}/CUDA_PARALLEL_LANES.md +0 -0
  13. {rns_engine-0.11.0 → rns_engine-0.11.2}/G4_SERIES1_EVIDENCE.md +0 -0
  14. {rns_engine-0.11.0 → rns_engine-0.11.2}/LICENSE +0 -0
  15. {rns_engine-0.11.0 → rns_engine-0.11.2}/MANIFEST.in +0 -0
  16. {rns_engine-0.11.0 → rns_engine-0.11.2}/PRE_CUDA_READINESS.md +0 -0
  17. {rns_engine-0.11.0 → rns_engine-0.11.2}/README.md +0 -0
  18. {rns_engine-0.11.0 → rns_engine-0.11.2}/benchmarks/weighted_int32_baseline.py +0 -0
  19. {rns_engine-0.11.0 → rns_engine-0.11.2}/colab/T4_EXACT_GEMM_BRINGUP.ipynb +0 -0
  20. {rns_engine-0.11.0 → rns_engine-0.11.2}/setup.cfg +0 -0
  21. {rns_engine-0.11.0 → rns_engine-0.11.2}/setup.py +0 -0
  22. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/_core.cpp +0 -0
  23. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/_weighted.cpp +0 -0
  24. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/capacity.py +0 -0
  25. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/coefficients.py +0 -0
  26. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/cuda_contract.py +0 -0
  27. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_public_summary.json +0 -0
  28. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part01.b64 +0 -0
  29. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part02.b64 +0 -0
  30. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part03.b64 +0 -0
  31. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part04.b64 +0 -0
  32. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part05.b64 +0 -0
  33. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part06a.b64 +0 -0
  34. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part06b.b64 +0 -0
  35. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part07.b64 +0 -0
  36. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part08a.b64 +0 -0
  37. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part08b.b64 +0 -0
  38. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part09.b64 +0 -0
  39. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part10a.b64 +0 -0
  40. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part10b1.b64 +0 -0
  41. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part10b2.b64 +0 -0
  42. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part10b4.b64 +0 -0
  43. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part11.b64 +0 -0
  44. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part12a.b64 +0 -0
  45. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part12b.b64 +0 -0
  46. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part13.b64 +0 -0
  47. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part14a.b64 +0 -0
  48. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part14b.b64 +0 -0
  49. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part15a.b64 +0 -0
  50. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part15b.b64 +0 -0
  51. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part16a.b64 +0 -0
  52. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part16b.b64 +0 -0
  53. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part17a.b64 +0 -0
  54. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part17b1.b64 +0 -0
  55. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part17b2a.b64 +0 -0
  56. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part17b2b1.b64 +0 -0
  57. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part17b2b2.b64 +0 -0
  58. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_replay.part17b2b3.b64 +0 -0
  59. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/data/g4s1_t4_runtime.json +0 -0
  60. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/engine.py +0 -0
  61. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/exact_gemm.py +0 -0
  62. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/g4_benchmark.py +0 -0
  63. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/lane_plan.py +0 -0
  64. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/pre_cuda.py +0 -0
  65. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/rail_planning.py +0 -0
  66. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/signed.py +0 -0
  67. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/weighted.py +0 -0
  68. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine/wide.py +0 -0
  69. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine.egg-info/dependency_links.txt +0 -0
  70. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine.egg-info/entry_points.txt +0 -0
  71. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine.egg-info/not-zip-safe +0 -0
  72. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine.egg-info/requires.txt +0 -0
  73. {rns_engine-0.11.0 → rns_engine-0.11.2}/src/rns_engine.egg-info/top_level.txt +0 -0
  74. {rns_engine-0.11.0 → rns_engine-0.11.2}/tests/test_capacity.py +0 -0
  75. {rns_engine-0.11.0 → rns_engine-0.11.2}/tests/test_coefficients.py +0 -0
  76. {rns_engine-0.11.0 → rns_engine-0.11.2}/tests/test_cuda_contract.py +0 -0
  77. {rns_engine-0.11.0 → rns_engine-0.11.2}/tests/test_exact_gemm.py +0 -0
  78. {rns_engine-0.11.0 → rns_engine-0.11.2}/tests/test_g4_benchmark.py +0 -0
  79. {rns_engine-0.11.0 → rns_engine-0.11.2}/tests/test_packaging.py +0 -0
  80. {rns_engine-0.11.0 → rns_engine-0.11.2}/tests/test_pre_cuda.py +0 -0
  81. {rns_engine-0.11.0 → rns_engine-0.11.2}/tests/test_pre_cuda_assets.py +0 -0
  82. {rns_engine-0.11.0 → rns_engine-0.11.2}/tests/test_rail_planning.py +0 -0
  83. {rns_engine-0.11.0 → rns_engine-0.11.2}/tests/test_rns.py +0 -0
  84. {rns_engine-0.11.0 → rns_engine-0.11.2}/tests/test_session.py +0 -0
  85. {rns_engine-0.11.0 → rns_engine-0.11.2}/tests/test_signed.py +0 -0
  86. {rns_engine-0.11.0 → rns_engine-0.11.2}/tests/test_weighted.py +0 -0
  87. {rns_engine-0.11.0 → rns_engine-0.11.2}/tests/test_weighted_benchmark.py +0 -0
  88. {rns_engine-0.11.0 → rns_engine-0.11.2}/tests/test_wide.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rns_engine
3
- Version: 0.11.0
3
+ Version: 0.11.2
4
4
  Summary: Exact RNS engine with session/cache API.
5
5
  Author: Evan Wesley
6
6
  License-Expression: AGPL-3.0-only
@@ -11,7 +11,7 @@ build-backend = "setuptools.build_meta"
11
11
 
12
12
  [project]
13
13
  name = "rns_engine"
14
- version = "0.11.0"
14
+ version = "0.11.2"
15
15
  description = "Exact RNS engine with session/cache API."
16
16
  readme = "README.md"
17
17
  requires-python = ">=3.10,<3.15"
@@ -74,4 +74,4 @@ archs = ["x86_64"]
74
74
  environment = {PIP_ONLY_BINARY = "numpy"}
75
75
 
76
76
  [tool.cibuildwheel.windows]
77
- archs = ["AMD64"]
77
+ archs = ["AMD64"]
@@ -116,7 +116,7 @@ from .pre_cuda import (
116
116
  run_pre_cuda_readiness,
117
117
  )
118
118
  from .g4_results import g4_results
119
- from .g4_benchmark import g4_benchmark
119
+ from .g4_trust import g4_benchmark
120
120
 
121
121
 
122
122
  try:
@@ -180,4 +180,4 @@ def info():
180
180
  print(" Bridge APIs : weighted signed INT32 accumulation with range receipts")
181
181
  print(" Planning APIs : local/global capacity + exact Mersenne rail-set search")
182
182
  print(" Pre-CUDA APIs : seven-rail oracle + exact shared-scale GEMM fixtures")
183
- print(" G4 APIs : frozen Series 1 evidence + Tesla T4 reproduction benchmark")
183
+ print(" G4 APIs : frozen Series 1 evidence + Tesla T4 reproduction benchmark")
@@ -34,29 +34,31 @@ def _pct(value: float) -> str:
34
34
 
35
35
 
36
36
  def _print_integer(campaign: dict, stream: TextIO) -> None:
37
- print("[Exact integer / NVIDIA FP16-input cuBLASLt]", file=stream)
37
+ print("=== G4 INTEGERS vs NVIDIA FP16 cuBLASLt ===", file=stream)
38
+ print("Frozen Series 1 integer test — separate from the rational test below.", file=stream)
38
39
  print(
39
- f"Exact wins: {campaign['exact_wins']} / {campaign['declared_shapes']} "
40
+ f"G4 exact integers faster: {campaign['exact_wins']} / {campaign['declared_shapes']} "
40
41
  f"({_pct(campaign['exact_win_rate'])})",
41
42
  file=stream,
42
43
  )
43
- print(f"NVIDIA wins: {campaign['floating_wins']}", file=stream)
44
- print("Exact replay before + after timing: PASS on all 1,024 shapes", file=stream)
45
- print(f"Median speedup among exact wins: {campaign['exact_win_speedup_median']:.3f}x", file=stream)
46
- print(f"Best exact-win speedup: {campaign['best_exact_win_speedup']:.3f}x", file=stream)
44
+ print(f"NVIDIA FP16 faster: {campaign['floating_wins']} / {campaign['declared_shapes']}", file=stream)
45
+ print("Integer exactness: replay before + after timing PASS on all 1,024 shapes", file=stream)
46
+ print(f"Median integer speedup among G4 wins: {campaign['exact_win_speedup_median']:.3f}x", file=stream)
47
+ print(f"Best integer G4 speedup: {campaign['best_exact_win_speedup']:.3f}x", file=stream)
47
48
 
48
49
 
49
50
  def _print_rational(campaign: dict, stream: TextIO) -> None:
50
- print("[Exact rational / NVIDIA FP16]", file=stream)
51
+ print("=== G4 RATIONALS vs NVIDIA FP16 cuBLASLt ===", file=stream)
52
+ print("Frozen Series 1 rational test — separate from the integer test above.", file=stream)
51
53
  print(
52
- f"Certified exact wins: {campaign['certified_exact_wins']} / {campaign['target_shapes']} "
54
+ f"G4 exact rationals faster (certified): {campaign['certified_exact_wins']} / {campaign['target_shapes']} "
53
55
  f"({_pct(campaign['certified_exact_win_rate'])})",
54
56
  file=stream,
55
57
  )
56
- print(f"Remaining unresolved at archive freeze: {campaign['remaining_unresolved']}", file=stream)
57
- print("Certified winners: non-integer inputs PASS | range proof PASS | FP16 value-set proof PASS", file=stream)
58
- print(f"Median certified speedup: {campaign['certified_speedup_median']:.3f}x", file=stream)
59
- print(f"Best certified speedup: {campaign['best_certified_speedup']:.3f}x", file=stream)
58
+ print(f"Rational shapes unresolved at archive freeze: {campaign['remaining_unresolved']}", file=stream)
59
+ print("Certified rational winners: non-integer inputs PASS | range proof PASS | FP16 value-set proof PASS", file=stream)
60
+ print(f"Median rational speedup among certified G4 wins: {campaign['certified_speedup_median']:.3f}x", file=stream)
61
+ print(f"Best certified rational G4 speedup: {campaign['best_certified_speedup']:.3f}x", file=stream)
60
62
 
61
63
 
62
64
  def g4_results(
@@ -97,6 +99,7 @@ def g4_results(
97
99
  if display:
98
100
  out = stream if stream is not None else sys.stdout
99
101
  print("=== G4 SERIES 1 — TESLA T4 RESULTS ===", file=out)
102
+ print("Two separate tests are reported below. Do not combine their scores.", file=out)
100
103
  print(file=out)
101
104
  if selected in ("all", "integer_fp16_input_clean_sweep"):
102
105
  _print_integer(evidence["campaigns"]["integer_fp16_input_clean_sweep"], out)
@@ -106,9 +109,11 @@ def g4_results(
106
109
  _print_rational(evidence["campaigns"]["dynamic_exact_rational"], out)
107
110
  if selected == "all":
108
111
  print(file=out)
109
- print("91.60% integer and 84.96% rational are separate benchmark results.", file=out)
112
+ print("INTEGER RESULT: 938 / 1024 = 91.60%", file=out)
113
+ print("RATIONAL RESULT: 870 / 1024 = 84.96%", file=out)
114
+ print("These are separate benchmark results against NVIDIA FP16 cuBLASLt.", file=out)
110
115
 
111
116
  return result
112
117
 
113
118
 
114
- __all__ = ["g4_results"]
119
+ __all__ = ["g4_results"]
@@ -0,0 +1,356 @@
1
+ """Human-readable, cryptographically committed trust receipt for G4 replay runs."""
2
+ from __future__ import annotations
3
+
4
+ from datetime import datetime, timezone
5
+ import hashlib
6
+ import json
7
+ import os
8
+ import platform
9
+ import re
10
+ import subprocess
11
+ import sys
12
+ from importlib.metadata import PackageNotFoundError, version as distribution_version
13
+ from typing import TextIO
14
+
15
+ from .g4_benchmark import (
16
+ _BLOCKS,
17
+ _BOOTSTRAP_REPETITIONS,
18
+ _PROMOTION,
19
+ _REQUIRED_WINS,
20
+ _box,
21
+ _runtime_metadata,
22
+ g4_benchmark as _core_g4_benchmark,
23
+ )
24
+
25
+ _TRUST_SCHEMA = "RNS-ENGINE-G4S1-TRUST-PACK-1"
26
+
27
+ _LIVE_REPORT_REPLACEMENTS = (
28
+ ("EXACTNESS - FRESH RUN", "G4 RATIONALS - EXACTNESS - FRESH RUN"),
29
+ (
30
+ "SPEED - FRESH RUN DIRECTLY AGAINST NVIDIA FP16",
31
+ "G4 RATIONALS - SPEED vs NVIDIA FP16 - FRESH RUN",
32
+ ),
33
+ ("REPRODUCIBILITY", "G4 RATIONALS - REPRODUCIBILITY"),
34
+ ("Exact rational calculations correct:", "G4 rational calculations correct:"),
35
+ ("Exact rational faster:", "G4 RATIONALS faster than NVIDIA FP16:"),
36
+ ("NVIDIA FP16 faster:", "NVIDIA FP16 faster than G4 RATIONALS:"),
37
+ ("Too close to call:", "G4 RATIONALS / NVIDIA FP16 statistical ties:"),
38
+ ("Median speedup when exact wins:", "Median speedup when G4 RATIONALS win:"),
39
+ (
40
+ "Same winner/tie result as original:",
41
+ "RATIONAL winner/tie classification matches original RATIONAL benchmark:",
42
+ ),
43
+ )
44
+
45
+
46
+ class _RationalLiveReportStream:
47
+ """Relabel the existing live report without touching benchmark math or progress output."""
48
+
49
+ def __init__(self, target: TextIO):
50
+ self._target = target
51
+
52
+ @staticmethod
53
+ def _replace(text: str) -> str:
54
+ for old, new in _LIVE_REPORT_REPLACEMENTS:
55
+ text = text.replace(old, new)
56
+ return text
57
+
58
+ def _rewrite_line(self, line: str) -> str:
59
+ newline = "\n" if line.endswith("\n") else ""
60
+ body = line[:-1] if newline else line
61
+ if body.startswith("| ") and body.endswith(" |"):
62
+ inner_width = len(body) - 4
63
+ content = body[2:-2].rstrip()
64
+ content = self._replace(content)
65
+ return "| " + content[:inner_width].ljust(inner_width) + " |" + newline
66
+ return self._replace(body) + newline
67
+
68
+ def write(self, text: str) -> int:
69
+ rewritten = "".join(self._rewrite_line(line) for line in text.splitlines(keepends=True))
70
+ return self._target.write(rewritten)
71
+
72
+ def flush(self) -> None:
73
+ self._target.flush()
74
+
75
+
76
+ def _utc_now() -> str:
77
+ return datetime.now(timezone.utc).isoformat(timespec="seconds").replace("+00:00", "Z")
78
+
79
+
80
+ def _canonical_json_bytes(value: object) -> bytes:
81
+ return json.dumps(
82
+ value,
83
+ sort_keys=True,
84
+ separators=(",", ":"),
85
+ ensure_ascii=True,
86
+ allow_nan=False,
87
+ ).encode("utf-8")
88
+
89
+
90
+ def _sha256_json(value: object) -> str:
91
+ return hashlib.sha256(_canonical_json_bytes(value)).hexdigest()
92
+
93
+
94
+ def _package_version() -> str:
95
+ try:
96
+ return distribution_version("rns_engine")
97
+ except PackageNotFoundError:
98
+ return "0+unknown"
99
+
100
+
101
+ def _environment_name() -> str:
102
+ if (
103
+ "google.colab" in sys.modules
104
+ or os.environ.get("COLAB_RELEASE_TAG")
105
+ or os.environ.get("COLAB_BACKEND_VERSION")
106
+ or os.environ.get("COLAB_GPU")
107
+ ):
108
+ return "Google Colab"
109
+ return platform.platform()
110
+
111
+
112
+ def _current_cuda_version() -> str:
113
+ try:
114
+ proc = subprocess.run(
115
+ ["nvidia-smi"],
116
+ text=True,
117
+ capture_output=True,
118
+ check=False,
119
+ timeout=10,
120
+ )
121
+ except (FileNotFoundError, subprocess.TimeoutExpired):
122
+ return "unavailable"
123
+ if proc.returncode != 0:
124
+ return "unavailable"
125
+ match = re.search(r"CUDA Version:\s*([0-9.]+)", proc.stdout)
126
+ return match.group(1) if match else "unavailable"
127
+
128
+
129
+ def _gpu_state_snapshot() -> dict:
130
+ command = [
131
+ "nvidia-smi",
132
+ "--query-gpu=pstate,temperature.gpu,power.draw,clocks.current.sm,clocks.current.memory",
133
+ "--format=csv,noheader,nounits",
134
+ ]
135
+ try:
136
+ proc = subprocess.run(
137
+ command,
138
+ text=True,
139
+ capture_output=True,
140
+ check=False,
141
+ timeout=10,
142
+ )
143
+ except (FileNotFoundError, subprocess.TimeoutExpired) as exc:
144
+ return {"available": False, "error": type(exc).__name__}
145
+ if proc.returncode != 0:
146
+ return {
147
+ "available": False,
148
+ "error": proc.stderr.strip() or f"nvidia-smi exit {proc.returncode}",
149
+ }
150
+ rows = [line.strip() for line in proc.stdout.splitlines() if line.strip()]
151
+ if len(rows) != 1:
152
+ return {"available": False, "error": f"expected one GPU row, got {len(rows)}"}
153
+ parts = [part.strip() for part in rows[0].split(",")]
154
+ if len(parts) != 5:
155
+ return {"available": False, "error": f"unexpected GPU state row: {rows[0]}"}
156
+ return {
157
+ "available": True,
158
+ "pstate": parts[0],
159
+ "temperature_c": parts[1],
160
+ "power_w": parts[2],
161
+ "sm_clock_mhz": parts[3],
162
+ "memory_clock_mhz": parts[4],
163
+ }
164
+
165
+
166
+ def _format_gpu_state(snapshot: dict) -> str:
167
+ if snapshot.get("available") is not True:
168
+ return "unavailable"
169
+ return (
170
+ f"{snapshot['pstate']} | {snapshot['temperature_c']} C | {snapshot['power_w']} W | "
171
+ f"SM {snapshot['sm_clock_mhz']} MHz | MEM {snapshot['memory_clock_mhz']} MHz"
172
+ )
173
+
174
+
175
+ def _build_cuda_summary(build_nvcc: str) -> str:
176
+ match = re.search(r"release\s+([0-9.]+),\s+V([0-9.]+)", build_nvcc)
177
+ if match:
178
+ return f"CUDA {match.group(1)} / nvcc V{match.group(2)}"
179
+ for line in reversed(build_nvcc.splitlines()):
180
+ if line.strip():
181
+ return line.strip()
182
+ return "unavailable"
183
+
184
+
185
+ def _print_test_scope(stream: TextIO) -> None:
186
+ _box(
187
+ "G4 SERIES 1 - TWO SEPARATE TESTS",
188
+ [
189
+ "G4 INTEGERS vs NVIDIA FP16 cuBLASLt: frozen result 938 / 1024 (91.60%)",
190
+ "G4 RATIONALS vs NVIDIA FP16 cuBLASLt: frozen result 870 / 1024 (84.96%)",
191
+ "",
192
+ "LIVE BENCHMARK BELOW: G4 RATIONALS vs NVIDIA FP16 ONLY.",
193
+ "g4_benchmark() does not rerun the integer benchmark; the integer score is context only.",
194
+ ],
195
+ stream,
196
+ width=112,
197
+ )
198
+
199
+
200
+ def _add_species_labels(result: dict) -> None:
201
+ result["live_test"] = "G4_RATIONALS_vs_NVIDIA_FP16_cuBLASLt"
202
+ summary = result.setdefault("summary", {})
203
+ if "frozen_decision_matches" in summary:
204
+ summary["rational_frozen_decision_matches"] = summary["frozen_decision_matches"]
205
+
206
+
207
+ def _make_trust_pack(
208
+ result: dict,
209
+ *,
210
+ started_utc: str,
211
+ completed_utc: str,
212
+ environment: str,
213
+ package_version: str,
214
+ current_cuda: str,
215
+ gpu_before: dict,
216
+ gpu_after: dict,
217
+ ) -> dict:
218
+ meta = _runtime_metadata()
219
+ rows = result["rows"]
220
+ rows_sha256 = _sha256_json(rows)
221
+ exact_rows = sum(bool(row.get("exact_replay_passed")) for row in rows)
222
+
223
+ receipt = {
224
+ "schema": _TRUST_SCHEMA,
225
+ "series": result.get("series"),
226
+ "campaign": result.get("campaign"),
227
+ "live_test": result.get("live_test", "G4_RATIONALS_vs_NVIDIA_FP16_cuBLASLt"),
228
+ "mode": result.get("mode"),
229
+ "started_utc": started_utc,
230
+ "completed_utc": completed_utc,
231
+ "package": {
232
+ "name": "rns_engine",
233
+ "version": package_version,
234
+ "release_tag": f"v{package_version}",
235
+ },
236
+ "environment": {
237
+ "name": environment,
238
+ "python": platform.python_version(),
239
+ "platform": platform.platform(),
240
+ "current_cuda_reported_by_nvidia_smi": current_cuda,
241
+ },
242
+ "gpu": result.get("gpu", {}),
243
+ "gpu_state_before": gpu_before,
244
+ "gpu_state_after": gpu_after,
245
+ "protocol": {
246
+ "comparison": "G4 exact rational GEMM vs NVIDIA FP16 cuBLASLt",
247
+ "paired_timing_blocks_per_shape": _BLOCKS,
248
+ "bootstrap_resamples_per_shape": _BOOTSTRAP_REPETITIONS,
249
+ "bootstrap_confidence_interval": 0.95,
250
+ "promotion_threshold": _PROMOTION,
251
+ "required_exact_block_wins": _REQUIRED_WINS,
252
+ "fail_closed_on_runtime_error": True,
253
+ "fail_closed_on_exactness_failure": True,
254
+ },
255
+ "exactness": {
256
+ "rows_exact": exact_rows,
257
+ "rows_total": len(rows),
258
+ "runtime_errors": int(result.get("summary", {}).get("runtime_errors", 0)),
259
+ "exact_replay_failures": int(
260
+ result.get("summary", {}).get("exact_replay_failures", 0)
261
+ ),
262
+ },
263
+ "runtime": {
264
+ "binary_sha256": result["runtime"]["binary_sha256"],
265
+ "payload_sha256": result["runtime"]["payload_sha256"],
266
+ "source_archive_sha256": result["runtime"]["source_archive_sha256"],
267
+ "public_runtime_source_sha256": meta.get("public_runtime_source_sha256"),
268
+ "build_nvcc": result["runtime"]["build_nvcc"],
269
+ },
270
+ "timing_seconds": result.get("timing_seconds", {}),
271
+ "summary": result.get("summary", {}),
272
+ "result_rows_sha256": rows_sha256,
273
+ }
274
+ receipt_sha256 = _sha256_json(receipt)
275
+ return {**receipt, "run_receipt_sha256": receipt_sha256}
276
+
277
+
278
+ def _print_trust_pack(trust: dict, stream: TextIO) -> None:
279
+ gpu = trust["gpu"]
280
+ package = trust["package"]
281
+ exactness = trust["exactness"]
282
+ runtime = trust["runtime"]
283
+ protocol = trust["protocol"]
284
+ environment = trust["environment"]
285
+
286
+ _box(
287
+ "TRUST PACK - G4 RATIONAL RUN RECEIPT",
288
+ [
289
+ "Live test: G4 RATIONALS vs NVIDIA FP16 cuBLASLt",
290
+ f"Environment: {environment['name']} | rns_engine {package['version']} | release {package['release_tag']}",
291
+ f"Python: {environment['python']} | CUDA reported by NVIDIA: {environment['current_cuda_reported_by_nvidia_smi']}",
292
+ f"GPU: {gpu.get('name', 'unknown')} | compute capability {gpu.get('compute_capability', 'unknown')} | driver {gpu.get('driver_version', 'unknown')}",
293
+ f"Replay build toolchain: {_build_cuda_summary(runtime['build_nvcc'])}",
294
+ f"GPU state before: {_format_gpu_state(trust['gpu_state_before'])}",
295
+ f"GPU state after: {_format_gpu_state(trust['gpu_state_after'])}",
296
+ "",
297
+ f"Protocol: {protocol['paired_timing_blocks_per_shape']} paired timing blocks/shape | {protocol['bootstrap_resamples_per_shape']:,} bootstrap resamples/shape | 95% CI",
298
+ f"Rational exactness gate: {exactness['rows_exact']} / {exactness['rows_total']} exact | runtime errors {exactness['runtime_errors']} | exactness failures {exactness['exact_replay_failures']}",
299
+ "",
300
+ f"Replay binary SHA-256: {runtime['binary_sha256']}",
301
+ f"Replay payload SHA-256: {runtime['payload_sha256']}",
302
+ f"Source archive SHA-256: {runtime['source_archive_sha256']}",
303
+ f"All result rows SHA-256: {trust['result_rows_sha256']}",
304
+ f"Run receipt SHA-256: {trust['run_receipt_sha256']}",
305
+ "",
306
+ f"Started UTC: {trust['started_utc']} | Completed UTC: {trust['completed_utc']}",
307
+ ],
308
+ stream,
309
+ width=112,
310
+ )
311
+
312
+
313
+ def g4_benchmark(
314
+ mode: str = "quick",
315
+ *,
316
+ display: bool = True,
317
+ stream: TextIO | None = None,
318
+ ) -> dict:
319
+ """Run the public rational G4 benchmark and append a cryptographic trust receipt."""
320
+ out = stream if stream is not None else sys.stdout
321
+ started_utc = _utc_now()
322
+ environment = _environment_name()
323
+ package_version = _package_version()
324
+ current_cuda = _current_cuda_version()
325
+ gpu_before = _gpu_state_snapshot()
326
+
327
+ if display:
328
+ _print_test_scope(out)
329
+ print(file=out)
330
+
331
+ live_out = _RationalLiveReportStream(out) if display else out
332
+ result = _core_g4_benchmark(mode, display=display, stream=live_out)
333
+ _add_species_labels(result)
334
+
335
+ gpu_after = _gpu_state_snapshot()
336
+ completed_utc = _utc_now()
337
+ trust = _make_trust_pack(
338
+ result,
339
+ started_utc=started_utc,
340
+ completed_utc=completed_utc,
341
+ environment=environment,
342
+ package_version=package_version,
343
+ current_cuda=current_cuda,
344
+ gpu_before=gpu_before,
345
+ gpu_after=gpu_after,
346
+ )
347
+ result["trust_pack"] = trust
348
+
349
+ if display:
350
+ print(file=out)
351
+ _print_trust_pack(trust, out)
352
+
353
+ return result
354
+
355
+
356
+ __all__ = ["g4_benchmark"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rns_engine
3
- Version: 0.11.0
3
+ Version: 0.11.2
4
4
  Summary: Exact RNS engine with session/cache API.
5
5
  Author: Evan Wesley
6
6
  License-Expression: AGPL-3.0-only
@@ -19,6 +19,7 @@ src/rns_engine/engine.py
19
19
  src/rns_engine/exact_gemm.py
20
20
  src/rns_engine/g4_benchmark.py
21
21
  src/rns_engine/g4_results.py
22
+ src/rns_engine/g4_trust.py
22
23
  src/rns_engine/lane_plan.py
23
24
  src/rns_engine/pre_cuda.py
24
25
  src/rns_engine/rail_planning.py
@@ -71,6 +72,8 @@ tests/test_cuda_contract.py
71
72
  tests/test_exact_gemm.py
72
73
  tests/test_g4_benchmark.py
73
74
  tests/test_g4_results.py
75
+ tests/test_g4_species_labels.py
76
+ tests/test_g4_trust.py
74
77
  tests/test_packaging.py
75
78
  tests/test_pre_cuda.py
76
79
  tests/test_pre_cuda_assets.py
@@ -28,15 +28,19 @@ def test_g4_results_keeps_integer_and_rational_claims_distinct():
28
28
  assert rational["all_certified_fp16_value_set_proved"] is True
29
29
 
30
30
 
31
- def test_g4_results_report_labels_both_percentages():
31
+ def test_g4_results_report_labels_both_species_and_percentages():
32
32
  stream = io.StringIO()
33
33
  g4_results(stream=stream)
34
34
  text = stream.getvalue()
35
- assert "938 / 1024 (91.60%)" in text
36
- assert "870 / 1024 (84.96%)" in text
35
+ assert "G4 INTEGERS vs NVIDIA FP16 cuBLASLt" in text
36
+ assert "G4 RATIONALS vs NVIDIA FP16 cuBLASLt" in text
37
+ assert "G4 exact integers faster: 938 / 1024 (91.60%)" in text
38
+ assert "G4 exact rationals faster (certified): 870 / 1024 (84.96%)" in text
39
+ assert "INTEGER RESULT: 938 / 1024 = 91.60%" in text
40
+ assert "RATIONAL RESULT: 870 / 1024 = 84.96%" in text
37
41
  assert "separate benchmark results" in text
38
42
 
39
43
 
40
44
  def test_g4_results_bad_campaign_rejected():
41
45
  with pytest.raises(ValueError):
42
- g4_results("series2", display=False)
46
+ g4_results("series2", display=False)
@@ -0,0 +1,109 @@
1
+ from copy import deepcopy
2
+ from io import StringIO
3
+
4
+ import rns_engine.g4_trust as trust
5
+
6
+
7
+ def _result():
8
+ return {
9
+ "schema": "RNS-ENGINE-G4S1-LIVE-BENCHMARK-2",
10
+ "series": 1,
11
+ "campaign": "dynamic_exact_rational_vs_fp16",
12
+ "mode": "full",
13
+ "gpu": {"name": "Tesla T4", "compute_capability": "7.5", "driver_version": "580.82.07"},
14
+ "runtime": {
15
+ "binary_sha256": "a" * 64,
16
+ "payload_sha256": "b" * 64,
17
+ "source_archive_sha256": "c" * 64,
18
+ "build_nvcc": "Cuda compilation tools, release 12.8, V12.8.93",
19
+ "config_provenance": {},
20
+ },
21
+ "timing_seconds": {"gpu_test": 1.0, "result_verification": 1.0, "total": 2.0},
22
+ "summary": {
23
+ "shapes_run": 2,
24
+ "runtime_errors": 0,
25
+ "exact_replay_failures": 0,
26
+ "live_exact_wins": 1,
27
+ "live_floating_wins": 1,
28
+ "live_statistical_ties": 0,
29
+ "frozen_decision_matches": 2,
30
+ },
31
+ "rows": [
32
+ {"shape_id": "A", "exact_replay_passed": True, "live_decision": "EXACT_WIN"},
33
+ {"shape_id": "B", "exact_replay_passed": True, "live_decision": "FLOATING_WIN"},
34
+ ],
35
+ }
36
+
37
+
38
+ def _snapshot():
39
+ return {
40
+ "available": True,
41
+ "pstate": "P0",
42
+ "temperature_c": "45",
43
+ "power_w": "38.50",
44
+ "sm_clock_mhz": "1590",
45
+ "memory_clock_mhz": "5001",
46
+ }
47
+
48
+
49
+ def _fake_core(mode, *, display, stream):
50
+ if display:
51
+ trust._box(
52
+ "EXACTNESS - FRESH RUN",
53
+ ["Exact rational calculations correct: 2 / 2", "Result: PASS"],
54
+ stream,
55
+ )
56
+ trust._box(
57
+ "SPEED - FRESH RUN DIRECTLY AGAINST NVIDIA FP16",
58
+ [
59
+ "Exact rational faster: 1 / 2 (50.00%)",
60
+ "NVIDIA FP16 faster: 1 / 2 (50.00%)",
61
+ "Too close to call: 0 / 2 (0.00%)",
62
+ "Median speedup when exact wins: 1.400x",
63
+ "Median speedup including rational bookkeeping: 1.350x",
64
+ ],
65
+ stream,
66
+ )
67
+ trust._box(
68
+ "REPRODUCIBILITY",
69
+ [
70
+ "Same winner/tie result as original: 2 / 2 (100.00%)",
71
+ "Validated replay binary SHA-256: " + "a" * 64,
72
+ "Total elapsed: 00:02",
73
+ ],
74
+ stream,
75
+ )
76
+ return deepcopy(_result())
77
+
78
+
79
+ def test_live_report_is_explicitly_rational(monkeypatch):
80
+ monkeypatch.setattr(trust, "_core_g4_benchmark", _fake_core)
81
+ monkeypatch.setattr(trust, "_gpu_state_snapshot", _snapshot)
82
+ monkeypatch.setattr(trust, "_environment_name", lambda: "Google Colab")
83
+ monkeypatch.setattr(trust, "_package_version", lambda: "0.11.2")
84
+ monkeypatch.setattr(trust, "_current_cuda_version", lambda: "12.8")
85
+ times = iter(["2026-08-09T06:00:00Z", "2026-08-09T06:10:00Z"])
86
+ monkeypatch.setattr(trust, "_utc_now", lambda: next(times))
87
+
88
+ output = StringIO()
89
+ result = trust.g4_benchmark("full", display=True, stream=output)
90
+ text = output.getvalue()
91
+
92
+ assert result["live_test"] == "G4_RATIONALS_vs_NVIDIA_FP16_cuBLASLt"
93
+ assert result["summary"]["rational_frozen_decision_matches"] == 2
94
+ assert "G4 INTEGERS vs NVIDIA FP16 cuBLASLt" in text
95
+ assert "G4 RATIONALS vs NVIDIA FP16 cuBLASLt" in text
96
+ assert "LIVE BENCHMARK BELOW: G4 RATIONALS vs NVIDIA FP16 ONLY." in text
97
+
98
+ assert "G4 RATIONALS - EXACTNESS - FRESH RUN" in text
99
+ assert "G4 rational calculations correct: 2 / 2" in text
100
+ assert "G4 RATIONALS - SPEED vs NVIDIA FP16 - FRESH RUN" in text
101
+ assert "G4 RATIONALS faster than NVIDIA FP16: 1 / 2" in text
102
+ assert "NVIDIA FP16 faster than G4 RATIONALS:" in text
103
+ assert "G4 RATIONALS / NVIDIA FP16 statistical ties:" in text
104
+ assert "G4 RATIONALS - REPRODUCIBILITY" in text
105
+ assert "RATIONAL winner/tie classification matches original RATIONAL benchmark:" in text
106
+
107
+ assert "Same winner/tie result as original:" not in text
108
+ assert "Too close to call:" not in text
109
+ assert "TRUST PACK - G4 RATIONAL RUN RECEIPT" in text
@@ -0,0 +1,119 @@
1
+ from __future__ import annotations
2
+
3
+ from copy import deepcopy
4
+ from io import StringIO
5
+
6
+ import rns_engine.g4_trust as trust
7
+
8
+
9
+ def _fake_result() -> dict:
10
+ return {
11
+ "schema": "RNS-ENGINE-G4S1-LIVE-BENCHMARK-2",
12
+ "series": 1,
13
+ "campaign": "dynamic_exact_rational_vs_fp16",
14
+ "mode": "full",
15
+ "gpu": {
16
+ "name": "Tesla T4",
17
+ "compute_capability": "7.5",
18
+ "driver_version": "580.82.07",
19
+ },
20
+ "runtime": {
21
+ "binary_sha256": "a" * 64,
22
+ "payload_sha256": "b" * 64,
23
+ "source_archive_sha256": "c" * 64,
24
+ "build_nvcc": "Cuda compilation tools, release 12.8, V12.8.93",
25
+ "config_provenance": {},
26
+ },
27
+ "timing_seconds": {
28
+ "gpu_test": 12.5,
29
+ "result_verification": 3.0,
30
+ "total": 15.5,
31
+ },
32
+ "summary": {
33
+ "shapes_run": 2,
34
+ "runtime_errors": 0,
35
+ "exact_replay_failures": 0,
36
+ "live_exact_wins": 1,
37
+ "live_floating_wins": 1,
38
+ "live_statistical_ties": 0,
39
+ },
40
+ "rows": [
41
+ {"shape_id": "A", "exact_replay_passed": True, "live_decision": "EXACT_WIN"},
42
+ {"shape_id": "B", "exact_replay_passed": True, "live_decision": "FLOATING_WIN"},
43
+ ],
44
+ }
45
+
46
+
47
+ def _snapshot() -> dict:
48
+ return {
49
+ "available": True,
50
+ "pstate": "P0",
51
+ "temperature_c": "45",
52
+ "power_w": "38.50",
53
+ "sm_clock_mhz": "1590",
54
+ "memory_clock_mhz": "5001",
55
+ }
56
+
57
+
58
+ def test_trust_pack_hashes_all_rows_and_commits_to_receipt():
59
+ result = _fake_result()
60
+ pack = trust._make_trust_pack(
61
+ result,
62
+ started_utc="2026-08-09T06:00:00Z",
63
+ completed_utc="2026-08-09T06:10:00Z",
64
+ environment="Google Colab",
65
+ package_version="0.11.1",
66
+ current_cuda="12.8",
67
+ gpu_before=_snapshot(),
68
+ gpu_after=_snapshot(),
69
+ )
70
+
71
+ assert pack["schema"] == "RNS-ENGINE-G4S1-TRUST-PACK-1"
72
+ assert pack["package"]["release_tag"] == "v0.11.1"
73
+ assert pack["exactness"] == {
74
+ "rows_exact": 2,
75
+ "rows_total": 2,
76
+ "runtime_errors": 0,
77
+ "exact_replay_failures": 0,
78
+ }
79
+ assert len(pack["result_rows_sha256"]) == 64
80
+ assert len(pack["run_receipt_sha256"]) == 64
81
+
82
+ changed = _fake_result()
83
+ changed["rows"][0]["live_decision"] = "STATISTICAL_TIE"
84
+ changed_pack = trust._make_trust_pack(
85
+ changed,
86
+ started_utc="2026-08-09T06:00:00Z",
87
+ completed_utc="2026-08-09T06:10:00Z",
88
+ environment="Google Colab",
89
+ package_version="0.11.1",
90
+ current_cuda="12.8",
91
+ gpu_before=_snapshot(),
92
+ gpu_after=_snapshot(),
93
+ )
94
+ assert changed_pack["result_rows_sha256"] != pack["result_rows_sha256"]
95
+ assert changed_pack["run_receipt_sha256"] != pack["run_receipt_sha256"]
96
+
97
+
98
+ def test_public_wrapper_adds_and_prints_trust_pack(monkeypatch):
99
+ monkeypatch.setattr(trust, "_core_g4_benchmark", lambda *args, **kwargs: deepcopy(_fake_result()))
100
+ monkeypatch.setattr(trust, "_gpu_state_snapshot", _snapshot)
101
+ monkeypatch.setattr(trust, "_environment_name", lambda: "Google Colab")
102
+ monkeypatch.setattr(trust, "_package_version", lambda: "0.11.1")
103
+ monkeypatch.setattr(trust, "_current_cuda_version", lambda: "12.8")
104
+
105
+ timestamps = iter(["2026-08-09T06:00:00Z", "2026-08-09T06:10:00Z"])
106
+ monkeypatch.setattr(trust, "_utc_now", lambda: next(timestamps))
107
+
108
+ output = StringIO()
109
+ result = trust.g4_benchmark("full", display=True, stream=output)
110
+ text = output.getvalue()
111
+
112
+ assert "trust_pack" in result
113
+ assert "TRUST PACK - G4 RATIONAL RUN RECEIPT" in text
114
+ assert "Environment: Google Colab | rns_engine 0.11.1 | release v0.11.1" in text
115
+ assert "Replay binary SHA-256: " + "a" * 64 in text
116
+ assert "Replay payload SHA-256: " + "b" * 64 in text
117
+ assert "Source archive SHA-256: " + "c" * 64 in text
118
+ assert result["trust_pack"]["result_rows_sha256"] in text
119
+ assert result["trust_pack"]["run_receipt_sha256"] in text
File without changes
File without changes
File without changes
File without changes
File without changes