API Reference

Complete Python module documentation for the simulation library

Modules

nonlinear_photonics.device

class Device

Core device physics simulation class.

class Device:
    def __init__(
        self,
        length: float = 7e-3,      # Waveguide length (m)
        width: float = 1.2e-6,     # Waveguide width (m)
        height: float = 400e-9,    # Waveguide height (m)
        chi3: float = 2.5e-19,     # Third-order susceptibility (m²/V²)
        n_pump: float = 1.89,      # Effective index at pump
        n_shg: float = 1.95,       # Effective index at SHG
        pixel_size: float = 7.5e-6 # Programmable pixel size (m)
    )

Methods

set_bias_voltage(voltage: float) -> None

Set the DC bias voltage for χ⁽²⁾ induction.

get_chi2_effective() -> float

Calculate induced χ⁽²⁾ from χ⁽³⁾ and E-field.

compute_efield_distribution() -> np.ndarray

Calculate 2D electric field distribution in device cross-section.

get_mode_overlap() -> float

Compute overlap integral between pump and SHG modes.

nonlinear_photonics.shg

class SHGSimulator

Second harmonic generation simulation engine.

class SHGSimulator:
    def __init__(
        self,
        device: Device,
        pump_wavelength: float = 1550e-9,
        pump_power: float = 50e-3
    )

Methods

simulate(chi2_pattern: np.ndarray) -> SHGResult

Run SHG simulation with given χ⁽²⁾ spatial pattern.

compute_phase_mismatch() -> float

Calculate Δk for current wavelength configuration.

get_conversion_efficiency() -> float

Return pump-to-SHG conversion efficiency.

sweep_wavelength(start: float, stop: float, points: int) -> np.ndarray

Sweep pump wavelength and compute SHG spectrum.

nonlinear_photonics.qpm

class QPMGrating

Quasi-phase matching grating design and generation.

class QPMGrating:
    def __init__(
        self,
        period: float,             # Grating period (m)
        duty_cycle: float = 0.5,   # Duty cycle (0-1)
        num_periods: int = 100,
        grating_type: str = 'uniform'  # 'uniform', 'chirped', 'apodized'
    )

Methods

generate_pattern() -> np.ndarray

Generate 1D χ⁽²⁾ modulation pattern.

set_chirp(rate: float) -> None

Set linear chirp rate (m/m) for chirped gratings.

set_apodization(type: str, param: float) -> None

Apply apodization ('gaussian', 'raised_cosine', 'sinc').

get_fourier_coefficients(orders: int = 5) -> np.ndarray

Compute Fourier series coefficients of grating.

Functions

calculate_qpm_period(pump_wl: float, n_pump: float, n_shg: float, order: int = 1) -> float

Calculate optimal QPM period for given wavelength and indices.

nonlinear_photonics.spectral

class SpectralEngine

Multi-wavelength spectral engineering tools.

class SpectralEngine:
    def __init__(self, device: Device)

Methods

add_channel(wavelength: float, power: float) -> None

Add a pump wavelength channel.

design_multiperiod_grating() -> np.ndarray

Generate superposed grating for all channels.

simulate_output_spectrum(resolution: float = 0.1e-9) -> tuple[np.ndarray, np.ndarray]

Compute output SHG spectrum (wavelengths, powers).

nonlinear_photonics.spatial

class SpatialBeam

Spatial beam shaping and structured light generation.

class SpatialBeam:
    def __init__(
        self,
        mode: str = 'gaussian',  # 'gaussian', 'airy', 'vortex', 'bessel'
        device: Device = None
    )

Methods

set_focal_length(f: float) -> None

Set focal length for Gaussian focusing.

set_airy_scale(x0: float) -> None

Set characteristic scale for Airy beam.

set_oam_order(l: int) -> None

Set orbital angular momentum order for vortex beam.

generate_phase_pattern() -> np.ndarray

Generate 2D phase pattern for χ⁽²⁾ programming.

propagate(z: float) -> np.ndarray

Compute beam intensity at distance z.

nonlinear_photonics.optimizer

class FeedbackOptimizer

Real-time feedback optimization algorithms.

class FeedbackOptimizer:
    def __init__(
        self,
        algorithm: str = 'spgd',  # 'spgd', 'gradient', 'genetic', 'bayesian'
        learning_rate: float = 0.1,
        num_pixels: int = 1000
    )

Methods

set_target(metric: Callable) -> None

Set optimization target metric function.

step() -> float

Execute one optimization iteration, return current metric.

run(max_iterations: int = 100, tolerance: float = 1e-4) -> OptimizationResult

Run optimization until convergence or max iterations.

enable_drift_compensation(rate: float = 10) -> None

Enable background drift compensation at specified rate (Hz).

get_optimal_pattern() -> np.ndarray

Return best χ⁽²⁾ pattern found.

Installation

git clone https://github.com/alovladi007/Programmable-on-chip-nonlinear-photonics.git
cd Programmable-on-chip-nonlinear-photonics
pip install -r requirements.txt