Skip to content

Commit 38e7ec1

Browse files
committed
[WIP] Change data input to have prefix 'input_'
1 parent acede9c commit 38e7ec1

32 files changed

+392
-302
lines changed

benchmark/benchmarks.jl

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function input_setup()
1919
connection,
2020
input_folder;
2121
schemas = TulipaEnergyModel.schema_per_table_name,
22+
table_name_prefix = "input_",
2223
)
2324
return connection
2425
end

benchmark/profiling/common.jl

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ dir = norse_dir
77

88
function _read_dir_and_return_connection(dir)
99
con = DBInterface.connect(DuckDB.DB)
10-
TulipaIO.read_csv_folder(con, dir; schemas = TulipaEnergyModel.schema_per_table_name)
10+
TulipaIO.read_csv_folder(
11+
con,
12+
dir;
13+
schemas = TulipaEnergyModel.schema_per_table_name,
14+
table_name_prefix = "input_",
15+
)
1116

1217
return con
1318
end

docs/src/20-how-to-use.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ All tests should pass.
2727
## Finding an input parameter
2828

2929
!!! tip "Are you looking for an input parameter?"
30-
Please visit the [Model Parameters](@ref schemas) section for a description and location of all model input parameters.
30+
Please visit the [Data](@ref data) section for a description and location of all model input parameters.
3131

3232
## Running a Scenario
3333

docs/src/30-concepts.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ unstacked_map[!,["k=1", "k=2", "k=3"]] = convert.(Float64, unstacked_map[!,["k=1
638638
unstacked_map # hide
639639
```
640640

641-
The file `assets-timeframe-partitions` has the information on how often we want to evaluate the inter-temporal constraints that combine the information of the representative periods. In this example, the file is missing in the folder, meaning that the default of a `uniform` distribution of one period will be use in the model, see [model parameters](@ref schemas) section. This assumption implies that the model will check the inter-storage level every day of the week timeframe.
641+
The file `assets-timeframe-partitions` has the information on how often we want to evaluate the inter-temporal constraints that combine the information of the representative periods. In this example, the file is missing in the folder, meaning that the default of a `uniform` distribution of one period will be use in the model, see the [schemas](@ref schemas) section. This assumption implies that the model will check the inter-storage level every day of the week timeframe.
642642

643643
!!! info
644644
For the sake of simplicity, we show how using three representative days can recover part of the chronological information of one week. The same method can be applied to more representative periods to analyze the seasonality across a year or longer timeframe.
@@ -651,7 +651,12 @@ using DuckDB, TulipaIO, TulipaEnergyModel
651651
input_dir = "../../test/inputs/Storage" # hide
652652
# input_dir should be the path to the Storage example
653653
connection = DBInterface.connect(DuckDB.DB)
654-
read_csv_folder(connection, input_dir; schemas = TulipaEnergyModel.schema_per_table_name)
654+
read_csv_folder(
655+
connection,
656+
input_dir;
657+
schemas = TulipaEnergyModel.schema_per_table_name,
658+
table_name_prefix = "input_",
659+
)
655660
energy_problem = run_scenario(connection)
656661
```
657662

docs/src/50-schemas.md

+52-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,56 @@
1-
# [Model Parameters](@id schemas)
1+
# [Data pipeline/workflow](@id data)
22

3-
The optimization model parameters with the input data must follow the schema below for each table. To create these tables we currently use CSV files that follow this same schema and then convert them into tables using TulipaIO, as shown in the basic example of the [Tutorials](@ref basic-example) section.
3+
---
4+
TODO:
5+
6+
- diagrams
7+
- Replace
8+
> To create these tables we currently use CSV files that follow this same schema and then convert them into tables using TulipaIO, as shown in the basic example of the [Tutorials](@ref basic-example) section.
9+
- Review below
10+
11+
---
12+
13+
Tulipa uses a DuckDB database to store the input data, the representation of variables, constraints, and other internal tables, as well as the output.
14+
This database is informed through the `connection` argument in various parts of the API. Most notably, for [`run_scenario`](@ref) and [`EnergyProblem`](@ref).
15+
16+
## [Minimum data and using defaults](@id minimum_data)
17+
18+
Since `TulipaEnergyModel` is at a late stage in the workflow, its input data requirements are stricter.
19+
Therefore, the input data required by the Tulipa model must follow the schema in the follow section.
20+
21+
Dealing with defaults is hard. A missing value might represent two different things to different people. That is why we require the tables to be complete.
22+
However, we also understand that it is not reasonable to expect people to fill a lot of things that they don't need for their models.
23+
Therefore, we have created the function [`populate_with_defaults!`](@ref) to fill the remaining columns of your tables with default values.
24+
25+
To know the defaults, check the table [Schemas](@ref schemas) below.
26+
27+
!!! warning "Beware implicit assumptions"
28+
When data is missing and you automatically fill it with defaults, beware of your assumptions on what that means.
29+
Check what are the default values and decide if you want to use them or not.
30+
If you think a default does not make sense, open an issue, or a discussion thread.
31+
32+
### Example of using `populate_with_defaults!`
33+
34+
```@example
35+
using TulipaEnergyModel, TulipaIO, DuckDB
36+
```
37+
38+
## Namespaces
39+
40+
After creating a `connection` and loading data in a way that follows the schema (see the previous section on [minimum data](@ref minimum_data)), then Tulipa will create tables to handle the model data and various internal tables.
41+
To differentiate between these tables, we use a prefix. This should also help differentiate between the data you might want to create yourself.
42+
Here are the different namespaces:
43+
44+
- `input_`: Tables expected by `TulipaEnergyModel`.
45+
- `var_`: Variable indices.
46+
- `cons_`: Constraints indices.
47+
- `expr_`: Expressions indices.
48+
- `resolution_`: Unrolled partition blocks of assets and flows.
49+
- `t_*`: Temporary tables.
50+
51+
## [Schemas](@id schemas)
52+
53+
The optimization model parameters with the input data must follow the schema below for each table.
454

555
The schemas can be found in the `input-schemas.json`. For more advanced users, they can also access the schemas at any time after loading the package by typing `TulipaEnergyModel.schema_per_table_name` in the Julia console. Here is the complete list of model parameters in the schemas per table (or CSV file):
656

src/constraints/capacity.jl

+8-8
Original file line numberDiff line numberDiff line change
@@ -376,19 +376,19 @@ function _append_capacity_data_to_indices_compact_method(connection, table_name)
376376
ANY_VALUE(asset_commission.investment_limit) AS investment_limit,
377377
ANY_VALUE(assets_profiles.profile_name) AS profile_name,
378378
FROM cons_$table_name AS cons
379-
LEFT JOIN asset
379+
LEFT JOIN input_asset as asset
380380
ON cons.asset = asset.asset
381-
LEFT JOIN asset_commission
381+
LEFT JOIN input_asset_commission as asset_commission
382382
ON cons.asset = asset_commission.asset
383383
AND cons.year = asset_commission.commission_year
384384
LEFT JOIN expr_available_asset_units_compact_method AS expr_avail
385385
ON cons.asset = expr_avail.asset
386386
AND cons.year = expr_avail.milestone_year
387-
LEFT OUTER JOIN assets_profiles
387+
LEFT OUTER JOIN input_assets_profiles as assets_profiles
388388
ON cons.asset = assets_profiles.asset
389389
AND cons.year = assets_profiles.commission_year
390390
AND assets_profiles.profile_type = 'availability'
391-
LEFT OUTER JOIN assets_profiles AS avail_profile
391+
LEFT OUTER JOIN input_assets_profiles AS avail_profile
392392
ON cons.asset = avail_profile.asset
393393
AND expr_avail.commission_year = avail_profile.commission_year
394394
AND avail_profile.profile_type = 'availability'
@@ -420,19 +420,19 @@ function _append_capacity_data_to_indices_simple_method(connection, table_name)
420420
asset_commission.investment_limit AS investment_limit,
421421
assets_profiles.profile_name AS profile_name,
422422
FROM cons_$table_name AS cons
423-
LEFT JOIN asset
423+
LEFT JOIN input_asset as asset
424424
ON cons.asset = asset.asset
425-
LEFT JOIN asset_commission
425+
LEFT JOIN input_asset_commission as asset_commission
426426
ON cons.asset = asset_commission.asset
427427
AND cons.year = asset_commission.commission_year
428428
LEFT JOIN expr_available_asset_units_simple_method AS expr_avail
429429
ON cons.asset = expr_avail.asset
430430
AND cons.year = expr_avail.milestone_year
431-
LEFT OUTER JOIN assets_profiles
431+
LEFT OUTER JOIN input_assets_profiles as assets_profiles
432432
ON cons.asset = assets_profiles.asset
433433
AND cons.year = assets_profiles.commission_year
434434
AND assets_profiles.profile_type = 'availability'
435-
LEFT OUTER JOIN assets_profiles AS avail_profile
435+
LEFT OUTER JOIN input_assets_profiles AS avail_profile
436436
ON cons.asset = avail_profile.asset
437437
AND expr_avail.commission_year = avail_profile.commission_year
438438
AND avail_profile.profile_type = 'availability'

src/constraints/consumer.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ function _create_consumer_table(connection)
6666
asset_milestone.peak_demand,
6767
assets_profiles.profile_name,
6868
FROM cons_balance_consumer AS cons
69-
LEFT JOIN asset
69+
LEFT JOIN input_asset as asset
7070
ON cons.asset = asset.asset
71-
LEFT JOIN asset_milestone
71+
LEFT JOIN input_asset_milestone as asset_milestone
7272
ON cons.asset = asset_milestone.asset
7373
AND cons.year = asset_milestone.milestone_year
74-
LEFT OUTER JOIN assets_profiles
74+
LEFT OUTER JOIN input_assets_profiles as assets_profiles
7575
ON cons.asset = assets_profiles.asset
7676
AND cons.year = assets_profiles.commission_year
7777
AND assets_profiles.profile_type = 'demand' -- This must be a ON condition not a where (note 1)

src/constraints/energy.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ function _append_energy_data_to_indices(connection, table_name, min_or_max)
7171
asset_milestone.$(min_or_max)_energy_timeframe_partition,
7272
assets_timeframe_profiles.profile_name
7373
FROM cons_$table_name AS cons
74-
LEFT JOIN asset_milestone
74+
LEFT JOIN input_asset_milestone as asset_milestone
7575
ON cons.asset = asset_milestone.asset
7676
AND cons.year = asset_milestone.milestone_year
77-
LEFT OUTER JOIN assets_timeframe_profiles
77+
LEFT OUTER JOIN input_assets_timeframe_profiles as assets_timeframe_profiles
7878
ON cons.asset = assets_timeframe_profiles.asset
7979
AND cons.year = assets_timeframe_profiles.commission_year
8080
AND assets_timeframe_profiles.profile_type = '$(min_or_max)_energy'

src/constraints/group.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ function _get_assets_in_group(connection, group)
7070
asset.group,
7171
asset.capacity,
7272
FROM var_assets_investment AS var
73-
JOIN asset
73+
JOIN input_asset as asset
7474
ON var.asset = asset.asset
75-
JOIN group_asset
75+
JOIN input_group_asset as group_asset
7676
ON asset.group = group_asset.name
7777
WHERE asset.group IS NOT NULL
7878
AND asset.group = '$group'

src/constraints/ramping-and-unit-commitment.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,9 @@ function _append_ramping_data_to_indices(connection, table_name)
271271
asset.max_ramp_down,
272272
assets_profiles.profile_name
273273
FROM cons_$table_name AS cons
274-
LEFT JOIN asset
274+
LEFT JOIN input_asset as asset
275275
ON cons.asset = asset.asset
276-
LEFT OUTER JOIN assets_profiles
276+
LEFT OUTER JOIN input_assets_profiles as assets_profiles
277277
ON cons.asset = assets_profiles.asset
278278
AND cons.year = assets_profiles.commission_year
279279
AND assets_profiles.profile_type = 'availability'
@@ -299,7 +299,7 @@ function _append_available_units_data_compact_method(connection, table_name)
299299
LEFT JOIN expr_available_asset_units_compact_method AS expr_avail
300300
ON cons.asset = expr_avail.asset
301301
AND cons.year = expr_avail.milestone_year
302-
LEFT JOIN asset
302+
LEFT JOIN input_asset as asset
303303
ON cons.asset = asset.asset
304304
WHERE asset.investment_method = 'compact'
305305
GROUP BY cons.id
@@ -324,7 +324,7 @@ function _append_available_units_data_simple_method(connection, table_name)
324324
LEFT JOIN expr_available_asset_units_simple_method AS expr_avail
325325
ON cons.asset = expr_avail.asset
326326
AND cons.year = expr_avail.milestone_year
327-
LEFT JOIN asset
327+
LEFT JOIN input_asset as asset
328328
ON cons.asset = asset.asset
329329
WHERE asset.investment_method in ('simple', 'none')
330330
ORDER BY cons.id

src/constraints/storage.jl

+7-7
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ function _append_storage_data_to_indices(connection, table_name)
270270
cons.period_block_start,
271271
SUM(mapping.num_timesteps) AS duration_period_block
272272
FROM cons_balance_storage_over_clustered_year AS cons
273-
LEFT JOIN timeframe_data AS mapping
273+
LEFT JOIN input_timeframe_data AS mapping
274274
ON mapping.year = cons.year
275275
AND mapping.period BETWEEN cons.period_block_start AND cons.period_block_end
276276
GROUP BY cons.asset, cons.year, cons.period_block_start
@@ -301,26 +301,26 @@ function _append_storage_data_to_indices(connection, table_name)
301301
min_storage_level_profile.profile_name AS min_storage_level_profile_name,
302302
expr_avail.id AS avail_energy_capacity_id
303303
FROM cons_$table_name AS cons
304-
LEFT JOIN asset
304+
LEFT JOIN input_asset as asset
305305
ON cons.asset = asset.asset
306-
LEFT JOIN asset_commission
306+
LEFT JOIN input_asset_commission as asset_commission
307307
ON cons.asset = asset_commission.asset
308308
AND cons.year = asset_commission.commission_year
309-
LEFT JOIN asset_milestone
309+
LEFT JOIN input_asset_milestone as asset_milestone
310310
ON cons.asset = asset_milestone.asset
311311
AND cons.year = asset_milestone.milestone_year
312312
LEFT JOIN expr_available_energy_capacity_simple_method AS expr_avail
313313
ON cons.asset = expr_avail.asset
314314
AND cons.year = expr_avail.milestone_year
315-
LEFT OUTER JOIN assets_profiles AS inflows_profile
315+
LEFT OUTER JOIN input_assets_profiles AS inflows_profile
316316
ON cons.asset = inflows_profile.asset
317317
AND cons.year = inflows_profile.commission_year
318318
AND inflows_profile.profile_type = 'inflows'
319-
LEFT OUTER JOIN assets_profiles AS max_storage_level_profile
319+
LEFT OUTER JOIN input_assets_profiles AS max_storage_level_profile
320320
ON cons.asset = max_storage_level_profile.asset
321321
AND cons.year = max_storage_level_profile.commission_year
322322
AND max_storage_level_profile.profile_type = 'max_storage_level'
323-
LEFT OUTER JOIN assets_profiles AS min_storage_level_profile
323+
LEFT OUTER JOIN input_assets_profiles AS min_storage_level_profile
324324
ON cons.asset = min_storage_level_profile.asset
325325
AND cons.year = min_storage_level_profile.commission_year
326326
AND min_storage_level_profile.profile_type = 'min_storage_level'

src/constraints/transport.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@ function _append_transport_data_to_indices(connection)
108108
expr_avail.id AS avail_id,
109109
flows_profiles.profile_name AS profile_name,
110110
FROM cons_transport_flow_limit_simple_method AS cons
111-
LEFT JOIN flow
111+
LEFT JOIN input_flow as flow
112112
ON cons.from_asset = flow.from_asset
113113
AND cons.to_asset = flow.to_asset
114114
LEFT JOIN expr_available_flow_units_simple_method AS expr_avail
115115
ON cons.from_asset = expr_avail.from_asset
116116
AND cons.to_asset = expr_avail.to_asset
117117
AND cons.year = expr_avail.milestone_year
118-
LEFT OUTER JOIN flows_profiles
118+
LEFT OUTER JOIN input_flows_profiles as flows_profiles
119119
ON cons.from_asset = flows_profiles.from_asset
120120
AND cons.to_asset = flows_profiles.to_asset
121121
AND cons.year = flows_profiles.year

0 commit comments

Comments
 (0)