Skip to content

Commit 0de3158

Browse files
gnawinabelsiqueira
andauthored
Year to milestone year (#51)
* year to milestone year * Fix tests * Relax TC dependency * Temporary fix Norse test * change downstream test version * Fix json lint * Add TC custom layout * Fix lint * Remove hack * Fix docs * Release v0.2.0 --------- Co-authored-by: Abel Soares Siqueira <abel.siqueira@esciencecenter.nl>
1 parent 79bf70c commit 0de3158

File tree

10 files changed

+39
-21
lines changed

10 files changed

+39
-21
lines changed

.github/downstream.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
{
33
"package": "TulipaEnergyModel",
44
"user": "TulipaEnergy",
5-
"version": "latest"
5+
"version": "1086-verbose-year"
66
}
77
]

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "TulipaBuilder"
22
uuid = "05fe4dc7-9a58-53a4-b912-b5673d74e816"
3-
version = "0.1.5"
3+
version = "0.2.0"
44
authors = ["Abel Soares Siqueira"]
55

66
[workspace]
@@ -19,6 +19,6 @@ DataFrames = "1.7.0"
1919
DuckDB = "1.3.1"
2020
Graphs = "1.13.0"
2121
MetaGraphsNext = "0.7.3, 0.8"
22-
TulipaEnergyModel = "0.17, 0.18, 0.19, 0.20"
22+
TulipaEnergyModel = "0.21"
2323
TulipaIO = "0.5.0"
2424
julia = "1.10"

docs/Project.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,3 @@ NetworkLayout = "0.4"
3232
Plots = "1"
3333
Statistics = "1"
3434
TulipaClustering = "0.5"
35-
TulipaEnergyModel = "0.19, 0.20"

docs/src/10-tutorials/10-basic.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ For completeness, here is rest of the pipeline for clustering, populating with d
6363
# Don't forget to cluster and populate with defaults before solving the problem
6464
using TulipaEnergyModel, TulipaClustering
6565
66-
dummy_cluster!(connection)
66+
dummy_cluster!(connection; layout = TC.ProfilesTableLayout(year = :milestone_year))
6767
populate_with_defaults!(connection)
6868
ep = run_scenario(connection)
6969
```

src/create-connection.jl

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ function create_connection(tulipa::TulipaData, db = ":memory:")
441441
connection,
442442
"CREATE OR REPLACE TABLE profiles (
443443
profile_name VARCHAR,
444-
year INT64,
444+
milestone_year INT64,
445445
scenario INT64,
446446
timestep INT64,
447447
value DOUBLE,
@@ -469,7 +469,7 @@ function create_connection(tulipa::TulipaData, db = ":memory:")
469469
# Use DataFrame for efficient bulk insertion
470470
profiles_df = DataFrame(
471471
profile_name = profile_name,
472-
year = year,
472+
milestone_year = year,
473473
scenario = scenario,
474474
timestep = 1:length(profile_value),
475475
value = profile_value,
@@ -511,7 +511,7 @@ function create_connection(tulipa::TulipaData, db = ":memory:")
511511
"CREATE OR REPLACE TABLE flows_profiles (
512512
from_asset VARCHAR,
513513
to_asset VARCHAR,
514-
year INT64,
514+
milestone_year INT64,
515515
profile_name VARCHAR,
516516
profile_type VARCHAR,
517517
)",
@@ -523,7 +523,7 @@ function create_connection(tulipa::TulipaData, db = ":memory:")
523523
profile_name = "$from_asset_name-$to_asset_name-$profile_type-$year"
524524
profiles_df = DataFrame(
525525
profile_name = profile_name,
526-
year = year,
526+
milestone_year = year,
527527
scenario = scenario,
528528
timestep = 1:length(profile_value),
529529
value = profile_value,
@@ -543,7 +543,7 @@ function create_connection(tulipa::TulipaData, db = ":memory:")
543543
"INSERT INTO flows_profiles BY NAME (SELECT
544544
'$from_asset_name' AS from_asset,
545545
'$to_asset_name' AS to_asset,
546-
$year AS year,
546+
$year AS milestone_year,
547547
'$profile_name' AS profile_name,
548548
'$profile_type' AS profile_type,
549549
)",
@@ -660,7 +660,7 @@ function create_connection(tulipa::TulipaData, db = ":memory:")
660660
end
661661

662662
# Table assets_rep_periods_partitions
663-
columns = ["asset", "year", "rep_period", "specification", "partition"]
663+
columns = ["asset", "milestone_year", "rep_period", "specification", "partition"]
664664
need_table = any(
665665
length(tulipa.graph[a].partitions) > 0 for a in MetaGraphsNext.labels(tulipa.graph)
666666
)
@@ -679,7 +679,7 @@ function create_connection(tulipa::TulipaData, db = ":memory:")
679679
end
680680
for ((year, rep_period), value) in partitions
681681
query = "INSERT INTO assets_rep_periods_partitions BY NAME (SELECT '$asset_name' AS asset, "
682-
query *= "$year as year, $rep_period as rep_period,"
682+
query *= "$year as milestone_year, $rep_period as rep_period,"
683683
specification = get(value, :specification, "uniform")
684684
partition = value[:partition] # no default for partition
685685
query *= _get_select_query_row(
@@ -698,7 +698,14 @@ function create_connection(tulipa::TulipaData, db = ":memory:")
698698
end
699699
end
700700

701-
columns = ["from_asset", "to_asset", "year", "rep_period", "specification", "partition"]
701+
columns = [
702+
"from_asset",
703+
"to_asset",
704+
"milestone_year",
705+
"rep_period",
706+
"specification",
707+
"partition",
708+
]
702709
need_table = any(
703710
length(tulipa.graph[e...].partitions) > 0 for
704711
e in MetaGraphsNext.edge_labels(tulipa.graph)
@@ -718,7 +725,7 @@ function create_connection(tulipa::TulipaData, db = ":memory:")
718725
end
719726
for ((year, rep_period), value) in partitions
720727
query = "INSERT INTO flows_rep_periods_partitions BY NAME (SELECT '$from_asset_name' AS from_asset, '$to_asset_name' AS to_asset,"
721-
query *= "$year as year, $rep_period as rep_period, "
728+
query *= "$year as milestone_year, $rep_period as rep_period, "
722729
specification = get(value, :specification, "uniform")
723730
partition = value[:partition] # no default for partition
724731
query *= _get_select_query_row(

test/Project.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,4 @@ JuMP = "1"
2323
TOML = "1"
2424
TestItemRunner = "1"
2525
TulipaClustering = "0.5"
26-
TulipaEnergyModel = "0.19, 0.20"
2726
XLSX = "0.10"

test/test-basic.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
connection = create_connection(tulipa)
5151

5252
# External
53-
TC.dummy_cluster!(connection)
53+
TC.dummy_cluster!(connection; layout = TC.ProfilesTableLayout(year = :milestone_year))
5454
TEM.populate_with_defaults!(connection)
5555
ep = TEM.run_scenario(connection, show_log = false, model_file_name = "model.lp")
5656
@test JuMP.is_solved_and_feasible(ep.model)

test/test-integration-norse.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,13 +501,18 @@ end
501501
# External
502502
period_duration = 24
503503
num_rep_periods = 1
504-
TC.cluster!(connection, period_duration, num_rep_periods)
504+
TC.cluster!(
505+
connection,
506+
period_duration,
507+
num_rep_periods;
508+
layout = TC.ProfilesTableLayout(year = :milestone_year),
509+
)
505510
# Manually changing the data because we can't currently cluster as Norse
506511
# See https://github.com/TulipaEnergy/TulipaClustering.jl/discussions/144
507512
DuckDB.query(connection, "UPDATE rep_periods_data SET num_timesteps = 168")
508513
DuckDB.query(
509514
connection,
510-
"INSERT INTO rep_periods_data (rep_period, year, num_timesteps, resolution) VALUES (2, 2030, 24, 1.0)",
515+
"INSERT INTO rep_periods_data (rep_period, milestone_year, num_timesteps, resolution) VALUES (2, 2030, 24, 1.0)",
511516
)
512517
TEM.populate_with_defaults!(connection)
513518

test/test-integration-tiny.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,12 @@ end
108108
# External
109109
period_duration = 24
110110
num_rep_periods = 3
111-
TC.cluster!(connection, period_duration, num_rep_periods)
111+
TC.cluster!(
112+
connection,
113+
period_duration,
114+
num_rep_periods;
115+
layout = TC.ProfilesTableLayout(year = :milestone_year),
116+
)
112117
TEM.populate_with_defaults!(connection)
113118

114119
# Comparison

test/test-output.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
function create_and_get_data(tulipa; cluster = false, populate_with_defaults = false)
1313
connection = create_connection(tulipa)
1414
if cluster
15-
TC.dummy_cluster!(connection)
15+
TC.dummy_cluster!(
16+
connection;
17+
layout = TC.ProfilesTableLayout(year = :milestone_year),
18+
)
1619
end
1720
if populate_with_defaults
1821
TEM.populate_with_defaults!(connection)
@@ -60,7 +63,7 @@
6063
),
6164
:profiles => DataFrame(
6265
profile_name = String[],
63-
year = Int[],
66+
milestone_year = Int[],
6467
scenario = Int[],
6568
timestep = Int[],
6669
value = Float64[],

0 commit comments

Comments
 (0)