spatial-computing 0.28.0__tar.gz → 0.29.0__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 (133) hide show
  1. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/PKG-INFO +2 -1
  2. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/README.md +1 -0
  3. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/pyproject.toml +1 -1
  4. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/__init__.py +1 -1
  5. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/cli.py +27 -0
  6. spatial_computing-0.29.0/spatial/verify/__init__.py +5 -0
  7. spatial_computing-0.29.0/spatial/verify/consensus.py +72 -0
  8. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial_computing.egg-info/PKG-INFO +2 -1
  9. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial_computing.egg-info/SOURCES.txt +4 -1
  10. spatial_computing-0.29.0/tests/test_verify.py +103 -0
  11. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/LICENSE +0 -0
  12. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/setup.cfg +0 -0
  13. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/ai/__init__.py +0 -0
  14. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/ai/kvcache.py +0 -0
  15. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/ai/llm.py +0 -0
  16. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/automotive/__init__.py +0 -0
  17. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/automotive/placement.py +0 -0
  18. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/compute/__init__.py +0 -0
  19. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/compute/cost.py +0 -0
  20. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/compute/detect.py +0 -0
  21. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/compute/monitor.py +0 -0
  22. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/compute/scheduler.py +0 -0
  23. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/compute/taskqueue.py +0 -0
  24. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/compute/worker.py +0 -0
  25. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/compute/workloads.py +0 -0
  26. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/core/__init__.py +0 -0
  27. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/core/auth.py +0 -0
  28. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/core/energy.py +0 -0
  29. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/core/ledger.py +0 -0
  30. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/core/model.py +0 -0
  31. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/core/protocol.py +0 -0
  32. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/core/registry.py +0 -0
  33. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/fabric/__init__.py +0 -0
  34. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/fabric/cuda.py +0 -0
  35. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/fabric/devices.py +0 -0
  36. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/fabric/metal.py +0 -0
  37. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/fabric/metal_mandel.swift +0 -0
  38. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/fabric/metal_run.swift +0 -0
  39. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/fleet/__init__.py +0 -0
  40. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/fleet/agent.py +0 -0
  41. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/fleet/alerts.py +0 -0
  42. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/fleet/dashboard.py +0 -0
  43. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/fleet/ha.py +0 -0
  44. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/fleet/hub.py +0 -0
  45. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/intelligence/__init__.py +0 -0
  46. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/intelligence/predictor.py +0 -0
  47. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/interconnect/__init__.py +0 -0
  48. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/interconnect/collectives.py +0 -0
  49. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/interconnect/comm.py +0 -0
  50. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/interconnect/model.py +0 -0
  51. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/interconnect/tasks.py +0 -0
  52. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/kernel/__init__.py +0 -0
  53. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/kernel/dsl.py +0 -0
  54. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/kernel/library.py +0 -0
  55. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/market/__init__.py +0 -0
  56. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/market/vast.py +0 -0
  57. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/memory/__init__.py +0 -0
  58. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/memory/fararray.py +0 -0
  59. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/memory/pageserver.py +0 -0
  60. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/memory/secure.py +0 -0
  61. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/memory/shared.py +0 -0
  62. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/memory/tiered.py +0 -0
  63. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/platform/__init__.py +0 -0
  64. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/platform/billing.py +0 -0
  65. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/platform/db.py +0 -0
  66. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/platform/invoice_rules.py +0 -0
  67. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/platform/mailer.py +0 -0
  68. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/platform/oidc.py +0 -0
  69. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/platform/pdf.py +0 -0
  70. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/platform/qr.py +0 -0
  71. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/platform/security.py +0 -0
  72. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/platform/server.py +0 -0
  73. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/platform/service.py +0 -0
  74. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/platform/static/app.js +0 -0
  75. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/platform/static/fonts/DMMono-normal-400.woff2 +0 -0
  76. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/platform/static/fonts/DMMono-normal-500.woff2 +0 -0
  77. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/platform/static/fonts/InstrumentSerif-italic-400.woff2 +0 -0
  78. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/platform/static/fonts/InstrumentSerif-normal-400.woff2 +0 -0
  79. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/platform/static/fonts/Inter-normal-400.woff2 +0 -0
  80. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/platform/static/fonts/Inter-normal-500.woff2 +0 -0
  81. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/platform/static/fonts/Inter-normal-600.woff2 +0 -0
  82. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/platform/static/fonts.css +0 -0
  83. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/platform/static/index.html +0 -0
  84. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/platform/static/logo.svg +0 -0
  85. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/platform/static/style.css +0 -0
  86. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/platform/totp.py +0 -0
  87. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/platform/ubl.py +0 -0
  88. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/platform/vat.py +0 -0
  89. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/runtime/__init__.py +0 -0
  90. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/runtime/arch.py +0 -0
  91. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/runtime/desktop/Dockerfile +0 -0
  92. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/runtime/desktop/__init__.py +0 -0
  93. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/runtime/desktop/start.sh +0 -0
  94. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/runtime/envs.py +0 -0
  95. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/runtime/inspect.py +0 -0
  96. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/runtime/microvm.py +0 -0
  97. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/runtime/planner.py +0 -0
  98. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/runtime/runner.py +0 -0
  99. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/runtime/toolchain.py +0 -0
  100. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/unified/__init__.py +0 -0
  101. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/unified/model.py +0 -0
  102. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/unified/planner.py +0 -0
  103. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial/unified/providers.py +0 -0
  104. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial_computing.egg-info/dependency_links.txt +0 -0
  105. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial_computing.egg-info/entry_points.txt +0 -0
  106. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial_computing.egg-info/requires.txt +0 -0
  107. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/spatial_computing.egg-info/top_level.txt +0 -0
  108. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/tests/test_auth.py +0 -0
  109. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/tests/test_automotive.py +0 -0
  110. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/tests/test_compute.py +0 -0
  111. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/tests/test_core.py +0 -0
  112. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/tests/test_dashboard.py +0 -0
  113. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/tests/test_domains.py +0 -0
  114. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/tests/test_engines.py +0 -0
  115. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/tests/test_fabric.py +0 -0
  116. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/tests/test_fleet.py +0 -0
  117. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/tests/test_ha.py +0 -0
  118. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/tests/test_hardening.py +0 -0
  119. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/tests/test_interconnect.py +0 -0
  120. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/tests/test_kernel.py +0 -0
  121. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/tests/test_market.py +0 -0
  122. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/tests/test_memory.py +0 -0
  123. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/tests/test_platform.py +0 -0
  124. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/tests/test_platform2.py +0 -0
  125. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/tests/test_qr.py +0 -0
  126. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/tests/test_quorum.py +0 -0
  127. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/tests/test_real_servers.py +0 -0
  128. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/tests/test_runtime.py +0 -0
  129. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/tests/test_sso.py +0 -0
  130. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/tests/test_unified.py +0 -0
  131. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/tests/test_v02.py +0 -0
  132. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/tests/test_v03.py +0 -0
  133. {spatial_computing-0.28.0 → spatial_computing-0.29.0}/tests/test_v05.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: spatial-computing
3
- Version: 0.28.0
3
+ Version: 0.29.0
4
4
  Summary: Spatial Computing: open-source infrastructure efficiency toolkit. Measure, decide, prove (compute, tiered memory, runtime routing, fleet)
5
5
  Author: Spatial Computing contributors
6
6
  License-Expression: Apache-2.0
@@ -103,6 +103,7 @@ st.put(0, b"..." * 1000); st.get(0); print(st.stats())
103
103
  | Portable kernels (one source, CPU/Metal/CUDA/HIP/Triton; market-vertical presets) | first components | `tests/test_kernel.py`, `benchmarks/bench_kernel.py` |
104
104
  | Live GPU market prices (`spatial market`, read-only, no account) | first components | `tests/test_market.py`, [docs/MARKET.md](docs/MARKET.md) |
105
105
  | In-vehicle multi-chip placement (`spatial automotive`, declared chip specs, no real silicon) | first components | `tests/test_automotive.py`, [docs/AUTOMOTIVE.md](docs/AUTOMOTIVE.md) |
106
+ | Redundant-execution verification (`spatial verify`, not cryptographic, see limits) | first components | `tests/test_verify.py`, [docs/VERIFY.md](docs/VERIFY.md) |
106
107
  | AI, Intelligence | first components (toy model) | `tests/test_engines.py`, `tests/test_domains.py` |
107
108
 
108
109
  Measured on the reference machine (AC power): Numba JIT ×31.6 over pure Python with an identical result; 0.88 s to boot an isolated Linux micro-VM on macOS; −75 % local RAM for a skewed-access dataset at 107× the mean access latency. Full table and conditions: [docs/RESULTATS.fr.md](docs/RESULTATS.fr.md).
@@ -77,6 +77,7 @@ st.put(0, b"..." * 1000); st.get(0); print(st.stats())
77
77
  | Portable kernels (one source, CPU/Metal/CUDA/HIP/Triton; market-vertical presets) | first components | `tests/test_kernel.py`, `benchmarks/bench_kernel.py` |
78
78
  | Live GPU market prices (`spatial market`, read-only, no account) | first components | `tests/test_market.py`, [docs/MARKET.md](docs/MARKET.md) |
79
79
  | In-vehicle multi-chip placement (`spatial automotive`, declared chip specs, no real silicon) | first components | `tests/test_automotive.py`, [docs/AUTOMOTIVE.md](docs/AUTOMOTIVE.md) |
80
+ | Redundant-execution verification (`spatial verify`, not cryptographic, see limits) | first components | `tests/test_verify.py`, [docs/VERIFY.md](docs/VERIFY.md) |
80
81
  | AI, Intelligence | first components (toy model) | `tests/test_engines.py`, `tests/test_domains.py` |
81
82
 
82
83
  Measured on the reference machine (AC power): Numba JIT ×31.6 over pure Python with an identical result; 0.88 s to boot an isolated Linux micro-VM on macOS; −75 % local RAM for a skewed-access dataset at 107× the mean access latency. Full table and conditions: [docs/RESULTATS.fr.md](docs/RESULTATS.fr.md).
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "spatial-computing"
7
- version = "0.28.0"
7
+ version = "0.29.0"
8
8
  description = "Spatial Computing: open-source infrastructure efficiency toolkit. Measure, decide, prove (compute, tiered memory, runtime routing, fleet)"
9
9
  readme = "README.md"
10
10
  license = "Apache-2.0"
@@ -3,4 +3,4 @@
3
3
  Status of every engine is declared in spatial.core.registry and must be backed
4
4
  by a test or benchmark before being set to OPERATIONAL.
5
5
  """
6
- __version__ = "0.28.0"
6
+ __version__ = "0.29.0"
@@ -293,6 +293,25 @@ def cmd_automotive(a):
293
293
  return 0
294
294
 
295
295
 
296
+ def cmd_verify(a):
297
+ from .kernel.library import LIBRARY
298
+ from .verify import VerificationError, verify_kernel
299
+ kernel = LIBRARY[a.family]
300
+ params = json.loads(a.params)
301
+ devices = a.devices.split(",")
302
+ try:
303
+ c = verify_kernel(kernel, devices, a.n, tolerance=a.tolerance, exact=a.exact, **params)
304
+ except VerificationError as e:
305
+ print(f"spatial: {e}", file=sys.stderr)
306
+ return 1
307
+ print(f"{'AGREE' if c.agreed else 'DISAGREE'}: {c.n_results} results ({', '.join(devices)}), "
308
+ f"max abs diff {c.max_abs_diff:g} -- {c.reason}")
309
+ if not c.agreed:
310
+ print("spatial: redundant execution did not agree; do not trust this result", file=sys.stderr)
311
+ return 1
312
+ return 0
313
+
314
+
296
315
  def cmd_token(a):
297
316
  from .core import auth
298
317
  if a.action == "init":
@@ -376,6 +395,14 @@ def main(argv=None):
376
395
  p = sub.add_parser("automotive", help="place a task graph on a declared in-vehicle chip catalogue (software only, no real automotive silicon here)")
377
396
  p.add_argument("--file", required=True, help="JSON: {\"chips\":[{\"name\",\"flops_per_s\",\"power_w\",\"supports_npu\"}], \"tasks\":[{\"name\",\"flops\",\"needs_npu\",\"after\"}]}")
378
397
  p.set_defaults(fn=cmd_automotive)
398
+ p = sub.add_parser("verify", help="redundant-execution check: run a kernel on 2+ devices and compare (not cryptographic proof, see docs/VERIFY.md)")
399
+ p.add_argument("--family", default="batch_score", choices=["mandelbrot", "collatz", "waves", "batch_score"])
400
+ p.add_argument("--n", type=int, default=64)
401
+ p.add_argument("--params", default="{}", help="JSON kernel parameters, e.g. '{\"signals\":16}'")
402
+ p.add_argument("--devices", default="cpu,metal", help="comma list, e.g. cpu,metal")
403
+ p.add_argument("--tolerance", type=float, default=0.0, help="max absolute difference allowed (ignored if --exact)")
404
+ p.add_argument("--exact", action="store_true", help="require a bit-exact match (integer kernels)")
405
+ p.set_defaults(fn=cmd_verify)
379
406
  p = sub.add_parser("agent", help="run a fleet agent: measure this machine, report to a hub, run allow-listed tasks")
380
407
  p.add_argument("--hub", required=True, help="host:port of the hub")
381
408
  p.add_argument("--token-file", required=True, help="shared secret file, or a scoped token with fleet:report,fleet:work")
@@ -0,0 +1,5 @@
1
+ """Redundant-execution verification. See spatial.verify.consensus."""
2
+
3
+ from .consensus import Consensus, VerificationError, consensus, verify_kernel
4
+
5
+ __all__ = ["Consensus", "VerificationError", "consensus", "verify_kernel"]
@@ -0,0 +1,72 @@
1
+ """Redundant-execution verification: trust a result only if an independent second execution
2
+ agrees. The same comparison this project already made ad hoc between CPU and Metal kernel
3
+ output (tests/test_kernel.py), made into a reusable, documented primitive instead of a
4
+ one-off test.
5
+
6
+ Not cryptographic proof: no zkML, no TEE attestation. It is the cheap, economical check 2026
7
+ production systems actually use for decentralized/untrusted GPU markets -- redundant execution
8
+ or spot-check agreement, not a proof of correct floating-point GPU execution (see
9
+ docs/VERIFY.md for what this does and does not prove, and why).
10
+
11
+ No network calls here, no rented hardware, no money spent: this module only compares results
12
+ you already have. Actually renting two independent untrusted providers (e.g. two different
13
+ Vast.ai listings) and running a job on each is a separate, later, money-spending step that
14
+ needs explicit go-ahead each time -- same boundary as spatial.market's read-only pricing.
15
+ """
16
+
17
+ from dataclasses import dataclass
18
+
19
+ import numpy as np
20
+
21
+
22
+ class VerificationError(Exception):
23
+ pass
24
+
25
+
26
+ @dataclass(frozen=True)
27
+ class Consensus:
28
+ agreed: bool
29
+ max_abs_diff: float
30
+ n_results: int
31
+ reason: str
32
+
33
+
34
+ def consensus(results, *, tolerance: float = 0.0, exact: bool = False) -> Consensus:
35
+ """Compare 2+ independent results for the same job.
36
+
37
+ exact=True: every value must match bit-for-bit (integer/deterministic kernels); tolerance
38
+ is ignored. exact=False: the largest absolute difference across all pairs must be <=
39
+ tolerance (float kernels, which legitimately differ in the last bits between devices).
40
+
41
+ Raises VerificationError for fewer than 2 results or results of different shapes -- there
42
+ is nothing to verify by redundancy with only one result."""
43
+ if len(results) < 2:
44
+ raise VerificationError("need at least 2 independent results to verify by redundancy")
45
+ arrays = [np.asarray(r) for r in results]
46
+ shape = arrays[0].shape
47
+ for a in arrays[1:]:
48
+ if a.shape != shape:
49
+ raise VerificationError(f"shape mismatch: {shape} vs {a.shape}")
50
+ ref = arrays[0]
51
+ max_diff = 0.0
52
+ for a in arrays[1:]:
53
+ if exact:
54
+ if not np.array_equal(ref, a):
55
+ diff = np.abs(ref.astype(np.int64) - a.astype(np.int64))
56
+ return Consensus(False, float(diff.max()), len(results), "exact match required, results differ")
57
+ else:
58
+ diff = np.abs(ref.astype(np.float64) - a.astype(np.float64))
59
+ d = float(diff.max())
60
+ max_diff = max(max_diff, d)
61
+ if d > tolerance:
62
+ return Consensus(False, d, len(results), f"max absolute difference {d:g} exceeds tolerance {tolerance:g}")
63
+ return Consensus(True, max_diff, len(results), "bit-exact match" if exact else "agreement within tolerance")
64
+
65
+
66
+ def verify_kernel(kernel, devices, n: int, *, tolerance: float = 0.0, exact: bool = False, **params) -> Consensus:
67
+ """Run the same portable kernel on 2+ devices (e.g. ("cpu", "metal")) and check the results
68
+ agree. This is what redundant-execution verification looks like when the two independent
69
+ executions are two of this project's own devices rather than two rented, untrusted ones --
70
+ the only thing actually measurable here (no second machine to rent)."""
71
+ results = [kernel.run(d, n, **params) for d in devices]
72
+ return consensus(results, tolerance=tolerance, exact=exact)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: spatial-computing
3
- Version: 0.28.0
3
+ Version: 0.29.0
4
4
  Summary: Spatial Computing: open-source infrastructure efficiency toolkit. Measure, decide, prove (compute, tiered memory, runtime routing, fleet)
5
5
  Author: Spatial Computing contributors
6
6
  License-Expression: Apache-2.0
@@ -103,6 +103,7 @@ st.put(0, b"..." * 1000); st.get(0); print(st.stats())
103
103
  | Portable kernels (one source, CPU/Metal/CUDA/HIP/Triton; market-vertical presets) | first components | `tests/test_kernel.py`, `benchmarks/bench_kernel.py` |
104
104
  | Live GPU market prices (`spatial market`, read-only, no account) | first components | `tests/test_market.py`, [docs/MARKET.md](docs/MARKET.md) |
105
105
  | In-vehicle multi-chip placement (`spatial automotive`, declared chip specs, no real silicon) | first components | `tests/test_automotive.py`, [docs/AUTOMOTIVE.md](docs/AUTOMOTIVE.md) |
106
+ | Redundant-execution verification (`spatial verify`, not cryptographic, see limits) | first components | `tests/test_verify.py`, [docs/VERIFY.md](docs/VERIFY.md) |
106
107
  | AI, Intelligence | first components (toy model) | `tests/test_engines.py`, `tests/test_domains.py` |
107
108
 
108
109
  Measured on the reference machine (AC power): Numba JIT ×31.6 over pure Python with an identical result; 0.88 s to boot an isolated Linux micro-VM on macOS; −75 % local RAM for a skewed-access dataset at 107× the mean access latency. Full table and conditions: [docs/RESULTATS.fr.md](docs/RESULTATS.fr.md).
@@ -94,6 +94,8 @@ spatial/unified/__init__.py
94
94
  spatial/unified/model.py
95
95
  spatial/unified/planner.py
96
96
  spatial/unified/providers.py
97
+ spatial/verify/__init__.py
98
+ spatial/verify/consensus.py
97
99
  spatial_computing.egg-info/PKG-INFO
98
100
  spatial_computing.egg-info/SOURCES.txt
99
101
  spatial_computing.egg-info/dependency_links.txt
@@ -125,4 +127,5 @@ tests/test_sso.py
125
127
  tests/test_unified.py
126
128
  tests/test_v02.py
127
129
  tests/test_v03.py
128
- tests/test_v05.py
130
+ tests/test_v05.py
131
+ tests/test_verify.py
@@ -0,0 +1,103 @@
1
+ """Redundant-execution verification: trust a result only if an independent second execution agrees."""
2
+ import numpy as np
3
+ import pytest
4
+
5
+ from spatial.fabric import metal
6
+ from spatial.kernel.library import batch_score, collatz, mandelbrot
7
+ from spatial.verify import VerificationError, consensus, verify_kernel
8
+
9
+ needs_metal = pytest.mark.skipif(not metal.available(), reason="no Metal")
10
+
11
+
12
+ def test_two_identical_results_agree_exact():
13
+ a = np.array([[1, 2], [3, 4]], dtype="uint32")
14
+ b = a.copy()
15
+ c = consensus([a, b], exact=True)
16
+ assert c.agreed and c.max_abs_diff == 0.0 and c.n_results == 2
17
+
18
+
19
+ def test_two_differing_results_disagree_exact():
20
+ a = np.array([[1, 2], [3, 4]], dtype="uint32")
21
+ b = np.array([[1, 2], [3, 99]], dtype="uint32")
22
+ c = consensus([a, b], exact=True)
23
+ assert not c.agreed and c.max_abs_diff == 95.0
24
+ assert "differ" in c.reason
25
+
26
+
27
+ def test_float_results_within_tolerance_agree():
28
+ a = np.array([1.0, 2.0, 3.0])
29
+ b = np.array([1.0, 2.0, 3.04])
30
+ c = consensus([a, b], tolerance=0.05)
31
+ assert c.agreed and c.max_abs_diff == pytest.approx(0.04)
32
+
33
+
34
+ def test_float_results_outside_tolerance_disagree():
35
+ a = np.array([1.0, 2.0, 3.0])
36
+ b = np.array([1.0, 2.0, 3.5])
37
+ c = consensus([a, b], tolerance=0.05)
38
+ assert not c.agreed and "exceeds tolerance" in c.reason
39
+
40
+
41
+ def test_three_results_checked_pairwise_against_the_first():
42
+ a = np.array([1, 2, 3])
43
+ b = np.array([1, 2, 3])
44
+ bad = np.array([1, 2, 4])
45
+ assert consensus([a, b, b], exact=True).agreed
46
+ assert not consensus([a, b, bad], exact=True).agreed
47
+
48
+
49
+ def test_single_result_raises():
50
+ with pytest.raises(VerificationError, match="at least 2"):
51
+ consensus([np.array([1, 2])])
52
+
53
+
54
+ def test_shape_mismatch_raises():
55
+ with pytest.raises(VerificationError, match="shape mismatch"):
56
+ consensus([np.array([1, 2]), np.array([1, 2, 3])])
57
+
58
+
59
+ def test_verify_kernel_cpu_against_itself_agrees_exact():
60
+ c = verify_kernel(collatz, ("cpu", "cpu"), 8, exact=True, limit=100)
61
+ assert c.agreed and c.n_results == 2
62
+
63
+
64
+ @needs_metal
65
+ def test_verify_kernel_cpu_vs_metal_integer_kernel_agrees_exact():
66
+ c = verify_kernel(collatz, ("cpu", "metal"), 64, exact=True, limit=300)
67
+ assert c.agreed
68
+
69
+
70
+ @needs_metal
71
+ def test_verify_kernel_cpu_vs_metal_float_kernel_agrees_within_tolerance():
72
+ c = verify_kernel(mandelbrot, ("cpu", "metal"), 128, tolerance=50, iters=100)
73
+ assert c.agreed
74
+ c2 = verify_kernel(batch_score, ("cpu", "metal"), 64, tolerance=5, signals=16)
75
+ assert c2.agreed
76
+
77
+
78
+ def test_cli_verify_runs(capsys):
79
+ from spatial.cli import main
80
+ assert main(["verify", "--family", "collatz", "--n", "8", "--devices", "cpu,cpu", "--exact", "--params", '{"limit":100}']) == 0
81
+ out = capsys.readouterr().out
82
+ assert "AGREE" in out
83
+
84
+
85
+ def test_cli_verify_disagree_exits_nonzero(capsys, monkeypatch):
86
+ import spatial.kernel.library as lib
87
+ from spatial.kernel.dsl import Kernel
88
+
89
+ calls = {"n": 0}
90
+ real_run = lib.collatz.run
91
+
92
+ def fake_run(device, n, **params):
93
+ calls["n"] += 1
94
+ out = real_run(device, n, **params)
95
+ if calls["n"] == 2:
96
+ out = out.copy()
97
+ out[0, 0] += 1
98
+ return out
99
+
100
+ monkeypatch.setattr(lib.collatz, "run", fake_run)
101
+ from spatial.cli import main
102
+ assert main(["verify", "--family", "collatz", "--n", "8", "--devices", "cpu,cpu", "--exact", "--params", '{"limit":100}']) == 1
103
+ assert "DISAGREE" in capsys.readouterr().out