Skip to content
Compilers & AI Scheduling · Ecosystem Interop

External Interop & Ecosystem Integration

Weyl's build-vs-reuse philosophy, four-tier interop hierarchy, bridges to Mathematica/FORM/SymPy/GAP/QuSpin/Julia/SDPB, and the `External` source tag for external results.

Theoretical and computational physics already possess decades of battle-tested engines—FORM for external-memory term streams, GAP for finite-group character tables, msolve for modular Gröbner bases, QuSpin/XDiag for sparse diagonalization, ITensor/TeNPy for tensor networks, SDPB/Clarabel for semidefinite programming, and Lean 4 / Mathlib for formal proofs. Weyl refuses to reinvent these wheels, following a strict engineering rule: build only what does not exist elsewhere.

Weyl's irreplaceable core consists of just four bespoke components: the physics type system for statically checking statistics, conserved charges, irreps, and anyon condensation across arbitrary lattice sizes; error tags providing static and runtime propagation of truncation, extrapolation, and sampling errors; a general pCUT and multivariate cluster-expansion engine spanning coefficient recursion, state-filtered TnT_n action, and rational reconstruction; and independent oracles paired with sandboxed, zero-write-access MCP scheduling for LLMs. Every other algebraic or numerical engine is reused through a disciplined interoperability hierarchy.

Build-vs-Reuse Decision Matrix ​

The table below defines the boundary between Weyl's bespoke crates and mature ecosystem tools:

Weyl ModuleMature ImplementationsPhase 1 StrategyRe-evaluation Trigger
Term streams (weyl-cas)FORM, SymbolicaIn-memory hash merge + sorted output; defer external spillPeak RAM exceeds 50% of node budget
Modular lift (weyl-num)FiniteFlow, FireFlyCRT + a priori bound Wang lift; defer rational interpolationPhase 2 symbolic parameters
Pauli/Clifford (weyl-canonical)Stim, QuantumClifford.jlBit-packed symplectic tableau; cross-check against StimNever
ED oracle (weyl-oracle)QuSpin, XDiag, HΦIndependent stabilizer reduction; export reduced model for cross-checksWhen off-the-shelf ED lacks Dd or sector support
Finite groups (weyl-topo)GAP, SageMathOffline GAP JSON tables committed in-repo; verified in-kernelNever
Gröbner & proofsmsolve, Lean 4External process + exact verification in weyl-num / LeanNever
E-Graph & bigintegg, num-bigintDirect pure-Rust crate dependenciesEvaluate egglog in Phase 2

Four-Tier Interop Priority & License Isolation ​

To keep the compiler core 100% pure Rust (guaranteeing determinism, memory safety, and data-race freedom), Weyl integrates external software in four strict priority tiers—never dropping to a lower tier when a higher one suffices:

PriorityIntegration MechanismTarget EcosystemKey Benefits & Constraints
1 (Default)Emit data or scripts; run out-of-processFORM, GAP, msolve, SDPB, QuSpin, TeNPy, MathematicaZero link coupling, clean GPL/commercial isolation, auditable artifacts
2Stable C ABI (bindgen -sys / weyl-ffi)LAPACK, ARPACK, Julia ccall, ClarabelZero-copy array exchange without C++ ABI fragility
3PyO3 Python extension (cdylib)Python, NumPy, SciPy, SymPy, TeNPyExposes SeriesTable and LinearOperator natively
4 (Last resort)Safe cxx C++ bridgeITensor C++, Eigen, MLIR C++ APIStrictly for template-only C++ libraries; exceptions mapped to Result

License & Oracle-Independence Boundaries

Because FORM and GAP are GPL-licensed and Symbolica carries commercial restrictions, Weyl invokes them strictly as external processes or offline data generators—never linking them into weylc—keeping the main repository cleanly dual-licensed under Apache-2.0 / MIT. Equally important, exporting a reduced effective Hamiltonian to QuSpin or SciPy treats the external solver strictly as a second implementation with zero shared code along the pCUT path, while stabilizer reduction itself remains independently implemented inside weyl-oracle.

Symbolic Interop: Mathematica, FORM, SymPy & GAP ​

1. Mathematica, FORM & SymPy Expression Exchange ​

Weyl exports verified SeriesTable outputs (univariate or multivariate rational series) and SIR templates in standardized JSON and native CAS formats. When intermediate term streams exceed single-node RAM budgets, KIR streams can be emitted as canonical .frm scripts to cross-check against FORM's external-memory sort-merge engine, with the resulting outputs re-verified by weyl-num. For interactive analysis, Weyl also exports exact rational series (Rational[p, q] for Mathematica or sympy.Rational(p, q) for SymPy) alongside parameterized Hamiltonians so physicists can inspect analytic continuations, plot dispersions, or diff term-by-term against legacy notebooks.

bash
# Export verified multivariate series to SymPy, Mathematica, or JSON
$ weylc export-series examples/toric_boundary.weyl --format=sympy -o gap_series.py
$ weylc export-series examples/toric_boundary.weyl --format=mathematica -o gap_series.wl

The emitted gap_series.py preserves exact rational coefficients and error metadata for direct SymPy diffing:

python
from sympy import Rational, symbols
x, k1, k2 = symbols("x kappa1 kappa2")
# Emitted by weylc export-series (Trunc: Box(total_order=12), Epi: Exact)
gap_series = Rational(2, 1) - Rational(2, 1)*x - Rational(1, 2)*x**2 + Rational(3, 4)*x*k1

2. Finite Groups & Character Tables with GAP (weyl-topo) ​

For non-abelian quantum double models D(G)D(G) (such as S3,A4,DnS_3, A_4, D_n), group-theoretic data—conjugacy classes, centralizers, character tables, modular SS/TT matrices, and 3-cocycles ω∈H3(G,U(1))\omega \in H^3(G, U(1))—are designed to be generated offline by GAP as deterministic, versioned JSON tables committed alongside the repository rather than hand-reimplemented in Rust. Current status: no GAP tables are shipped yet; weyl-topo currently computes groups, character tables (Burnside–Dixon), H2(G,U(1))H^2(G, U(1)), and the D(G)D(G) data itself, while an unrun generator script resides at tools/gen_group_tables.g. Regardless of origin, weyl-topo never blindly trusts imported tables; it independently checks the defining algebraic identities over Q(ζn)\mathbb{Q}(\zeta_n):

S†S=I,(ST)3=S2=C,Nabc=∑dSadSbdScd∗S0d∈Z≥0S^\dagger S = I, \qquad (ST)^3 = S^2 = C, \qquad N_{ab}^c = \sum_d \frac{S_{ad} S_{bd} S_{cd}^*}{S_{0d}} \in \mathbb{Z}_{\ge 0}

Only tables passing exact verification are admitted into the Exact type-checking layer.

3. Gröbner Bases (msolve) & Formal Proofs (Lean 4) ​

Current status

msolve is not called. The solve statement runs on an in-process implementation in weyl-num (solve/modular.rs): Buchberger over Fp\mathbb{F}_p under every embedding of Q(ζn)\mathbb{Q}(\zeta_n), Vandermonde interpolation, CRT, and exact verification in Q(ζn)\mathbb{Q}(\zeta_n), with exact Buchberger as the fallback. Delegating the Fp\mathbb{F}_p step to msolve remains the plan for systems too large for that.

For Phase 2 polynomial system solving (solve for ... such that ...), Weyl passes linearly reduced modular ideals out-of-process to msolve to compute monic reduced Gröbner bases over Fp\mathbb{F}_p, lifts back to Q(ζn)\mathbb{Q}(\zeta_n) via Vandermonde interpolation and CRT, and verifies two-way ideal containment plus zero S-polynomial reduction inside weyl-num. Similarly, weyl-lean translates Weyl theorem goals into Lean 4 source files checked by an external lean process.

Numerical Interop: Python, Julia & weyl.ed-model ​

1. Exporting Reduced ED Models (weylc export-ed) ​

As implemented in weyl-oracle/src/export.rs, stabilizer reduction is Weyl's unique contribution, leaving behind a standard sparse eigenproblem. weylc export-ed serializes that reduced problem using the weyl.ed-model schema alongside a standalone NumPy/SciPy runner (solve_ed.py) ready for cross-checks in QuSpin, XDiag, or HΦ:

json
{
  "schema": "weyl.ed-model",
  "n_eff": 24,
  "constant": "-48/1",
  "z_terms": [
    { "mask": "0x3", "coeff": "-1/1" },
    { "mask": "0x6", "coeff": "-1/1" }
  ],
  "x_terms": [
    { "mask": "0x1", "coeff": "-1/10" },
    { "mask": "0x5", "coeff": "-1/20" }
  ],
  "sectors": [
    { "name": "vacuum", "momentum": "0", "dimension": 352, "expected": { "0": -24.18293104 } },
    { "name": "one-particle", "momentum": "pi", "dimension": 348, "expected": { "pi": -22.39104822 } }
  ]
}

2. Python (PyO3), C / Julia (C ABI) and C++ (cxx) in weyl-ffi ​

weyl-ffi is the thin interop layer. It builds as an rlib and a cdylib; no core crate depends on it, and everything that crosses it is a double: foreign code is a numerical back end or a second implementation for checks, never a source of exact values.

On the outbound side, the C ABI (include/weyl.h, libweyl_ffi.so) exposes the kernels produced by weylc dump-ir --emit tir-json behind a single opaque handle; functions return 0 or a negative WEYL_E_* status code, strings are released with weyl_string_free, no panic ever unwinds into the caller, and a C program compiled with -Wall -Wextra -Werror exercises the library in the test suite. Enabling the python feature builds a PyO3 extension exposing the weyl module—providing Kernels.from_json, eval, eval_at, apply, matrix, spectrum(index, backend), cross_check, and backends()—which can be loaded by linking or copying libweyl_ffi.so as weyl.so or building with maturin.

On the inbound side, the eigen feature wraps Eigen's SelfAdjointEigenSolver via cxx behind an opaque DenseSolver, declaring fallible functions with -> Result<_> so that C++ exceptions (such as std::invalid_argument for a non-symmetric matrix or std::out_of_range) arrive in Rust as Err rather than unwinding. Enabling the lapack feature calls LAPACK's dsyev through its Fortran ABI using declarations generated at build time by bindgen from cabi/lapack_abi.h.

The three eigensolvers (a Jacobi reference written in Rust, Eigen, LAPACK) are run against one another by cross_check; on the four-site transverse-field Ising kernel of the tests they agree to 10−1010^{-10}.

c
#include "weyl.h"

char *error = NULL;
weyl_kernels *ks = weyl_kernels_from_json(json, &error);     /* NULL + message on failure */
size_t n = weyl_kernel_size(ks, 1);                           /* dimension of a matvec kernel */
int rc = weyl_kernel_apply(ks, 1, input, output, n);          /* 0, or WEYL_E_LENGTH, … */
double e;  weyl_kernel_eval(ks, 0, 0.1, &e);                  /* a series at x = 0.1 */
weyl_kernels_free(ks);
julia
# The same library from Julia
ks = ccall((:weyl_kernels_from_json, "libweyl_ffi"), Ptr{Cvoid}, (Cstring, Ptr{Ptr{UInt8}}), json, C_NULL)
rc = ccall((:weyl_kernel_apply, "libweyl_ffi"), Cint,
           (Ptr{Cvoid}, Csize_t, Ptr{Float64}, Ptr{Float64}, Csize_t), ks, 1, x, y, length(x))

What weyl-ffi does not do

Kernels that ask for double-double precision are refused (WEYL_E_PRECISION); there is no scipy.sparse.linalg.LinearOperator wrapper, no ITensor binding, and no Arrow / HDF5 writer. The columnar schema below is the planned exchange format, not an implemented one. The features need Eigen's headers (WEYL_EIGEN_INCLUDE), liblapack and libclang (WEYL_LAPACK_LIB_DIR, LIBCLANG_PATH), and the Python development files.

Arrow / HDF5 Columnar Exchange Schema (planned) ​

To preserve exact rational precision and error-lattice metadata across Pandas, Polars, DataFrames.jl, and TeNPy pipelines, Weyl's columnar exports are to follow a fixed schema:

ColumnArrow / HDF5 TypeSemantics
observableUtf8Observable identifier (e.g. e0, gap_k_pi)
total_orderUInt32Total multivariate degree n=∑iein = \sum_i e_i
exponentsList<UInt16>Exponent vector [ex,eκ1,eκ2][e_x, e_{\kappa_1}, e_{\kappa_2}]
coeff_num / coeff_denUtf8Arbitrary-precision decimal numerator/denominator (no f64 loss)
coeff_f64Float64Convenience double-precision preview for plotting only
err_trunc / err_epiUtf8Serialized truncation and epistemic error-lattice tags

Quantum Bootstrap & SDP Solver Export (SDPB / Clarabel) Draft ​

In Phase 2/3 quantum many-body bootstrap workflows, Weyl's symbolic kernel constructs symmetry-block-diagonalized Hermitian positivity matrices M(c⃗)⪰0M(\vec{c}) \succeq 0 with exact rational coefficients, then exports TirKernel::SdpBlock to specialized semidefinite solvers. For high-precision (256–1024 bit) conformal and many-body bootstrap runs, Weyl emits standard Polynomial Matrix Program (PMP) JSON/XML inputs targeting arbitrary-precision SDPB, whereas Clarabel (via pure Rust or its C ABI) serves for fast double-precision prototyping and feasibility scans.

bash
# Export reduced ED model and run standalone NumPy/SciPy second-implementation check
$ weylc export-ed examples/toric_boundary.weyl --L=12 --W=2 --at x=1/10 -o ed_model.json
$ python3 solve_ed.py ed_model.json
[solve_ed] vacuum (k=0):       weyl=-24.1829310400  scipy=-24.1829310400  diff=1.1e-14  OK
[solve_ed] one-particle (k=π): weyl=-22.3910482200  scipy=-22.3910482200  diff=1.8e-14  OK

# Export quantum bootstrap positivity blocks to SDPB
$ weylc export-sdp examples/ising_bootstrap.weyl --solver=sdpb --precision=512 -o pmp.json
$ pmp2sdp --precision=512 -i pmp.json -o sdp_out && sdpb --precision=512 -s sdp_out

Source Tags for External Results Draft ​

Whenever an external tool's output enters a Weyl derivation, the compiler adds the source EpiSource::External(name) to its error tag. name is a string, usually the tool name, displayed as Epi{name}; versions, precision and other parameters are not part of the tag:

weyl
// SDPB bounds carry the External("sdpb") source and cannot be used as Exact
let lower_bound: Scalar<Epi{sdpb}> =
    import_sdpb("runs/ising_bootstrap/out.txt")

// Only results re-checked by Weyl's exact kernel are Exact
let verified_groebner: Ideal<Exact> =
    verify_groebner(import_msolve("runs/d_s3_boundary.ms"))

Provenance Invariants

External numerical results (from QuSpin, SciPy, ITensor, or SDPB) always carry an External source and may serve only as compare oracles, extrapolation inputs, or numerical bounds. External symbolic candidates (such as msolve Gröbner bases, GAP character tables, or FORM outputs) likewise enter as untrusted candidates and are promoted to Exact only after independent exact verification inside Weyl's trusted kernel.

Weyl v0.1 · MIT License