Qubots Examples - Developer Guide
Build, test, and deploy optimization algorithms in minutes.
Quick Start
Create Locally
1. Install qubots
2. Create optimizer structure
mkdir my_optimizer && cd my_optimizer
3. Create qubot.py
from qubots import BaseOptimizer
class MyOptimizer(BaseOptimizer):
def optimize(self, problem):
# Your optimization logic here
solution = self.solve_problem(problem)
return self.create_result(solution)
def solve_problem(self, problem):
# Implement your algorithm
return problem.get_random_solution()
4. Create config.json
{
"type": "optimizer",
"entry_point": "qubot",
"class_name": "MyOptimizer",
"default_params": {
"time_limit": 60.0
},
"metadata": {
"name": "My Optimizer",
"description": "Custom optimization algorithm"
}
}
5. Test locally
from qubots import AutoOptimizer, AutoProblem
# Load your optimizer
optimizer = AutoOptimizer.from_repo(".")
# Test with example problem
problem = AutoProblem.from_repo("examples/maxcut_problem")
result = optimizer.optimize(problem)
print(f"Result: {result.best_value}")
Upload to Rastion
1. Get API token
Visit rastion.com/settings and copy your API token.
2. Upload your optimizer
# Install upload tool
pip install qubots[upload]
# Upload to platform
qubots upload . --name "my_optimizer" --token YOUR_TOKEN
3. Alternative: Python upload
import qubots.rastion as rastion
# Authenticate
rastion.authenticate("YOUR_TOKEN")
# Upload optimizer
rastion.upload_optimizer(
path=".",
name="my_optimizer",
description="My custom optimizer",
visibility="public" # or "private"
)
# Load from platform
optimizer = rastion.load_qubots_model("my_optimizer", username="your_username")
# Run in cloud
from qubots import execute_playground_optimization
result = execute_playground_optimization(
problem_name="maxcut_problem",
problem_username="examples",
optimizer_name="my_optimizer",
optimizer_username="your_username"
)
Example Problems
Advanced Usage
Benchmarking
from qubots import BenchmarkSuite
suite = BenchmarkSuite("My Comparison")
suite.add_problem(problem, "test_case")
suite.add_optimizer(optimizer, "my_algo")
results = suite.run_full_benchmark(num_runs=5)
Custom Parameters
# Override default parameters
optimizer = AutoOptimizer.from_repo(".", override_params={
"time_limit": 120.0,
"population_size": 200
})
Next Steps