Compiling and solving¶
compile ¶
compile(
problem: Problem,
params: PyTree[Any] = None,
options: CompileOptions = CompileOptions(),
) -> CompiledProblem
Compiles the functions of a problem for parameters of the given structure and shapes.
params may hold arrays or jax.ShapeDtypeStructs, since only their structure,
shapes and types matter. The result solves with any parameter values of that layout.
CompiledProblem ¶
Bases: NamedTuple
A problem whose functions are analysed and compiled, ready to solve.
solve ¶
solve(
problem: CompiledProblem | Problem,
params: PyTree[Any] = None,
options: SolveOptions = SolveOptions(),
compile_options: CompileOptions = CompileOptions(),
) -> Solution
Solves a problem for the given parameter values.
A Problem is compiled first with compile_options. Terms compiled earlier in the
process are reused, so this is cheap after the first call. A CompiledProblem ignores
compile_options.
solve_file ¶
Solves a problem file with SCIP's own readers and expression handlers.
The result is a reference for JAX-CIP's results on the same problem.
clear_caches ¶
Forgets the terms compiled in this process, so later builds use the disk cache.
save ¶
Saves a compiled problem to a file that load reads. .jcp is the usual extension.
load ¶
load(
path: str | PathLike[str],
variables: PyTree[Any],
params: PyTree[Any] = None,
*,
on_mismatch: Literal[
"recompile", "raise"
] = "recompile",
warm_up: bool = True,
threads: int | None = None,
) -> CompiledProblem
Returns the compiled problem that save wrote to a file, as loads does.
dumps ¶
Returns a compiled problem as bytes that loads reads.
The programs are stored together with their StableHLO, so a machine that cannot use the stored executables compiles the source instead.
loads ¶
loads(
data: bytes,
variables: PyTree[Any],
params: PyTree[Any] = None,
*,
on_mismatch: Literal[
"recompile", "raise"
] = "recompile",
warm_up: bool = True,
threads: int | None = None,
) -> CompiledProblem
Returns the compiled problem that dumps made from bytes.
variables and params are trees with the structure that the problem was compiled for.
The leaves of variables are Variables or arrays, and those of params are arrays or
jax.ShapeDtypeStructs, as for compile. Only their paths and shapes are checked
against the file, and the bounds and domains come from the file. The result solves like
a compiled problem, with the structure of variables for x. Its problem is None,
and its terms have no jaxprs.
Executables that were stored for another machine are replaced by a compilation of the
StableHLO, unless on_mismatch is raise. With warm_up each program runs once, so the
first solve is as fast as the later ones. The executables load on threads threads, or
one per CPU core.