#!/usr/bin/env python3
"""
DFD v4.0 "Golden Master" -- ONE-COMMAND REPRODUCTION
====================================================

    python3 reproduce.py

That is the whole quickstart. No installation is required for the core suite
(pure Python standard library). One optional dependency unlocks the live
cosmology gate:

    pip install camb        # optional: live sigma_8 / S_8 forward computation

WHAT RUNS
---------
The Golden Master gate suite (golden_master_gates.py), a set of REAL
recomputations -- not table lookups -- of the paper's headline numbers, each
checked against the value printed in the paper:

  0. alpha^-1 = 137.03599985 from the closed-form spectral truncation at
     k_max = 60 (0.0056 ppm from CODATA; neighboring rungs miss by ~1.7%).
  1. chi dark-matter modular measure, 8 internal gates: Omega_chi h^2 = 0.1182
     from the finite SU(2) level-60 Chern-Simons modular data, including the
     T^a S T^b presentation-invariance check, a real colored-Jones (Habiro)
     trefoil rival computation, and the meridian rival exclusion.
  2. H0 = alpha^28.5 / t_P = 72.0897 km/s/Mpc from CODATA constants alone
     (zero cosmological inputs).
  3. The locked CKM chain: |V_cb| = 108*31^2*alpha^3 = 0.04033,
     |V_td/V_ts| = 0.2109, DeltaM_s/DeltaM_d = 33.3 at FLAG xi = 1.206.
  4. The eps_K chain: (1.93-1.95)e-3 vs the measured 2.228e-3, reproducing the
     paper's honestly-booked -13% inherited-|V_cb| deficit (a deficit the
     theory cannot tune away -- printed as such).
  5. sigma_8 = 0.8193 / S_8 = 0.7843 by a live CAMB forward run at the DFD
     canonical parameter set (H0 = 72.09, Omega_chi h^2 = 0.11985, n_s = 0.9667,
     A_s = 32*pi*alpha^5). If CAMB is not installed this gate reports the
     recorded digit-reproduced value and says so explicitly.

Exit code 0 if and only if all gates pass.

GOING DEEPER
------------
  README_VERIFICATION.md          referee-oriented map of the full package:
                                  every script, what it prints, what passes
                                  cleanly, and which results carry caveats
                                  (flagged in bold, not papered over).
  DFD_CLASS_verification/         the CAMB-based DFD cosmology engine: CMB TT
                                  spectrum, matter power, BAO ladder,
                                  theta_star, lensing, joint likelihoods.
  head_to_head_pipeline/          DFD-vs-LCDM head-to-head comparison pipeline
                                  (run reproduce.py inside that directory).
  chi_verification/               the chi = 5.09 eV dark-sector derivation
                                  checks; dark_sector_verification/ likewise.
  scripts/, figures/              paper figure generation.

REBUILDING THE PAPERS
---------------------
  pdflatex main.tex && bibtex main && pdflatex main.tex && pdflatex main.tex
  pdflatex DFD_Extended_Derivations.tex && pdflatex DFD_Extended_Derivations.tex

  Both volumes build independently, in any order: the Extended volume carries a
  baked-in snapshot of its 28 cross-volume reference targets in its preamble,
  so no auxiliary files are needed.
"""
import os
import subprocess
import sys

HERE = os.path.dirname(os.path.abspath(__file__))

def main():
    print(__doc__.split("WHAT RUNS")[0])
    if sys.version_info < (3, 8):
        print("Python >= 3.8 required (found %s).  Aborting." % sys.version.split()[0])
        return 2
    missing = [f for f in ("golden_master_gates.py", "chi_modular_measure.py")
               if not os.path.exists(os.path.join(HERE, f))]
    if missing:
        print("SETUP PROBLEM (not a physics failure): missing %s." % ", ".join(missing))
        print("This script is the entry point of the full package and runs its gate")
        print("suite from sibling scripts in the same folder. Extract the complete")
        print("zip and run  python3 reproduce.py  from the extracted package folder.")
        return 3
    try:
        import camb  # noqa: F401
        print("[env] CAMB detected -- gate 5 will run the live forward computation.\n")
    except ImportError:
        print("[env] CAMB not installed -- gate 5 will cite the recorded value.")
        print("      (pip install camb  to unlock the live run; everything else is stdlib.)\n")
    rc = subprocess.call([sys.executable, os.path.join(HERE, "golden_master_gates.py")])
    print()
    if rc == 0:
        print("ALL GATES PASS.")
        print()
        print("These six gates are the sixty-second handshake. The full computation")
        print("behind each one is in this package -- to go deeper:")
        print()
        print("  python3 chi_modular_measure.py      full chi dark-matter chain: modular")
        print("                                      data, 8 internal gates, rival exclusions")
        print("  less golden_master_gates.py         every gate formula, readable inline")
        print("  README_VERIFICATION.md              referee map: every script, what it")
        print("                                      prints, which results carry caveats")
        print("  DFD_CLASS_verification/             cosmology engine: CMB TT, BAO, theta*,")
        print("                                      lensing, joint likelihoods (~50 scripts)")
        print("  head_to_head_pipeline/              DFD-vs-LCDM full likelihood comparison")
        print("  DFD_CLASS_verification/trials_factor_2026-07/")
        print("                                      the look-elsewhere/trials-factor audit")
        print("  supplement/                         lattice-QCD program: source, runs, logs")
        print()
        print("Every number above traces to a numbered theorem in DFD_Main.pdf.")
    else:
        print("ONE OR MORE GATES FAILED -- the output above pinpoints the discrepancy.")
        print("Please report it: that is exactly what this package is for.")
    return rc

if __name__ == "__main__":
    sys.exit(main())
