Skip to Content
SdkSDK Quick Start

SDK Quick Start

Get up and running with OptixLog SDK in minutes. This guide will walk you through your first successful log.

Setting Up Your API Key

Before you can use OptixLog, you need an API key. Get yours from https://optixlog.com .

Set your API key as an environment variable:

Linux/macOS:

export OPTIX_API_KEY="your_api_key_here"

Windows (PowerShell):

$env:OPTIX_API_KEY="your_api_key_here"

Windows (CMD):

set OPTIX_API_KEY=your_api_key_here

Option 2: Pass Directly to init()

You can also pass the API key directly when initializing:

client = optixlog.init(api_key="your_api_key_here", ...)

Minimal Working Example

Here’s the simplest possible example using the context manager (recommended):

import optixlog # API key is automatically read from OPTIX_API_KEY environment variable # Project can be set via OPTIX_PROJECT env var or passed as parameter with optixlog.run("my_first_run", project="MyProject") as client: client.log(step=0, message="Hello, OptixLog!")

That’s it! This will:

  1. Automatically use your API key from the OPTIX_API_KEY environment variable
  2. Initialize a connection to OptixLog
  3. Create a new run called “my_first_run”
  4. Log a simple message
  5. Automatically clean up when done

Note: optixlog.run() and optixlog.init() automatically use the OPTIX_API_KEY environment variable if set, so you don’t need to pass it explicitly.

Alternative (traditional approach):

import optixlog client = optixlog.init(run_name="my_first_run") client.log(step=0, message="Hello, OptixLog!")

Your First Successful Log

Let’s create a slightly more complete example using the context manager:

import optixlog import os # Use context manager (recommended) with optixlog.run( "quick_start_example", config={ "python_version": "3.9", "example_type": "quick_start" } ) as client: # Log some metrics for step in range(5): value = step * 2.5 result = client.log(step=step, value=value, squared=value**2) if result: print(f"Logged step {step}: value={value}") print("Successfully logged to OptixLog!")

What happens:

  1. Creates a run called “quick_start_example”
  2. Logs 5 data points with value and squared metrics
  3. Each log includes a step number

View your results:

  • Go to https://optixlog.com 
  • Navigate to your project
  • Find the run “quick_start_example”
  • See your logged metrics visualized!

Understanding Projects and Runs

Projects

A project is a container for related experiments. By default, runs are created in a project called “dev”, but you can specify a different project:

client = optixlog.init( project="my_research_project", run_name="experiment_1" )

If the project doesn’t exist, you can create it automatically:

client = optixlog.init( project="new_project", run_name="first_run", create_project_if_not_exists=True )

Runs

A run represents a single experiment or simulation. Each run can contain:

  • Metrics: Time-series data, scalars, arrays
  • Images: Plots, visualizations, snapshots
  • Files: Data files, configuration files, results
  • Config: Parameters and settings for the experiment
client = optixlog.init( run_name="waveguide_simulation_v1", config={ "wavelength": 1.55, "resolution": 30, "material": "silicon" } )

Basic Logging Workflow

The typical workflow is:

  1. Initialize the client
  2. Log metrics during your simulation/experiment
  3. Log images/files for visualization
  4. View results on the web dashboard

Example: Simple Simulation Loop

import optixlog import numpy as np # Initialize client = optixlog.init( run_name="simple_simulation", config={"iterations": 100} ) # Simulation loop for step in range(100): # Your simulation code here result = np.random.random() # Placeholder # Log metrics client.log( step=step, result=float(result), iteration=step ) if step % 10 == 0: print(f"Step {step}: result = {result:.4f}") print("Simulation complete!")

Example: Logging an Image (New Way - One Line!)

import optixlog import matplotlib.pyplot as plt import numpy as np with optixlog.run("plot_example") as client: # Create a simple plot x = np.linspace(0, 10, 100) y = np.sin(x) fig, ax = plt.subplots() ax.plot(x, y) ax.set_xlabel("x") ax.set_ylabel("sin(x)") ax.set_title("Simple Sine Wave") # Log matplotlib figure directly - one line! result = client.log_matplotlib("sine_wave", fig) if result: print(f"Image logged! URL: {result.url}") plt.close(fig)

Or use the helper to create and log in one call:

with optixlog.run("plot_example") as client: x = np.linspace(0, 10, 100) y = np.sin(x) # Create and log plot in one line! result = client.log_plot("sine_wave", x, y, title="Simple Sine Wave", xlabel="x", ylabel="sin(x)") print(f"Plot logged! URL: {result.url}")

Example: Logging a File

import optixlog import numpy as np client = optixlog.init(run_name="file_example") # Create some data data = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) # Save to CSV np.savetxt("results.csv", data, delimiter=",") # Log the file client.log_file("results", "results.csv", "text/csv") print("File logged!")

Environment Variables

You can configure OptixLog using environment variables:

# Required export OPTIX_API_KEY="your_api_key" # Optional export OPTIX_API_URL="https://backend.optixlog.com" # Default if not set export OPTIX_PROJECT="my_project" # Default: "dev"

Then in your code, you can use the defaults:

import optixlog # Uses OPTIX_API_KEY, OPTIX_API_URL, OPTIX_PROJECT from environment client = optixlog.init(run_name="my_run")

Next Steps

Now that you’ve logged your first data: