SDK

OptixLog Python SDK

Python library for experiment tracking in photonic simulations and hardware testing

OptixLog Python SDK

The OptixLog SDK is a Python library for experiment tracking in photonic simulations and hardware testing. Log metrics, images, and files with a clean, fluent API.

Installation

pip install optixlog

Quick Example

First, get your API key from optixlog.com. Then:

from optixlog import Optixlog

# Create client
client = Optixlog(api_key="your_api_key_here")

# Get or create a project
project = client.project(name="MyProject")

# Create a run
run = project.run(name="experiment_1", config={"lr": 0.001})

# Log metrics
for step in range(100):
    run.log(step=step, loss=0.5, accuracy=0.9)

# Log matplotlib plots
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1, 2, 3], [1, 4, 9])
run.log_matplotlib("my_plot", fig)

View results at optixlog.com.

Key Features

Fluent API

The SDK uses a clear, chainable API structure:

# Client → Project → Run
client = Optixlog(api_key=api_key)
project = client.project(name="my_project")
run = project.run(name="experiment_1")

All parameters are keyword-only for clarity and safety.

Context Manager Support

Use with statements for automatic cleanup:

run = project.run(name="experiment")
with run:
    run.log(step=0, loss=0.5)
# Automatic status reporting

Zero-Boilerplate Logging

Log matplotlib figures and create plots with no manual conversion:

# Log matplotlib figures directly
run.log_matplotlib("plot", fig)

# Create and log plots in one call
run.log_plot("spectrum", x, y, title="Spectrum")

# Convert arrays to heatmaps
run.log_array_as_image("field", field_data, cmap='hot')

# Create histograms, scatter plots, and more
run.log_histogram("distribution", data, bins=50)
run.log_scatter("correlation", x, y)

MPI Support

Automatic detection and coordination for parallel simulations:

mpirun -n 4 python simulation.py
# Only master process logs - no code changes needed
client = Optixlog(api_key=api_key)
print(f"Master: {client.is_master}, Rank: {client.rank}, Size: {client.size}")

run = client.project(name="sim").run(name="parallel_run")
run.log(step=step, power=power)  # Only master logs

Auto-Create Projects

Projects are created automatically if they don't exist:

# Creates "NewProject" if it doesn't exist
project = client.project(name="NewProject", create_if_not_exists=True)

Query Your Data

Retrieve and analyze your logged experiments:

import optixlog

runs = optixlog.list_runs(api_url, api_key, project="MyProject")
metrics = optixlog.get_metrics(api_url, api_key, run_id)
artifacts = optixlog.get_artifacts(api_url, api_key, run_id)
comparison = optixlog.compare_runs(api_url, api_key, [run_id1, run_id2])

What Can You Log?

TypeMethodsExample
Metricslog(), log_batch()Loss, accuracy, power, transmission
Imageslog_image(), log_matplotlib(), log_plot()Plots, field snapshots, visualizations
Fileslog_file()CSV, HDF5, JSON, MP4
Arrayslog_array_as_image(), log_histogram(), log_scatter()Field data, distributions, correlations

Use Cases

Training Loop

from optixlog import Optixlog

client = Optixlog(api_key="your_key")
run = client.project(name="training").run(
    name="experiment_v1",
    config={"lr": 0.001, "optimizer": "adam"}
)

for epoch in range(100):
    train_loss = train_epoch()
    val_loss = validate()
    run.log(step=epoch, train_loss=train_loss, val_loss=val_loss)

Photonic Simulations

import meep as mp
from optixlog import Optixlog

client = Optixlog(api_key="your_key")
run = client.project(name="simulations").run(
    name="waveguide_sim",
    config={"wavelength": 1.55, "resolution": 30}
)

sim = mp.Simulation(...)
for step in range(100):
    sim.run(until=1)
    power = calculate_power(sim)
    run.log(step=step, power=power)

    if step % 10 == 0:
        field = sim.get_array(...)
        run.log_array_as_image(f"field_{step}", field, cmap='hot')

Parameter Sweeps

client = Optixlog(api_key="your_key")
project = client.project(name="sweeps")

for wavelength in [1.3, 1.4, 1.5, 1.6]:
    run = project.run(
        name=f"sweep_{wavelength}",
        config={"wavelength": wavelength}
    )

    result = simulate(wavelength)
    run.log(step=0, transmission=result)

Hardware Testing

client = Optixlog(api_key="your_key")
run = client.project(name="hardware").run(name="spectrum_test")

for freq in range(1000, 2000, 10):
    instrument.write(f"FREQ {freq}MHz")
    power = float(instrument.query("POW?"))
    run.log(step=freq, power_dBm=power)

API Structure

from optixlog import Optixlog

# 1. Create client
client = Optixlog(api_key="your_key", api_url="https://optixlog.com")

# 2. Get or create a project
project = client.project(name="my_project", create_if_not_exists=True)

# 3. Create a run
run = project.run(name="experiment_1", config={"lr": 0.001})

# 4. Log data
run.log(step=0, loss=0.5)
run.log_matplotlib("plot", fig)
run.log_file("data", "results.csv", "text/csv")

# 5. Query data (module-level functions)
runs = optixlog.list_runs(api_url, api_key, project="my_project")
metrics = optixlog.get_metrics(api_url, api_key, run_id)

Requirements

  • Python: 3.8+ (3.9+ recommended)
  • Dependencies: requests, numpy, matplotlib, pillow, rich
  • Optional: mpi4py for MPI support, meep for photonic simulations

Environment Variables

You can set default values using environment variables:

VariableDescriptionDefault
OPTIX_API_KEYAPI key (not used in new API)None
OPTIX_API_URLAPI endpointhttps://optixlog.com

Example:

export OPTIX_API_URL="http://localhost:3000"

Next Steps

What's New in v0.2.0

  • New fluent API: OptixlogProjectRun structure
  • Keyword-only parameters: All parameters must be passed by name for clarity
  • Simplified logging: All logging methods on Run object
  • Auto project creation: Projects created automatically if they don't exist
  • Better MPI support: Improved detection and synchronization
  • Helper methods: Direct logging of plots, histograms, scatter plots, etc.

On this page