Skip to content

Use the same stable seed logic for SRF generation as HF#96

Open
lispandfound wants to merge 7 commits intopegasusfrom
segment_seeds
Open

Use the same stable seed logic for SRF generation as HF#96
lispandfound wants to merge 7 commits intopegasusfrom
segment_seeds

Conversation

@lispandfound
Copy link
Contributor

@lispandfound lispandfound commented Mar 10, 2026

Extracts the hf sim stable_hash utility into workflow.utils so that realisation-to-srf can use it to generate per-segment seeds from the root seed using the station name as extra entropy. Like the hf simulation, this ensures seeds are stable, and invariant to the order that segment SRFs are generated in. Added a few property tests in case we change the implementation in the future that should catch anything the code relies on namely:

  1. Hash should depend only on hash name,
  2. Hash should be within the integer range specified by the size argument.
  3. Hashes should be different for different names.

Any function satisfying the above should be fine.

Copilot AI review requested due to automatic review settings March 10, 2026 02:37
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the seed generation logic by centralizing the stable_hash utility. This change ensures that both high-frequency simulations and SRF generation processes use a consistent, order-invariant method for creating seeds based on station or segment names, leading to more reproducible and stable outputs across the workflow.

Highlights

  • Moved stable_hash utility: The stable_hash function, previously defined in workflow/scripts/hf_sim.py, has been extracted and moved to the shared workflow/utils.py module to promote reusability.
  • Consistent SRF seed generation: The realisation-to-srf script now utilizes the new utils.stable_hash function to generate per-segment seeds, ensuring stability and order-invariance, mirroring the logic used in HF simulation.
  • Updated hf_sim to use shared utility: The hf_sim script has been updated to import and use the stable_hash function from workflow/utils.py instead of its internal definition.
Changelog
  • workflow/scripts/hf_sim.py
    • Removed the local stable_hash function.
    • Updated station_seeds to import and use utils.stable_hash.
  • workflow/scripts/realisation_to_srf.py
    • Modified generate_fault_srf to incorporate utils.stable_hash with the segment name for seed generation.
  • workflow/utils.py
    • Added hashlib import.
    • Implemented a new stable_hash function for general string hashing.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly extracts the stable_hash function into a shared utility to ensure consistent seed generation logic. However, the changes introduce issues with testing. An existing test is broken by the refactoring, and the new logic in realisation-to-srf.py lacks test coverage. My review provides specific comments to address these critical and medium severity testing gaps.

I am having trouble creating individual review comments. Click here to see my feedback.

workflow/scripts/hf_sim.py (250-273)

critical

Removing stable_hash from this module breaks the test test_stable_hash in tests/test_hf.py, which will now fail with an AttributeError. To resolve this, the test needs to be moved and updated.

Please move test_stable_hash from tests/test_hf.py to tests/test_utils.py and adapt it to test utils.stable_hash. This will likely involve adding imports for hypothesis to tests/test_utils.py.

workflow/scripts/realisation_to_srf.py (549-552)

medium

This change introduces new seed generation logic, but it appears to be untested. To ensure the correctness and maintainability of this new feature, please add a unit test for generate_fault_srf that verifies the seed parameter passed to _build_genslip_command is calculated correctly using the stable hash of the fault name.

Copy link
Contributor

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 extracts the HF simulation’s stable hashing logic into workflow.utils and reuses it in SRF generation so that per-segment seeds are derived deterministically from a root seed and a segment/station name, making results invariant to generation order.

Changes:

  • Add utils.stable_hash() (blake2b-based) as a shared utility.
  • Update realisation-to-srf to derive a per-segment genslip seed using the stable hash of the segment name.
  • Update HF station seed derivation to use utils.stable_hash() instead of a local implementation.

Reviewed changes

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

File Description
workflow/utils.py Adds shared stable_hash() utility for stable, order-invariant name hashing.
workflow/scripts/realisation_to_srf.py Uses stable_hash(name) to derive per-segment genslip seeds from the root seed.
workflow/scripts/hf_sim.py Removes local stable_hash and switches station seed hashing to utils.stable_hash.

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

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