- Light makes a cosine
- A number sets the phase
- Cosines add into a curve
- Curves make a network
- Run it in Python
1. Light makes a cosine
Split a beam of light into two paths and bring them back together. If both paths are the same length, the waves line up and add. Delay one by half a wavelength and they cancel. In between, the brightness at the output follows a smooth curve, and that curve is a cosine of the delay.
Drag the phase and watch the detector. Nothing calculates the cosine. It is what interfering light does.
brightness1.00
(1 + cos φ) / 21.00
2. A number sets the phase
On Q.ANT's chip the delay is set electrically. The core is lithium niobate, a crystal whose optical behaviour shifts with voltage. So a number goes in as a voltage, the voltage shifts the phase, and the light computes a cosine of it.
Put a number x through a frequency k, add an offset φ, and scale the result by an amplitude a. One optical operation then gives you:
a · cos(k · x + φ) Q.ANT's documentation calls the device's function tcos: a 2π-periodic shape between −1 and 1, similar to a cosine. The toolkit's CPU emulator uses an exact cosine instead. Everything on this page uses the emulator's maths, so it shows how the algorithm behaves, not what a physical card measures.
3. Cosines add into a curve
Add a few of those terms with different frequencies and you can draw almost any smooth curve. This is a Fourier series. Set the amplitude and phase of each term and watch the black curve change.
This is exactly what one connection in a Fourier KAN learns: an amplitude and a phase for each frequency. Training finds these numbers for you. The card evaluates every cosine optically.
4. Curves make a network
A normal neural network puts a fixed activation like ReLU on every neuron and learns a single weight on every connection. A Kolmogorov-Arnold Network (KAN) flips that. Every connection learns a whole curve. In a Fourier KAN, each of those curves is the sum of cosines you just built:
y_out = bias + Σ_in Σ_k a[out, in, k] · cos(k · x_in + φ[out, in, k]) The amplitudes and phases are learned. The frequencies k = 1 … grid are fixed. A layer has in × out × grid × 2 + out parameters. On a GPU every one of those cosines costs arithmetic. On a photonic card they are the native operation, which is why this kind of network fits the hardware. The toolkit runs a whole layer in one call, ai.calc_kan_layer_fprop.
5. Run it in Python
These cells run real Python with NumPy in your browser, using Pyodide. The first run downloads Python once, about 15 MB, then each run takes seconds. Edit any line and run it again. Nothing leaves your computer.
toolkit_kan_layer repeats the Q.ANT toolkit emulator's arithmetic: every multiply, add and cosine rounded to bfloat16 in the same order as the toolkit's source. It matched the real emulator bit for bit on 40 of 40 random layers and on a full trained network. Read the code.
The difference is the cost of bfloat16. Every intermediate value is rounded to about three significant digits.
Takes a few seconds. The training uses hand-written NumPy backprop with the same AdamW update as PyTorch.
One edge with 16 cosines follows the slow middle of the chirp but not its fast edges. That is the grid limit from step 3. The comment at the end of the cell shows the fix: more edges, not more cosines per edge.