Skip to content

Add PrecompileTools.jl#208

Draft
odow wants to merge 1 commit into
mainfrom
od/precompile
Draft

Add PrecompileTools.jl#208
odow wants to merge 1 commit into
mainfrom
od/precompile

Conversation

@odow

@odow odow commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Rebased #204
Part of #115

This needs some discussing/direction, because we need to decide what to precompile.

Things we can precompile:

  • Anything that uses ONLY stuff inside PowerOperationsModels or its direct dependencies

Things we cannot precompile:

  • Anything that uses a package that is not a direct dependency. This means stuff like solve! which require an optimizer.

I think we also need a small-scale system that we can build with some data. What's the best way to do this? Can we include a file that we read in at precompile time?

A downside to the design of a mix of packages is that it's harder to precompile things. It would be trivial if there was a single Sienna.jl where we could build and load an entire test system.

In PowerModels, we do:

PrecompileTools.@setup_workload begin
    logger_config!("error")  # Turn off logging for this precompile block
    case3 = joinpath(dirname(@__DIR__), "test/data/matpower/case3.m")
    case9 = joinpath(dirname(@__DIR__), "test/data/matpower/case9.m")
    PrecompileTools.@compile_workload begin
        for case in [case3, case9]
            data = parse_file(case)
            _ = instantiate_model(data, ACPPowerModel, build_opf)
            _ = instantiate_model(data, ACPPowerModel, build_pf)
            _ = instantiate_model(data, DCPPowerModel, build_opf)
            _ = instantiate_model(data, DCPPowerModel, build_pf)
        end
        _ = compute_ac_pf(case9)
        _ = compute_dc_pf(case9)
    end
    logger_config!("info")   # Re-enable default logging
end

We chose two small systems, and we choose to precompile only ACP and DCP, for both OPF and PF. This is a win, but it doesn't help the user if they're doing something more exotic.

@odow

odow commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator Author

@jd-lara says

the biggest challenge is that we don't want to rely on loading a whole system to do this from CaseBuilder. I wonder if we can precompile pieces with mock components.

Except this is part of the problem. If the system data is separate from the implementation, then we can't precompile the relevant stuff here. We could use mock components only if they will hit the same methods that will actually be hit when the user runs.

@jd-lara
jd-lara marked this pull request as draft July 24, 2026 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant