Hybrid quantum-classical optimization: convert Pyomo MIP/MIQP models to QUBO for D-Wave quantum annealing, with classical polishing via IPOPT/GLPK/CBC.
curl -LsSf https://astral.sh/uv/install.sh | shuv venv
source .venv/bin/activate # macOS/Linux
# .venv\Scripts\activate # Windowsuv pip install -e .This installs pyomo and dimod (the required packages for simulation via simulated annealing).
To solve on real D-Wave hardware or use LeapHybridSampler, install the dwave extra:
uv pip install -e ".[dwave]"You will also need a D-Wave Leap account and API token — set it via:
export DWAVE_API_TOKEN=your_token_herehybridsolve.py uses a classical solver (IPOPT, GLPK, or CBC) to polish continuous variables after the quantum stage. Install at least one:
# GLPK (open source, handles LP/MIP)
conda install -c conda-forge glpk
# or on macOS:
brew install glpk
# IPOPT (open source, handles nonlinear)
conda install -c conda-forge ipopt
# CBC (open source, handles MIP)
conda install -c conda-forge coin-or-cbcimport pyomo.environ as pyo
from scripts.pyomo_to_qubo import PyomoToQUBO
from scripts.hybridsolve import HybridSolver
# Build a Pyomo model
model = pyo.ConcreteModel()
# ... define variables, constraints, objective ...
# Convert to QUBO
converter = PyomoToQUBO(model)
qubo, offset = converter.to_qubo()
# Or solve end-to-end with the hybrid pipeline
solver = HybridSolver()
result = solver.solve(model)| Package | Role | Required |
|---|---|---|
pyomo |
Optimization modeling | Yes |
dimod |
QUBO/BQM representation + simulated annealing | Yes |
dwave-ocean-sdk |
D-Wave hardware samplers (LeapHybridSampler) |
Optional |
| IPOPT / GLPK / CBC | Classical polishing solver | One required for HybridSolver |