Skip to content

CModel accepts a library path, and a fixed library needs no arguments - #1

Merged
sshin23 merged 3 commits into
masterfrom
robin/path-and-fixed
Aug 11, 2026
Merged

CModel accepts a library path, and a fixed library needs no arguments#1
sshin23 merged 3 commits into
masterfrom
robin/path-and-fixed

Conversation

@sshin23

@sshin23 sshin23 commented Aug 11, 2026

Copy link
Copy Markdown
Member

Summary

Mirrors MadNLP/CNLPModels.jl's path + fixed-library support, so the two consumers keep one contract (producer side: madsuite-org/ExaModels.jl#301):

  • CModel accepts a library path directly. A string with a directory part or the platform's shared-library extension is loaded directly and cached by absolute path, with the prefix defaulting to the file name stripped of lib and the extension; a bare name resolves against CNLPMODELS_PATH as before.
  • A fixed library needs no arguments. With no arguments, _instantiate consults <prefix>_nargs() and, when it reports 0, instantiates through <prefix>_new directly (ignored integer and all). Libraries that do not declare their arity keep the old behaviour.

So cnlpmodels.CModel("/opt/models/fixed/lib/libfixed.so") is a complete construction.

Tests

Fixture and tests mirror the Julia repo's (fx prefix: tq fixed at n = 3). Disabling the _nargs consult fails exactly the two new tests; 14 passed, 1 skipped with it in place.

🤖 Generated with Claude Code

Mirrors the CNLPModels.jl change, so the two consumers keep one contract.

A string is a library PATH when it has a directory part or the platform's
shared-library extension, and a search-path NAME otherwise. A path is
loaded directly and cached by absolute path, with the prefix defaulting to
the file name stripped of lib and the extension; a name resolves against
CNLPMODELS_PATH as before.

With no arguments, _instantiate consults <prefix>_nargs() — exported by
libraries ExaModelsC compiles from a placeholder-free core — and when it
reports 0 instantiates through <prefix>_new directly, ignored integer and
all. Libraries that do not declare their arity keep the old behaviour.

Fixture and tests mirror the Julia repo's (fx prefix: tq fixed at n = 3);
disabling the _nargs consult fails exactly the two new tests (14 passed,
1 skipped with it in place).
Mirrors the CNLPModels.jl change: "@opf" resolves the name opf against
CNLPMODELS_PATH; any other string is a filesystem path exactly as written
("opf" = file in the current directory, "/path/to/opf" = full path, and
a bundle directory resolves to the library inside it). Prefix defaults from
the name or the resolved stem. Tests updated to the sigil, including the
bare-string-is-a-local-file pin.
Mirrors the CNLPModels.jl fix: dlopen treats a slash-free relative like
qp.so as a soname to search the system path for, not as a file in the
current directory, so the bare-string semantics only worked where
LD_LIBRARY_PATH happened to contain an empty entry. _resolve_path now
returns absolute paths. Verified with LD_LIBRARY_PATH scrubbed.
@sshin23
sshin23 merged commit 39bb5aa into master Aug 11, 2026
2 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