Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pt ut): make separated uts deterministic #4162

Merged
merged 1 commit into from
Sep 25, 2024

Conversation

iProzd
Copy link
Collaborator

@iProzd iProzd commented Sep 24, 2024

Fix failed uts in #4145 .

Summary by CodeRabbit

  • New Features

    • Added a "seed" property to multiple JSON configuration files, enhancing control over randomness in model training and evaluation.
    • Introduced a global seed parameter in various test functions to improve reproducibility across test runs.
  • Bug Fixes

    • Ensured consistent random number generation in tests by integrating a global seed parameter.
  • Documentation

    • Updated configuration files and test methods to reflect the addition of the seed parameter for clarity and consistency.

Copy link
Contributor

coderabbitai bot commented Sep 24, 2024

Walkthrough

Walkthrough

The pull request introduces a new parameter, "seed", across various JSON configuration files and test functions, enhancing the handling of randomness and reproducibility in model training and testing. The "seed" parameter is added to multiple model configuration files and test functions, allowing for consistent random number generation. Additionally, existing test functions are updated to accept this parameter, ensuring that tests can be executed with a specified seed value for improved reliability.

Changes

Files Change Summary
source/tests/pt/model/models/dpa1.json, source/tests/pt/model/models/dpa2.json Added property "seed": 1 to the JSON configuration files for model parameters.
source/tests/pt/model/test_descriptor_se_r.py, source/tests/pt/model/test_dipole_fitting.py, source/tests/pt/model/test_ener_fitting.py, source/tests/pt/model/test_polarizability_fitting.py, source/tests/pt/model/test_property_fitting.py, source/tests/pt/model/test_se_atten_v2.py, source/tests/pt/model/test_se_e2_a.py, source/tests/pt/model/test_se_t.py Added seed=GLOBAL_SEED parameter to multiple test functions, enhancing reproducibility.
source/tests/pt/model/test_embedding_net.py Replaced hardcoded seed value with GLOBAL_SEED in test_consistency function.
source/tests/pt/model/test_permutation.py Added "seed": 1 to various configuration dictionaries within the file.
source/tests/pt/model/water/se_atten.json Added property "seed": 1 to the configuration object.

Possibly related PRs

Suggested labels

Python, Docs, Examples

Suggested reviewers

  • njzjz
  • wanghan-iapcm

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range and nitpick comments (19)
source/tests/pt/model/water/se_atten.json (1)

27-28: LGTM! Consider parameterizing the seed value.

The addition of the "seed" property to the descriptor configuration is a good step towards ensuring reproducibility and aligns well with the PR objective of making separated unit tests deterministic. The consistency of the seed value (1) between the descriptor and fitting_net sections is commendable.

To improve flexibility, consider parameterizing the seed value. This would allow easier changes for different test scenarios without modifying the JSON file. For example:

"seed": "${SEED:-1}"

This suggestion uses a placeholder that can be replaced at runtime, defaulting to 1 if not specified. Implement this change only if it aligns with your current configuration management practices.

source/tests/pt/model/test_se_t.py (3)

66-66: LGTM! Consider adding a default value for the seed parameter.

The addition of the seed parameter to the DescrptSeT constructor is a good step towards making the unit tests deterministic. This change aligns well with the PR objective.

Consider adding a default value for the seed parameter in the function signature. This would maintain backwards compatibility and allow for easier testing with different seeds if needed. For example:

def test_consistency(self, seed=GLOBAL_SEED):

135-135: LGTM! Consider adding a default value for the seed parameter.

The addition of the seed parameter to the DescrptSeT constructor in the test_jit function is consistent with the changes made to test_consistency and aligns with the PR objective of making unit tests deterministic.

As suggested for test_consistency, consider adding a default value for the seed parameter in the function signature:

def test_jit(self, seed=GLOBAL_SEED):

This change would maintain consistency between the two test functions and provide flexibility for future testing scenarios.


Line range hint 1-135: Overall, the changes look good and achieve the PR objective.

The modifications to both test_consistency and test_jit functions are consistent and contribute to making the unit tests more deterministic. The use of GLOBAL_SEED ensures reproducibility across test runs.

To further improve the code:

  1. Consider extracting the GLOBAL_SEED into a configuration file or environment variable. This would allow easier management of the seed value across the entire test suite.
  2. If not already done, ensure that the GLOBAL_SEED is documented in the project's testing guidelines or README, explaining its purpose and how it contributes to deterministic test results.
source/tests/pt/model/test_se_atten_v2.py (3)

70-70: LGTM: Addition of GLOBAL_SEED parameter

The addition of GLOBAL_SEED as a parameter to the DescrptSeAttenV2 initialization enhances the reproducibility of the test, which is in line with the PR objective.

Consider adding a comment explaining the purpose of using GLOBAL_SEED here, for better code readability. For example:

seed=GLOBAL_SEED,  # Ensure deterministic behavior across test runs

142-142: LGTM: Addition of GLOBAL_SEED parameter

The addition of GLOBAL_SEED as a parameter to the DescrptSeAttenV2 initialization in the test_jit method is consistent with the changes made in test_consistency and aligns with the PR objective of making tests deterministic.

Similar to the suggestion for test_consistency, consider adding a comment explaining the purpose of using GLOBAL_SEED here:

seed=GLOBAL_SEED,  # Ensure deterministic behavior across test runs

Line range hint 1-142: Summary: Enhancing test determinism with GLOBAL_SEED

The changes in this file consistently apply GLOBAL_SEED to the DescrptSeAttenV2 initialization in both test_consistency and test_jit methods. This implementation aligns well with the PR objective of making separated unit tests deterministic.

These changes will improve the reproducibility of test results, making it easier to debug issues and ensure consistent behavior across different test runs.

To further improve the implementation:

  1. Consider adding a brief comment in the file docstring explaining the use of GLOBAL_SEED for test determinism.
  2. If GLOBAL_SEED is used in other test files, ensure consistent implementation across the test suite.
source/tests/pt/model/test_ener_fitting.py (4)

68-68: LGTM! Consider extracting GLOBAL_SEED to a constant.

The addition of the seed parameter to the InvarFitting constructor is a good step towards making the tests deterministic. This change aligns well with the PR objective.

To improve code readability and maintainability, consider extracting GLOBAL_SEED to a constant at the top of the file:

SEED = GLOBAL_SEED

# Then use it in the test:
seed=SEED,

This makes it easier to update the seed value for all tests in this file if needed in the future.


172-172: LGTM! Ensure consistency with SEED constant.

The addition of the seed parameter here is consistent with the changes in the test_consistency function and aligns with the PR objective.

If you implement the suggestion to extract GLOBAL_SEED to a SEED constant, ensure you use it here as well for consistency:

seed=SEED,

182-185: LGTM! Good use of consistent seeding.

The addition of the seed parameter to the InvarFitting constructor and the use of the same seed for the random number generator is an excellent approach to ensure test determinism.

If you implement the suggestion to extract GLOBAL_SEED to a SEED constant, ensure you use it here as well for consistency:

SEED = GLOBAL_SEED

# Then in the test:
seed=SEED,
)
rng = np.random.default_rng(SEED)

This change maintains the good practice of using the same seed for both the InvarFitting constructor and the random number generator while improving code readability.


Line range hint 1-191: Summary: Excellent progress on making tests deterministic

The changes in this file consistently add a seed parameter to the InvarFitting constructor calls in various test functions. This aligns perfectly with the PR objective of making separated unit tests deterministic.

Key points:

  1. The use of GLOBAL_SEED ensures consistency across different test runs.
  2. The changes don't alter the logic of the tests but enhance reproducibility.
  3. In the test_get_set function, the same seed is used for both the InvarFitting constructor and the random number generator, which is a good practice.

To further improve the code:

  1. Consider extracting GLOBAL_SEED to a SEED constant at the top of the file for better readability and maintainability.
  2. Ensure that all randomness in the tests is seeded, including any random operations in the tested functions themselves.
  3. Document the purpose of using a fixed seed in the test file's docstring to explain the deterministic nature of these tests to other developers.
source/tests/pt/model/test_descriptor_se_r.py (2)

66-66: LGTM! Consider documenting the seed usage.

The addition of the seed parameter to the DescrptSeR constructor is a good step towards making the tests deterministic. This change aligns well with the PR objective.

Consider adding a brief comment explaining the purpose of setting the seed, e.g.:

# Set seed for reproducibility
seed=GLOBAL_SEED,

This would help other developers understand the importance of this change at a glance.


134-134: LGTM! Consider consistent formatting.

The addition of the seed parameter to the DescrptSeR constructor is correct and aligns with the PR objective.

For consistency with the surrounding code, consider aligning the seed parameter with the other parameters:

seed=GLOBAL_SEED,

This minor adjustment would improve code readability and maintain a consistent style throughout the file.

source/tests/pt/model/test_embedding_net.py (1)

159-159: LGTM: Use of GLOBAL_SEED improves test determinism.

Replacing the hardcoded seed value with GLOBAL_SEED enhances the test's consistency and aligns with the PR objective of making unit tests deterministic. This change will ensure that the random number generation in this test is consistent with other tests using the same global seed.

Consider adding a brief comment explaining the purpose of using GLOBAL_SEED here, for improved code readability. For example:

seed=GLOBAL_SEED,  # Use global seed for consistent random number generation across tests
source/tests/pt/model/test_dpa1.py (2)

74-74: LGTM! Consider documenting the purpose of the seed parameter.

The addition of the seed parameter with GLOBAL_SEED is a good step towards making the unit tests deterministic. This change aligns well with the PR objective.

Consider adding a brief comment explaining the purpose of the seed parameter, e.g.:

seed=GLOBAL_SEED,  # Ensures deterministic behavior in tests

This would help other developers understand the importance of this parameter at a glance.


215-215: LGTM! Consider extracting common test parameters.

The addition of the seed parameter with GLOBAL_SEED to the JIT test is consistent with the previous changes and maintains deterministic behavior across different test methods.

To improve code maintainability and reduce duplication, consider extracting common test parameters (including the seed) into a separate method or fixture. This could look like:

def get_test_params(self):
    return {
        "rcut": self.rcut,
        "rcut_smth": self.rcut_smth,
        "sel": self.sel,
        "nt": self.nt,
        "seed": GLOBAL_SEED,
        # ... other common parameters ...
    }

# Then in your test methods:
dd0 = DescrptDPA1(**self.get_test_params(), precision=prec, resnet_dt=idt, ...)

This approach would make it easier to ensure consistency across different test methods and simplify future updates to common parameters.

source/tests/pt/model/test_permutation.py (3)

91-91: LGTM! Consider using a constant for the seed value.

The addition of the "seed" parameter to the descriptor configuration is a good practice for ensuring reproducibility.

Consider defining a constant for the seed value (e.g., DEFAULT_SEED = 1) at the module level and using it across all configurations. This would make it easier to change the seed value globally if needed in the future.


271-271: LGTM! Comprehensive seed implementation in hybrid model.

The addition of the "seed" parameter to both descriptor configurations in the model_hybrid is thorough and consistent with other changes, ensuring reproducibility across all components of the hybrid model.

Consider using a single seed value for the entire hybrid model configuration, rather than specifying it separately for each descriptor. This could be achieved by moving the seed parameter to the top level of the hybrid model configuration. This approach would ensure that all components of the hybrid model use the same seed, potentially simplifying configuration management.

Also applies to: 304-304


91-91: Overall LGTM! Consider global seed management.

The consistent addition of the "seed" parameter across all model configurations is a significant improvement for ensuring reproducibility in the tests. This change will help in debugging and maintaining consistent behavior across different runs and environments.

To further improve the code:

  1. Define a global constant for the seed value at the module level, e.g., DEFAULT_SEED = 1.
  2. Use this constant throughout all model configurations.
  3. Consider adding a function to generate model configurations with a customizable seed, allowing for easy manipulation of the seed value across all models when needed.

Example:

DEFAULT_SEED = 1

def add_seed_to_config(config, seed=DEFAULT_SEED):
    if isinstance(config, dict):
        for key, value in config.items():
            if isinstance(value, dict):
                config[key] = add_seed_to_config(value, seed)
        if "type" in config and "seed" not in config:
            config["seed"] = seed
    return config

# Usage
model_se_e2_a = add_seed_to_config({
    "type_map": ["O", "H", "B"],
    "descriptor": {
        "type": "se_e2_a",
        # ... other parameters ...
    },
    # ... other configurations ...
})

This approach would centralize seed management, making it easier to modify or randomize seeds for all models simultaneously when needed.

Also applies to: 159-159, 212-212, 241-241, 271-271, 304-304

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0b72dae and c1167e8.

Files selected for processing (15)
  • source/tests/pt/model/models/dpa1.json (1 hunks)
  • source/tests/pt/model/models/dpa2.json (1 hunks)
  • source/tests/pt/model/test_descriptor_se_r.py (3 hunks)
  • source/tests/pt/model/test_dipole_fitting.py (6 hunks)
  • source/tests/pt/model/test_dpa1.py (3 hunks)
  • source/tests/pt/model/test_dpa2.py (4 hunks)
  • source/tests/pt/model/test_embedding_net.py (2 hunks)
  • source/tests/pt/model/test_ener_fitting.py (3 hunks)
  • source/tests/pt/model/test_permutation.py (6 hunks)
  • source/tests/pt/model/test_polarizability_fitting.py (6 hunks)
  • source/tests/pt/model/test_property_fitting.py (8 hunks)
  • source/tests/pt/model/test_se_atten_v2.py (3 hunks)
  • source/tests/pt/model/test_se_e2_a.py (3 hunks)
  • source/tests/pt/model/test_se_t.py (2 hunks)
  • source/tests/pt/model/water/se_atten.json (1 hunks)
Additional comments not posted (40)
source/tests/pt/model/models/dpa1.json (1)

24-25: LGTM! Consider making the seed configurable.

The addition of the "seed" property is a good practice for ensuring reproducibility in model training and testing. This change aligns well with the PR objective of making unit tests deterministic.

Consider making the seed value configurable rather than hardcoded. This would allow for easy adjustment in different environments (e.g., development, testing, production) without modifying the configuration file. You could use environment variables or command-line arguments to set the seed value.

Let's verify if the "seed" property in the "fitting_net" section was intentionally left unchanged:

If this returns true, it suggests that both seeds are intentionally set to the same value. If false, you might want to consider aligning them or explaining why they differ.

Verification successful

Verified that both "descriptor.seed" and "fitting_net.seed" are correctly set to the same value.

The synchronization of the seed values ensures consistent behavior across different components of the model.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if "seed" property exists in both "descriptor" and "fitting_net" sections
# and if they have the same value

jq '.descriptor.seed == .fitting_net.seed' source/tests/pt/model/models/dpa1.json

Length of output: 88

source/tests/pt/model/test_se_atten_v2.py (1)

19-21: LGTM: Import of GLOBAL_SEED

The import of GLOBAL_SEED from the seed module is correctly placed and aligns with the PR objective of making separated unit tests deterministic.

source/tests/pt/model/test_descriptor_se_r.py (2)

66-66: Overall assessment: Changes improve test determinism.

The addition of the seed=GLOBAL_SEED parameter to the DescrptSeR constructor calls in all three test methods (test_consistency, test_load_stat, and test_jit) is a positive change that aligns well with the PR objective of making unit tests deterministic.

These modifications should enhance the reproducibility of test results across different runs, which is crucial for maintaining a stable test suite. The consistent implementation across all methods demonstrates a thorough approach to addressing the issue.

To further improve the code:

  1. Consider adding brief comments explaining the purpose of setting the seed.
  2. Ensure consistent formatting of the new parameter across all methods.
  3. Verify that the JIT compilation works correctly with the added seed parameter.

These changes contribute to better code quality and test reliability.

Also applies to: 134-134, 185-185


185-185: LGTM! Verify JIT compilation with seed.

The addition of the seed parameter to the DescrptSeR constructor in the test_jit method is correct and consistent with the changes in other test methods.

To ensure that the JIT compilation works correctly with the added seed parameter, please run the following verification script:

This verification step will help ensure that the addition of the seed parameter doesn't introduce any issues with JIT compilation.

source/tests/pt/model/test_se_e2_a.py (4)

63-63: Excellent addition of the seed parameter for deterministic testing!

The inclusion of seed=GLOBAL_SEED in the DescrptSeA constructor is a crucial step towards ensuring reproducible test results. This change aligns perfectly with the PR objective of making unit tests deterministic.


117-117: Great consistency in applying the seed parameter!

Adding seed=GLOBAL_SEED to the DescrptSeA constructor with old_impl=True ensures that both the new and old implementations use the same seed. This is crucial for fair and consistent comparisons between the two implementations, further enhancing the determinism and reliability of the tests.


173-173: Excellent consistency in applying the seed parameter to JIT testing!

The addition of seed=GLOBAL_SEED to the DescrptSeA constructor in the test_jit method ensures that the JIT-compiled version of the model also uses a deterministic seed. This change is crucial for maintaining consistency across different testing scenarios and contributes significantly to the overall goal of making all aspects of testing deterministic.


Line range hint 1-173: Summary: Excellent implementation of deterministic seeding across all test scenarios!

The changes made to this file consistently apply the GLOBAL_SEED to all instances of DescrptSeA creation, including the new implementation, old implementation, and JIT-compiled version. This comprehensive approach ensures that all test scenarios are deterministic and reproducible, which is crucial for maintaining reliable and consistent test results.

These changes align perfectly with the PR objective of making unit tests deterministic and represent a significant improvement in the testing framework's robustness.

source/tests/pt/model/test_embedding_net.py (2)

42-44: LGTM: Import of GLOBAL_SEED enhances test determinism.

The addition of GLOBAL_SEED import aligns with the PR objective of making separated unit tests deterministic. This change will help ensure consistent random number generation across tests, improving reproducibility.


Line range hint 1-259: Summary: Changes effectively contribute to test determinism.

The modifications in this file, namely the import and use of GLOBAL_SEED, successfully contribute to the PR objective of making separated unit tests deterministic. These changes are minimal yet impactful, enhancing the reproducibility of the test_consistency method without altering its core logic. The implementation is clean and well-integrated with the existing code.

source/tests/pt/model/test_dpa1.py (2)

Line range hint 1-215: Overall, the changes effectively address the PR objective.

The consistent addition of the seed parameter using GLOBAL_SEED across different test methods (consistency, old implementation, and JIT) is a solid approach to ensuring deterministic behavior in the unit tests. This change aligns well with the PR objective of making separated unit tests deterministic.

Key points:

  1. Deterministic behavior is now ensured across different implementations and test methods.
  2. The use of a global seed (GLOBAL_SEED) promotes consistency throughout the test suite.
  3. The changes maintain backwards compatibility by including the seed in the old implementation test.

Suggestions for further improvement:

  1. Consider adding brief comments explaining the purpose of the seed parameter.
  2. Explore the possibility of extracting common test parameters to reduce code duplication and improve maintainability.
  3. Verify that the seed is being used consistently across all relevant parts of the test suite.

These changes represent a significant step towards more reliable and reproducible unit tests.


129-129: LGTM! Verify seed consistency across implementations.

The addition of the seed parameter with GLOBAL_SEED to the old implementation is consistent with the previous change and supports the goal of deterministic testing.

To ensure that the seed is being used consistently across both new and old implementations, consider adding an assertion to verify that the random states are identical after initialization. You can use the following script to check for any occurrences where the seed might not be used consistently:

If this script returns any results, it might indicate places where the seed is not being used consistently, which could lead to non-deterministic behavior.

Verification successful

Seed consistency across implementations confirmed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent use of GLOBAL_SEED across the file

# Test: Search for occurrences of DescrptDPA1 without GLOBAL_SEED
rg 'DescrptDPA1\([^)]*\)' source/tests/pt/model/test_dpa1.py | grep -v 'seed=GLOBAL_SEED'

Length of output: 89


Script:

#!/bin/bash
# Description: Verify that all DescrptDPA1 constructor calls include seed=GLOBAL_SEED

# Using rg to find all DescrptDPA1 constructor calls
rg 'DescrptDPA1\s*\([^)]*\)' source/tests/pt/model/test_dpa1.py | grep -v 'seed=GLOBAL_SEED' || echo "No instances without seed=GLOBAL_SEED found."

Length of output: 191

source/tests/pt/model/test_dpa2.py (4)

23-25: LGTM: Import of GLOBAL_SEED for deterministic testing

The addition of the GLOBAL_SEED import is a good practice for ensuring reproducibility in tests. This change aligns well with the PR objective of making separated unit tests deterministic.


158-158: LGTM: Added GLOBAL_SEED to DescrptDPA2 constructor calls

The addition of the seed=GLOBAL_SEED parameter to the DescrptDPA2 constructor calls in both the new and old implementations is a positive change. This ensures that the DescrptDPA2 instances are initialized with a consistent random state, contributing to the deterministic behavior of the test. This modification aligns well with the PR objective of making the unit tests deterministic.

Also applies to: 208-208


354-354: LGTM: Added GLOBAL_SEED to DescrptDPA2 constructor in test_jit

The addition of the seed=GLOBAL_SEED parameter to the DescrptDPA2 constructor call in the test_jit function is consistent with the changes made elsewhere in the file. This modification ensures deterministic behavior during JIT compilation testing, which is in line with the PR objective of making the unit tests deterministic.


Line range hint 1-354: Overall assessment: Changes effectively improve test determinism

The modifications made to this file consistently add the GLOBAL_SEED parameter to DescrptDPA2 constructor calls in various test functions. These changes effectively address the PR objective of making separated unit tests deterministic. The implementation is consistent throughout the file and should contribute to more reliable and reproducible test results.

source/tests/pt/model/test_dipole_fitting.py (7)

90-90: LGTM: Added seed parameter for deterministic testing

The addition of the seed parameter with GLOBAL_SEED value to the DipoleFittingNet initialization is a good practice. This change aligns with the PR objective of making unit tests deterministic, ensuring consistent results across different test runs.


143-143: LGTM: Consistent use of seed parameter

The addition of the seed parameter with GLOBAL_SEED value to this DipoleFittingNet initialization is consistent with the previous change. This ensures deterministic behavior in JIT compilation tests as well.


185-185: LGTM: Consistent use of seed parameter in rotation tests

The addition of the seed parameter with GLOBAL_SEED value to the DipoleFittingNet initialization in the test_rot method is consistent with the previous changes. This ensures deterministic behavior in rotation invariance tests.


240-240: LGTM: Consistent use of seed parameter in permutation tests

The addition of the seed parameter with GLOBAL_SEED value to the DipoleFittingNet initialization in the test_permu method is consistent with the previous changes. This ensures deterministic behavior in permutation invariance tests.


287-287: LGTM: Consistent use of seed parameter in translation tests

The addition of the seed parameter with GLOBAL_SEED value to the DipoleFittingNet initialization in the test_trans method is consistent with the previous changes. This ensures deterministic behavior in translation invariance tests.


335-335: LGTM: Consistent use of seed parameter in TestDipoleModel setup

The addition of the seed parameter with GLOBAL_SEED value to the DipoleFittingNet initialization in the setUp method of TestDipoleModel class is consistent with the previous changes. This ensures deterministic behavior in the setup of the TestDipoleModel class.


Line range hint 1-400: Overall assessment: Consistent implementation of deterministic testing

The changes made to this file are consistent and well-implemented. The seed parameter has been added to all DipoleFittingNet initializations, using the GLOBAL_SEED constant throughout. This approach ensures deterministic behavior across all tests, including consistency, JIT compilation, rotation, permutation, and translation invariance tests.

These changes align perfectly with the PR objective of making unit tests deterministic, which will improve the reliability and reproducibility of the test suite. The core test logic remains unchanged, maintaining the integrity of the existing tests while enhancing their consistency.

Great job on implementing these changes systematically throughout the file!

source/tests/pt/model/test_polarizability_fitting.py (7)

80-80: LGTM: Added seed parameter for reproducibility

The addition of the seed parameter with GLOBAL_SEED value to the PolarFittingNet initialization is a good practice. This change aligns with the PR objective to make separated unit tests deterministic, which is crucial for ensuring consistent and reproducible test results across different runs.


147-147: LGTM: Consistent seed parameter addition

The addition of the seed parameter with GLOBAL_SEED value to the PolarFittingNet initialization in the test_jit method is consistent with the previous change. This demonstrates a systematic approach to making the tests deterministic across different methods, which is commendable.


191-191: LGTM: Seed parameter added for rotational invariance test

The addition of the seed parameter with GLOBAL_SEED value to the PolarFittingNet initialization in the test_rot method is consistent with previous changes. This is particularly important for rotational invariance testing, as it ensures that any random elements in the test (such as the rotation matrix generation) are reproducible, allowing for consistent verification of this critical property.


254-254: LGTM: Seed parameter added for permutation invariance test

The addition of the seed parameter with GLOBAL_SEED value to the PolarFittingNet initialization in the test_permu method maintains consistency with previous changes. This is particularly valuable for permutation invariance testing, as it ensures that any random elements in the test are reproducible. This allows for consistent verification of the model's behavior under different atom orderings, which is a crucial property for physical systems.


305-305: LGTM: Seed parameter added for translational invariance test

The addition of the seed parameter with GLOBAL_SEED value to the PolarFittingNet initialization in the test_trans method maintains consistency with previous changes. This is particularly important for translational invariance testing, as it ensures that any random elements in the test are reproducible. This allows for consistent verification of the model's behavior under different spatial translations, which is a fundamental property for physical systems.


355-355: LGTM: Seed parameter added to test class setup

The addition of the seed parameter with GLOBAL_SEED value to the PolarFittingNet initialization in the setUp method of the TestPolarModel class is a good practice. This ensures that all tests within this class will use the same deterministic initialization, promoting consistency across the entire test suite. This change aligns well with the overall goal of making the tests more reproducible and reliable.


Line range hint 80-355: Summary: Excellent implementation of deterministic testing

The changes made in this file consistently add a seed parameter with GLOBAL_SEED value to various PolarFittingNet initializations across different test methods and classes. This implementation aligns perfectly with the PR objective of making separated unit tests deterministic. The changes cover all relevant test methods, including those for rotational, permutational, and translational invariance, as well as the general model setup.

These modifications will significantly improve the reproducibility and reliability of the test suite, making it easier to debug issues and ensure consistent behavior across different environments. The use of a global seed is a good practice that ensures uniformity throughout the tests.

Overall, this is a well-executed change that should have a positive impact on the testing process and the overall quality of the codebase.

source/tests/pt/model/test_permutation.py (3)

159-159: LGTM! Consistent use of seed parameter.

The addition of the "seed" parameter to the model_zbl descriptor configuration is consistent with other changes, ensuring reproducibility across different model types.


212-212: LGTM! Consistent seed parameter implementation.

The addition of the "seed" parameter to the model_dpa2tebd descriptor configuration maintains consistency with other model configurations, ensuring reproducibility.


241-241: LGTM! Seed parameter added consistently.

The addition of the "seed" parameter to the model_dpa1 descriptor configuration is in line with the changes made to other model configurations, ensuring consistent reproducibility across different model types.

source/tests/pt/model/test_property_fitting.py (7)

35-37: LGTM: New import for GLOBAL_SEED.

The addition of the GLOBAL_SEED import is appropriate and follows the existing import structure. This constant will help ensure consistent seeding across tests, improving reproducibility.


84-84: LGTM: Added GLOBAL_SEED to PropertyFittingNet initialization.

The addition of GLOBAL_SEED as a parameter to PropertyFittingNet initialization is a good practice. This ensures that the network is initialized consistently across test runs, contributing to the overall goal of making the tests deterministic.


153-153: LGTM: Added GLOBAL_SEED to PropertyFittingNet initialization in test_jit.

The addition of GLOBAL_SEED as a parameter to PropertyFittingNet initialization in the test_jit method is consistent with the previous change. This ensures that the network is initialized consistently during JIT compilation tests, further contributing to test determinism.


207-207: LGTM: Added GLOBAL_SEED to PropertyFittingNet initialization in TestInvarianceRandomShift.

The addition of GLOBAL_SEED as a parameter to PropertyFittingNet initialization in the TestInvarianceRandomShift class is consistent with previous changes. This ensures that the network is initialized consistently during rotation invariance tests, further enhancing test determinism.


330-330: LGTM: Added GLOBAL_SEED to PropertyFittingNet initialization in test_permu.

The addition of GLOBAL_SEED as a parameter to PropertyFittingNet initialization in the test_permu method is consistent with previous changes. This ensures that the network is initialized consistently during permutation invariance tests, further contributing to overall test determinism.


429-429: LGTM: Added GLOBAL_SEED to PropertyFittingNet initialization in TestPropertyModel.

The addition of GLOBAL_SEED as a parameter to PropertyFittingNet initialization in the TestPropertyModel class is consistent with previous changes. This ensures that the network is initialized consistently during PropertyModel tests, further enhancing overall test determinism.


Line range hint 1-458: Summary: Consistent implementation of GLOBAL_SEED across all tests.

The changes in this file consistently add the GLOBAL_SEED parameter to all PropertyFittingNet initializations across various test classes and methods. This implementation successfully addresses the goal of making the tests deterministic by ensuring consistent seeding. The modifications are well-executed and should significantly improve the reproducibility of the test results.

Some potential benefits of these changes include:

  1. Improved debugging capabilities due to reproducible test results.
  2. Easier identification of regressions in model performance.
  3. More reliable comparison of test results across different environments or test runs.

source/tests/pt/model/models/dpa2.json Show resolved Hide resolved
Copy link

codecov bot commented Sep 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.43%. Comparing base (0b72dae) to head (c1167e8).
Report is 191 commits behind head on devel.

Additional details and impacted files
@@           Coverage Diff           @@
##            devel    #4162   +/-   ##
=======================================
  Coverage   83.43%   83.43%           
=======================================
  Files         537      537           
  Lines       52146    52146           
  Branches     3046     3046           
=======================================
+ Hits        43507    43508    +1     
  Misses       7692     7692           
+ Partials      947      946    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@wanghan-iapcm wanghan-iapcm added this pull request to the merge queue Sep 25, 2024
Merged via the queue into deepmodeling:devel with commit 508759c Sep 25, 2024
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants