|
| 1 | +using ExaPowerIO, BenchmarkTools, PowerModels, PGLib, Profile, PProf, Logging, JLD2 |
| 2 | + |
| 3 | +PowerModels.silence() |
| 4 | + |
| 5 | +NUM_SAMPLES = 10 |
| 6 | +for (i, arg) in enumerate(ARGS) |
| 7 | + if arg == "--num-samples" || arg == "-n" |
| 8 | + global NUM_SAMPLES |
| 9 | + NUM_SAMPLES = ARGS[i+1] |
| 10 | + break |
| 11 | + end |
| 12 | +end |
| 13 | +COMPARE_PM = "--compare-pm" in ARGS |
| 14 | +COMPARE_JLD2 = "--compare-jld2" in ARGS |
| 15 | +PROFILE = "--profile" in ARGS |
| 16 | +CASES = PGLib.find_pglib_case("") |
| 17 | +@info """ |
| 18 | +Running benchmarks with settings: |
| 19 | +num-samples: $NUM_SAMPLES |
| 20 | +compare to PowerModels: $COMPARE_PM |
| 21 | +compare to JLD2: $COMPARE_JLD2 |
| 22 | +output pprof file: $(PROFILE) |
| 23 | +""" |
| 24 | + |
| 25 | +datadir = "../data/" |
| 26 | + |
| 27 | +function run_exapower!() |
| 28 | + data = Vector{NamedTuple}(undef, length(CASES)) |
| 29 | + for (i, dataset) in enumerate(CASES) |
| 30 | + data[i] = ExaPowerIO.parse_pglib(Float64, Vector, dataset; out_type=NamedTuple) |
| 31 | + end |
| 32 | + data |
| 33 | +end |
| 34 | + |
| 35 | +function run_jld2() |
| 36 | + for dataset in CASES |
| 37 | + JLD2.load(joinpath(datadir, dataset * ".jld2")) |
| 38 | + end |
| 39 | +end |
| 40 | + |
| 41 | +function run_pm() |
| 42 | + for dataset in CASES |
| 43 | + path = joinpath(PGLib.PGLib_opf, dataset * ".m") |
| 44 | + pm_output = PowerModels.parse_file(path) |
| 45 | + PowerModels.standardize_cost_terms!(pm_output, order = 2) |
| 46 | + PowerModels.calc_thermal_limits!(pm_output) |
| 47 | + end |
| 48 | +end |
| 49 | + |
| 50 | +@info "Precompiling" |
| 51 | +global_logger(ConsoleLogger(stderr, Logging.Warn)) # Consistent logging level |
| 52 | + |
| 53 | +data = run_exapower!() |
| 54 | +COMPARE_JLD2 && run_jld2() |
| 55 | +COMPARE_PM && run_pm() |
| 56 | + |
| 57 | +GC.gc() |
| 58 | +Profile.clear() |
| 59 | +global_logger(ConsoleLogger(stderr, Logging.Info)) |
| 60 | + |
| 61 | +@info "Running ExaPowerIO:" |
| 62 | +global_logger(ConsoleLogger(stderr, Logging.Warn)) |
| 63 | +if PROFILE |
| 64 | + @profile run_exapower!() |
| 65 | + pprof() |
| 66 | +else |
| 67 | + @btime run_exapower!() |
| 68 | +end |
| 69 | +global_logger(ConsoleLogger(stderr, Logging.Info)) |
| 70 | + |
| 71 | +if COMPARE_JLD2 |
| 72 | + for (i, dataset) in enumerate(CASES) |
| 73 | + JLD2.save(joinpath(datadir, dataset * ".jld2"), Dict("data" => data[i])) |
| 74 | + end |
| 75 | + @info "Running JLD2:" |
| 76 | + @btime run_jld2() |
| 77 | +end |
| 78 | + |
| 79 | +if COMPARE_PM |
| 80 | + @info "Running PowerModels:" |
| 81 | + @btime run_pm() |
| 82 | +end |
0 commit comments