1. Install the SDK
NEROX requires Python 3.9+. Install via pip:
bash
pip install nerox
2. Get your API key
Create a free account at app.driftrail.com and copy your API key from Settings → API Keys. Then set it as an environment variable:
bash
export NEROX_API_KEY="nrx_sk_..." # Or pass it directly in code (not recommended for production) import nerox nerox.api_key = "nrx_sk_..."
3. Solve a TSP
Submit a Travelling Salesman Problem with a random 20-city distance matrix:
python
import nerox
import numpy as np
# Generate a random 20-city distance matrix
np.random.seed(42)
n = 20
coords = np.random.rand(n, 2) * 100
dist = np.sqrt(((coords[:, None] - coords[None, :]) ** 2).sum(-1))
# Submit to GPU Annealing solver
job = nerox.optimize.tsp(
distance_matrix=dist,
solver="gpu", # gpu | sa | tabu | hybrid
n_runs=50, # independent annealing chains
)
# Stream results as they arrive
for event in job.stream():
print(f" Iteration {event.iteration:>5} | Energy {event.energy:.2f}")
print(f"\nBest tour length: {job.result.objective:.2f}")
print(f"Solved in: {job.result.runtime_s:.2f}s")4. Read the result
python
result = job.result result.objective # float — best tour length found result.solution # list[int] — city visit order result.runtime_s # float — wall-clock seconds result.gpu_seconds # float — billed GPU compute time result.gap_to_best # float | None — % above known best (if available) result.solver # str — "gpu_annealing" result.n_iterations # int — total annealing steps run
5. Try a different solver
Switching solvers requires changing one parameter:
python
# QAOA — good for MaxCut, portfolio, small graphs
job = nerox.optimize.maxcut(
adjacency_matrix=adj,
solver="qaoa",
depth=4, # circuit depth p
)
# Tabu Search — good for problems with hard constraints
job = nerox.optimize.tsp(
distance_matrix=dist,
solver="tabu",
tenure=15,
max_iterations=10_000,
)
# Hybrid — for large problems (1k+ variables)
job = nerox.optimize.portfolio(
returns=mu,
covariance=sigma,
solver="hybrid",
n_assets=500,
)6. Submit raw QUBO
If your problem doesn't match a built-in mapper, submit a raw Q matrix directly:
python
import nerox import numpy as np n = 64 Q = np.random.rand(n, n) * 2 - 1 # your QUBO matrix Q = (Q + Q.T) / 2 # symmetrize job = nerox.optimize.qubo(Q=Q, solver="gpu", n_runs=100) result = job.wait() print(result.solution) # binary vector x* minimizing x'Qx print(result.objective) # x*'Q x*
