Skip to content

Commit

Permalink
Merge pull request #1088 from NREL-Sienna/jd/add_solve_call_to_perf_c…
Browse files Browse the repository at this point in the history
…hecks

add solve call
  • Loading branch information
jd-lara authored Mar 26, 2024
2 parents ad463ac + ad655ea commit 8adee35
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 66 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/performance_comparison.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ jobs:
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo "::set-output name=body::$body"
- name: Read solve results
id: solve_results
run: |
body="$(cat solve_time.txt)"
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo "::set-output name=body::$body"
- name: Find Comment
uses: peter-evans/find-comment@v1
id: fc
Expand All @@ -54,6 +62,10 @@ jobs:
| Version | Build Time |
| :--- | :----: |
${{ steps.build_results.outputs.body }}
| Version | Solve Time |
| :--- | :----: |
${{ steps.solve_results.outputs.body }}
- name: Update comment
if: steps.fc.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v1
Expand All @@ -69,4 +81,8 @@ jobs:
| :--- | :----: |
${{ steps.build_results.outputs.body }}
| Version | Build Time |
| :--- | :----: |
${{ steps.solve_results.outputs.body }}
edit-mode: replace
2 changes: 1 addition & 1 deletion src/core/dataset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,6 @@ end

function set_value!(s::HDF5Dataset, vals, index::Int)
# Temporary while there is no implementation of caching of em_data
_write_dataset!(s.values, vals, index:index)
_write_dataset!(s.values, vals, index)
return
end
15 changes: 13 additions & 2 deletions src/devices_models/devices/common/objective_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,26 @@ function _add_service_bid_cost!(
start_time = initial_time,
len = length(time_steps),
)
forecast_data_values = PSY.get_cost.(TimeSeries.values(forecast_data)) .* base_power
forecast_data_values = PSY.get_cost.(TimeSeries.values(forecast_data))
# Single Price Bid
if eltype(forecast_data_values) == Float64
data_values = forecast_data_values
# Single Price/Quantity Bid
elseif eltype(forecast_data_values) == NTuple{2, Float64}
data_values = [v[1] for v in forecast_data_values]
else
error("$(eltype(forecast_data_values)) not supported for MarketBidCost")
end

reserve_variable = get_variable(container, U(), T, PSY.get_name(service))
component_name = PSY.get_name(component)
for t in time_steps
add_to_objective_invariant_expression!(
container,
forecast_data_values[t] * reserve_variable[component_name, t],
data_values[t] * base_power * reserve_variable[component_name, t],
)
end
return
end

function _add_service_bid_cost!(::OptimizationContainer, ::PSY.Component, ::PSY.Service) end
Expand Down
78 changes: 18 additions & 60 deletions src/simulation/hdf_simulation_store.jl
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ function _read_result(
#end
columns = get_column_names(key, dataset)
data = permutedims(data)
@assert_op size(data)[2] == length(columns)
@assert_op size(data)[2] == length(columns[1])
@assert_op size(data)[1] == 1
return data, columns
end
Expand Down Expand Up @@ -644,41 +644,15 @@ function write_result!(
key::OptimizationContainerKey,
index::EmulationModelIndexType,
simulation_time::Dates.DateTime,
data::Array{Float64},
data::DenseAxisArray,
)
dataset = _get_em_dataset(store, key)
_write_dataset!(dataset.values, data, index)
_write_dataset!(dataset.values, to_matrix(data), index)
set_last_recorded_row!(dataset, index)
set_update_timestamp!(dataset, simulation_time)
return
end

function write_result!(
store::HdfSimulationStore,
model_name::Symbol,
key::OptimizationContainerKey,
index::EmulationModelIndexType,
simulation_time::Dates.DateTime,
data::DenseAxisArray{Float64, 2},
)
data_array = Array{Float64, 3}(undef, size(data)[1], size(data)[2], 1)
data_array[:, :, 1] = data
write_result!(store, model_name, key, index, simulation_time, data_array)
return
end

function write_result!(
store::HdfSimulationStore,
model_name::Symbol,
key::OptimizationContainerKey,
index::EmulationModelIndexType,
simulation_time::Dates.DateTime,
data::DenseAxisArray{Float64, 1},
)
write_result!(store, model_name, key, index, simulation_time, to_matrix(data))
return
end

function _check_state(store::HdfSimulationStore)
if has_dirty(store.cache)
error("BUG!!! dirty cache is present at shutdown: $(store.file)")
Expand Down Expand Up @@ -1014,60 +988,44 @@ function _read_length(::Type{OptimizerStats}, store::HdfSimulationStore)
return HDF5.read(HDF5.attributes(dataset), "columns")
end

# Specific data set writing function that writes decision model data. It dispatches on the index type of the dataset as a range
function _write_dataset!(
dataset::HDF5.Dataset,
array::Matrix{Float64},
row_range::UnitRange{Int64},
::Val{3},
)
dataset[:, 1, row_range] = array
@debug "wrote dataset" dataset row_range
return
end

function _write_dataset!(
dataset::HDF5.Dataset,
array::Matrix{Float64},
array::Array{Float64, 3},
row_range::UnitRange{Int64},
::Val{2},
)
dataset[row_range, :] = array
@debug "wrote dataset" dataset row_range
dataset[:, :, row_range] = array
@debug "wrote dm dataset" dataset row_range
return
end

function _write_dataset!(
dataset::HDF5.Dataset,
array::Array{Float64, 3},
array::Array{Float64, 4},
row_range::UnitRange{Int64},
::Val{3},
)
dataset[row_range, :, :] = array
@debug "wrote dataset" dataset row_range
return
end

function _write_dataset!(dataset::HDF5.Dataset, array::Array{Float64}, index::Int)
_write_dataset!(dataset, array, index:index, Val{ndims(dataset)}())
dataset[:, :, :, row_range] = array
@debug "wrote dm dataset" dataset row_range
return
end

# Specific data set writing function that writes emulation model data. It dispatches on the index type of the dataset
function _write_dataset!(
dataset::HDF5.Dataset,
array::Array{Float64, 3},
row_range::UnitRange{Int64},
array::Array{Float64, 2},
index::EmulationModelIndexType,
)
dataset[:, :, row_range] = array
@debug "wrote dataset" dataset row_range
dataset[index, :] = array
@debug "wrote em dataset" dataset index
return
end

function _write_dataset!(
dataset::HDF5.Dataset,
array::Array{Float64, 4},
row_range::UnitRange{Int64},
index::EmulationModelIndexType,
)
dataset[:, :, :, row_range] = array
@debug "wrote dataset" dataset row_range
dataset[index, :, :] = array
@debug "wrote em dataset" dataset index
return
end
21 changes: 18 additions & 3 deletions test/performance/performance_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ try
)

template_ed = deepcopy(template_uc)
set_device_model!(template_ed, ThermalMultiStart, ThermalStandardDispatch)
set_device_model!(template_ed, ThermalMultiStart, ThermalBasicDispatch)
set_device_model!(template_ed, ThermalStandard, ThermalBasicDispatch)
set_device_model!(template_ed, HydroDispatch, HydroDispatchRunOfRiver)
set_device_model!(template_ed, HydroEnergyReservoir, HydroDispatchRunOfRiver)
Expand All @@ -64,7 +64,8 @@ try
template_uc,
sys_rts_da;
name = "UC",
optimizer = optimizer_with_attributes(HiGHS.Optimizer),
optimizer = optimizer_with_attributes(HiGHS.Optimizer,
"mip_rel_gap" => 0.01),
system_to_file = false,
initialize_model = true,
optimizer_solve_log_print = true,
Expand All @@ -75,7 +76,8 @@ try
template_ed,
sys_rts_rt;
name = "ED",
optimizer = optimizer_with_attributes(HiGHS.Optimizer),
optimizer = optimizer_with_attributes(HiGHS.Optimizer,
"mip_rel_gap" => 0.01),
system_to_file = false,
initialize_model = true,
check_numerical_bounds = false,
Expand Down Expand Up @@ -133,6 +135,19 @@ try
write(io, "| $(ARGS[1])- Build Time $name | FAILED TO TEST |\n")
end
end

solve_out, time_solve, _, _ = @timed execute!(sim; enable_progress_bar = false)

if solve_out == PSI.RunStatus.SUCCESSFUL
name = i > 1 ? "Postcompile" : "Precompile"
open("solve_time.txt", "a") do io
write(io, "| $(ARGS[1])-Solve Time $name | $(time_solve) |\n")
end
else
open("solve_time.txt", "a") do io
write(io, "| $(ARGS[1])- Solve Time $name | FAILED TO TEST |\n")
end
end
end
catch e
rethrow(e)
Expand Down

0 comments on commit 8adee35

Please sign in to comment.