Repository navigation
Add check_resources hook for resource checks in check_case_data - #109
espenbodal wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The linked issue’s element-level hook and resource log grouping are missing, and two documentation links are unresolved.
3 open findings
What changed in this PR
Adds resource-level validation to the case consistency-checking framework.
Changes:
- Adds the
check_resourcesextension hook. - Adds resource-check tests and extension guidance.
- Updates internal documentation and release notes.
| File | Description |
|---|---|
src/checks.jl |
Implements and invokes the resource-check hook. |
test/test_checks.jl |
Tests custom resource validation. |
docs/src/how-to/extend-resource-functionality.md |
Documents implementing resource checks. |
docs/src/library/internals/functions.md |
Lists the new internal function. |
NEWS.md |
Records the new API. |
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
|
|
||
| # Check the resources of the case per resource family | ||
| for 𝒫ˢᵘᵇ ∈ res_types_vec(get_products(case)) | ||
| check_resources(case, 𝒫ˢᵘᵇ, modeltype, check_timeprofiles) |
There was a problem hiding this comment.
The question is whether that should be invoked directly here or could be a different PR. Given the description, it would not be necessary to have it here while I agree that Issue #107 states that it should be included. In this case, however, the question is where it is based located. As this is still up to debate, I would leave it at the moment be and ignore this comment.
| for 𝒫ˢᵘᵇ ∈ res_types_vec(get_products(case)) | ||
| check_resources(case, 𝒫ˢᵘᵇ, modeltype, check_timeprofiles) | ||
| end |
| - The individual elements vector must be unique, that it is not possible to have two vector | ||
| of nodes within the elements vector. | ||
| - Check that the coupling functions do return elements and not only an empty vector | ||
| - Call of [`check_resources`](@ref) for every resource family ([`resource_family`](@ref)) of |
JulStraus
left a comment
There was a problem hiding this comment.
Not too many things to adjust. There is however an issue that we only consider ResourceEmits that are included in the case description. Any other Resources directly in the case description do not matter.
That is however something we have to consider separately.
|
|
||
| # Check the resources of the case per resource family | ||
| for 𝒫ˢᵘᵇ ∈ res_types_vec(get_products(case)) | ||
| check_resources(case, 𝒫ˢᵘᵇ, modeltype, check_timeprofiles) |
There was a problem hiding this comment.
The question is whether that should be invoked directly here or could be a different PR. Given the description, it would not be necessary to have it here while I agree that Issue #107 states that it should be included. In this case, however, the question is where it is based located. As this is still up to debate, I would leave it at the moment be and ignore this comment.
| for 𝒫ˢᵘᵇ ∈ res_types_vec(get_products(case)) | ||
| check_resources(case, 𝒫ˢᵘᵇ, modeltype, check_timeprofiles) | ||
| end |
| Check the resources `𝒫ˢᵘᵇ` of a single resource type segment ([`res_types_vec`](@ref)) of | ||
| the `case`. The function is called from [`check_case_data`](@ref) for every resource type | ||
| segment of the case products. The default method does not check anything; extension | ||
| packages that introduce resource types provide methods for their resource types. | ||
|
|
||
| The `case` is included as argument so that the combination of the resources with the | ||
| elements carrying them can be checked as well, *e.g.*, through iterating over | ||
| `get_nodes(case)`. Checks that depend only on the type of an element belong in the check | ||
| functions of the package introducing the element type ([`check_node`](@ref), | ||
| [`check_node_data`](@ref), [`check_link`](@ref)). |
There was a problem hiding this comment.
Too verbose.
| Check the resources `𝒫ˢᵘᵇ` of a single resource type segment ([`res_types_vec`](@ref)) of | |
| the `case`. The function is called from [`check_case_data`](@ref) for every resource type | |
| segment of the case products. The default method does not check anything; extension | |
| packages that introduce resource types provide methods for their resource types. | |
| The `case` is included as argument so that the combination of the resources with the | |
| elements carrying them can be checked as well, *e.g.*, through iterating over | |
| `get_nodes(case)`. Checks that depend only on the type of an element belong in the check | |
| functions of the package introducing the element type ([`check_node`](@ref), | |
| [`check_node_data`](@ref), [`check_link`](@ref)). | |
| Check the resources `𝒫ˢᵘᵇ` of a single resource type segment ([`res_types_vec`](@ref)) of | |
| the `case`. | |
| The default method does not check anything; extension packages that introduce resource types | |
| provide methods for their resource types. |
| * Added the function `check_resources(case, 𝒫ˢᵘᵇ, modeltype, check_timeprofiles)`, called from `check_case_data` for every resource family of the case products. | ||
| * The default method does not check anything. | ||
| * Extension packages that introduce resource types can provide methods for checking the resource parameters and the combination of the resources with the elements carrying them. | ||
| * `check_case_data` has the additional arguments `modeltype` and `check_timeprofiles`. |
There was a problem hiding this comment.
| * Added the function `check_resources(case, 𝒫ˢᵘᵇ, modeltype, check_timeprofiles)`, called from `check_case_data` for every resource family of the case products. | |
| * The default method does not check anything. | |
| * Extension packages that introduce resource types can provide methods for checking the resource parameters and the combination of the resources with the elements carrying them. | |
| * `check_case_data` has the additional arguments `modeltype` and `check_timeprofiles`. | |
| * Added the function `check_resources(case, 𝒫ˢᵘᵇ, modeltype, check_timeprofiles)` for every resource family of the case products. | |
| The default method does not check anything. |
| end | ||
|
|
||
| # Function for setting up the system | ||
| function resource_graph(p_checked) |
There was a problem hiding this comment.
Please rename the function resource_graph to check_graph_res as we only use it for testing the checks. That requires adjustments in all @test_throws calls.
| # A positive parameter leaves the node check, which still fails | ||
| case, model = resource_graph(CheckedResource("checked", 0.0, 1.0)) | ||
| @test_throws AssertionError create_model(case, model) | ||
|
|
||
| # The checks are not run if the resource is not included in the case products | ||
| case, model = resource_graph(CheckedResource("checked", 0.0, -1.0)) | ||
| CO2 = get_products(case)[2] | ||
| case_wo = Case( | ||
| get_time_struct(case), | ||
| [CO2], | ||
| [get_nodes(case), get_links(case)], | ||
| [[get_nodes, get_links]], | ||
| ) | ||
| @test create_model(case_wo, model) isa JuMP.Model | ||
|
|
||
| # A resource without a method is not affected | ||
| Power = ResourceCarrier("Power", 0.0) | ||
| case, model = resource_graph(Power) | ||
| @test create_model(case, model) isa JuMP.Model |
There was a problem hiding this comment.
These tests are not relevant. We only have to test that the function you created is actually called. However, l. 1025 points towards another issue, i.e., that a resource in the current stage only must be included in the products field if and only if it is a ResourceEmit.


Closes #107. Adds
check_resources(case, 𝒫ˢᵘᵇ, modeltype, check_timeprofiles), called fromcheck_case_datafor every resource family; the default checks nothing.check_case_datagains the argumentsmodeltypeandcheck_timeprofiles. See the issue for the discussion. Includes tests, NEWS entry and documentation.