Skip to content

Commit

Permalink
Update with lint formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
datejada committed Oct 9, 2024
1 parent 6e56609 commit 1753660
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 45 deletions.
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/10-bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ body:
Please, before submitting, make sure that:
- There is not an [existing issue](https://github.com/TulipaEnergy/TulipaClustering.jl/issues) with the same question
- You have read the [contributing guide](https://TulipaEnergy.github.io/TulipaClustering.jl/dev/90-contributing/)
- You are following the [code of conduct](https://github.com/TulipaEnergy/TulipaClustering.jl/blob/main/CODE_OF_CONDUCT.md)
The form below should help you in filling out this issue.
- type: textarea
Expand Down
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/20-feature-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ body:
Please, before submitting, make sure that:
- There is not an [existing issue](https://github.com/TulipaEnergy/TulipaClustering.jl/issues) with the same question
- You have read the [contributing guide](https://TulipaEnergy.github.io/TulipaClustering.jl/dev/90-contributing/)
- You are following the [code of conduct](https://github.com/TulipaEnergy/TulipaClustering.jl/blob/main/CODE_OF_CONDUCT.md)
The form below should help you in filling out this issue.
- type: textarea
Expand Down
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/30-usage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ body:
- You have checked the [documentation](https://TulipaEnergy.github.io/TulipaClustering.jl) and haven't found enough information
- There is not an [existing issue](https://github.com/TulipaEnergy/TulipaClustering.jl/issues) with the same question
- You have read the [contributing guide](https://TulipaEnergy.github.io/TulipaClustering.jl/dev/90-contributing/)
- You are following the [code of conduct](https://github.com/TulipaEnergy/TulipaClustering.jl/blob/main/CODE_OF_CONDUCT.md)
The form below should help you in filling out this issue.
- type: textarea
Expand Down
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/99-general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ body:
Please, before submitting, make sure that:
- There is not an [existing issue](https://github.com/TulipaEnergy/TulipaClustering.jl/issues) with the same question
- You have read the [contributing guide](https://TulipaEnergy.github.io/TulipaClustering.jl/dev/90-contributing/)
- You are following the [code of conduct](https://github.com/TulipaEnergy/TulipaClustering.jl/blob/main/CODE_OF_CONDUCT.md)
The form below should help you in filling out this issue.
- type: textarea
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@

If you use TulipaClustering.jl in your work, please cite using the reference given in [CITATION.cff](https://github.com/TulipaEnergy/TulipaClustering.jl/blob/main/CITATION.cff).


## Contributing

If you want to make contributions of any kind, please first that a look into our [contributing guide directly on GitHub](docs/src/90-contributing.md) or the [contributing page on the website](https://TulipaEnergy.github.io/TulipaClustering.jl/dev/90-contributing/).


---

### Contributors
Expand Down
25 changes: 16 additions & 9 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
using TulipaClustering
using Documenter

DocMeta.setdocmeta!(TulipaClustering, :DocTestSetup, :(using TulipaClustering); recursive = true)
DocMeta.setdocmeta!(
TulipaClustering,
:DocTestSetup,
:(using TulipaClustering);
recursive = true,
)

const page_rename = Dict("developer.md" => "Developer docs") # Without the numbers
const numbered_pages = [
file for
file in readdir(joinpath(@__DIR__, "src")) if file != "index.md" && splitext(file)[2] == ".md"
file for file in readdir(joinpath(@__DIR__, "src")) if
file != "index.md" && splitext(file)[2] == ".md"
]

makedocs(;
modules = [TulipaClustering],
authors = "Greg Neustroev <[email protected]> and contributors",
repo = "https://github.com/TulipaEnergy/TulipaClustering.jl/blob/{commit}{path}#{line}",
sitename = "TulipaClustering.jl",
format = Documenter.HTML(; canonical = "https://TulipaEnergy.github.io/TulipaClustering.jl"),
pages = ["index.md"; numbered_pages],
modules = [TulipaClustering],
authors = "Greg Neustroev <[email protected]> and contributors",
repo = "https://github.com/TulipaEnergy/TulipaClustering.jl/blob/{commit}{path}#{line}",
sitename = "TulipaClustering.jl",
format = Documenter.HTML(;
canonical = "https://TulipaEnergy.github.io/TulipaClustering.jl",
),
pages = ["index.md"; numbered_pages],
)

deploydocs(; repo = "github.com/TulipaEnergy/TulipaClustering.jl")
2 changes: 0 additions & 2 deletions docs/src/90-contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ First of all, thanks for the interest!

We welcome all kinds of contribution, including, but not limited to code, documentation, examples, configuration, issue creating, etc.


Be polite and respectful, and follow the code of conduct.


## Bug reports and discussions

If you think you found a bug, feel free to open an [issue](https://github.com/TulipaEnergy/TulipaClustering.jl/issues).
Expand Down
21 changes: 17 additions & 4 deletions src/cluster.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ julia> TulipaClustering.split_into_periods!(df)
3 │ 1 3 3
```
"""
function split_into_periods!(df::AbstractDataFrame; period_duration::Union{Int, Nothing} = nothing)
function split_into_periods!(
df::AbstractDataFrame;
period_duration::Union{Int, Nothing} = nothing,
)
# If the periods already exist, combine them into the time steps if necessary
combine_periods!(df)

Expand Down Expand Up @@ -197,9 +200,15 @@ function find_auxiliary_data(clustering_data::AbstractDataFrame)
key_columns = validate_df_and_find_key_columns(clustering_data)
n_periods = maximum(clustering_data.period)
period_duration = maximum(clustering_data.timestep)
last_period_duration = maximum(clustering_data[clustering_data.period .== n_periods, :timestep])
last_period_duration =
maximum(clustering_data[clustering_data.period .== n_periods, :timestep])

return AuxiliaryClusteringData(key_columns, period_duration, last_period_duration, n_periods)
return AuxiliaryClusteringData(
key_columns,
period_duration,
last_period_duration,
n_periods,
)
end

"""
Expand Down Expand Up @@ -409,7 +418,11 @@ function find_representative_periods(
# Check that the number of RPs makes sense. The first check can be done immediately,
# The second check is done after we compute the auxiliary data
if n_rp < 1
throw(ArgumentError("The number of representative periods is $n_rp but has to be at least 1."))
throw(
ArgumentError(
"The number of representative periods is $n_rp but has to be at least 1.",
),
)
end

# Find auxiliary data and pre-compute additional constants that are used multiple times alter
Expand Down
10 changes: 8 additions & 2 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ Converts a weight matrix from a (sparse) matrix, which is more convenient for
internal computations, to a dataframe, which is better for saving into a file.
Zero weights are dropped to avoid cluttering the dataframe.
"""
function weight_matrix_to_df(weights::Union{SparseMatrixCSC{Float64, Int64}, Matrix{Float64}})
function weight_matrix_to_df(
weights::Union{SparseMatrixCSC{Float64, Int64}, Matrix{Float64}},
)
weights = sparse(weights)
periods, rep_periods, values = weights |> findnz
result = DataFrame(; period = periods, rep_period = rep_periods, weight = values)
Expand Down Expand Up @@ -39,7 +41,11 @@ function write_clustering_result_to_tables(
period_duration[end] = aux.last_period_duration
DuckDB.register_data_frame(
connection,
DataFrame(; rep_period = 1:num_rep_periods, num_timesteps = period_duration, resolution = 1.0),
DataFrame(;
rep_period = 1:num_rep_periods,
num_timesteps = period_duration,
resolution = 1.0,
),
"rep_periods_data",
)
return nothing
Expand Down
15 changes: 13 additions & 2 deletions src/structures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ mutable struct AuxiliaryClusteringData
last_period_duration::Int
n_periods::Int

function AuxiliaryClusteringData(key_columns, period_duration, last_period_duration, n_periods)
function AuxiliaryClusteringData(
key_columns,
period_duration,
last_period_duration,
n_periods,
)
return new(key_columns, period_duration, last_period_duration, n_periods)
end
end
Expand All @@ -23,7 +28,13 @@ mutable struct ClusteringResult
rp_matrix::Union{Matrix{Float64}, Nothing}
auxiliary_data::Union{AuxiliaryClusteringData, Nothing}

function ClusteringResult(profiles, weight_matrix, clustering_matrix, rp_matrix, auxiliary_data)
function ClusteringResult(
profiles,
weight_matrix,
clustering_matrix,
rp_matrix,
auxiliary_data,
)
return new(profiles, weight_matrix, clustering_matrix, rp_matrix, auxiliary_data)
end

Expand Down
3 changes: 2 additions & 1 deletion src/weight_fitting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ function fit_rep_period_weights!(
else
x = Vector(weight_matrix[period, 1:n_rp])
end
x = projected_subgradient_descent!(x; subgradient, projection, tol = tol * 0.01, args...)
x =
projected_subgradient_descent!(x; subgradient, projection, tol = tol * 0.01, args...)
x[x .< tol] .= 0.0 # replace insignificant small values with zeros
if weight_type == :convex || weight_type == :conical_bounded
# Because some values might have been removed, convexity can be lost.
Expand Down
3 changes: 2 additions & 1 deletion test/test-cluster.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ end
@testset "Data valudation" begin
@testset "Make sure that when the columns are right validation works and the key columns are found" begin
@test begin
df = DataFrame([:period => [1, 1, 2], :timestep => [1, 2, 1], :a .=> "a", :value => 1:3])
df =
DataFrame([:period => [1, 1, 2], :timestep => [1, 2, 1], :a .=> "a", :value => 1:3])
keys = TulipaClustering.validate_df_and_find_key_columns(df)

keys == [:timestep, :a]
Expand Down
13 changes: 9 additions & 4 deletions test/test-io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
TulipaClustering.write_clustering_result_to_tables(connection, clustering_data)

tables = DBInterface.execute(connection, "SHOW TABLES") |> DataFrame |> df -> df.name
@test sort(tables) ==
Union{Missing, String}["profiles_rep_periods", "rep_periods_data", "rep_periods_mapping"]
@test sort(tables) == Union{Missing, String}[
"profiles_rep_periods",
"rep_periods_data",
"rep_periods_mapping",
]

@testset "rep_periods_data" begin
rep_periods_data_df =
Expand All @@ -36,8 +39,10 @@
end

@testset "ClusteringResult constructor without auxiliary data" begin
clustering_result =
TulipaClustering.ClusteringResult(clustering_data.profiles, clustering_data.weight_matrix)
clustering_result = TulipaClustering.ClusteringResult(
clustering_data.profiles,
clustering_data.weight_matrix,
)

@test clustering_result.profiles == clustering_data.profiles
@test clustering_result.weight_matrix == clustering_data.weight_matrix
Expand Down
12 changes: 10 additions & 2 deletions test/test-weight-fitting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ end
distance = SqEuclidean(),
init = :kmcen,
)
TulipaClustering.fit_rep_period_weights!(clustering_result; weight_type = :dirac, niters = 5)
TulipaClustering.fit_rep_period_weights!(
clustering_result;
weight_type = :dirac,
niters = 5,
)
all(sum(clustering_result.weight_matrix[1:(end - 1), :]; dims = 2) .== 1.0)
end
end
Expand All @@ -88,7 +92,11 @@ end
distance = SqEuclidean(),
init = :kmcen,
)
TulipaClustering.fit_rep_period_weights!(clustering_result; weight_type = :convex, niters = 5)
TulipaClustering.fit_rep_period_weights!(
clustering_result;
weight_type = :convex,
niters = 5,
)
sum(clustering_result.weight_matrix) round(365 / 7, RoundUp) &&
all(sum(clustering_result.weight_matrix[1:(end - 1), :]; dims = 2) .≈ 1.0)
end
Expand Down

0 comments on commit 1753660

Please sign in to comment.