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

796 always return #953

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ align_matrix = true
align_pair_arrow = true
align_struct_field = true
always_for_in = true
always_use_return = true
conditional_to_if = true
for_in_replacement = "in"
format_docstrings = false
Expand Down
4 changes: 2 additions & 2 deletions benchmark/profiling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ for file in readdir(NORSE_PATH; join = false)
end
# Add another line to rep-periods-data.csv and rep-periods-mapping.csv
open(joinpath(input_dir, "rep-periods-data.csv"), "a") do io
println(io, "3,$new_rp_length,0.1")
return println(io, "3,$new_rp_length,0.1")
end
open(joinpath(input_dir, "rep-periods-mapping.csv"), "a") do io
println(io, "216,3,1")
return println(io, "216,3,1")
end
# Add profiles to flow and asset
open(joinpath(input_dir, "flows-profiles.csv"), "a") do io
Expand Down
4 changes: 2 additions & 2 deletions docs/src/91-developer.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +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`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- Explicitly state what a function will `return`, including `return nothing`.
- Explicitly state what a function will `return`, including `return nothing`.


## Contributing Workflow

Expand Down Expand Up @@ -441,8 +442,7 @@ See the file <benchmark/profiling.jl> for an example of profiling code.
When publishing a new version of the model to the Julia Registry, follow this procedure:

> **Note:**
> To be able to register, you need to be a member of the organisation TulipaEnergy and have your visibility set to public:<br>
> ![Screenshot of public members of TulipaEnergy on GitHub](./images/PublicMember.png)
> To be able to register, you need to be a member of the organisation TulipaEnergy and have your visibility set to public:<br> > ![Screenshot of public members of TulipaEnergy on GitHub](./images/PublicMember.png)
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure why this changed.


1. Click on the `Project.toml` file on GitHub.

Expand Down
2 changes: 1 addition & 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)
model[:consumer_balance] = [
return model[:consumer_balance] = [
Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder if this is correct or these should all be return nothing.

Copy link
Member

Choose a reason for hiding this comment

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

The JuliaFormatter is technically correct, because these were indeed being returned implicitly. But we don't expect any return, so adding an empty return after this is better, in my opinion

@constraint(
model,
incoming_flow_highest_in_out_resolution[row.index] -
Expand Down
2 changes: 1 addition & 1 deletion src/constraints/conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ 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]
model[:conversion_balance] = [
return model[:conversion_balance] = [
@constraint(
model,
incoming[row.index] == outgoing[row.index],
Expand Down
2 changes: 1 addition & 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
model[:min_energy_inter_rp] = [
return model[:min_energy_inter_rp] = [
@constraint(
model,
constraints[:min_energy_inter_rp].expressions[:outgoing][row.index] ≥
Expand Down
2 changes: 1 addition & 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))
model[:investment_group_min_limit] = [
return model[:investment_group_min_limit] = [
@constraint(
model,
investment_group[group] ≥ group.min_investment_limit,
Expand Down
2 changes: 1 addition & 1 deletion src/constraints/hub.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ 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)
model[:hub_balance] = [
return model[:hub_balance] = [
@constraint(
model,
incoming_flow_highest_in_out_resolution[row.index] ==
Expand Down
2 changes: 1 addition & 1 deletion src/constraints/transport.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function add_transport_constraints!(model, variables, graph, sets)
]

# - Min transport flow limit
model[:min_transport_flow_limit] = [
return model[:min_transport_flow_limit] = [
@constraint(
model,
flow[row.index] ≥ -lower_bound_transport_flow[idx],
Expand Down
6 changes: 3 additions & 3 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
@assert table_name in ("asset_$year_prefix", "flow_$year_prefix")

result = _query_data_per_year(table_name, col, year_col; where_pairs...)
Dict(row[Symbol(year_col)] => getproperty(row, Symbol(col)) for row in result)
return Dict(row[Symbol(year_col)] => getproperty(row, Symbol(col)) for row in result)
end

_query_data_per_both_years(table_name, col; where_pairs...) = begin
Expand Down Expand Up @@ -331,7 +331,7 @@
if !energy_problem.solved
error("The energy_problem has not been solved yet.")
end
save_solution_to_file(output_folder, energy_problem.graph, energy_problem.solution)
return save_solution_to_file(output_folder, energy_problem.graph, energy_problem.solution)
end

"""
Expand Down Expand Up @@ -507,7 +507,7 @@
The ending value is the value for the grouped timesteps or periods.
"""
function _interpolate_storage_level!(df, time_column)
DataFrames.flatten(
return DataFrames.flatten(

Check warning on line 510 in src/io.jl

View check run for this annotation

Codecov / codecov/patch

src/io.jl#L510

Added line #L510 was not covered by tests
DataFrames.transform(
df,
[time_column, :value, :processed_value] =>
Expand Down
2 changes: 1 addition & 1 deletion src/run-scenario.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function run_scenario(

if log_file != ""
open(log_file, "w") do io
show(io, to)
return show(io, to)
end
end

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

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

# Union of all assets, and incoming and outgoing flows
DuckDB.execute(
return 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 @@ -297,7 +297,7 @@ function _append_lowest_helper(appender, group, s, e)
end
DuckDB.append(appender, s)
DuckDB.append(appender, e)
DuckDB.end_row(appender)
return DuckDB.end_row(appender)
end

function tmp_create_lowest_resolution_table(connection)
Expand Down
2 changes: 1 addition & 1 deletion src/variables/investments.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function _create_investment_variable!(
base_name = "$name[" * join(keys_from_row(row), ",") * "]"
) for row in eachrow(this_var.indices)
]
this_var.lookup = OrderedDict(
return this_var.lookup = OrderedDict(
keys_from_row(row) => var for
(var, row) in zip(this_var.container, eachrow(this_var.indices))
)
Expand Down
10 changes: 5 additions & 5 deletions utils/csv-modifications.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ Saves the CSV file at `path`.
"""
function write_tulipa_csv(tulipa_csv::TulipaCSV, path)
open(path, "w") do io
println(io, join(tulipa_csv.units, ","))
return println(io, join(tulipa_csv.units, ","))
end
CSV.write(path, tulipa_csv.csv; append = true, writeheader = true)
return CSV.write(path, tulipa_csv.csv; append = true, writeheader = true)
end

"""
Expand All @@ -59,7 +59,7 @@ 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)
insertcols!(tulipa_csv.csv, position, Symbol(colname) => content)
return insertcols!(tulipa_csv.csv, position, Symbol(colname) => content)
end

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

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

input_files_folders = [
Expand Down
4 changes: 2 additions & 2 deletions utils/scripts/assets-data-revamp-2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ apply_to_files_named("asset-both.csv") do path

# Remove from asset-both
df = t_both_csv.csv
unit, _ = remove_column(t_both_csv, "units_on_cost")
return unit, _ = remove_column(t_both_csv, "units_on_cost")
end
end
end
Expand All @@ -54,7 +54,7 @@ apply_to_files_named("flow-both.csv") do path

# Remove from flow-both
df = t_both_csv.csv
unit, _ = remove_column(t_both_csv, "variable_cost")
return unit, _ = remove_column(t_both_csv, "variable_cost")
end
end
end
16 changes: 8 additions & 8 deletions utils/scripts/assets-data-revamp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ apply_to_files_named("asset.csv"; include_missing = true) do path
",
) |> DataFrame

tcsv.units = ["" for _ in 1:size(tcsv.csv, 2)]
return tcsv.units = ["" for _ in 1:size(tcsv.csv, 2)]
end
end

Expand Down Expand Up @@ -115,7 +115,7 @@ apply_to_files_named("flow.csv"; include_missing = true) do path
",
) |> DataFrame

tcsv.units = ["" for _ in 1:size(tcsv.csv, 2)]
return tcsv.units = ["" for _ in 1:size(tcsv.csv, 2)]
end
end

Expand Down Expand Up @@ -157,7 +157,7 @@ apply_to_files_named("asset-milestone.csv"; include_missing = true) do path
",
) |> DataFrame

tcsv.units = ["" for _ in 1:size(tcsv.csv, 2)]
return tcsv.units = ["" for _ in 1:size(tcsv.csv, 2)]
end
end

Expand Down Expand Up @@ -190,7 +190,7 @@ apply_to_files_named("flow-milestone.csv"; include_missing = true) do path
",
) |> DataFrame

tcsv.units = ["" for _ in 1:size(tcsv.csv, 2)]
return tcsv.units = ["" for _ in 1:size(tcsv.csv, 2)]
end
end

Expand Down Expand Up @@ -235,7 +235,7 @@ apply_to_files_named("asset-commission.csv"; include_missing = true) do path
",
) |> DataFrame

tcsv.units = ["" for _ in 1:size(tcsv.csv, 2)]
return tcsv.units = ["" for _ in 1:size(tcsv.csv, 2)]
end
end

Expand Down Expand Up @@ -275,7 +275,7 @@ apply_to_files_named("flow-commission.csv"; include_missing = true) do path
",
) |> DataFrame

tcsv.units = ["" for _ in 1:size(tcsv.csv, 2)]
return tcsv.units = ["" for _ in 1:size(tcsv.csv, 2)]
end
end

Expand Down Expand Up @@ -319,7 +319,7 @@ apply_to_files_named("asset-both.csv"; include_missing = true) do path
",
) |> DataFrame

tcsv.units = ["" for _ in 1:size(tcsv.csv, 2)]
return tcsv.units = ["" for _ in 1:size(tcsv.csv, 2)]
end
end

Expand Down Expand Up @@ -362,7 +362,7 @@ apply_to_files_named("flow-both.csv"; include_missing = true) do path
",
) |> DataFrame

tcsv.units = ["" for _ in 1:size(tcsv.csv, 2)]
return tcsv.units = ["" for _ in 1:size(tcsv.csv, 2)]
end
end

Expand Down
6 changes: 3 additions & 3 deletions utils/scripts/create-multiyear-data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ cd(multiyear_folder) do
change_file(filename) do tcsv
df_2050 = copy(tcsv.csv)
df_2050.year .= 2050
tcsv.csv = [tcsv.csv; df_2050]
return tcsv.csv = [tcsv.csv; df_2050]
end
end

change_file("assets-data.csv") do tcsv
tcsv.csv[end, :active] = "false"
return tcsv.csv[end, :active] = "false"
end

change_file("flows-data.csv") do tcsv
tcsv.csv[end, :active] = "false"
return tcsv.csv[end, :active] = "false"
end
end
16 changes: 8 additions & 8 deletions utils/scripts/prepare-for-multiyear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ run(`git restore test/inputs/ benchmark/EU/`)
for filename in ["assets-data.csv", "flows-data.csv"]
apply_to_files_named(filename) do path
change_file(path) do tcsv
add_column(tcsv, "year", 2030; position = 5)
return add_column(tcsv, "year", 2030; position = 5)
end
end
end
Expand All @@ -24,7 +24,7 @@ apply_to_files_named("year-data.csv"; include_missing = true) do path
touch(path)
change_file(path) do tcsv
tcsv.units = ["", "h"]
tcsv.csv = DataFrame(:year => [2030], :length => [8760])
return tcsv.csv = DataFrame(:year => [2030], :length => [8760])
end
end

Expand Down Expand Up @@ -53,7 +53,7 @@ apply_to_files_named("timeframe-data.csv"; include_missing = true) do path
),
)
tcsv.units = ["", ""]
add_column(tcsv, "year", 2030; position = 1)
return add_column(tcsv, "year", 2030; position = 1)
end
end

Expand All @@ -69,7 +69,7 @@ for filename in [
change_file(path) do tcsv
idx = findfirst(==("rep_period"), names(tcsv.csv))
@assert idx !== nothing
add_column(tcsv, "year", 2030; position = idx)
return add_column(tcsv, "year", 2030; position = idx)
end
end
end
Expand All @@ -81,7 +81,7 @@ for filename in ["profiles-timeframe.csv", "rep-periods-mapping.csv"]
change_file(path) do tcsv
idx = findfirst(==("period"), names(tcsv.csv))
@assert idx !== nothing
add_column(tcsv, "year", 2030; position = idx)
return add_column(tcsv, "year", 2030; position = idx)
end
end
end
Expand All @@ -99,7 +99,7 @@ for filename in [
change_file(path) do tcsv
idx = findfirst(==("profile_type"), names(tcsv.csv))
@assert idx !== nothing
add_column(tcsv, "year", 2030; position = idx)
return add_column(tcsv, "year", 2030; position = idx)
end
end
end
Expand All @@ -108,13 +108,13 @@ end
# Maybe this should be renamed to `assets-year-partitions.csv`?
apply_to_files_named("assets-timeframe-partitions.csv") do path
change_file(path) do tcsv
add_column(tcsv, "year", 2030; position = 2)
return add_column(tcsv, "year", 2030; position = 2)
end
end

# And don't forget groups
apply_to_files_named("groups-data.csv") do path
change_file(path) do tcsv
add_column(tcsv, "year", 2030; position = 2)
return add_column(tcsv, "year", 2030; position = 2)
end
end
Loading
Loading