Skip to content

Use compact aliases when displaying polynomial basis types - #418

Merged
blegat merged 3 commits into
mainfrom
bl/basis_type_display
Nov 23, 2026
Merged

blegat merged 3 commits into
mainfrom
bl/basis_type_display

Conversation

@blegat

@blegat blegat commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

FullBasis and SubBasis are aliases for StarAlgebras types. Julia's default type display expands their internal mapping, iterator, and storage types, including inside SOS sets and certificates. Add explicit show methods using the existing MP aliases and preserve the basis family, variables, and exponent types. Support partial families, upper bounds, unions, and nested types; defer lower-bounded families to the default display.

For typeof(FullBasis{Monomial}([x, y])) with default DP variables, before printing expanded the implementation:

StarAlgebras.MappedBasis{
    AbstractMonomial{
        Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}},
        Vector{Int64}
    },
    Vector{Int64},
    ExponentsIterator{Graded{LexOrder}, Nothing, Vector{Int64}},
    Variables{
        Monomial,
        Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}}
    },
    typeof(exponents)
}

After:

MultivariatePolynomials.FullBasis{
    Monomial,
    Vector{Variable{DynamicPolynomials.Commutative{DynamicPolynomials.CreationOrder}, Graded{LexOrder}}},
    Vector{Int64}
}
Configuration Build + solve (ms) Solver (ms) Other time (ms) Allocated (MB)
Clarabel 486.3 456.9 29.5 51.7
Dual Hypatia released display 1007.8 97.7 910.4 319.0

These display methods remove most of the error-formatting overhead but do not eliminate it. Generic alias lookup for the retained vector types remains expensive. A separate warmed REPL measurement of 200 displays per type (also with zero compilation time) illustrates that residual cost:

Type displayed Time per display (ms) Allocated per display (bytes)
Compact FullBasis 0.576 182496
Compact SubBasis 0.582 182496
Vector of DP variables 0.306 109584
Vector{Int} 0.234 72848

FullBasis and SubBasis are aliases for StarAlgebras types. Julia's default
type display expands their internal mapping, iterator, and storage types,
including inside SOS sets and certificates. Add explicit show methods
using the existing MP aliases and preserve the basis family, variables,
and exponent types. Support partial families, upper bounds, unions, and
nested types; defer lower-bounded families to the default display.

Validation: 27 standalone MP display assertions pass using the environment
from test/Project.toml; temporary line markers exercise every new display
branch. The existing DP (50) and TP (165) display assertions and six frontend
integration assertions pass. Format the repository with JuliaFormatter 2.

Ellipsoid benchmark: four relaxations (degrees 2, 4, 6, 8), 11 warmed runs,
medians, Julia 1.13.3, one Julia and one BLAS thread, matched feasibility
and absolute/relative optimality tolerances of 1e-7. MP 0.6.4 with this
change, DP 0.7.0, released Dualization 0.7.7, Hypatia 0.11.0, Clarabel 0.11.1.
An in-memory switch compares the released and compact type displays in
the same process. Dualization is unmodified. Every measured run has zero
compilation/recompilation time and passes all eight tutorial assertions.

| Configuration | Build + solve (ms) | Solver (ms) | Other time (ms) | Allocated (MB) |
| --- | ---: | ---: | ---: | ---: |
| Clarabel | 486.3 | 456.9 | 29.5 | 51.7 |
| Dual Hypatia released display | 1007.8 | 97.7 | 910.4 | 319.0 |
| Dual Hypatia compact display | 413.0 | 97.2 | 315.7 | 125.0 |

These display methods remove most of the error-formatting overhead but
do not eliminate it. Generic alias lookup for the retained vector types
remains expensive. A separate warmed REPL measurement of 200 displays per
type (also with zero compilation time) illustrates that residual cost:

| Type displayed | Time per display (ms) | Allocated per display (bytes) |
| --- | ---: | ---: |
| Compact FullBasis | 0.576 | 182496 |
| Compact SubBasis | 0.582 | 182496 |
| Vector of DP variables | 0.306 | 109584 |
| Vector{Int} | 0.234 | 72848 |
Track type display invalidations separately while retaining the existing arithmetic invalidation limit. Handle SnoopCompile entries without an associated method and exercise that case explicitly.

Use one show method for both basis families to avoid ambiguity at Union{} on Julia 1.14. Defer bottom types and union families to the default type printer, including UnionAll wrappers.

Validation: the standalone invalidation tests (2 assertions) and type display tests (31 assertions) pass on Julia 1.10.13, 1.13.4, and 1.14.0-beta1 using test/Project.toml environments and the CI dependency exclusions on 1.14. Temporary line markers confirm coverage of the changed branches. JuliaFormatter 2 checks pass for src and test.
@blegat
blegat force-pushed the bl/basis_type_display branch from 5ab1271 to f5d33e3 Compare November 17, 2026 16:27
Use explicit Int64 and Int32 exponent types so the union remains distinct on both architectures. Int aliases Int32 on 32-bit Julia, causing the union to collapse.

Validation: test/type_display.jl passes all 31 assertions on Julia 1.13.4 x64; temporary line markers confirm both basis families execute the changed line. Ran JuliaFormatter 2 on src and test.
@blegat
blegat merged commit 482e2d8 into main Nov 23, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant