How osmanttne/onn-backend works
Purpose and execution model
This is a notebook-first backend for an optical neural network (ONN) bench. Its core operation maps a temporal image batch X (T,h,w) through a DMD and optical path to camera measurements/predictions Y (T,gh,gw). The main operator entry point is onn_backend.ipynb; it supports simulation and physical-bench execution. Supporting scripts include onn_server.py and benchmark utilities.
Orchestration and forward pipeline
onn/forward.py contains ONNForward, the central pipeline abstraction responsible for driving X -> Y and persisting results. It is expected to coordinate device setup, temporal DMD presentation, camera capture, and result saving. onn_backend.ipynb instantiates and runs this flow interactively; data/run_sim.npz is a representative persisted run.
Grounding paths:
• onn/forward.py
• onn_backend.ipynb
• data/run_sim.npz
Hardware abstraction boundary
hardware/base.py defines the shared device-layer boundary. Hardware-specific implementations are separated from ONN logic so the same forward flow can target real instruments or software twins. This isolates vendor SDKs, device connection details, lifecycle management, and low-level commands from pattern generation and measurement processing.
Grounding paths:
• hardware/base.py
• hardware/__init__.py
• hardware/simulators.py
Illumination and spatial modulation
The optical input path comprises laser control and spatial modulators. hardware/laser.py controls an OBIS laser through SCPI/serial-style communications. hardware/dmd.py drives a ViALUX DMD via ALP4lib and is the primary temporal input display device. hardware/slm.py manages a Meadowlark SLM through slmsuite, including a coverglass safety/lockout concern.
Grounding paths:
• hardware/laser.py
• hardware/dmd.py
• hardware/slm.py
Acquisition and measurement output
hardware/camera.py wraps FLIR camera operation through PySpin. The camera is the physical output boundary: it captures optical frames produced after DMD/SLM modulation and provides the raw measurements used to construct Y. Simulation counterparts in hardware/simulators.py permit this acquisition contract to run without attached devices.
Grounding paths:
• hardware/camera.py
• hardware/simulators.py
• onn/forward.py
Pattern and image representation layer
Named optical patterns for DMD and SLM are centralized in onn/patterns.py, keeping display content separate from device transport. onn/tensor_bitmap.py bridges numerical tensor/image data into bitmap-compatible representations required by modulator APIs. This is the main format boundary between model-style arrays and hardware display buffers.
Grounding paths:
• onn/patterns.py
• onn/tensor_bitmap.py
• onn/forward.py
Configuration, runtimes, and external dependencies
The bench profile is stored in config/onn_nico.yaml; physical deployment requires completing bench-specific parameters before disabling simulation. The runtime is Python/Jupyter with NumPy-based data handling and .npz run storage. Material external integrations are ALP4lib (ViALUX DMD), slmsuite (Meadowlark SLM), PySpin (FLIR camera), and pyserial/SCPI for laser communication. Simulation mode avoids these vendor dependencies.
Grounding paths:
• config/onn_nico.yaml
• hardware/dmd.py
• hardware/camera.py
Main entry points: forward.py ONNForward · base.py Device contracts · dmd.py ViALUX DMD · slm.py Meadowlark SLM
Components 15
Interactive runtime
- ONN backend notebook · Interactive launcher for simulation and bench runs.
onn_backend.ipynb - Bench profile · Bench-specific settings select and configure physical execution.
config/onn_nico.yaml
ONN pipeline
- ONNForward · Drives temporal X-to-Y runs and persists results.
onn/forward.py - Optical patterns
onn/patterns.py - Tensor bitmap bridge · Converts numerical image data to modulator buffers.
onn/tensor_bitmap.py - Persisted run · Representative simulated X-to-Y run.
data/run_sim.npz
Hardware boundary
- Device contracts · Separates ONN orchestration from device lifecycle and low-level commands.
hardware/base.py - Hardware package
hardware/__init__.py - Software twins · Implement device and acquisition contracts without instruments.
hardware/simulators.py
Physical bench adapters
- OBIS laser · Controls illumination through SCPI or serial communication.
hardware/laser.py - ViALUX DMD · Displays temporal input patterns via ALP4lib.
hardware/dmd.py - Meadowlark SLM · Applies SLM patterns and coverglass safety lockout via slmsuite.
hardware/slm.py - FLIR camera · Captures optical output frames through PySpin.
hardware/camera.py - Optical path · Carries modulated illumination from input display to camera.
- Vendor SDKs · ALP4lib, slmsuite, PySpin, and serial/SCPI interfaces.
Connections 24
- ONN backend notebook → ONNForward: runs
- Bench profile → ONNForward: configures mode
- ONNForward → Optical patterns: selects
- Optical patterns → Tensor bitmap bridge: rendered as
- ONNForward → Tensor bitmap bridge: converts X
- ONNForward → Device contracts: uses contracts
- Hardware package → Device contracts: exports
- Software twins → Device contracts: implements
- OBIS laser → Device contracts: implements
- ViALUX DMD → Device contracts: implements
- Meadowlark SLM → Device contracts: implements
- FLIR camera → Device contracts: implements
- Tensor bitmap bridge → ViALUX DMD: presents temporal X
- Tensor bitmap bridge → Meadowlark SLM: loads spatial pattern
- OBIS laser → Optical path: illuminates
- ViALUX DMD → Optical path: modulates input
- Meadowlark SLM → Optical path: modulates field
- Optical path → FLIR camera: produces frames
- FLIR camera → ONNForward: raw measurements Y
- ONNForward → Persisted run: saves run
- ViALUX DMD → Vendor SDKs: ALP4lib
- Meadowlark SLM → Vendor SDKs: slmsuite
- FLIR camera → Vendor SDKs: PySpin
- OBIS laser → Vendor SDKs: SCPI/serial