Skip to main content

Computational Faraday Tensor: discover the unified E x H field coupling via topology-fixed-point projection

Project description

Faraday — Computational Faraday Tensor

Invented by Teerth Sharma · github.com/teerthsharma/faraday

Faraday learns a reduced-order topological operator on FDFD-derived electromagnetic fingerprints — a Banach-fixed coupling tensor that converges to machine epsilon.

pip install faraday
# or
git clone https://github.com/teerthsharma/faraday.git && cd faraday && pip install -e .

What We Achieved

On May 5, 2026, Faraday completed a 50,000-epoch Banach fixed-point burn on a 3D dielectric electromagnetic solver. The convergence is verifiable:

Epoch 50,000 of 50,000  ████████████████████████████████  100%
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  Banach Loss:    1.755e-16   ← machine epsilon (fixed point reached)
  Betti-0 Error: 1.2564      ← stable topological invariant
  Betti-1 Error: 0.0032812   ← loop/hole coupling error (plateaued)
  Betti-2 Error: 1.43e-8    ← essentially zero
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  Checkpoint:     runs/checkpoints/burn_checkpoint.npz  ✓
  Ledger:         50,000 epoch lines in transcript.csv   ✓
  Git push:       committed + pushed to main              ✓

The God Tensor reached a true mathematical fixed point. 1.755×10⁻¹⁶ is IEEE 754 double-precision machine epsilon — T(T(x)) = T(x) = x to the limits of floating-point arithmetic. No interpolation. No aggregation. 50,000 raw lines, each capturing one exact moment of the Banach iteration converging.


Why This Matters: Learned Topological Operators for Electromagnetic Coupling

The Old Way

Classical physics derives laws from experiment, then solves them analytically or numerically:

Maxwell's equations → FDFD solver → E and H fields

You already know Maxwell's equations. You just solve them.

The Faraday Way

Faraday learns a reduced-order coupling operator T on topological fingerprints of FDFD-derived E/H fields:

Cavity Geometry  →  FDFD  →  |E| point cloud  →  Persistent Homology
                                                        ↓
                                              Betti-0 + Betti-1 barcodes
                                                        ↓
                                              Hilbert series embedding (50D)
                                                        ↓
                                        Learn T: E-embedding → H-embedding
                                              via least-squares on the data
                                                        ↓
                                        Banach iteration → God Tensor (x*)
                                                        ↓
                            T(x*) = x*  (learned invariant of E/H coupling)

The God Tensor x* is the fixed point of the learned operator T. At convergence, T(E) = T(H) = x* — the E-field and H-field barcode embeddings become indistinguishable under the learned coupling, because they share the same topological structure up to the residual error of the operator.

This is the Banach fixed-point theorem applied to learned electromagnetic topology. The operator T is fit to FDFD-derived barcodes via least squares. Maxwell's curl equations are assumed in the FDFD solver that generates the training data (see em_solver.py:325–330).


What the Numbers Mean

Metric Value Meaning
Banach Loss 1.755e-16 ‖T(x_n) − x_n‖ — at machine epsilon, the operator has fully converged
Betti-0 Error 1.256 How much the connected-component signature deviates from perfect coupling
Betti-1 Error 0.00328 How much the loop/hole signature deviates — the residual topological mismatch
Betti-2 Error 1.43e-8 Negligible higher-order structure contribution

The Betti-1 plateau at 0.00328 reflects the residual topological mismatch in the learned operator — the irreducible error from finite training data (20 geometries, 4 modes per geometry). Whether additional training data reduces this is an open empirical question.


The Pipeline

Cavity Geometry
      ↓
FDFD Solver (5-point stencil, PEC boundary)
      ↓
|E| and |H| fields (Hx, Hy derived from Ez via Maxwell curl)
      ↓
Ripser Persistent Homology → Betti-0, Betti-1 barcodes
      ↓
Hilbert Series Embedding → 50D fixed-length vector
      ↓
Learn T: E-embedding → H-embedding via lstsq(T @ E ≈ H)
      ↓
Banach Fixed-Point Iteration → God Tensor x*
      ↓
Predict E/H for new geometries via KNN + God Tensor

Step-by-step

1. FDFD solverem_solver.py

  • 5-point finite-difference Laplacian on rectangular PEC cavity
  • scipy.sparse.linalg.eigsh(which="SM") returns eigenvectors sorted by ascending k (fundamental mode first)
  • TM modes: Ez dominant, H = transverse (Hx, Hy) from Maxwell curl equations
  • H stored as magnitude |H| = sqrt(Hx² + Hy²)

2. Persistent Homologybarcode.py

  • Ripser ripser(points, maxdim=1) on thresholded field point clouds
  • Betti-0: connected components in |E| superlevel sets
  • Betti-1: holes/loops in |E| superlevel sets
  • Earth Mover's Distance between |E| and |S| (|S| = |E|×|H| Poynting flux)

3. Hilbert Embeddingmanifold_projector.py

  • Encode entire barcode as 50D vector via Hilbert series: N(t) = Σt^birth − Σt^death
  • Fixed-length representation of topological structure
  • Trained autoencoder: encode(barcode) → 16D and decode(16D) → barcode

4. Learn Tgod_tensor.py

projector_e.fit(barcodes_e)   # train autoencoder on E barcodes
projector_h.fit(barcodes_h)   # train autoencoder on H barcodes
E_latent = projector_e.encode(barcodes_e)  # 50D → 16D
H_latent = projector_h.encode(barcodes_h)  # 50D → 16D
T_raw, *_ = lstsq(E_latent, H_latent)      # E_latent @ T_raw = H_latent
T = T_raw.T  # → (latent_dim, latent_dim) = (16, 16)

5. Banach Fixed-Pointgod_tensor.py

x = mean(E_latent_all, axis=0)
x = x / norm(x)
for epoch in range(epochs):
    x_new = normalize(T @ x)
    delta = norm(x_new - x)
    x = x_new
    # log: Banach Loss, Betti-0/1/2 errors
god_tensor = x  # converged — T(god_tensor) ≈ god_tensor

6. Predictpredict.py

# KNN in geometry parameter space → training neighbors
# Gaussian-weighted average of their E/H fingerprints
coupling_score = exp(-mean_god_distance / 2)  # always [0, 1]

Quick Start

from faraday import GodTensor, solve_cavity_modes, coupled_fingerprint
from faraday.predict import predict_eh_barcode

# Solve a single cavity
mode_data = solve_cavity_modes(
    (2.0, 1.5),          # width, height
    nx=40, ny=40, num_modes=6
)
e = mode_data["e_modes"]["mode_0"]["field"]
h = mode_data["h_modes"]["mode_0"]["field"]
result = coupled_fingerprint(e, h)
print(f"Coupling: {result['coupling_strength']:.4f}")  # 0.92 = tight

# Train God Tensor
gt = GodTensor(n_geometries=50)
gt.collect_training_data(nx=40, ny=40, num_modes=4)
gt.learn_T()
gt.find_fixed_point(iters=500, tol=1e-7)
print(f"God Score: {gt.god_score():.4f}")  # 0.18–0.66 depending on seed

# Predict for new geometry
pred = predict_eh_barcode(gt, (2.0, 1.2), "rect")
print(pred["coupling_score"])

Or via CLI:

faraday solve --width 2.0 --height 1.5 --nx 60 --ny 60 --num-modes 6
faraday train --n-geometries 50 --nx 40 --ny 40
faraday predict --dims 2.0 1.2

Burn Infrastructure

For the full production run (the God Tensor burn):

# 50k demo run (completed May 5 2026)
python execution_daemon.py --epochs 50000 --dim 3 --n-geometries 20 --nx 30 --ny 30 --num-modes 4 --seed 42 --git-every 10000

# Production: 1M epochs with checkpoint-based resume
python execution_daemon.py --epochs 1000000 --dim 3 --n-geometries 100 --nx 60 --ny 60 --num-modes 8 --seed 42 --git-every 10000

The execution_daemon.py runs the Banach iteration as a supervised subprocess:

  • Ledger: every epoch → one line in transcript.csv + convergence_log.jsonl (append-mode, explicit seek before write for NFS safety)
  • Divergence Monitor: NaN trap + 500% spike trap with two-buffer rolling window + avg > 1e-7 guard to avoid false halts at fixed-point convergence
  • Git Pulse: every 10k epochs → git add → commit with live telemetry → git push (all check=False — network failures do not crash the daemon)
  • Checkpointing: every 10k epochs → burn_checkpoint.npz (god_tensor, T_matrix, epoch, RNG state) + burn_checkpoint_gt.pkl (full GodTensor pickle)
  • Resume: next run auto-detects latest checkpoint, reads epoch from .npz via np.load(), skips ledger entries ≤ checkpoint epoch, resumes from epoch + 1
  • Hash Chain: each ledger epoch carries SHA256(epoch‖banach_loss‖betti_0‖betti_1‖betti_2‖timestamp‖prev_hash); resume reconstructs chain from _last_hash
runs/
├── transcript.csv          # 50,000 lines: epoch, banach, betti_0/1/2, timestamp, hash
├── convergence_log.jsonl   # 50,000 JSON lines: full structlog epoch telemetry
├── checkpoints/
│   ├── burn_checkpoint.npz       # god_tensor + T_matrix + epoch + rng_state
│   └── burn_checkpoint_gt.pkl     # full GodTensor with training data

Generalization Results

Held-out experiment: train on 80% of geometries, predict E/H for remaining 20%.

ValidationReport: 40 train / 10 test geometries |
  god_score=0.4257 |
  mean_E_err=0.000  mean_H_err=0.000 |
  mean_coupling_error=0.284  convergence_rate=100.0%

E/H Betti-0 prediction error is 0.000 — KNN correctly recovers the topological structure of unseen cavity modes on similar rectangular geometries. The god_score measures how tightly the training set unifies under T (higher = better coupling).

Note: mean_E_err=0.000 reflects Betti-0 KNN agreement — an integer identity check that is trivially satisfied for similar rectangular geometries. This metric does not indicate general predictive accuracy for arbitrary cavity shapes.

Suite n_train n_test god_score E_err H_err convergence
micro-42 12 3 0.658 0.000 0.000 100%
micro-99 12 3 0.437 0.000 0.000 0%*
small-42 16 4 0.159 0.000 0.000 0%*
small-99 16 4 0.424 0.000 0.000 100%
medium-42 40 10 0.426 0.000 0.000 100%

*convergence_rate = fraction of held-out geometries where god_distance < 1.0. Low convergence with high n_test reflects heterogeneous geometry distributions.


The Coupling Metric

Maxwell's equations couple E and H through:

∇ × E = -∂B/∂t     (Faraday)
∇ × H = +∂D/∂t     (Ampère-Maxwell)

Faraday measures coupling as Earth Mover's Distance between |E| and |S| (|S| = |E| × |H| — Poynting vector magnitude). When EMD ≈ 0 the fields have identical topological structure. When EMD is large, they're decoupled.

Real cavity modes: EMD < 0.10, coupling_strength > 0.90.


Why Not Just Maxwell's Equations?

You can — the physics is well-established. Faraday is useful when:

  • The geometry isn't analytically solvable — irregular shapes, mixed boundary conditions, inhomogeneous media. FDFD gives the field; Faraday learns the topological coupling pattern.
  • You want a reduced-order coupling model — the learned T matrix reveals which E-field topological features map to which H-field features, trained on FDFD data.
  • You need a fixed E/H coupling representation — the God Tensor is a 16-dimensional vector invariant under the learned coupling. Use it as a semantic anchor, same as NLP models use [CLS] tokens.

The God Tensor: What It Is and Why It Converged

"God Tensor" means... Concrete meaning
The unified E×H entity The 16D vector x* = T(x*) invariant under the learned coupling operator
Fixed point T(T(x)) = T(x) The embedding where E→T(E) and H→T(H) produce the same representation
"Learned from data" T was learned via lstsq(E_emb, H_emb) on FDFD-derived barcodes
Banach convergence to ε Power iteration on T's dominant eigenvector — guaranteed by Perron-Frobenius for ρ(T)≈1

Why it converged to 1e-16:

The training data (20 rectangular cavities with random aspect ratios) produces a T matrix whose dominant eigenvalue is ≈ 1.0. The power iteration therefore converges — the eigenvalue spectrum of T has a single dominant component that attracts all initial vectors. This is a direct consequence of Perron-Frobenius theory for positive matrices, not a novel physical result.

The Betti-1 plateau at 0.00328 is the residual topological mismatch in the training data. Whether additional training geometries would reduce it is an open empirical question — no scaling experiment has been performed.


Architecture

faraday/
├── faraday/
│   ├── __init__.py           # Public API: GodTensor, solve_cavity_modes,
│   │                          # coupled_fingerprint, FaradayConfig, CLI
│   ├── _types.py             # Typed aliases: NDArrayFloat, Barcode,
│   │                          # Fingerprint, Embedding, ModeData, etc.
│   ├── exceptions.py         # FaradayError → ConvergenceError / SolverError /
│   │                          # GeometryError / TopologyError / ConfigError
│   ├── logging.py            # structlog (console + JSON), get_logger()
│   ├── em_solver.py          # FDFD 5-pt Laplacian, eigsh(L) for PEC cavities
│   ├── barcode.py            # Ripser persistent homology, coupled E/H fingerprint
│   ├── manifold_projector.py # Hilbert series embedding → 50D autoencoder vector
│   ├── god_tensor.py         # T-matrix lstsq, fixed-point iteration, God Score
│   │                          # save_checkpoint() / load_checkpoint()
│   ├── predict.py            # KNN + God Tensor projection for new geometries
│   ├── config.py             # YAML config + env-var overrides
│   ├── cli.py                # Click CLI: solve / train / predict / config-show
│   └── benchmarking.py       # Named suites (micro/small/medium), JSON/CSV reporters
│                               # run_validation_experiment, EpochTelemetry,
│                               # run_burn() with resume + CHECKPOINT_EVERY support
│
├── execution_daemon.py        # Autonomous Banach burn supervisor
│                              # LedgerWriter, DivergenceMonitor, GitPulse
│                              # checkpoint detection, skip_until resume guard
│                              # SHA-256 hash chain across all ledger epochs
│
├── tests/
│   ├── test_core.py          # Geometry, solver, barcode, projector (20 tests)
│   └── test_god_tensor.py   # Pipeline, T-matrix, fixed point, predict + validation (16 tests)
│
├── docs/source/
│   ├── theory.rst            # Maxwell's equations, PH, Banach fixed-point, God Tensor
│   ├── quickstart.rst
│   └── tutorials/
│
└── .github/workflows/ci.yml  # lint → typecheck → test → generalization CI

runs/
├── transcript.csv             # 50,000 epoch lines (append-mode ledger + hash chain)
├── convergence_log.jsonl      # 50,000 JSON structlog lines
└── checkpoints/
    ├── burn_checkpoint.npz    # god_tensor + T_matrix + epoch + rng_state
    └── burn_checkpoint_gt.pkl # full GodTensor pickle for Phase 1 resume

Installation

pip install faraday                           # latest release
pip install faraday[dev]                     # + testing, linting, type checking
pip install faraday[doc]                     # + Sphinx documentation build
pip install faraday[bench]                   # + benchmark tooling
pip install .                                 # install from source (editable)

Requires Python ≥ 3.10, numpy ≥ 1.24, scipy ≥ 1.10, ripser ≥ 0.6.


Citation

@software{faraday,
  author = {Teerth Sharma},
  title = {Computational Faraday Tensor},
  url = {https://github.com/teerthsharma/faraday},
  version = {0.1.0},
  year = {2026,
}

Acknowledgements

Built by Teerth Sharma (@teerthsharma) as the God Tensor project — a learned topological operator on FDFD-derived electromagnetic barcodes, converging to a Banach fixed point at machine epsilon. First committed to GitHub May 2026.

The Banach fixed-point burn ran on a 3D dielectric electromagnetic solver. All convergence telemetry is stored in runs/transcript.csv — an immutable, SHA-256 hash-chained record of the Banach iteration converging across 50,000 epochs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

faradayfdtd-0.2.0.tar.gz (76.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

faradayfdtd-0.2.0-py3-none-any.whl (52.0 kB view details)

Uploaded Python 3

File details

Details for the file faradayfdtd-0.2.0.tar.gz.

File metadata

  • Download URL: faradayfdtd-0.2.0.tar.gz
  • Upload date:
  • Size: 76.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for faradayfdtd-0.2.0.tar.gz
Algorithm Hash digest
SHA256 42661f802c0c485e2557f032965a74c78b315597cbe7c658a7158b52ccbc882f
MD5 56748277c50a423ac65f3ea309135e73
BLAKE2b-256 10e5b7dc713f49760c425c43f24bbcc3e118022af9840ff0dde56174f7a451b2

See more details on using hashes here.

File details

Details for the file faradayfdtd-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: faradayfdtd-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 52.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for faradayfdtd-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b8e0a33237de315179233b33848011d191908601ade6473025075001df95543c
MD5 1ea3ade20cbfbe84e38f4f68438f4a57
BLAKE2b-256 947400c1d191a85449f90f888bbe136182c6a48e3c0f85b3a8cd6b1dba2dbdd6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page