Skip to main content

Module nl_external

Module nl_external 

Source
Expand description

AMPL imported (external) function support via the funcadd_ASL ABI.

This module implements enough of AMPL’s funcadd.h ABI to:

  1. dlopen a user-supplied shared library;
  2. resolve the funcadd_ASL symbol and call it;
  3. receive registration callbacks of the form Addfunc(name, rfunc, type, nargs, funcinfo, ae) and record them;
  4. later call back into the registered rfunc with an arglist to 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§

AmplExports
The AmplExports struct from AMPL’s funcadd.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 arglist struct from AMPL’s funcadd.h. Layout must match exactly.
EvalResult
Return value from ExternalLibrary::eval.
ExternalLibrary
A loaded external-function library plus its registered functions.
ExternalResolver
Resolved AMPL imported function: shared library + registered name. NlProblem carries one of these per ImportedFunc id when external functions are wired up at problem-build time. The same Arc<ExternalLibrary> may be shared across many funcall ids (one library typically registers several functions).
RegisteredFunc
A function registered by a library via Addfunc. Mirrors the ASL FUNCADD_TYPE bits in funcadd.h.

Enums§

ExternalArg
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 Expr and collect every funcall id it references (including through CSEs). Used to build an ExternalResolver covering exactly the functions a problem actually uses.

Type Aliases§

AddfuncFn
Pointer to the Addfunc callback provided by the caller.
AddrandinitFn
Pointer to the Addrandinit callback.
AtResetFn
Pointer to the AtReset callback.
RandSeedSetter
Pointer to the RandSeedSetter callback.
Rfunc
Pointer to a user-defined real-valued function, matching typedef real (*rfunc)(arglist*).