-
Notifications
You must be signed in to change notification settings - Fork 529
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)Make the weighted avarange fit for all kinds of systems #4593
Open
SumGuo-88
wants to merge
41
commits into
deepmodeling:devel
Choose a base branch
from
SumGuo-88:debug-weightedavg
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 20 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
b3a925d
fix and ut
SumGuo-88 08e4a55
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] bdc260a
fix ut bug (make the def name not start with 'test'
SumGuo-88 875ee01
Merge branch 'debug-weightedavg' of https://github.com/SumGuo-88/deep…
SumGuo-88 7d137d6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 8ab5ab9
Make code simple
SumGuo-88 33c4161
Merge branch 'debug-weightedavg' of https://github.com/SumGuo-88/deep…
SumGuo-88 db637f9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a6e5ee1
Merge branch 'devel' into debug-weightedavg
SumGuo-88 4ac6b45
Merge branch 'devel' into debug-weightedavg
SumGuo-88 fa0aa4f
check change
SumGuo-88 ab9ec6e
Merge branch 'debug-weightedavg' of https://github.com/SumGuo-88/deep…
SumGuo-88 d2c9c4b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] f87ef49
Merge branch 'devel' into debug-weightedavg
SumGuo-88 99d6942
reverse
SumGuo-88 984a78e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 603b6f2
reverse2
SumGuo-88 0f669b8
Merge branch 'debug-weightedavg' of https://github.com/SumGuo-88/deep…
SumGuo-88 5273168
remake the ut
SumGuo-88 57ba28f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 322b4c0
remake ut- still with error 2
SumGuo-88 8407b0c
Merge branch 'debug-weightedavg' of https://github.com/SumGuo-88/deep…
SumGuo-88 11d0c68
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 1942dfa
remake ut --still with error 3
SumGuo-88 c7ca682
Merge branch 'debug-weightedavg' of https://github.com/SumGuo-88/deep…
SumGuo-88 80a8589
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4e882f3
remake test with two def
SumGuo-88 66bb904
Merge branch 'debug-weightedavg' of https://github.com/SumGuo-88/deep…
SumGuo-88 687b08d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2b1f4bb
Merge branch 'devel' into debug-weightedavg
SumGuo-88 8d48ba4
remake all
SumGuo-88 b95ad66
Merge branch 'debug-weightedavg' of https://github.com/SumGuo-88/deep…
SumGuo-88 824472a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] accc321
make ops input right
SumGuo-88 7ea19b2
Merge branch 'debug-weightedavg' of https://github.com/SumGuo-88/deep…
SumGuo-88 daf9235
change def name
SumGuo-88 a949ebc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7653e34
change to dict_to_return
SumGuo-88 edc1744
Merge branch 'debug-weightedavg' of https://github.com/SumGuo-88/deep…
SumGuo-88 5bfa822
coverage
SumGuo-88 96c2108
no coverage
SumGuo-88 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
import unittest | ||
from unittest.mock import ( | ||
MagicMock, | ||
patch, | ||
) | ||
|
||
from deepmd.entrypoints.test import test # Import the test function | ||
|
||
|
||
class TestDeepPotModel(unittest.TestCase): | ||
@patch("deepmd.entrypoints.test.DeepEval") # Mock DeepEval class | ||
@patch("deepmd.entrypoints.test.DeepmdData") # Mock DeepmdData class | ||
@patch("deepmd.entrypoints.test.test_ener") # Mock test_ener function | ||
@patch("deepmd.entrypoints.test.weighted_average") # Mock weighted_average function | ||
@patch("builtins.open") # Mock the open function to avoid FileNotFoundError | ||
def test_deep_pot( | ||
self, | ||
mock_open, | ||
mock_weighted_avg, | ||
mock_test_ener, | ||
mock_deepmd_data, | ||
mock_deep_eval, | ||
): | ||
# Mock the file reading behavior to return mock data instead | ||
mock_open.return_value.__enter__.return_value.read.return_value = ( | ||
"mock_system_1\nmock_system_2" | ||
) | ||
|
||
# Setup mock return values | ||
mock_deep_eval_instance = MagicMock() | ||
mock_deep_eval.return_value = mock_deep_eval_instance | ||
mock_deep_eval_instance.get_type_map.return_value = "mock_type_map" | ||
|
||
mock_deepmd_data_instance = MagicMock() | ||
mock_deepmd_data.return_value = mock_deepmd_data_instance | ||
|
||
# Define the base_data to simulate the test_ener output | ||
base_data = [ | ||
{ # System 1 | ||
"mae_e": (2.0, 5), | ||
"mae_ea": (1.5, 5), | ||
"rmse_e": (2.5, 5), | ||
"rmse_ea": (2.0, 5), | ||
"mae_f": (0.3, 15), | ||
"rmse_f": (0.4, 15), | ||
"mae_v": (1.2, 5), | ||
"rmse_v": (1.5, 5), | ||
"mae_va": (0.8, 5), | ||
"rmse_va": (1.0, 5), | ||
}, | ||
{ # System 2 | ||
"mae_e": (3.0, 10), | ||
"mae_ea": (2.5, 10), | ||
"rmse_e": (3.5, 10), | ||
"rmse_ea": (3.0, 10), | ||
"mae_f": (0.5, 30), | ||
"rmse_f": (0.6, 30), | ||
"mae_v": (2.0, 10), | ||
"rmse_v": (2.5, 10), | ||
"mae_va": (1.5, 10), | ||
"rmse_va": (2.0, 10), | ||
}, | ||
{ # System 3 | ||
"mae_e": (4.0, 15), | ||
"mae_ea": (3.5, 15), | ||
"rmse_e": (4.5, 15), | ||
"rmse_ea": (4.0, 15), | ||
"mae_f": (0.7, 45), | ||
"rmse_f": (0.8, 45), | ||
"mae_v": (3.0, 15), | ||
"rmse_v": (3.5, 15), | ||
"mae_va": (2.5, 15), | ||
"rmse_va": (3.0, 15), | ||
}, | ||
] | ||
|
||
# Simulate err values for each system, adding the (1, 1, 1) triplet | ||
mock_test_ener.return_value = ( | ||
base_data[0], # Using the first system's base data | ||
1, # find_energy | ||
1, # find_force | ||
1, # find_virial | ||
) | ||
|
||
# Call the function with mock data | ||
test( | ||
model="mock_model_path", | ||
system="mock_system_path", | ||
datafile="mock_datafile.txt", # Still passing mock file name | ||
numb_test=10, | ||
rand_seed=None, | ||
shuffle_test=True, | ||
detail_file="mock_detail.txt", | ||
atomic=True, | ||
) | ||
|
||
# Check if mocks are called as expected | ||
mock_deep_eval.assert_called_once_with("mock_model_path", head=None) | ||
mock_deepmd_data.assert_called_once_with( | ||
"mock_system_path", | ||
set_prefix="set", | ||
shuffle_test=True, | ||
type_map="mock_type_map", | ||
sort_atoms=False, | ||
) | ||
mock_test_ener.assert_called_once() # Check if test_ener was called for DeepPot | ||
mock_weighted_avg.assert_called_once() | ||
|
||
# Check if the file was opened (mocked) | ||
mock_open.assert_called_once_with("mock_datafile.txt", "r") | ||
|
||
# Check results | ||
self.assertEqual(mock_weighted_avg.return_value["mae_e"], 0.7) | ||
self.assertEqual(mock_weighted_avg.return_value["rmse_e"], 0.4) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note your modification is not covered by UT.