Skip to content

Fix inconsistent keys for overwrite_saved_data in MultipleBuildingTypes#7

Merged
Zetison merged 2 commits intomainfrom
fix/MultipleBuildingsTypes_overwrite_saved_data
Dec 12, 2025
Merged

Fix inconsistent keys for overwrite_saved_data in MultipleBuildingTypes#7
Zetison merged 2 commits intomainfrom
fix/MultipleBuildingsTypes_overwrite_saved_data

Conversation

@Zetison
Copy link
Collaborator

@Zetison Zetison commented Dec 11, 2025

There was a bug when writing data to file in MultipleBuildingTypes as the read keys are not mapped to the Resource-type. In this PR, this is resolved by storing the original keys (which is in String format anyways), and handling the mapping on node usage.

@Zetison Zetison requested a review from Copilot December 11, 2025 12:20
@Zetison Zetison self-assigned this Dec 11, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug in MultipleBuildingTypes where data keys were inconsistently mapped between reading and writing operations. The fix stores original string keys when reading data and only maps them to Resource types when calculating node usage, ensuring consistent key handling throughout the data lifecycle.

Key changes:

  • Modified key mapping in MultipleBuildingTypes to use original string keys in intermediate storage
  • Updated resource mapping to occur only when accumulating capacity vectors
  • Changed test configuration to verify data persistence by running tests twice (once writing, once reading saved data)

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/datastructures.jl Fixed key mapping by storing original string keys and mapping to Resource types only when summing demands
test/utils.jl Changed overwrite_saved_data to false to enable testing with persisted data
test/test_buildings.jl Added loop to run tests twice for verifying saved data handling, plus formatting improvements
test/test_CSPandPV.jl Added loop to run tests twice for verifying saved data handling, plus formatting improvements

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Zetison Zetison requested a review from JulStraus December 11, 2025 12:49
Copy link
Member

@JulStraus JulStraus left a comment

Choose a reason for hiding this comment

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

The changes seem reasonable to me.

I realized however a different thing which I am not entirely happy about:
We always scale in the current design from W used in the original model to MW. In practice, we should however also allow the user to specify the unit. I would hence say that we should have another PR in which we allow with a keyword argument to adjust the value, e.g.,

function MultipleBuildingTypes(
    id::Any,
    process_pay_load::Dict,
    time_start::DateTime,
    time_end::DateTime,
    buildings::Vector{String},
    resources_map::Dict{String,<:Resource},
    T::TimeStructure,
    penalty_surplus::Dict{<:Resource,<:TimeProfile},
    penalty_deficit::Dict{<:Resource,<:TimeProfile};
    data::Vector{<:Data} = Data[],
    data_location::String = joinpath(tempdir(), "buildings"),
    overwrite_saved_data::Bool = false,
    unit::String = "MW",
)

and in the code than an if-loop to check for the unit. Required units are probably W, kW, MW, and GW with MW being the default value.

If we explain it in the docstring and include an exception handling, it should be not an issue. I am a bit uncertain what type of error it is, but I would tend to DomainError or ArgumentError. You can also check the Julia documentation for it .

@JulStraus
Copy link
Member

Thinking about it, you can also call unit model_unit to be more precise.

@Zetison Zetison merged commit b43f8b1 into main Dec 12, 2025
3 checks passed
@Zetison Zetison deleted the fix/MultipleBuildingsTypes_overwrite_saved_data branch December 12, 2025 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants