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

Implement solution saving and exporting for refactored code #1000

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

abelsiqueira
Copy link
Member

@abelsiqueira abelsiqueira commented Jan 15, 2025

  • Update function to compute dual
  • Create function to save solution and dual values to DuckDB connection
  • Update save_solution_to_file
  • Update tests

Related issues

Closes #115
Closes #818

Checklist

  • I am following the contributing guidelines

  • Tests are passing

  • Lint workflow is passing

  • Docs were updated and workflow is passing

@abelsiqueira abelsiqueira added the benchmark PR only - Run benchmark on PR label Jan 15, 2025
Copy link
Contributor

github-actions bot commented Jan 15, 2025

Benchmark Results

8322b5c... 1285127... 8322b5c.../128512721d0c7a...
energy_problem/create_model 32.4 ± 2.1 s 32.3 ± 2.5 s 1
energy_problem/input_and_constructor 17.3 ± 0.57 s 17.9 ± 0.44 s 0.967
time_to_load 4.09 ± 0.03 s 4.2 ± 0.13 s 0.973
8322b5c... 1285127... 8322b5c.../128512721d0c7a...
energy_problem/create_model 0.311 G allocs: 15.6 GB 0.311 G allocs: 15.6 GB 1
energy_problem/input_and_constructor 0.0532 G allocs: 1.98 GB 0.0531 G allocs: 1.97 GB 1
time_to_load 0.159 k allocs: 11.2 kB 0.159 k allocs: 11.2 kB 1

Benchmark Plots

A plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR.
Go to "Actions"->"Benchmark a pull request"->[the most recent run]->"Artifacts" (at the bottom).

@abelsiqueira abelsiqueira marked this pull request as ready for review January 15, 2025 15:44
@abelsiqueira abelsiqueira requested a review from datejada January 15, 2025 15:44
Copy link

codecov bot commented Jan 15, 2025

Codecov Report

Attention: Patch coverage is 93.33333% with 4 lines in your changes missing coverage. Please review.

Project coverage is 95.06%. Comparing base (8322b5c) to head (1285127).

Files with missing lines Patch % Lines
src/solve-model.jl 91.30% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1000      +/-   ##
==========================================
- Coverage   95.43%   95.06%   -0.38%     
==========================================
  Files          29       29              
  Lines        1140     1155      +15     
==========================================
+ Hits         1088     1098      +10     
- Misses         52       57       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

energy_problem.termination_status = JuMP.termination_status(model)
if energy_problem.solution === nothing
if energy_problem.termination_status != JuMP.OPTIMAL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This option in JuMP is more generic, I propose using it instead of only the optimal condition:

Suggested change
if energy_problem.termination_status != JuMP.OPTIMAL
if !JuMP.is_solved_and_feasible(model)

Comment on lines +99 to +106
status = JuMP.termination_status(model)
if status == JuMP.OPTIMIZE_NOT_CALLED
@error("The model was not solved yet, use one of the solve_model functions")
return
elseif status != JuMP.OPTIMAL
@error("The model was not solved to optimality, cannot get solution")
return
end
Copy link
Member

@datejada datejada Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the same, I propose simplifying like this:

Suggested change
status = JuMP.termination_status(model)
if status == JuMP.OPTIMIZE_NOT_CALLED
@error("The model was not solved yet, use one of the solve_model functions")
return
elseif status != JuMP.OPTIMAL
@error("The model was not solved to optimality, cannot get solution")
return
end
if !JuMP.is_solved_and_feasible(model)
@error("The model has a termination status: $JuMP.termination_status(model), with primal status $JuMP.primal_status(model), and dual status $JuMP.dual_status(model)")
return
end

@@ -320,158 +320,52 @@ end
save_solution_to_file(output_folder, energy_problem)

Saves the solution from `energy_problem` in CSV files inside `output_file`.
Notice that this assumes that the solution has been computed by [`save_solution!`](@ref).
"""
function save_solution_to_file(output_folder, energy_problem::EnergyProblem)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To differentiate more from the save_solution function and account for future options to export to another format, I propose renaming this function as export_solution_to_csv_files

Copy link
Member

@datejada datejada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @abelsiqueira; I have left some comments. Let me know what you think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
benchmark PR only - Run benchmark on PR
Projects
None yet
2 participants