Skip to content

Commit

Permalink
Fix return nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
clizbe committed Dec 17, 2024
1 parent c410531 commit b5d844b
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docs/src/91-developer.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ We will try to follow these during development and reviews.
- List obvious objects, e.g., `using JuMP: @variable`, since `@variable` is obviously from JuMP in this context, or `using Graph: SimpleDiGraph`, because it's a constructor with an obvious name.
- For other objects inside `Package`, use `using Package: Package` and explicitly call `Package.A` to use it, e.g., `DataFrames.groupby`.
- List all `using` in <src/TulipaEnergyModel.jl>.
- Explicitly state what a function will `return`, including `return nothing`.
- Explicitly state what a function will `return`; if returning nothing, simply use `return`.
## Contributing Workflow
Expand Down
4 changes: 3 additions & 1 deletion src/constraints/consumer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function add_consumer_constraints!(model, constraints, graph, sets)

# - Balance constraint (using the lowest temporal resolution)
df = filter(:asset => (Ac), constraints[:highest_in_out].indices; view = true)
return model[:consumer_balance] = [
model[:consumer_balance] = [
@constraint(
model,
incoming_flow_highest_in_out_resolution[row.index] -
Expand All @@ -37,4 +37,6 @@ function add_consumer_constraints!(model, constraints, graph, sets)
base_name = "consumer_balance[$(row.asset),$(row.year),$(row.rep_period),$(row.time_block_start):$(row.time_block_end)]"
) for row in eachrow(df)
]

return
end
4 changes: 3 additions & 1 deletion src/constraints/conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ function add_conversion_constraints!(model, constraints, sets)
df = filter(:asset => (Acv), constraints[:lowest].indices; view = true)
incoming = constraints[:lowest].expressions[:incoming]
outgoing = constraints[:lowest].expressions[:outgoing]
return model[:conversion_balance] = [
model[:conversion_balance] = [
@constraint(
model,
incoming[row.index] == outgoing[row.index],
base_name = "conversion_balance[$(row.asset),$(row.year),$(row.rep_period),$(row.time_block_start):$(row.time_block_end)]"
) for row in eachrow(df)
]

return
end
4 changes: 3 additions & 1 deletion src/constraints/energy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function add_energy_constraints!(model, constraints, graph)
]

# - Minimum outgoing energy within each period block
return model[:min_energy_inter_rp] = [
model[:min_energy_inter_rp] = [
@constraint(
model,
constraints[:min_energy_inter_rp].expressions[:outgoing][row.index]
Expand All @@ -45,4 +45,6 @@ function add_energy_constraints!(model, constraints, graph)
base_name = "min_energy_inter_rp_limit[$(row.asset),$(row.year),$(row.period_block_start):$(row.period_block_end)]"
) for row in eachrow(constraints[:min_energy_inter_rp].indices)
]

return
end
3 changes: 2 additions & 1 deletion src/constraints/group.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function add_group_constraints!(model, variables, graph, sets, groups)

groups_with_min_investment_limit =
(group for group in groups if !ismissing(group.min_investment_limit))
return model[:investment_group_min_limit] = [
model[:investment_group_min_limit] = [
@constraint(
model,
investment_group[group] group.min_investment_limit,
Expand All @@ -52,4 +52,5 @@ function add_group_constraints!(model, variables, graph, sets, groups)

# - TODO: More group constraints e.g., limits on the accumulated investments of a group

return
end
4 changes: 3 additions & 1 deletion src/constraints/hub.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ function add_hub_constraints!(model, constraints, sets)
outgoing_flow_highest_in_out_resolution = constraints[:highest_in_out].expressions[:outgoing]
# - Balance constraint (using the lowest temporal resolution)
df = filter(:asset => (Ah), constraints[:highest_in_out].indices; view = true)
return model[:hub_balance] = [
model[:hub_balance] = [
@constraint(
model,
incoming_flow_highest_in_out_resolution[row.index] ==
outgoing_flow_highest_in_out_resolution[row.index],
base_name = "hub_balance[$(row.asset),$(row.year),$(row.rep_period),$(row.time_block_start):$(row.time_block_end)]"
) for row in eachrow(df)
]

return
end
4 changes: 3 additions & 1 deletion src/constraints/transport.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ function add_transport_constraints!(model, variables, graph, sets)
]

# - Min transport flow limit
return model[:min_transport_flow_limit] = [
model[:min_transport_flow_limit] = [
@constraint(
model,
flow[row.index] -lower_bound_transport_flow[idx],
base_name = "min_transport_flow_limit[($(row.from),$(row.to)),$(row.year),$(row.rep_period),$(row.time_block_start):$(row.time_block_end)]"
) for (idx, row) in enumerate(eachrow(transport_flows_indices))
]

return
end
5 changes: 3 additions & 2 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ function _check_if_table_exist(connection, table_name)
create_table_query =
DuckDB.query(connection, "CREATE TABLE $table_name ($columns_in_table)")
end
return nothing
return
end

"""
Expand All @@ -331,7 +331,8 @@ function save_solution_to_file(output_folder, energy_problem::EnergyProblem)
if !energy_problem.solved
error("The energy_problem has not been solved yet.")
end
return save_solution_to_file(output_folder, energy_problem.graph, energy_problem.solution)
save_solution_to_file(output_folder, energy_problem.graph, energy_problem.solution)
return
end

"""
Expand Down
9 changes: 6 additions & 3 deletions src/tmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ function tmp_create_partition_tables(connection)
end
_append_given_durations(appender, row, durations)
end
return DuckDB.close(appender)
DuckDB.close(appender)
return
end

function tmp_create_union_tables(connection)
Expand Down Expand Up @@ -280,7 +281,7 @@ function tmp_create_union_tables(connection)
)

# Union of all assets, and incoming and outgoing flows
return DuckDB.execute(
DuckDB.execute(
connection,
"CREATE OR REPLACE TEMP TABLE t_union_all AS
SELECT DISTINCT asset, year, rep_period, time_block_start, time_block_end
Expand All @@ -289,6 +290,7 @@ function tmp_create_union_tables(connection)
FROM t_union_all_flows
",
)
return
end

function _append_lowest_helper(appender, group, s, e)
Expand All @@ -297,7 +299,8 @@ function _append_lowest_helper(appender, group, s, e)
end
DuckDB.append(appender, s)
DuckDB.append(appender, e)
return DuckDB.end_row(appender)
DuckDB.end_row(appender)
return
end

function tmp_create_lowest_resolution_table(connection)
Expand Down
3 changes: 2 additions & 1 deletion src/variables/investments.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ function _create_investment_variable!(
base_name = "$name[" * join(keys_from_row(row), ",") * "]"
) for row in eachrow(this_var.indices)
]
return this_var.lookup = OrderedDict(
this_var.lookup = OrderedDict(
keys_from_row(row) => var for
(var, row) in zip(this_var.container, eachrow(this_var.indices))
)
return
end

"""
Expand Down
15 changes: 10 additions & 5 deletions utils/csv-modifications.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ Saves the CSV file at `path`.
"""
function write_tulipa_csv(tulipa_csv::TulipaCSV, path)
open(path, "w") do io
return println(io, join(tulipa_csv.units, ","))
println(io, join(tulipa_csv.units, ","))
return
end
return CSV.write(path, tulipa_csv.csv; append = true, writeheader = true)
CSV.write(path, tulipa_csv.csv; append = true, writeheader = true)
return
end

"""
Expand All @@ -59,7 +61,8 @@ The `content` can be a value or a vector of proper size.
function add_column(tulipa_csv::TulipaCSV, unit::String, colname, content, position::Int)
@debug "Adding column $colname ($unit) at $position"
insert!(tulipa_csv.units, position, unit)
return insertcols!(tulipa_csv.csv, position, Symbol(colname) => content)
insertcols!(tulipa_csv.csv, position, Symbol(colname) => content)
return
end

function add_column(
Expand All @@ -69,7 +72,8 @@ function add_column(
unit = "",
position = size(tulipa_csv.csv, 2) + 1,
)
return add_column(tulipa_csv, unit, colname, content, position)
add_column(tulipa_csv, unit, colname, content, position)
return
end

"""
Expand Down Expand Up @@ -136,7 +140,8 @@ end
function change_file(f, path)
tulipa_csv = TulipaCSV(path)
f(tulipa_csv)
return write_tulipa_csv(tulipa_csv, path)
write_tulipa_csv(tulipa_csv, path)
return
end

input_files_folders = [
Expand Down

0 comments on commit b5d844b

Please sign in to comment.