Skip to main content

Photonic KAN: Bridging PyTorch, KAN, and Q.ANT photonic hardware

Project description

PhotoKAN

Photonic Kolmogorov-Arnold Networks — bridging PyTorch · KAN · Q.ANT photonic hardware.

Python PyTorch Status

Phase 1 (CPU simulation) is fully functional. Q.PAL/NPU integration ships in Phase 2.


Why PhotoKAN?

Standard MLPs use fixed activations on nodes and linear weights on edges.
KANs invert this: learnable nonlinear functions sit on the edges, summed at nodes.

Photonic hardware is physically structured around edge-level nonlinear transforms — light through a waveguide produces exactly the kind of parametric nonlinear function a KAN edge needs. This is not an analogy; it is a direct structural match.

Published benchmarks show:

  • 43% fewer parameters vs equivalent MLPs
  • 46% fewer operations vs equivalent MLPs
  • 30× energy efficiency gain on Q.ANT NPU vs CMOS

Installation

pip install photokan          # CPU simulation (no hardware required)
pip install photokan[qpal]    # + Q.ANT NPU support
pip install photokan[llm]     # + HuggingFace integration (Phase 3)
pip install photokan[dev]     # + development tools

Quick Start

import torch
import photokan as pk

# Works on CPU sim if no NPU — no code changes needed
model = pk.PhotoKAN(
    layer_sizes=[4, 16, 16, 1],
    activation='sine',   # 'sine' | 'fourier' | 'spline' | 'relu'
    backend='auto',      # auto-detects NPU, falls back to CPU
)

x = torch.randn(32, 4)
y = model(x)

# Standard PyTorch training
optimizer = torch.optim.Adam(model.parameters(), lr=1e-3)
loss = torch.nn.MSELoss()(y, torch.randn(32, 1))
loss.backward()
optimizer.step()

# Check what hardware is available
print(pk.available_backends())
# → {'cpu': True, 'cuda': True, 'qpal': False}

Activation Variants

Name Formula Best for Photonic native
sine Σ w·sin(f·x + p) Periodic targets, photonic deployment
fourier a₀ + Σ [a·cos + b·sin] Multi-frequency signals
spline B-spline basis Non-periodic, high precision Via LUT
relu Σ w·ReLU(a·x + b) Edge inference, speed

Photonic Noise Simulation

Test accuracy against realistic hardware impairments before deploying to NPU:

sim = pk.PhotonicSimulator()
sim.set_hardware_profile('npu2')   # SNR=16dB, 8-bit

results = sim.sweep_snr(model, x_test, y_test,
                         snr_range=[8, 10, 12, 14, 16, 20])
sim.plot_snr_accuracy(results)

Architecture

User PyTorch model
    └── PhotoKAN / PhotoKANLayer   (nn.Module, drop-in)
            └── EdgeActivations    (sine / fourier / spline / relu)
                    └── QPALFunction (torch.autograd.Function)
                            ├── QPALBackend  → Q.ANT NPU via Q.PAL
                            └── SimBackend   → CPU physics simulation

Project Status

Phase Features Status
Phase 1 Activations, SimBackend, Layers, Utils ✅ Complete
Phase 2 Q.PAL integration, QPALBackend, gradient tests 🔜 Months 4–6
Phase 3 AOT compiler, LLM integration, arXiv paper 🔜 Months 7–12

Running Tests

pip install -e ".[dev]"
pytest                          # fast tests only
pytest -m slow                  # include convergence tests
pytest --cov=photokan           # with coverage

References

  • Liu et al. (2024) — KAN: Kolmogorov-Arnold Networks
  • Peng et al. (2024) — Photonic KAN via RAMZI (98% MNIST, 65× energy-area reduction)
  • Reinhardt et al. (2024) — SineKAN
  • Q.ANT NPU — https://qant.com/photonic-computing/

PhotoKAN v0.1 — Build the bridge. Light does the math.

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

photokan-0.1.0.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

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

photokan-0.1.0-py3-none-any.whl (27.4 kB view details)

Uploaded Python 3

File details

Details for the file photokan-0.1.0.tar.gz.

File metadata

  • Download URL: photokan-0.1.0.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for photokan-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5022f1db79df75b806a84565fac7f8e4dd40312b5153dfbd65a631b07268bf7e
MD5 632e18353482b7cda1861c89a0961125
BLAKE2b-256 5e6d484203e664c0bfb40da4c205da43da5cfc01e176d4e2073ef5dee2d87ad0

See more details on using hashes here.

File details

Details for the file photokan-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: photokan-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 27.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for photokan-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 edbebb16d76ffdadd667c9d1e28126eaa4017761e2982ca382d20417ea59c20e
MD5 9b9d9c3e22e65dfe6871b4af5bd314b4
BLAKE2b-256 17d90e11eda3a31a01755290ff4e1e1be6e9bf3ba1650ada67d6a23bc287b0b8

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