Repository navigation
Use adjoint map for Hermitian PSD variable bridge - #3141
Conversation
Represent Hermitian PSD variables by the adjoint of the constraint bridge's real PSD embedding, removing the structural equality constraints. Reuse the constraint bridge's map methods through Variable.SetMapBridge and retain support for partial variable starts. Use half the real PSD embedding as the inverse adjoint, preserving positive semidefiniteness of starts. Add regression coverage for unstructured PSD representatives, rank-one preimages, triangle inner products, and affine substitutions. Validation: both affected bridge test files pass (267 assertions). All 15 temporary line markers were hit, including numeric and VectorOfVariables adjoint paths. JuliaFormatter 2.14.10 was run over the repository; a second pass left git diff empty.
Query the dimension with output_dim instead of constructing a scalar iterator. Build eachscalar once for the full adjoint and reuse its cache when mapping components, avoiding repeated scans of affine and quadratic terms. Add symbolic affine and quadratic regression tests for full and indexed adjoint evaluation. Both affected bridge test files pass (277 assertions); temporary line and type markers verified both symbolic paths and were removed. Repository-wide JuliaFormatter 2.14.10 passes with no unstaged diff.
|
Wow. I was planning to do a PR, but it would have taken me considerably longer. Thanks! |
|
I did a few benchmarks. I tested the explicit dual: max t subject to C − tI ⪰ 0, using the constraint bridge. SCS slightly prefers the old bridge:
For Clarabel it's mostly unchanged and for CSDP, the new bridge is way better
Since the new bridge Variable bridge is the equivalent of the old constraint bridge it's definitely better to have it like that. Since it's slightly better for SCS, one could try having the primal-dual pair of the old bridge as variable and constraint bridge add them to JuMP and remove the ones in MOI but for simplicity let's not add them in MOI unless there is a strong incentive. |
|
Why should it make any difference for SCS? It doesn't use this bridge, it has a native complex PSD cone. I tested to check whether SCS was accidentally using the bridge, and it indeed wasn't. I then ran the benchmarks anyway and got no difference:
Perhaps you used an AI to do it and it just hallucinated some numbers instead of running the code? |
Use incremented triangular indices for the full-vector adjoint instead of calling the indexed method for every component. Avoid repeated matrix-size calculations and inverse_trimap/isqrt calls. Keep the indexed method for individual components, coefficient-type-aware scalar operations, and one cached scalar iterator for symbolic inputs. Extend full-map tests to include VectorOfVariables alongside affine and quadratic functions. Compare the exact indexed implementation at bc1d764f with the sequential loop using identical dependencies, Julia 1.13.3, and BenchmarkTools 1.8.0 on the Core i7-12700K. Compilation is warmed; use medians of up to 100 samples / 2 seconds with one full-vector evaluation per sample. n is the Hermitian order; the input is a Float64 triangle of real PSD order 2n. | n | Indexed (ms) | Sequential (ms) | Speedup | Bytes (both) | Allocations (both) | | ---: | ---: | ---: | ---: | ---: | ---: | | 100 | 0.195760 | 0.030335 | 6.45x | 80072 | 3 | | 500 | 4.782259 | 0.545091 | 8.77x | 2000072 | 3 | | 1000 | 20.064708 | 3.352298 | 5.99x | 8000072 | 3 | Validation: both affected bridge test files pass (282 assertions). All four added-loop coverage markers were hit, including numeric vectors, variables, affine functions, and quadratic functions; markers were removed. Full maps agree exactly with indexed components at all three benchmark sizes. JuliaFormatter 2.14.10 run repository-wide with a stable second pass. Performance probes and raw results are kept on the companion perf branch.
|
Yes SCS is not using that bridge, I used a For the performance of the bridge itself, with Hermitian of size 500, comparing the original implementation with the final version:
The full variable is a bit slower because when we substitute variables into the bridged variables, we now have two terms so it's a bit slower, but this is to be expected so it's ok |
|
COSMO also has a native complex PSD cone. |
a96f117 to
1136b04
Compare
|
Ahah then a hypothetical ADMM solver then ^^ |
Closes #3139