Compilation Is Very Slow

If set_* functions take a long time to run, you're experiencing slow compilation (yes, it is indeed slow). This is because set_* calls Numba to compile the required functions to accelerate subsequent problem solving. While pockit has optimized this process as much as possible, compilation time can still be lengthy for complex problems (potentially taking several minutes).

If compilation time is too long, try these methods:

Check Problem Settings

  • Don't set simplify=True or parallel=True, as these will increase compilation time. (Default values are False, so ignore this if you haven't manually set them.)
  • Input expressions should be compilation-friendly. For example, \(x^2\) should be input as x * x or x ** 2, rather than pow(x, 2.0), so that symbolic differentiation can better handle the expression.

Optimize Solution Process

To avoid repeated compilation, pockit's set_* functions are designed to be decoupled. When setting new dynamics equations, constraints, objective functions, boundary conditions, or discretization parameters, you don't need to recompile other functions. For example, if you need to solve the same system with different boundary conditions, you only need to call set_boundary_condition without recalling set_dynamics, thus avoiding recompilation.

Note: If you call Phase's set_* functions after System.set_phase, you need to call System.update once afterward to update the problem information. (System.update doesn't require compiling any functions and is very fast.)

Cache Compilation Results

For users repeatedly working on the same problem, compilation results can be cached locally to avoid recompilation. This can significantly reduce compilation time. Here's how:

  1. Create a cache folder to store compilation results.
  2. Set the cache parameter in set_* functions to the cache directory path. For example with set_dynamics:
    P.set_dynamics(..., cache='./path/to/cache')
    Supported functions include Phase.set_dynamics, Phase.set_integral, Phase.set_phase_constraint, Phase.set_boundary_condition, System.set_objective, System.set_system_constraint

This way, compilation results will be saved to the cache folder and will be loaded directly the next time you run.

Using Pre-compiled Functions

If the above methods still don't meet your needs, you can completely bypass pockit's symbolic differentiation and compilation features by using pre-compiled functions directly. See Skip Symbolic Differentiation.