Download src/verify_computation.py from PureOne/VSCE-Vacuum-State-Cognitive-Engineering-v6: direct link, hf CLI and curl.
- Browser
- Download file 4.24 kB
-
https://huggingface.co/datasets/PureOne/VSCE-Vacuum-State-Cognitive-Engineering-v6/resolve/main/src/verify_computation.py
- Command line
-
hf download hf://datasets/PureOne/VSCE-Vacuum-State-Cognitive-Engineering-v6/src/verify_computation.py
-
curl -L -o verify_computation.py https://huggingface.co/datasets/PureOne/VSCE-Vacuum-State-Cognitive-Engineering-v6/resolve/main/src/verify_computation.py
4.24 kB
| """Independent numerical sanity checks for the computation section. | |
| These verify specified finite-dimensional examples, not hardware or novelty. | |
| Run from any directory; output is written alongside this source. | |
| """ | |
| from pathlib import Path | |
| import json | |
| import math | |
| import numpy as np | |
| from scipy.integrate import quad | |
| def stable_f(u): | |
| if abs(u) < 1e-3: | |
| return sum((-1.0) ** k * u ** k / math.factorial(k) | |
| for k in range(2, 12)) | |
| return u + math.expm1(-u) | |
| def spectral_variance(lam, horizon, theta): | |
| return 2 * theta * stable_f(lam * horizon) / (horizon ** 2 * lam ** 3) | |
| cases = [] | |
| for lam in (0.01, 0.7, 1.0, 8.0): | |
| for horizon in (1e-3, 0.3, 10.0): | |
| theta = 0.4 | |
| formula = spectral_variance(lam, horizon, theta) | |
| integral = quad(lambda s: 2 * theta * (horizon - s) | |
| * math.exp(-lam * s) / (horizon ** 2 * lam), | |
| 0, horizon, epsabs=1e-12, epsrel=1e-11)[0] | |
| error = abs(formula - integral) / max(abs(integral), 1e-15) | |
| assert error < 1e-8, (lam, horizon, error) | |
| assert formula > 0 | |
| assert formula <= theta / lam * (1 + 1e-10) | |
| assert formula <= 2 * theta / (horizon * lam ** 2) * (1 + 1e-10) | |
| cases.append({"lambda": lam, "T": horizon, "theta": theta, | |
| "closed_form_variance": formula, | |
| "independent_quadrature_variance": integral, | |
| "relative_difference": error}) | |
| rng = np.random.default_rng(173) | |
| calibration = [] | |
| for d in (2, 5, 11): | |
| Q, _ = np.linalg.qr(rng.normal(size=(d, d))) | |
| A_half = Q @ np.diag(np.sqrt(np.geomspace(.08, 5, d))) @ Q.T | |
| A = A_half @ A_half | |
| R, _ = np.linalg.qr(rng.normal(size=(d, d))) | |
| eps = .08 | |
| E = R @ np.diag(np.linspace(-eps, eps, d)) @ R.T | |
| A_implemented = A + A_half @ E @ A_half | |
| covariance = np.linalg.inv(A_implemented) | |
| observed_error = np.linalg.norm(A_half @ covariance @ A_half | |
| - np.eye(d), ord=2) | |
| bound = eps / (1 - eps) | |
| assert observed_error <= bound * (1 + 1e-10) | |
| calibration.append({"dimension": d, "relative_perturbation_limit": eps, | |
| "whitened_covariance_error": observed_error, | |
| "bound": bound}) | |
| dephasing = [] | |
| for gamma_t in (.01, .1, 1, 10): | |
| observed = -math.expm1(-gamma_t) / 2 | |
| bound = min(1, gamma_t / 2) | |
| assert observed <= bound | |
| dephasing.append({"gamma_times_T": gamma_t, | |
| "plus_state_trace_distance": observed, | |
| "half_diamond_distance": observed, | |
| "generator_bound": bound, | |
| "braid_error": 0}) | |
| # sigma_1^2 has exponent sum two and hence is not the identity braid, | |
| # but its population endpoint permutation is exactly identity. | |
| labels = [0, 1] | |
| for _ in range(2): | |
| labels[0], labels[1] = labels[1], labels[0] | |
| assert labels == [0, 1] | |
| # Bit-flip channel: all errors point along the same channel difference, | |
| # so the input-independent mixture certificate is attained. | |
| p, delta = .1, .05 | |
| bitflip_error = p + (1 - p) * delta | |
| assert abs(bitflip_error - .145) < 1e-15 | |
| result = { | |
| "status": "passed", | |
| "scope": "finite-dimensional analytical examples and numerical quadrature", | |
| "hardware_claims": False, | |
| "novelty_claims": False, | |
| "stationary_averaging_cases": cases, | |
| "calibration_cases": calibration, | |
| "same_braid_dephasing_counterexamples": dephasing, | |
| "pure_braid_counterexample": {"word": "sigma_1^2", "exponent_sum": 2, | |
| "permutation": labels}, | |
| "mixture_tight_example": {"bad_event_probability": p, | |
| "good_channel_distance": delta, | |
| "actual_distance": bitflip_error, | |
| "certified_bound": bitflip_error}, | |
| } | |
| out = Path(__file__).resolve().parents[1] / "results" / "computation_verification.json" | |
| out.parent.mkdir(parents=True, exist_ok=True) | |
| out.write_text(json.dumps(result, indent=2) + "\n") | |
| print(f"Passed {len(cases)} quadrature comparisons, {len(calibration)} matrix " | |
| f"calibration cases, {len(dephasing)} coherence counterexamples; " | |
| "pure-braid and tight mixture examples.") | |