Solvers¶
Declare an optimization problem with problem and ProblemSpec, then select an installed backend
with solver. The result is a Solver that you call with the problem parameters.
Use x0= for an initial guess or warm= for a previous result, and .stats()
to inspect the latest numerical solve. Its .function exposes the full input signature
for integrations that need a Function.
See the solver guide for a complete example and
solver backends for backend-specific options.
Problem construction and statistics are useful in application code. Plugin descriptors and graph queries support solver integrations and compiler extensions.
Problem construction¶
Bounded
dataclass
¶
A named constraint group with an optional lower and upper bound.
Source code in src/scaly/solvers/problem.py
bounded ¶
Declare a lower- and/or upper-bounded inequality group.
Source code in src/scaly/solvers/problem.py
NO_LB
module-attribute
¶
A scalar expression that leaves one variable block unbounded below.
NO_UB
module-attribute
¶
A scalar expression that leaves one variable block unbounded above.
ProblemSpec
dataclass
¶
The objective, constraint groups, and box bounds returned by a problem body.
lb and ub have the variables’ tree structure. Scalar expression leaves broadcast over
their variable blocks. Use NO_LB or NO_UB for an open side of one leaf.
Source code in src/scaly/solvers/problem.py
Problem
dataclass
¶
A traced backend-free problem and its declared variable and parameter trees.
Source code in src/scaly/solvers/problem.py
problem ¶
problem(*, vars: Tree[Any, Any], params: Tree[Any, Any] | None = None, name: str | None = None) -> Callable[[Callable[..., ProblemSpec[Any]]], Problem[Any, Any, Any, Any]]
Trace a backend-free problem over declared variables and parameters.
Source code in src/scaly/solvers/problem.py
Solver selection¶
solver ¶
solver(problem: Problem[SV, NV, SP, NP], backend: str, /, *, name: str | None = None, options: dict[str, Any] | None = None) -> Solver[SV, NV, SP, NP]
Build a typed Solver for one backend-free problem.
Source code in src/scaly/solvers/solver.py
Solver
dataclass
¶
A compiled solver called with its parameters. The initial point and multipliers default to zero.
function is the plain Function with the full five-group signature, for code generation,
input_names and anything else that takes a Function. Its four outputs are its first four
inputs, so passing a previous result as warm warm-starts the next call.
Source code in src/scaly/solvers/solver.py
solver_loadable ¶
Return whether the discovered solver can be dlopened and has headers for JIT/AOT codegen.
Source code in src/scaly/solvers/paths.py
SolverLibraryError ¶
Bases: ToolchainError
Raised when a solver's shared library or C headers cannot be located or loaded.
Compiling or calling a function that reaches the solver raises it. The message lists the
locations searched, as scaly_toolchain reports them.
Source code in src/scaly/solvers/paths.py
qp_problem ¶
qp_problem(n: int, n_eq: int, n_ineq: int) -> Problem[Expr, np.ndarray, QPData[Expr], QPData[np.ndarray]]
Return the typed matrix-data form of a quadratic problem.
Source code in src/scaly/solvers/qp.py
NotQuadratic ¶
Plugin interfaces¶
These are the names a solver plugin builds on. Solver plugins explains how they fit together.
SolverBackend ¶
Bases: Protocol
The full solver plugin protocol: packaging metadata plus the C wrapper template. Solves always run through the generated C wrapper, and plugins ship no Python solve path.
Source code in src/scaly/solvers/registry.py
render_wrapper ¶
Emit the C wrapper for one solver Function (see docs/dev/solver_plugins.md).
Must define static void <ctx.raw_symbol>(...) with the descriptor's
in*/out* signature plus a trailing double* w, drive the solver's
C API with the oracle kernels (ctx.raw_symbol_of), and fill
ctx.stats_symbol on every call.
Source code in src/scaly/solvers/registry.py
NlpSolverBackend ¶
Bases: SolverBackend, Protocol
Solver backend protocol for NLP plugins, including Hessian layout.
Source code in src/scaly/solvers/registry.py
SolverWrapperCtx
dataclass
¶
Codegen kit handed to a plugin's render_wrapper hook.
symbol is the solver's mangled C identifier (prefix for any static the
template declares), raw_symbol the function the template must define,
stats_symbol the scaly_solver_stats static it must fill (declared by
core, one per solver). raw_symbol_of resolves the C symbol of an oracle
/ derivative Function from the descriptor.
Source code in src/scaly/codegen/solver.py
SolverDescriptor
dataclass
¶
Everything a solver plugin's generated C wrapper needs to drive a solve.
Stored as a single attr on every ExprOp.SOLVER_CALL node so that nodes for
different outputs of the same solve share one identity. Frozen + identity
hash (via id) so it can live inside Expr.attrs without surprising
structural equality.
Source code in src/scaly/solvers/model.py
structural_key ¶
Stable per-instance key used by Expr.structural_key for SOLVER_CALL nodes.
ExternalOracle
dataclass
¶
A C-ABI oracle supplied by a plugin consumer instead of an Scaly graph.
source must define raw_symbol with the same flat-buffer convention
as generated Scaly kernels: one const double* per input, one double*
per output, and a trailing double* workspace argument. workspace_size
declares the number of doubles available through that final argument.
Source code in src/scaly/solvers/model.py
descriptor_function ¶
descriptor_function(descriptor: SolverDescriptor, input_tree: Tree[Any, Any] | None = None, output_tree: Tree[Any, Any] | None = None) -> Function[Any, Any, Any, Any]
Build the plain Function whose opaque outputs share descriptor.
Source code in src/scaly/solvers/model.py
Statistics¶
SolverStats
dataclass
¶
The statistics of one numerical solve, as returned by Solver.stats().
The fields mirror the generated scaly_solver_stats struct, whose layout and meaning are
described on the generated-interface page of How it works. Diagnostics
a backend does not report are zero.
Source code in src/scaly/solvers/stats.py
to_solver_status ¶
Summarize these statistics. ok holds for OK and ACCEPTABLE.
Source code in src/scaly/solvers/stats.py
SolverStatus
dataclass
¶
A short solve summary from SolverStats.to_solver_status(): the status, iterations and oracle evaluation counts.
Source code in src/scaly/solvers/stats.py
ScalySolveStatus ¶
Bases: IntEnum
Backend-neutral solve outcome, as reported in the generated statistics struct.
Each backend maps its own native status onto these, so calling code does not have to know
which solver ran. OK and ACCEPTABLE are the successful ones.
Source code in src/scaly/solvers/stats.py
Graph queries¶
is_solver_function ¶
Return whether fun is a solver's own function, the one Solver.function exposes.
solver_callees ¶
Return the inner Functions a solver Function depends on at codegen time.
Source code in src/scaly/solvers/graph.py
solver_compile_flags ¶
Compiler/linker flags an AOT consumer needs for fun.
Returns [] when fun does not transitively reach any solver.
Otherwise: plugin package -I / -L paths, each reached backend's
link_flags, and an -Wl,-rpath pointing at the vendored lib
directories so the resulting binary finds the shared libs at load time
without LD_LIBRARY_PATH / DYLD_LIBRARY_PATH overrides.
Set rpath=False if the consumer plans to bundle the libs elsewhere and
will set the rpath / install_name themselves.