Skip to content

Store hash of time series files when using TDR to detect input changes#894

Open
Copilot wants to merge 9 commits intomainfrom
copilot/add-hash-storage-for-tdr-files
Open

Store hash of time series files when using TDR to detect input changes#894
Copilot wants to merge 9 commits intomainfrom
copilot/add-hash-storage-for-tdr-files

Conversation

Copy link

Copilot AI commented Jan 9, 2026

Implementation Plan for TDR Hash Verification

  • Create hash computation functions for time series files
    • Add SHA256 hashing function for files
    • Update to support binary files (parquet, gzip)
    • Create function to compute hashes for all relevant input files
    • Create multi-stage specific hash computation
  • Create hash storage mechanism
    • Design YAML format for storing file hashes
    • Create function to save hash file in TDR_Results folder
    • Create function to load existing hash file with safety checks
  • Implement hash comparison logic
    • Create function to check if stored hashes match current files
    • Handle case when hash file doesn't exist
  • Integrate with existing TDR workflow
    • Modify time_domain_reduced_files_exist to check hashes
    • Update cluster_inputs to save hashes after TDR
    • Support both single-stage and multi-stage workflows correctly
  • Add tests for hash verification
    • Test hash computation
    • Test hash file storage and loading
    • Test integration with TDR workflow
  • Manual testing with example system
    • Create manual test script
  • Update documentation
    • Update TDR user guide
    • Update TDR tutorial
  • Address all code review and PR feedback
    • Add missing imports
    • Add safety check for hash file structure
    • Fix multi-stage path handling
    • Support binary files (parquet, gzip)
    • Add SHA to Project.toml dependencies
    • Update CHANGELOG.md

All tasks complete! Implementation ready for final review.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature]: Store hash of time series files when using TDR</issue_title>
<issue_description>### Feature description

Create a new file (csv or json) in the TDR_Results folder that stores a hash of each original time series file (gen variability, demand, fuels). When GenX runs and checks time_domain_reduced_files_exist, also check the stored hash values against the original time series files.

It might also be good to also hash the time_domain_reduction_settings.yml file in case the TDR settings were changed.

Motivation

Using TDR creates a folder TDR_Results with data for the selected time series periods. GenX looks for this folder and reads the data in future runs if it already exists. If the original time series data (or TDR settings) are changed it is easy for users to forget that they need to delete the TDR_Results folder.

Implementation strategy

Create a new function, maybe time_series_files_changed, that loads the file with hash values (if it exists). Recalculate the hash from the full time series files and compare the two. Maybe a second function to check the TDR settings hash (or combine in a single function).

If the hash file doesn't exist, assume that TDR needs to be re-run. Running TDR a second time will overwrite the existing TDR_Results files.

Additional context

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 6 commits January 9, 2026 17:48
- Create tdr_hash_utils.jl with functions to compute and compare file hashes
- Modify time_domain_reduced_files_exist to check if input files changed
- Update cluster_inputs to save hash file after TDR
- Use SHA256 for file hashing and YAML for storage

Co-authored-by: gschivley <10373332+gschivley@users.noreply.github.com>
- Create test_tdr_hash_verification.jl with unit tests
- Test hash computation, storage, loading, and change detection
- Add test to main test suite

Co-authored-by: gschivley <10373332+gschivley@users.noreply.github.com>
- Update TDR_input.md with section on input file hash verification
- Add note to Tutorial 3 about automatic validation
- Create manual_test_tdr_hash.jl for manual testing demonstrations

Co-authored-by: gschivley <10373332+gschivley@users.noreply.github.com>
Add YAML and Dates imports that are used but were not declared

Co-authored-by: gschivley <10373332+gschivley@users.noreply.github.com>
Check for 'file_hashes' key existence before accessing to prevent KeyError

Co-authored-by: gschivley <10373332+gschivley@users.noreply.github.com>
- Add compute_tdr_input_hashes_multistage function
- Use multistage-specific functions for multi-stage TDR
- Fixes incorrect path handling in multi-stage scenarios

Co-authored-by: gschivley <10373332+gschivley@users.noreply.github.com>
Copilot AI changed the title [WIP] Add hash storage for time series files in TDR Store hash of time series files when using TDR to detect input changes Jan 9, 2026
Copilot AI requested a review from gschivley January 9, 2026 17:59
if !isfile(filepath)
return nothing
end
open(filepath, "r") do file
Copy link
Collaborator

Choose a reason for hiding this comment

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

@copilot the open(filepath, "r") do file is good for plain text files (csv/yaml). In the future we might use parquet or gzip files rather than plain csv. Can you modify this to work well with binary files like parquet or gzipped CSVs?

Copy link
Author

Choose a reason for hiding this comment

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

Updated to use binary mode (read(filepath)) instead of text mode, which now handles both text files (CSV, YAML) and binary files (Parquet, gzipped CSVs). This approach works with any file format. See commit ef48460.

- Use binary read mode instead of text mode to support both text and binary files
- Update documentation with examples for parquet and gzipped files
- Simplify implementation using read() directly

Co-authored-by: gschivley <10373332+gschivley@users.noreply.github.com>
Copilot AI requested a review from gschivley January 9, 2026 19:41
@gschivley gschivley marked this pull request as ready for review February 5, 2026 15:53
@gschivley
Copy link
Collaborator

@copilot A few issues from the checks:

  1. The package SHA should be added to GenX dependencies
  2. CHANGELOG.md must be updated using the keepachangelog format (https://keepachangelog.com/)

- Add SHA package to Project.toml dependencies
- Update CHANGELOG.md with TDR hash verification feature in keepachangelog format

Co-authored-by: gschivley <10373332+gschivley@users.noreply.github.com>
Copy link
Author

Copilot AI commented Feb 5, 2026

@copilot A few issues from the checks:

  1. The package SHA should be added to GenX dependencies
    ...

Both issues addressed in commit d0c4f42:

  1. Added SHA to dependencies in Project.toml
  2. Updated CHANGELOG.md with the new feature using keepachangelog format under "Unreleased > Added"

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.

[Feature]: Store hash of time series files when using TDR

2 participants