Skip to content

Add a name mapping to DualNames - #236

Open
joaquimg wants to merge 1 commit into
masterfrom
jg/dualname-mapping-master
Open

Add a name mapping to DualNames#236
joaquimg wants to merge 1 commit into
masterfrom
jg/dualname-mapping-master

Conversation

@joaquimg

@joaquimg joaquimg commented Sep 9, 2026

Copy link
Copy Markdown
Member

Closes #114.

Closes #114.

The names of the dual objects are derived from the names of the primal
objects they come from. Until now the only available transformation was
to prepend a fixed prefix, which gives names such as
`dualaffine_cons[1]` where one would rather read `α[1]`.

`DualNames` gains a `mapping` field, a vector of `"from" => "to"` pairs.
Each entry replaces the leading `"from"` of a primal name with `"to"`,
so the index part of a container name is preserved:

    dualize(model; dual_names = DualNames(; mapping = ["affine_cons" => "α"]))
    # λ : α[1] + α[2] + α[3] == 1

Entries are tried in order and the first match is applied. The prefixes
are the fallback, so a mapping can cover only part of the model.

`DualNames` is now built with keyword arguments. The positional
constructors are kept for backwards compatibility, and the field names
are unchanged.

Two behaviour changes worth noting:

  * `is_empty(::DualNames)` now checks the fields instead of comparing
    against the `EMPTY_DUAL_NAMES` sentinel. `DualNames` is mutable, so
    that comparison was an identity check, which made any explicitly
    built `DualNames()` enable the naming. A `DualNames` with no prefix
    and no mapping now names nothing. `test_JuMP_dualize.jl` relied on
    the old behaviour to get the default prefixes of the parameters and
    of the quadratic slacks, and now asks for them explicitly.

  * The naming of each family of dual object goes through its own
    internal function, so the prefix is selected at the call site
    instead of being looked up from a `Symbol`.
@codecov

codecov Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.38%. Comparing base (565af97) to head (423ed97).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #236      +/-   ##
==========================================
+ Coverage   95.22%   95.38%   +0.16%     
==========================================
  Files          17       17              
  Lines         858      888      +30     
==========================================
+ Hits          817      847      +30     
  Misses         41       41              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@joaquimg
joaquimg added this pull request to stack #238 September 9, 2026 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

DualNames mapping rather than prefix

1 participant