Skip to content

Commit

Permalink
Rename save_solution_to_file to export_solution_to_csv_files
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsiqueira committed Jan 20, 2025
1 parent 9885646 commit 8f3f4ec
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ end samples = 3 evals = 1 seconds = 86400
create_model!(energy_problem)

# SUITE["energy_problem"]["output"] = @benchmarkable begin
# save_solution_to_file($OUTPUT_FOLDER_BM, $energy_problem)
# export_solution_to_csv_files($OUTPUT_FOLDER_BM, $energy_problem)
# end
4 changes: 2 additions & 2 deletions docs/src/20-tutorials.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,11 @@ The value of the constraint is obtained by looking only at the part with variabl

### Writing the output to CSV

To save the solution to CSV files, you can use [`save_solution_to_file`](@ref):
To save the solution to CSV files, you can use [`export_solution_to_csv_files`](@ref):

```@example solution
mkdir("outputs")
save_solution_to_file("outputs", energy_problem)
export_solution_to_csv_files("outputs", energy_problem)
```

### Plotting
Expand Down
12 changes: 6 additions & 6 deletions src/io.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export create_internal_structures, save_solution_to_file
export create_internal_structures, export_solution_to_csv_files

"""
graph, representative_periods, timeframe = create_internal_structures(connection)
Expand Down Expand Up @@ -317,16 +317,16 @@ function _create_empty_unless_exists(connection, table_name)
end

"""
save_solution_to_file(output_folder, energy_problem)
export_solution_to_csv_files(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)
function export_solution_to_csv_files(output_folder, energy_problem::EnergyProblem)
if !energy_problem.solved
error("The energy_problem has not been solved yet.")
end
save_solution_to_file(
export_solution_to_csv_files(
output_folder,
energy_problem.db_connection,
energy_problem.variables,
Expand All @@ -336,12 +336,12 @@ function save_solution_to_file(output_folder, energy_problem::EnergyProblem)
end

"""
save_solution_to_file(output_file, connection, variables, constraints)
export_solution_to_csv_files(output_file, connection, variables, constraints)
Saves the solution in CSV files inside `output_folder`.
Notice that this assumes that the solution has been computed by [`save_solution!`](@ref).
"""
function save_solution_to_file(output_folder, connection, variables, constraints)
function export_solution_to_csv_files(output_folder, connection, variables, constraints)
# Save each variable
for (name, var) in variables
if length(var.container) == 0
Expand Down
5 changes: 4 additions & 1 deletion src/run-scenario.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ function run_scenario(

if output_folder != ""
@timeit to "save_solution" save_solution!(energy_problem)
@timeit to "save_solution_to_file" save_solution_to_file(output_folder, energy_problem)
@timeit to "export_solution_to_csv_files" export_solution_to_csv_files(
output_folder,
energy_problem,
)
end

show_log && show(to)
Expand Down
12 changes: 9 additions & 3 deletions test/test-io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ end
_read_csv_folder(connection, joinpath(INPUT_FOLDER, "Tiny"))
energy_problem = TulipaEnergyModel.EnergyProblem(connection)
output_dir = mktempdir()
@test_throws Exception TulipaEnergyModel.save_solution_to_file(output_dir, energy_problem)
@test_throws Exception TulipaEnergyModel.export_solution_to_csv_files(
output_dir,
energy_problem,
)
TulipaEnergyModel.create_model!(energy_problem)
@test_throws Exception TulipaEnergyModel.save_solution_to_file(output_dir, energy_problem)
@test_throws Exception TulipaEnergyModel.export_solution_to_csv_files(
output_dir,
energy_problem,
)
TulipaEnergyModel.solve_model!(energy_problem)
@test TulipaEnergyModel.save_solution_to_file(output_dir, energy_problem) === nothing
@test TulipaEnergyModel.export_solution_to_csv_files(output_dir, energy_problem) === nothing
end
end

Expand Down
4 changes: 2 additions & 2 deletions test/test-pipeline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
energy_problem = TulipaEnergyModel.EnergyProblem(connection)
TulipaEnergyModel.create_model!(energy_problem)
TulipaEnergyModel.solve_model!(energy_problem, HiGHS.Optimizer)
TulipaEnergyModel.save_solution_to_file(mktempdir(), energy_problem)
TulipaEnergyModel.export_solution_to_csv_files(mktempdir(), energy_problem)
end

@testset "Test that everything works for $input from beginning to end without EnergyProblem struct" for input in
Expand Down Expand Up @@ -46,5 +46,5 @@ end
# Solve model
TulipaEnergyModel.solve_model(model, HiGHS.Optimizer)
TulipaEnergyModel.save_solution!(connection, model, variables, constraints)
TulipaEnergyModel.save_solution_to_file(mktempdir(), connection, variables, constraints)
TulipaEnergyModel.export_solution_to_csv_files(mktempdir(), connection, variables, constraints)
end

0 comments on commit 8f3f4ec

Please sign in to comment.