Skip to content

Select a model by name in a library carrying several - #5

Merged
sshin23 merged 1 commit into
masterfrom
anvil/model-selection
Aug 13, 2026
Merged

Select a model by name in a library carrying several#5
sshin23 merged 1 commit into
masterfrom
anvil/model-selection

Conversation

@sshin23

@sshin23 sshin23 commented Aug 13, 2026

Copy link
Copy Markdown
Member

One shared library may export several models, each under its own symbol prefix with its own schema and instances — the multi-model form ExaModelsC.compile_library now emits (madsuite-org/ExaModels.jl#308). Selecting by prefix= already worked; this adds the first-class selection spelling, mirroring CNLPModels.jl's CNLPModel(lib, :acopf, ...) (madsuite-org/CNLPModels.jl#6):

m = cnlpmodels.CModel("grid", "acopf", bus, 100.0)   # acopf_* inside libgrid.so
d = cnlpmodels.CModel("grid", "dcopf", bus)          # dcopf_* in the same file
sch = cnlpmodels.schema(lib, "acopf")                # schemas are per model

A leading string argument names the model (unambiguous — a model argument is never a string). A mistyped name is refused at selection with the witness symbol named — {model}_nvar, which the ABI requires of every model however it instantiates — instead of surfacing as a raw ctypes undefined symbol several calls later. Giving both a model name and a disagreeing prefix= is a TypeError; omitting the name keeps the single-model spelling, so one-model libraries are unaffected.

Tests cover selection of both fixture models (one-knob tq and builder-only sq) out of one library, instance independence across models, the refusal message, the conflict check, and per-model schemas; also verified against a compiled two-surface ExaModelsC library. Suite: 16 passed, 1 pre-existing environment skip.

🤖 Generated with Claude Code

A leading string argument names the model — the name is the symbol
prefix its ABI functions are exported under, the same selection
spelling as CNLPModels.jl's CNLPModel(lib, :acopf, ...). Unambiguous,
since a model argument is never a string. A mistyped name is refused
at selection with the witness symbol named ({model}_nvar, which the
ABI requires of every model however it instantiates) instead of
surfacing as a raw ctypes undefined-symbol error several calls later;
schema() takes the same optional name, and lib() tolerates the @name
sigil spelling. Rebuilt on current master, whose string-spec
convention (@name vs path) already matched the Julia consumer — the
earlier version of this branch had re-implemented it from a stale
base.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sshin23
sshin23 force-pushed the anvil/model-selection branch from 8a96c8d to 3856751 Compare August 13, 2026 04:56
@sshin23
sshin23 merged commit a396190 into master Aug 13, 2026
0 of 2 checks passed
sshin23 added a commit that referenced this pull request Aug 13, 2026
One ruff finding (FURB188) in the sigil tolerance merged in #5; the
merge landed before its CI leg reported.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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