Choosing a level of detail (LOD) for each object in a 3D scene under a hard per-frame triangle budget, written as a QUBO and solved with QAOA (Qiskit), then compared honestly with exact dynamic programming, a greedy baseline and random sampling.
No results yet. Run make experiments, then
uv run python scripts/results_table.py --write-readme to fill this table.
AR top-1 is the value of the most frequent feasible sample divided by the DP optimum. P_feas is the fraction of shots that are one-hot and within budget. Budget use is the budget used by the best feasible sample divided by the available budget. P_opt gain is the probability of sampling the DP optimum divided by its probability under uniform sampling. DP and Greedy are deterministic, so their P_opt gain is 1 / P_opt(uniform) when they return the DP choice and 0 when they do not.
Problem. A scene has N = 5 objects, each with M = 3 LODs: j = 0 is the most detailed and j = 2 the coarsest. Exactly one LOD is picked per object, and the total triangle count must fit the frame budget while maximising visual utility. This is a multiple-choice knapsack problem (MCKP).
Utility. For object i at LOD j, vij = Si · qj / diα, where Si = 4πRi2 · importancei, di is the distance to the camera, α = 1.5 and q = (1.0, 0.65, 0.25). v is normalised so that max v = 1.
Delta weights and budget quantisation. Every object costs at least its coarsest LOD, so that cost is moved into a fixed base Wbase = Σi wi,M−1. The remaining weights and budget are counted in blocks of 5000 triangles:
Rounding the weights up and the budget down means that every choice the model accepts also fits the real triangle budget.
Baselines. DP solves the MCKP exactly and is the reference. Greedy starts from the coarsest LOD everywhere and keeps applying the upgrade with the best utility gain per budget block. Random is the exact uniform distribution over all 219 bitstrings, the same baseline that P_opt gain is measured against.
Scenes. scenes/default.yaml is the base scene. greedy_trap_1..3 were found
with scripts/find_greedy_trap.py: there Greedy stops with budget it cannot use and
misses the optimum, so it is a fair test for QAOA. random_000..019 are random scenes
for configs/main_random.yaml.
QUBO. Binary xij = 1 means object i uses LOD j. The inequality is turned into an equality with K = ⌊log2 dW⌋ + 1 slack bits sk of weight 2k. The energy to minimise is
\[E(x, s) = -\sum_{i,j} v_{ij} x_{ij} + A \sum_i \Big(1 - \sum_j x_{ij}\Big)^2 + B \Big(\sum_{i,j} dw_{ij} x_{ij} + \sum_k 2^k s_k - dW\Big)^2\]Qubits. With dW ≤ 15 this gives N·M = 15 decision qubits plus K = 4 slack qubits, 19 qubits in total.
Penalties. A = 1.5 · max v. Going over the budget by one block costs only B, so B must be larger than the biggest gain from a single upgrade, B > maxij (vij − vi,M−1). We use 1.2 times that value. The common rule of thumb B ≈ max(Δv/Δw) is not safe here.
Verification. For every scene, all 219 states are enumerated
(lodq.qubo.verify_qubo). The penalties are accepted only if the ground state is
unique, feasible and equal to the DP solution, with an energy margin to every
infeasible state. The QUBO → Ising mapping is checked the same way against a statevector.
QAOA. The standard X mixer, and an XY mixer that keeps the one-hot constraint
(started from W states, with A = 0). Angles are optimised with multistart COBYLA using
linear-ramp, random and warm starts from depth p − 1. Experiments use an exact numpy
statevector (fastsim), and the final counts are sampled with Qiskit Aer.
Requires uv. Python 3.12 is installed by uv.
make all QUICK=1 # install, test, build assets, quick experiments, figures, renders
make precompute # DP, Greedy, QAOA (X and XY mixers) for every camera frame, ~9 min
make demo # interactive Streamlit demo
make all without QUICK=1 runs the full grid from configs/main.yaml: the three
greedy trap scenes, p = 1..4, X and XY mixers, 5 seeds each.
The demo reads its camera frames from cache/path, so run make precompute once before
make demo. Add --limit 10 to scripts/precompute_path.py for a quick try on the
first 10 frames.
Without uv, every target is the same command run with the virtualenv’s Python:
python3.12 -m venv .venv
.venv/bin/pip install -e . pytest ruff
.venv/bin/python -m pytest -q
.venv/bin/python scripts/precompute_path.py --exact
.venv/bin/python -m streamlit run app/streamlit_app.py
| Target | What it does |
|---|---|
make install |
uv sync |
make test |
The full test suite; uv run pytest -m "not slow" skips the 2^19 enumerations of random scenes |
make lint |
ruff check src tests |
make assets |
Rebuilds the LOD meshes in assets/lods/ (they are committed) |
make experiments |
Experiment grid from configs/main.yaml (or configs/smoke.yaml with QUICK=1) into runs/ and runs/summary.csv |
make figures |
Figures in figures/ from the saved runs |
make render |
figures/compare_render.png and figures/compare_zoom.png with PyVista |
make precompute |
Camera frames for the demo in cache/path |
make demo |
Streamlit demo |
make all |
install, test, assets, experiments, figures and render |
scripts/check_release.py checks that the figures are newer than runs/summary.csv and
that this README has its results block.
The demo has four pages:
The 3D views need a browser with WebGL. On the first start the app writes the viewer
meshes to app/static/meshes/. Environment variables:
| Variable | Default | Meaning |
|---|---|---|
LODQ_FRAMES_DIR |
cache/path |
Precomputed camera frames |
LODQ_MESH_DIR |
app/static/meshes |
Where the viewer meshes are written |
LODQ_LIVE_BACKEND |
fastsim |
Simulator for live QAOA runs |
| Module | Purpose |
|---|---|
src/lodq/scene.py |
Scene and camera data model, YAML I/O, random scenes and camera paths |
src/lodq/metrics.py |
Utility matrix, delta weights, budget quantisation and qubit count |
src/lodq/meshes.py |
Builds the LOD meshes in assets/lods/ by mesh simplification |
src/lodq/classical.py |
Exact DP, brute force, greedy and random baselines |
src/lodq/qubo.py |
QUBO construction, encoding and decoding, penalty rules, full 2^n verification |
src/lodq/ising.py |
QUBO → Ising (SparsePauliOp) mapping and its diagonal |
src/lodq/qaoa.py |
QAOA circuits (X and XY mixers), angle initialisation, optimisation and sampling |
src/lodq/fastsim.py |
Exact numpy QAOA statevector (X mixer, and XY on the one-hot subspace), fast optimiser and the p = 1 landscape |
src/lodq/evaluate.py |
Sample and distribution metrics (AR, P_feas, P_opt gain) and the uniform baseline |
src/lodq/experiments.py |
Command-line runner for the experiment grid and runs/summary.csv |
src/lodq/storage.py |
Saving and loading run records under runs/ |
src/lodq/config.py |
Experiment configuration schema (pydantic) |
src/lodq/plots.py |
Figures rebuilt from saved runs |
src/lodq/render.py |
3D renders of the chosen LODs with PyVista |
src/lodq/demo.py |
Data and figures for the Streamlit demo in app/ |
src/lodq/viewer.py |
LOD meshes and scene data for the WebGL viewer in app/static/viewer/ |
| Folder | Contents |
|---|---|
app/ |
Streamlit entry point streamlit_app.py, shared UI code ui.py, one module per page in views/ |
app/static/ |
WebGL viewer (viewer/) and the vendored three.js (vendor/) |
scripts/ |
One-off tools: penalty calibration, greedy trap search, random scenes, QAOA sweeps, mixer comparison, circuit report, demo precompute, results table, release check |
configs/ |
Experiment grids: smoke.yaml, main.yaml, main_random.yaml |
scenes/ |
Scene presets and the demo camera path greedy_trap_path.json |
assets/lods/ |
LOD meshes (.ply) |
tests/ |
pytest suite |
runs/, cache/, figures/ |
Generated results, energy and frame caches, figures (not committed) |
app/static/vendor/ under the MIT
licence (LICENSE-three.txt).