Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add profiling #36

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open

Add profiling #36

wants to merge 21 commits into from

Conversation

joaquimg
Copy link
Member

@joaquimg joaquimg commented Nov 16, 2024

close #7

@joaquimg
Copy link
Member Author

Percentages of total runtime

PowerModels,JuMP,HiGHS,Highs_run
pglib_opf_case162_ieee_dtc.m,59.166666666666664,55.00000000000001,49.166666666666664

Sienna,JuMP,HiGHS,Highs_run
CopperPlate-12-29,56.16152585307703,55.014155863507675,54.671434957532405

GenX,JuMP,HiGHS,Highs_run
1_three_zones,92.62319268220715,75.19917379758041,68.20596046031278

Tulipa,JuMP,HiGHS,Highs_run
1_EU_investment_simple_24h,16.839772884642016,2.354244564464756,2.104971610580252

@joaquimg joaquimg changed the title Add profiling [WIP] Add profiling Nov 17, 2024
@odow
Copy link
Member

odow commented Nov 17, 2024

So if I read that right, lots of room for improvement in GenX and Tulipa?

@joaquimg
Copy link
Member Author

Yes, we might improve on the JuMP side on both Tulipa and GenX! Although JuMP is certainly not the main bottleneck.

Sienna seems pretty much optimized on the JuMP side. About 50% of the time, it's doing other stuff (probably IO).

@odow
Copy link
Member

odow commented Nov 17, 2024

I only see three numbers. Where' the total time?

@joaquimg
Copy link
Member Author

joaquimg commented Nov 17, 2024

In this first pass I only considered relative time, not total time.

So, this:

Tulipa,JuMP,HiGHS,Highs_run
1_EU_investment_simple_24h,16.839772884642016,2.354244564464756,2.104971610580252

means that
16.8% of the total time is spent in JuMP.jl, (including everything downstream: HiGHS and Highs_run),
2.35% of the total time is spent in HiGHS.jl (including everything downstream: Highs_run),
2.1% of the total time is spent in Highs_run.

Therefore:
14.4% is only in JuMP
0.25% is only in HiGHS.jl
2.1% is in Highs_run

The remaining 83.17% of the time is spent in other routines that are not from JuMP nor from HiGHS.

Does it make sense to you?

Open to suggestions on how to report those times.

@odow
Copy link
Member

odow commented Nov 17, 2024

Oh I just assumed they were seconds

@joaquimg
Copy link
Member Author

PowerModels,JuMP (%),HiGHS (%),Highs_run (%)
pglib_opf_case162_ieee_dtc.m,80.70,70.18,61.40

is it better?

is total time really useful?

@odow
Copy link
Member

odow commented Nov 18, 2024

Total time is useful to track over different versions

@joaquimg
Copy link
Member Author

PowerModels,time (s),JuMP (%),HiGHS (%),Highs_run (%)
pglib_opf_case162_ieee_dtc.m,0.15,80.26,72.37,65.79

@joaquimg joaquimg changed the title [WIP] Add profiling Add profiling Nov 19, 2024
@joaquimg
Copy link
Member Author

Not a WIP anymore

@joaquimg
Copy link
Member Author

joaquimg commented Dec 9, 2024

Sienna gets stuck during profile in Linux.

The linux fail happens consistently in CI and in my WSL virtual machine.

MWE:

# necessary sienna stack
import PowerSystems
import PowerSimulations
import HydroPowerSimulations
import PowerSystemCaseBuilder
# solver
import JuMP
import HiGHS
# julia base
import Dates
import Logging
# profile
import Profile

# Profile.init() # default fails
# @show Profile.init(n = 10^6, delay = 0.001) #fails
# @show Profile.init(n = 10^6, delay = 0.1) # works

function build_and_solve(problem)
    PowerSimulations.build!(
        problem;
        output_dir = mktempdir(),
        console_level = Logging.Info,
    )
    PowerSimulations.solve!(problem; console_level = Logging.Info)
    return
end

function main()

    # case data is downloaded from a julia artifcat
    sys = PowerSystemCaseBuilder.build_system(
        PowerSystemCaseBuilder.PSISystems,
        "modified_RTS_GMLC_DA_sys",
    )

    template_uc = PowerSimulations.ProblemTemplate()

    PowerSimulations.set_device_model!(
        template_uc,
        PowerSystems.Line,
        PowerSimulations.StaticBranch,
    )
    PowerSimulations.set_device_model!(
        template_uc,
        PowerSystems.Transformer2W,
        PowerSimulations.StaticBranch,
    )
    PowerSimulations.set_device_model!(
        template_uc,
        PowerSystems.TapTransformer,
        PowerSimulations.StaticBranch,
    )

    PowerSimulations.set_device_model!(
        template_uc,
        PowerSystems.ThermalStandard,
        PowerSimulations.ThermalStandardUnitCommitment,
    )
    PowerSimulations.set_device_model!(
        template_uc,
        PowerSystems.RenewableDispatch,
        PowerSimulations.RenewableFullDispatch,
    )
    PowerSimulations.set_device_model!(
        template_uc,
        PowerSystems.PowerLoad,
        PowerSimulations.StaticPowerLoad,
    )
    PowerSimulations.set_device_model!(
        template_uc,
        PowerSystems.HydroDispatch,
        HydroPowerSimulations.HydroDispatchRunOfRiver,
    )
    PowerSimulations.set_device_model!(
        template_uc,
        PowerSystems.RenewableNonDispatch,
        PowerSimulations.FixedOutput,
    )

    PowerSimulations.set_service_model!(
        template_uc,
        PowerSystems.VariableReserve{PowerSystems.ReserveUp},
        PowerSimulations.RangeReserve,
    )
    PowerSimulations.set_service_model!(
        template_uc,
        PowerSystems.VariableReserve{PowerSystems.ReserveDown},
        PowerSimulations.RangeReserve,
    )

    solver =
        JuMP.optimizer_with_attributes(HiGHS.Optimizer, "mip_rel_gap" => 0.5)

    PowerSimulations.set_network_model!(
        template_uc,
        PowerSimulations.NetworkModel(PowerSimulations.CopperPlatePowerModel),
    )

    problem = PowerSimulations.DecisionModel(
        template_uc,
        sys;
        optimizer = solver,
        horizon = Dates.Hour(12),
        initial_time = Dates.DateTime("2020-01-01T00:00:00") +
                       Dates.Hour((29 - 1) * 24),
        optimizer_solve_log_print = true,
    )

    @show 1
    # precompile
    build_and_solve(problem)
    @show 2
    Profile.@profile build_and_solve(problem) # stuck here
    @show 3

    return
end

main()

@joaquimg
Copy link
Member Author

joaquimg commented Dec 9, 2024

cc @jd-lara

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Add a way to profile package runs
2 participants