Downloads · 30 days
0
NeuralVerified/neural-photonic
neural-photonic is a machine learning model from NeuralVerified. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for pytorch. The card lists the license as mit.
Neural networks that emulate the operations of a hybrid photonic computer, built to the same exhaustive (N/N) verification discipline as NeuralVerified/neural-aarch64-units: every unit is a small neural net trained un…
Downloads · 30 days
0
Access
Public
Updated Jul 21, 2026
Repo size
1.1 MB
Likes
0
Public
Click a slice to open those files.
.pt1.1 MB · 92%
From the Hugging Face model README
Neural networks that emulate the operations of a hybrid photonic computer, built to the same exhaustive (N/N) verification discipline as NeuralVerified/neural-aarch64-units: every unit is a small neural net trained until it is bit-identical to a golden reference over its entire finite input domain.
Light does the linear algebra by interference; a neural CPU does everything passive light cannot (gain, bias, nonlinearity, integer readout).
Exhaustive (N/N) verification proves the discrete, quantized logic exactly and
fabrication-independently. Real analog photonic hardware is a regime that
cannot be exhaustively verified, so correctness there becomes a bounded-error /
yield claim. photonic/nonideal.py + robustness_demo.py model it:
process fidelity (thermal drift): sigma=0.02 -> 0.997 (100% yield); sigma=0.10 -> 0.93 (0% yield)
two-moons classifier: 99% on idealized HW -> 61% on real (noisy) HW
noise-aware training: recovers to 98% on real (noisy) HW
per-device calibration: fabrication fidelity 0.90 -> 1.0000; thermal floor 0.983
Non-idealities modeled: coupler split error + static phase offsets (fabrication),
thermal phase drift, detector responsivity + saturation, ADC gain/offset/
quantization/noise. Calibration tunes each device's control phases against its
fixed fab errors, recovering the deterministic loss to ~unity; thermal drift and
ADC noise are the irreducible floor. Run python robustness_demo.py. The
interactive version is in the companion Space (NeuralVerified/neural-photonic-hybrid,
"Hardware reality" section).
Exact where it can be proven (digital); error-bounded where it can't (analog); deterministic error is calibratable, random drift is the floor.
photonic/mzi.py, linear.py, and prism.py
model how light actually behaves — complex fields (amplitude + phase),
interference, Snell/Sellmeier dispersion. This produces the golden reference.MZI2.pt and PD.pt are bit-exact functional
replicas of quantized photonic operations — they reproduce the reference's
output exactly (verified N/N), they do not re-derive the physics. This is the
same sense in which a CPU emulator reproduces a datapath: exactly the framing
of the companion neural-aarch64 units.This repository packages the trained models (emulators) and the training + verification process. The interactive 3D demo lives in the companion Space.
| file | unit | maps | domain | verification |
|---|---|---|---|---|
MZI2.pt | Neural Photonic MZI | phase settings (4b θ, 4b φ) → quantized 2×2 interferometer matrix | 2⁸ = 256 | 256 / 256 bit-exact |
PD.pt | Neural Photodetector | complex field (5b re, 5b im) → intensity byte (learned |·|²) | 2¹⁰ = 1024 | 1024 / 1024 bit-exact |
cpu_units/ADC8.pt | 8-bit adder (from neural-aarch64-units, included for the hybrid) | a, b, carry → sum, flags | 2¹⁷ | N/N (see source repo) |
MZI2.pt and PD.pt are the two models trained here. ADC8.pt is reproduced
from the author's neural-aarch64-units
so the end-to-end hybrid is runnable in one place; all credit for it is there.
Forward light-transport renders of optical energy moving through the mesh —
produced by step6_demo.py (photonic/visualize.py), visualization only and
firewalled from the compute path.
Energy of a single injected beam as it propagates through the interferometer mesh. Each column is a mesh layer (light flows left→right), each row a waveguide mode; brightness is optical intensity. One input mode fans out across many — this spreading is interference performing a matrix multiply, the thing ray optics cannot represent.
The same forward-transport view for the optical core inside the trained hybrid network — the light path that feeds the neural photodetector and, in turn, the neural-CPU readout.
Photonic computing performs a matrix multiply with light: a mesh of Mach-Zehnder interferometers (MZIs) makes beams interfere, and the interference is the arithmetic. The catch is that the computation lives in the phase and amplitude of a coherent field — something geometric ray optics cannot represent. So the core of this project is an honest, complex-valued (wave-optics) model of an MZI mesh, then a path to make it verifiable the way a digital datapath is.
The bridge from "continuous physics" to "verifiable unit" is quantization: discretize the phase/amplitude controls to a finite grid, and the input domain becomes finite and enumerable — the precondition for exhaustive N/N verification.
Each step ships as a runnable script with its own acceptance tests.
| step | file | what it establishes | result |
|---|---|---|---|
| 1 | step1_demo.py, photonic/mzi.py | MZI mesh: matrix-vector multiply by coherent interference (unitary, energy-conserving, differentiable) | 4/4 |
| 2 | step2_demo.py, photonic/linear.py | Arbitrary linear map via SVD mesh U Σ Vᴴ; passive optics realize contractions (‖M‖₂ ≤ 1) | 4/4 |
| 3 | step3_demo.py, photonic/quantize.py | Quantize phases/amps → finite domain; phase quantization preserves unitarity exactly | 5/5 |
| 4 | step4_train_verify.py, photonic/unit.py | Train + exhaustively verify MZI2.pt | 256/256 |
| 5 | step5_demo.py, photonic/hybrid.py, photonic/cpu_bridge.py | Hybrid net: optical core + real ADC8 electronic half; 99% on two-moons | 3/3 |
| 6 | step6_demo.py, photonic/visualize.py | Forward-transport visualization, firewalled from compute | 3/3 |
The photodetector unit was added afterwards:
| file | what it does | result |
|---|---|---|
train_detector.py, photonic/detector.py | Train + exhaustively verify PD.pt (a learned |·|²) | 1024/1024 |
bench.py measures speed (see below). photonic/prism.py is the forward
spectral ray-trace used for the dispersion visual.
pip install torch numpy
python step1_demo.py # ... through step6_demo.py
python step4_train_verify.py # retrains + verifies MZI2.pt (256/256)
python train_detector.py # retrains + verifies PD.pt (1024/1024)
python bench.py # speed: sim vs frozen-deploy vs projection
import torch
from photonic.unit import NeuralPhotonicMZI, bits_of
from photonic.detector import NeuralPhotodetector
mzi = NeuralPhotonicMZI(); mzi.load_state_dict(torch.load("MZI2.pt")["state_dict"]); mzi.eval()
pd = NeuralPhotodetector(); pd.load_state_dict(torch.load("PD.pt")["state_dict"]); pd.eval()
# MZI2: phase indices (theta=3, phi=10) -> quantized 2x2 interferometer matrix
block = mzi.forward_int(bits_of(3, 10).unsqueeze(0)) # int8 components
# PD: detect a complex field vector -> intensity bytes (learned |.|^2)
field = torch.tensor([0.7+0.2j, 0.1-0.3j], dtype=torch.complex64)
bytes_out = pd.detect(field)
The hybrid pipeline (MZI2 → PD → ADC8) is assembled in photonic/hybrid.py
and demonstrated end-to-end in step5_demo.py.
bench.py, measured on CUDA:
| N | ① SIM (rebuild) | ② DEPLOY (frozen) | ③ DIGITAL |
|---|---|---|---|
| 64 | 2283 ms | 0.102 ms | 0.101 ms |
This project is deliberately built so a nice-looking result can never stand in for a correct one:
MZI2 and PD are verified on their quantized,
finite domains, at finite resolution (4-bit phases, 5-bit field components).MZI2.pt, PD.pt trained + verified models
cpu_units/ADC8.pt adder from neural-aarch64-units (for the hybrid)
photonic/ mzi, linear, quantize, unit, detector,
hybrid, cpu_bridge, visualize, prism
step1..6_demo.py the build, with acceptance tests
step4_train_verify.py train + verify MZI2 (256/256)
train_detector.py train + verify PD (1024/1024)
bench.py speed benchmark
core_energy.svg forward-transport render: energy per mode/layer
hybrid_core_energy.svg same, for the hybrid net's optical core
The two SVGs are produced by step6_demo.py (photonic/visualize.py) — a
forward light-transport render of optical energy flowing through the mesh,
layer by layer. They are visualization only, firewalled from the compute path.
Companion Space: NeuralVerified/neural-photonic-hybrid — live 3D visualization
of light → detector → CPU → output.
Related: neural-aarch64-units,
neural-raytracing.
@misc{byrne2026neuralphotonic,
title = {Neural Photonic: Verified Optical Compute Units},
author = {Byrne, Dean (Quazim0t0)},
year = {2026},
howpublished = {\url{https://huggingface.co/NeuralVerified/neural-photonic}},
note = {Neural networks that emulate photonic-computer operations, exhaustively (N/N) verified}
}
Dean Byrne (Quazim0t0) · 2026
Now hosted by NeuralVerified.
This repo was moved into the NeuralVerified organization to help organize my profile. Originally published at
Quazim0t0/neural-photonic.