Commit 795450d
committed
feat(app,qqa): EA preview safety, TSP penalty method, spin arrows on topology
Summary
-------
* `app/_common.py` — stop building O(N^2) Plotly heatmaps in the
problem preview. For coupling matrices above ~600 spins fall back to
a sparse non-zero scatter (O(nnz) markers). The default
Edwards-Anderson selection (`L=32, dim=3`, N=32 768) used to OOM the
browser tab; it now renders a structural spy plot instead. Default EA
lattice side dropped from 32 to 6 so the first interaction also
converges in <1 s.
* `src/qqa/problems/extras.py` — TSP rewritten as a true penalty
method following Lucas (2014). `BinaryRelaxation(shape_fn=...)` lifts
the latent into `(B, N, N)`; `loss_fn` returns
`tour + lambda_r * row_pen + lambda_c * col_pen` so the optimiser
sees both permutation constraints as gradients (the previous
`CategoricalRelaxation` formulation hid the row constraint inside
the relaxation's softmax). `score_summary` runs Hungarian assignment
on every replica's projected matrix, mutates `best_sol` to the
cleaned permutation, and surfaces `extra.raw_feasible` /
`extra.snapped` so the dashboard can distinguish optimiser-converged
tours from post-hoc-snapped ones.
* `app/streamlit_app.py` — sidebar replaces the single
`column_penalty` slider with `row_penalty` + `col_penalty`, plus an
explanatory caption. Per-problem `size_default` / `size_max` updated
to keep EA, TSP usable out-of-the-box.
* `app/_solution_viz.py` — spin-system renderers now place up / down
triangle markers on the actual topology of the problem:
- 1D Ising -> ring with periodic bonds
- SK -> circle (no spatial structure) + complementary local-energy
bar (positive = frustrated)
- 2D EA -> lattice grid with bond ribbons
- 3D EA -> side-by-side z-slices (capped at six)
Title carries colour-coded up / down counts. The TSP renderer adds
segment direction arrows, an optional pairwise-distance backdrop for
small N, and a "raw permutation" / "Hungarian-snapped" badge.
* `tests/test_extra_problems.py` — three new TSP regression tests
(BinaryRelaxation + two penalties; per-term decomposition; Hungarian
snap always returns a valid permutation) and one EA preview test
ensuring the sparse scatter fallback fires for `L=16, dim=3`.
ruff format && ruff check clean. pytest: 91 passed, 1 skipped.1 parent efd6e4b commit 795450d
5 files changed
Lines changed: 646 additions & 118 deletions
File tree
- app
- src/qqa/problems
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
946 | 946 | | |
947 | 947 | | |
948 | 948 | | |
949 | | - | |
| 949 | + | |
| 950 | + | |
950 | 951 | | |
951 | 952 | | |
952 | 953 | | |
| |||
1001 | 1002 | | |
1002 | 1003 | | |
1003 | 1004 | | |
1004 | | - | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
1005 | 1053 | | |
1006 | | - | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
1007 | 1059 | | |
1008 | 1060 | | |
1009 | | - | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
1010 | 1064 | | |
1011 | 1065 | | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
1012 | 1070 | | |
1013 | 1071 | | |
1014 | 1072 | | |
| |||
0 commit comments