Expand description
AMPL imported (external) function support via the funcadd_ASL ABI.
This module implements enough of AMPL’s funcadd.h ABI to:
dlopena user-supplied shared library;- resolve the
funcadd_ASLsymbol and call it; - receive registration callbacks of the form
Addfunc(name, rfunc, type, nargs, funcinfo, ae)and record them; - later call back into the registered
rfuncwith anarglistto obtain function values, gradients, and Hessians.
The AmplExports and Arglist struct layouts are taken from
AMPL-MP/ASL funcadd.h; cross-checked against the ctypes mapping in
pyomo.core.base.external. Fields we don’t populate are left null —
Pyomo does the same and it is sufficient for IDAES’s Helmholtz library
(see issue #15).
All unsafe FFI is contained in this module. Public surface is safe.
Structs§
- Ampl
Exports - The
AmplExportsstruct from AMPL’sfuncadd.h. Layout must match exactly. Function pointers we don’t implement are held as*mut c_void(null) — AMPL’s ABI does not require a caller to populate them unless the loaded library actually invokes them. - Arglist
- The
argliststruct from AMPL’sfuncadd.h. Layout must match exactly. - Eval
Result - Return value from
ExternalLibrary::eval. - External
Library - A loaded external-function library plus its registered functions.
- External
Resolver - Resolved AMPL imported function: shared library + registered name.
NlProblemcarries one of these perImportedFuncid when external functions are wired up at problem-build time. The sameArc<ExternalLibrary>may be shared across many funcall ids (one library typically registers several functions). - Registered
Func - A function registered by a library via
Addfunc. Mirrors the ASLFUNCADD_TYPEbits infuncadd.h.
Enums§
- External
Arg - One positional argument to an external function.
Constants§
- FUNCADD_
OUTPUT_ ARGS - Set if the function is allowed to have a variable number of args.
- FUNCADD_
RANDOM_ VALUED - FUNCADD_
REAL_ VALUED - FUNCADD_TYPE bits (mirrors
funcadd.h). - FUNCADD_
STRING_ ARGS - Set if the function consumes string arguments. Value is still real.
Functions§
- collect_
funcall_ ids - Walk an
Exprand collect every funcall id it references (including through CSEs). Used to build anExternalResolvercovering exactly the functions a problem actually uses.
Type Aliases§
- Addfunc
Fn - Pointer to the
Addfunccallback provided by the caller. - Addrandinit
Fn - Pointer to the
Addrandinitcallback. - AtReset
Fn - Pointer to the
AtResetcallback. - Rand
Seed Setter - Pointer to the
RandSeedSettercallback. - Rfunc
- Pointer to a user-defined real-valued function, matching
typedef real (*rfunc)(arglist*).