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.
The programs run in 64-bit floats, whatever the setting of jax.enable_x64 is.
CompiledProblem ¶
Bases: NamedTuple
A problem whose functions are compiled, ready to solve.
problem
instance-attribute
¶
The problem that was compiled, or None for one that load returned.
constraint_shapes
instance-attribute
¶
The shape of the output of each constraint.
native
instance-attribute
¶
The compiled programs with the buffers that Ipopt's callbacks share.
structure
instance-attribute
¶
Where the Jacobian and the Hessian have entries, in the order of their values.
solve ¶
solve(problem: CompiledProblem | Problem, x0: PyTree[Any] = None, params: PyTree[Any] = None, options: SolveOptions = SolveOptions(), compile_options: CompileOptions = CompileOptions(), warm_start: Solution | None = None) -> Solution
Solves a problem for the given parameter values, starting from x0.
A Problem is compiled first with compile_options, while a CompiledProblem ignores
them. Without x0 the start is the point nearest to the origin inside the bounds.
A previous Solution as warm_start supplies the multipliers that Ipopt starts from,
and x0 should then be its x.
save ¶
Saves a compiled problem to a file that load reads. .xip 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) -> 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) -> 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 come from the file. The result solves like a compiled
problem, with the structure of variables for x, except that its problem is None.
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.
SparsityDetectionError ¶
Bases: RuntimeError
The sparsity pattern of a derivative could not be detected.
ipopt_version ¶
Returns the major, minor and patch version of the linked Ipopt.