-
Notifications
You must be signed in to change notification settings - Fork 33
support spin #286
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
base: master
Are you sure you want to change the base?
support spin #286
Conversation
for more information, see https://pre-commit.ci
📝 WalkthroughWalkthroughThis pull request introduces multiple formatting improvements across the codebase. Changes include converting single-line argument declarations into multi-line formats, reordering import statements, and adjusting comment spacings. New class constants for deviation metrics are added and integrated into validation checks. Additionally, two new link variables are incorporated into a report method, and a helper function ( Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant LmpSpinTaskGroup
participant ReviseByKeys
Caller->>LmpSpinTaskGroup: set_lmp(numb_models, lmp_template_fname, plm_template_fname, revisions)
LmpSpinTaskGroup->>ReviseByKeys: revise_by_keys(lmp_lines, keys, values)
ReviseByKeys-->>LmpSpinTaskGroup: revised lmp_lines
LmpSpinTaskGroup-->>Caller: proceed with updated lmp_lines
Suggested reviewers
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note ⚡️ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure ✨ Finishing Touches
🧪 Generate Unit Tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (12)
tests/op/test_run_dp_train.py (1)
657-658
: Remove duplicated line.There appears to be a duplicated line that should be removed.
- self.assertDictEqual(jdata, self.expected_init_model_odict_v2_spin)
tests/exploration/test_report_trust_levels.py (1)
103-147
: Well-structured magnetic force selection test.The test correctly validates that the exploration report handles magnetic force deviation metrics similarly to how it handles force deviation metrics. The test follows the same pattern as existing tests making it consistent and maintainable.
One minor issue: the variable
all_cand_sel
on line 128 is defined but never used.- all_cand_sel = [(0, 6), (0, 5), (1, 8), (1, 6), (1, 0), (1, 5)]
🧰 Tools
🪛 Ruff (0.8.2)
128-128: Local variable
all_cand_sel
is assigned to but never usedRemove assignment to unused variable
all_cand_sel
(F841)
dpgen2/exploration/task/make_task_group_from_config.py (1)
213-218
: Avoid using a mutabledict
as default argumentUsing a mutable default (
{}
) for theArgument("revisions", ...)
parameter can lead to unexpected behavior if therevisions
are modified. Consider usingNone
or an immutable fallback to be safe.A possible fix:
-Argument( - "revisions", - dict, - optional=True, - default={}, - doc=doc_revisions, -) +def_revisions_default = {} +Argument( + "revisions", + dict, + optional=True, + default=def_revisions_default, + doc=doc_revisions, +)tests/exploration/test_devi_manager.py (1)
122-139
: Remove extraneous 'f' prefixesThe lines at 130 and 136 use 'f' strings without placeholders, triggering lint warnings. Removing the 'f' prefix is recommended.
- f"Error: the number of frames in", + "Error: the number of frames in",🧰 Tools
🪛 Ruff (0.8.2)
130-130: f-string without any placeholders
Remove extraneous
f
prefix(F541)
136-136: f-string without any placeholders
Remove extraneous
f
prefix(F541)
dpgen2/exploration/task/lmp_spin_task_group.py (2)
2-2
: Clean up unused importsThe imports
random
,List
,lmp_traj_name
,plm_output_name
, andmake_lmp_input
are unused, which can create confusion and bloat. Consider removing them.-import random ... -from typing import ( - List, - Optional, -) ... -from dpgen2.constants import ( - lmp_traj_name, ... - plm_output_name, -) ... -from .lmp import ( - make_lmp_input, -)Also applies to: 7-7, 14-14, 17-17, 24-24
🧰 Tools
🪛 Ruff (0.8.2)
2-2:
random
imported but unusedRemove unused import:
random
(F401)
44-44
: Avoid a mutabledict
default in function signaturesHaving
revisions: dict = {}
as a default argument can be risky. Consider setting the default toNone
, then initializing it inside the function body to prevent shared state between calls.-def set_lmp( - self, - numb_models: int, - lmp_template_fname: str, - plm_template_fname: Optional[str] = None, - revisions: dict = {}, -) -> None: +def set_lmp( + self, + numb_models: int, + lmp_template_fname: str, + plm_template_fname: Optional[str] = None, + revisions: Optional[dict] = None, +) -> None: + if revisions is None: + revisions = {}🧰 Tools
🪛 Ruff (0.8.2)
44-44: Do not use mutable data structures for argument defaults
Replace with
None
; initialize within function(B006)
dpgen2/exploration/render/traj_render_lammps.py (1)
45-52
: Handle potential file reading errors.You've introduced an optional
lammps_input_file
parameter and setself.lammps_input
by reading the contents of the file. Consider catching exceptions (e.g.,FileNotFoundError
) or validating the file path to avoid runtime errors if the file is missing or unreadable.+ import os if lammps_input_file is not None: + if not os.path.exists(lammps_input_file): + raise FileNotFoundError(f"{lammps_input_file} does not exist.") self.lammps_input = Path(lammps_input_file).read_text() else: self.lammps_input = Nonetests/exploration/test_lmp_spin_task_group.py (4)
9-10
: Clean up unused imports.The following imports are flagged as unused by static analysis:
•typing.List
•typing.Set
•numpy
•exploration.context.dpgen2
•unittest.mock.Mock
•unittest.mock.patch
•dpgen2.constants.plm_input_name
•dpgen2.exploration.task.ExplorationStage
Consider removing these to keep the file tidy and avoid confusion.
-from typing import ( - List, - Set, -) -import numpy as np -try: - from exploration.context import ( - dpgen2, - ) -except ModuleNotFoundError: - pass -from unittest.mock import ( - Mock, - patch, -) -from dpgen2.constants import ( - plm_input_name, -) -from dpgen2.exploration.task import ( - ExplorationStage, -)Also applies to: 13-13, 17-17, 23-24, 30-30, 33-33
🧰 Tools
🪛 Ruff (0.8.2)
9-9:
typing.List
imported but unusedRemove unused import
(F401)
10-10:
typing.Set
imported but unusedRemove unused import
(F401)
15-21
: Use contextlib.suppress for clarity.Instead of an empty
try
-except ModuleNotFoundError: pass
, consider usingcontextlib.suppress
to make the intent clearer and reduce code nesting:-import os -import textwrap -import unittest -from pathlib import ( - Path, -) -from typing import ( - List, - Set, -) -try: - from exploration.context import ( - dpgen2, - ) -except ModuleNotFoundError: - pass +import contextlib +with contextlib.suppress(ModuleNotFoundError): + from exploration.context import dpgen2🧰 Tools
🪛 Ruff (0.8.2)
15-21: Use
contextlib.suppress(ModuleNotFoundError)
instead oftry
-except
-pass
(SIM105)
17-17:
exploration.context.dpgen2
imported but unused; consider usingimportlib.util.find_spec
to test for availability(F401)
193-193
: Use enumerate for loop index.Replacing manual index tracking with
enumerate
can make the loop more readable and less error-prone:- idx = 0 - for cc, ii, jj, kk in itertools.product(...): - ... - idx += 1 + for idx, (cc, ii, jj, kk) in enumerate(itertools.product(...)): + ...🧰 Tools
🪛 Ruff (0.8.2)
193-193: Use
enumerate()
for index variableidx
infor
loop(SIM113)
218-218
: Use enumerate for loop index.Same suggestion here: use
enumerate
to handle indexing in your loop.🧰 Tools
🪛 Ruff (0.8.2)
218-218: Use
enumerate()
for index variableidx
infor
loop(SIM113)
dpgen2/exploration/report/report_trust_levels_base.py (1)
247-254
: Consider using non-Yoda conditionals for better readabilityThe consistency checks use Yoda conditions (
0 == len(...)
) which can be rewritten for better readability.- assert 0 == len(accu & cand) - assert 0 == len(accu & fail) - assert 0 == len(cand & fail) + assert len(accu & cand) == 0 + assert len(accu & fail) == 0 + assert len(accu & fail) == 0
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (31)
dpgen2/entrypoint/args.py
(2 hunks)dpgen2/entrypoint/submit.py
(3 hunks)dpgen2/exploration/deviation/deviation_manager.py
(3 hunks)dpgen2/exploration/deviation/deviation_std.py
(1 hunks)dpgen2/exploration/render/traj_render_lammps.py
(3 hunks)dpgen2/exploration/report/report_adaptive_lower.py
(13 hunks)dpgen2/exploration/report/report_trust_levels_base.py
(9 hunks)dpgen2/exploration/report/report_trust_levels_max.py
(1 hunks)dpgen2/exploration/task/__init__.py
(1 hunks)dpgen2/exploration/task/lmp_spin_task_group.py
(1 hunks)dpgen2/exploration/task/make_task_group_from_config.py
(4 hunks)dpgen2/op/run_dp_train.py
(3 hunks)tests/exploration/test_devi_manager.py
(4 hunks)tests/exploration/test_lmp_spin_task_group.py
(1 hunks)tests/exploration/test_report_adaptive_lower.py
(2 hunks)tests/exploration/test_report_trust_levels.py
(2 hunks)tests/op/test_run_dp_train.py
(3 hunks)dpgen2/entrypoint/args.py
(1 hunks)dpgen2/entrypoint/submit.py
(3 hunks)dpgen2/exploration/render/traj_render_lammps.py
(3 hunks)dpgen2/exploration/report/report_adaptive_lower.py
(5 hunks)dpgen2/exploration/report/report_trust_levels_base.py
(2 hunks)dpgen2/exploration/task/__init__.py
(1 hunks)dpgen2/exploration/task/lmp_spin_task_group.py
(2 hunks)dpgen2/exploration/task/make_task_group_from_config.py
(3 hunks)dpgen2/op/run_dp_train.py
(1 hunks)tests/exploration/test_devi_manager.py
(2 hunks)tests/exploration/test_lmp_spin_task_group.py
(3 hunks)tests/exploration/test_report_adaptive_lower.py
(2 hunks)tests/exploration/test_report_trust_levels.py
(3 hunks)tests/op/test_run_dp_train.py
(3 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
dpgen2/exploration/task/__init__.py
17-17: .lmp_template_task_group.LmpTemplateTaskGroup
imported but unused; consider removing, adding to __all__
, or using a redundant alias
(F401)
17-17: .lmp_template_task_group.LmpTemplateTaskGroup
imported but unused; consider removing, adding to __all__
, or using a redundant alias
(F401)
dpgen2/entrypoint/submit.py
85-85: dpgen2.exploration.task.LmpTemplateTaskGroup
imported but unused
Remove unused import
(F401)
85-85: dpgen2.exploration.task.LmpTemplateTaskGroup
imported but unused
Remove unused import
(F401)
dpgen2/exploration/report/report_trust_levels_base.py
255-255: Yoda condition detected
Rewrite as len(accu & cand) == 0
(SIM300)
256-256: Yoda condition detected
Rewrite as len(accu & fail) == 0
(SIM300)
257-257: Yoda condition detected
Rewrite as len(cand & fail) == 0
(SIM300)
255-255: Yoda condition detected
Rewrite as len(accu & cand) == 0
(SIM300)
256-256: Yoda condition detected
Rewrite as len(accu & fail) == 0
(SIM300)
257-257: Yoda condition detected
Rewrite as len(cand & fail) == 0
(SIM300)
dpgen2/exploration/task/lmp_spin_task_group.py
44-44: Do not use mutable data structures for argument defaults
Replace with None
; initialize within function
(B006)
2-2: random
imported but unused
Remove unused import: random
(F401)
7-7: typing.List
imported but unused
Remove unused import: typing.List
(F401)
14-14: dpgen2.constants.lmp_traj_name
imported but unused
Remove unused import
(F401)
17-17: dpgen2.constants.plm_output_name
imported but unused
Remove unused import
(F401)
24-24: .lmp.make_lmp_input
imported but unused
Remove unused import: .lmp.make_lmp_input
(F401)
44-44: Do not use mutable data structures for argument defaults
Replace with None
; initialize within function
(B006)
tests/exploration/test_report_trust_levels.py
128-128: Local variable all_cand_sel
is assigned to but never used
Remove assignment to unused variable all_cand_sel
(F841)
tests/exploration/test_lmp_spin_task_group.py
9-9: typing.List
imported but unused
Remove unused import
(F401)
10-10: typing.Set
imported but unused
Remove unused import
(F401)
13-13: numpy
imported but unused
Remove unused import: numpy
(F401)
15-21: Use contextlib.suppress(ModuleNotFoundError)
instead of try
-except
-pass
(SIM105)
17-17: exploration.context.dpgen2
imported but unused; consider using importlib.util.find_spec
to test for availability
(F401)
23-23: unittest.mock.Mock
imported but unused
Remove unused import
(F401)
24-24: unittest.mock.patch
imported but unused
Remove unused import
(F401)
30-30: dpgen2.constants.plm_input_name
imported but unused
Remove unused import: dpgen2.constants.plm_input_name
(F401)
33-33: dpgen2.exploration.task.ExplorationStage
imported but unused
Remove unused import: dpgen2.exploration.task.ExplorationStage
(F401)
193-193: Use enumerate()
for index variable idx
in for
loop
(SIM113)
218-218: Use enumerate()
for index variable idx
in for
loop
(SIM113)
tests/exploration/test_devi_manager.py
130-130: f-string without any placeholders
Remove extraneous f
prefix
(F541)
136-136: f-string without any placeholders
Remove extraneous f
prefix
(F541)
🔇 Additional comments (44)
dpgen2/exploration/task/__init__.py (1)
16-18
:✅ Verification successful
Resolve unused import warning.
The import
LmpTemplateTaskGroup
is flagged as unused by static analysis. This import appears to be part of the infrastructure needed for the new spin support functionality since the PR mentions "lmp-spin" is similar to existing "lmp-template".
🏁 Script executed:
#!/bin/bash # Check if LmpTemplateTaskGroup is used elsewhere in the codebase rg "LmpTemplateTaskGroup" --type py | grep -v "__init__.py"Length of output: 2890
Review Verified: Retain 'LmpTemplateTaskGroup' Import
Our verification confirms that the
LmpTemplateTaskGroup
import is indeed used (in tests and core modules such asdpgen2/entrypoint/submit.py
and others). Although static analysis flags it as unused within the package files, its usage in the test suite and its role as part of the public API for the new spin support functionality justify keeping the import. If the static analyzer continues to complain, consider adding an inline suppression comment to document its intentional usage.🧰 Tools
🪛 Ruff (0.8.2)
17-17:
.lmp_template_task_group.LmpTemplateTaskGroup
imported but unused; consider removing, adding to__all__
, or using a redundant alias(F401)
dpgen2/op/run_dp_train.py (1)
525-525
: Simplified documentation string format.The documentation string for the
spin
parameter has been simplified from multi-line to single-line format, which is appropriate for this short description.dpgen2/exploration/deviation/deviation_manager.py (3)
22-24
: Good addition of magnetic force deviation metrics.These new class constants for magnetic force deviation (MF) align with the PR objective to include magnetic force as a judgment index. They follow the same naming pattern as existing constants.
38-40
: Proper validation for new metrics.The new magnetic force deviation constants are correctly added to the validation check in
_check_name
method.
73-75
: Updated documentation to include new metrics.The docstring for the
get
method is appropriately updated to include the new magnetic force deviation metrics in the list of valid deviation names.dpgen2/entrypoint/args.py (2)
215-215
: Clear documentation for new parameter.The documentation string clearly explains the purpose of the new
lammps_input_file
parameter, indicating it will be passed to dpdata to parse LAMMPS dump files in spin jobs.
263-265
: Well-implemented parameter addition.The new parameter is correctly implemented as an optional string argument with proper documentation. This addition aligns with the PR objective to add a LAMMPS input file option to support reading spin information.
dpgen2/exploration/deviation/deviation_std.py (1)
68-70
: Good addition of magnetic force deviation constants.The addition of these three constants (MAX_DEVI_MF, MIN_DEVI_MF, AVG_DEVI_MF) to the model_devi_names tuple properly extends the validation checks to support magnetic force deviations in the DeviManagerStd class.
dpgen2/exploration/report/report_trust_levels_max.py (2)
112-115
: Good addition of magnetic force links.The addition of level_mf_hi_link and level_mf_lo_link variables correctly follows the existing pattern for creating documentation links.
117-117
: Documentation properly updated to include magnetic force model deviation.The return statement has been appropriately extended to include references to magnetic force model deviation thresholds, which aligns with the PR objective of including magnetic force as a judgment index.
tests/op/test_run_dp_train.py (3)
90-102
: Good addition of spin configuration.The spin configuration is correctly defined with appropriate parameters, including the essential
init_model_start_pref_fm
parameter required for magnetic force loss calculation.
181-209
: Well-structured expected output dictionary for spin models.The expected output dictionary for spin models is correctly structured with appropriate loss parameters including
start_pref_fr
andstart_pref_fm
instead of juststart_pref_f
.
590-653
: Good implementation of spin model test.The test method properly validates the spin training configuration by:
- Setting up a test with spin-specific parameters
- Verifying proper script generation with magnetic force loss parameters
- Confirming correct model initialization with the expected parameters
This test appropriately covers the PR objective of supporting spin in the training configuration.
tests/exploration/test_report_trust_levels.py (1)
39-41
: Good addition of magnetic force tests.The new test methods are properly added to the existing test suite, ensuring that both random and max selection strategies are tested with magnetic force deviation.
dpgen2/exploration/task/make_task_group_from_config.py (1)
25-27
: Skip the false positive about 'unused import'Although the static analysis hints at removing
LmpTemplateTaskGroup
, it is indeed referenced within this file (e.g., for"lmp-template"
), so please retain it.dpgen2/entrypoint/submit.py (1)
85-85
: Newly introducedLmpSpinTaskGroup
looks goodThis addition is used by
"lmp-spin"
in the downstream logic and appears functionally consistent.🧰 Tools
🪛 Ruff (0.8.2)
85-85:
dpgen2.exploration.task.LmpTemplateTaskGroup
imported but unusedRemove unused import
(F401)
tests/exploration/test_devi_manager.py (4)
34-35
: Confirmed test coverage forMIN_DEVI_MF
These new lines accurately verify that
MIN_DEVI_MF
defaults to[None, None]
, matching expected behavior.
40-41
: Post-clear behavior confirmedVerifying that the list is empty after
clear()
is a solid addition to ensure reliability.
77-77
: Extended coverage withMAX_DEVI_MF
Adding this extra assertion broadens test coverage for the new deviation metric.
88-93
: Assertion checks for mismatch scenariosThese additional checks help validate error conditions when
model_devi.get
is called with incorrect frames, improving robustness.dpgen2/exploration/render/traj_render_lammps.py (3)
82-86
: Looks good for managing MF columns.The conditional check for
dd.shape[1] >= 10
properly guards against out-of-bounds access when adding magnetic force deviations tomodel_devi
.
130-134
: Good handling of the optional input file.Writing the LAMMPS input data to
"lammps_input.in"
whenself.lammps_input
is notNone
aligns well with the newly introducedlammps_input_file
logic. No concerns here.
141-142
: Clear inline documentation for spin usage.The inline comment and updated instantiation of
dpdata.System
withinput_file=lammps_input_file
illustrate how the spin data is processed. This is consistent with the new spin job requirements.tests/exploration/test_lmp_spin_task_group.py (1)
1-220
: Overall test coverage looks solid for spin tasks.This new test suite thoroughly checks the spin template generation and revision logic, helping ensure correctness for different revision parameters and configurations.
🧰 Tools
🪛 Ruff (0.8.2)
9-9:
typing.List
imported but unusedRemove unused import
(F401)
10-10:
typing.Set
imported but unusedRemove unused import
(F401)
13-13:
numpy
imported but unusedRemove unused import:
numpy
(F401)
15-21: Use
contextlib.suppress(ModuleNotFoundError)
instead oftry
-except
-pass
(SIM105)
17-17:
exploration.context.dpgen2
imported but unused; consider usingimportlib.util.find_spec
to test for availability(F401)
23-23:
unittest.mock.Mock
imported but unusedRemove unused import
(F401)
24-24:
unittest.mock.patch
imported but unusedRemove unused import
(F401)
30-30:
dpgen2.constants.plm_input_name
imported but unusedRemove unused import:
dpgen2.constants.plm_input_name
(F401)
33-33:
dpgen2.exploration.task.ExplorationStage
imported but unusedRemove unused import:
dpgen2.exploration.task.ExplorationStage
(F401)
193-193: Use
enumerate()
for index variableidx
infor
loop(SIM113)
218-218: Use
enumerate()
for index variableidx
infor
loop(SIM113)
tests/exploration/test_report_adaptive_lower.py (2)
299-368
: Comprehensive test for MF deviation handling.The
test_mf
method thoroughly verifies how magnetic force deviations are recorded, with sensible checks for candidate, accurate, and failed sets. The convergence logic is also well-covered.
369-439
: Good addition of combined V + MF tests.Testing both virial and magnetic force deviation paths in
test_v_mf
ensures consistent coverage for multi-deviation scenarios, reflecting real usage patterns.dpgen2/exploration/report/report_adaptive_lower.py (7)
30-31
: Well-documented MF parameters.Your docstring expansions and parameter definitions for
level_mf_hi
,numb_candi_mf
, andrate_candi_mf
are clear, ensuring users understand how magnetic force fits into the adaptive-lower logic.Also applies to: 35-41, 64-71
90-90
: Initialization logic for MF is consistent.Setting
has_mf
and defaulting to maximum float values if MF is not provided mirrors the existing pattern for virial. This maintains internal consistency.Also applies to: 93-95, 102-102, 114-118
128-129
: Extended printing format for MF.Appending
mf_lo
andmf_hi
to the print tuple and spacing arrays is consistent with how forces and virials are handled.Also applies to: 148-154
268-268
: Appropriate references to MF in record method.Including MF in the arrays and adding the new column from
DeviManager.MAX_DEVI_MF
ensures that the final candidate sets properly account for MF.Also applies to: 272-272, 278-278, 281-283, 286-286
308-308
: Clear handling of MF candidates and trust levels.Adjusting
level_mf_lo
and the logic fornumb_candi_mf
parallels force/virial blocks. It's good to see consistent checks for empty sets.Also applies to: 313-315, 323-329, 339-344
345-356
: Properly flags frames exceeding MF thresholds.The
_record_one_traj
method integrates MF checks alongside force and virial, systematically marking frames as failed if any exceed the high threshold.Also applies to: 357-364
425-429
: MF convergence logic is correctly integrated.Including
level_mf_lo
in the_sequence_conv
method ensures that the magnetic force trust levels also factor into the ultimate convergence determination.Also applies to: 442-446
dpgen2/exploration/report/report_trust_levels_base.py (11)
34-35
: Good implementation of magnetic force level parametersThe addition of magnetic force level parameters (
level_mf_lo
andlevel_mf_hi
) is well-implemented, with proper initialization and a flag to track if both parameters are set. This aligns with the PR objective to include magnetic force as a judgment index.Also applies to: 42-43, 47-47
67-72
: Clean extension of the print formatThe conditional logic for including magnetic force levels in the output follows the same pattern as for virial levels, maintaining code consistency.
89-114
: Well-documented parameter additionsThe new magnetic force level parameters are properly documented with clear descriptions and follow the same pattern as existing parameters. The formatting of the argument declarations is consistent with the project style.
141-141
: Proper integration of magnetic force deviation dataThe magnetic force model deviation data is correctly retrieved and processed using the same pattern as force and virial deviations, ensuring consistent handling across all deviation types.
Also applies to: 150-152
160-162
: Consistent parameter updatesThe additional parameters for the
_record_one_traj
method call correctly pass the magnetic force indexes, maintaining compatibility with the updated method signature.
207-209
: Method signature properly extendedThe
_record_one_traj
method signature has been updated to include parameters for magnetic force indexes, following the same pattern as existing parameters.
220-223
: Good error checking for magnetic force dataThe implementation correctly handles the case when magnetic force data is not available, following the same pattern as for virial data.
229-233
: Thorough validation of frame countsThe validation of frame counts for magnetic force data ensures data consistency, mirroring the existing validation for virial data.
242-244
: Consistent set operations for magnetic forceThe set operations for magnetic force follow the same pattern as for force and virial, maintaining code consistency.
256-258
: Clean integration of magnetic force in set operationsThe set operations to determine accurate, failed, and candidate frames now correctly incorporate magnetic force data alongside force and virial data, ensuring comprehensive evaluation.
🧰 Tools
🪛 Ruff (0.8.2)
256-256: Yoda condition detected
Rewrite as
len(accu & fail) == 0
(SIM300)
257-257: Yoda condition detected
Rewrite as
len(cand & fail) == 0
(SIM300)
329-334
: Consistent output formattingThe conditional inclusion of magnetic force levels in the printed output follows the same pattern as for virial levels, maintaining formatting consistency.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #286 +/- ##
==========================================
+ Coverage 84.32% 84.37% +0.04%
==========================================
Files 104 105 +1
Lines 6030 6195 +165
==========================================
+ Hits 5085 5227 +142
- Misses 945 968 +23 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
let me remove the UT under py3.7 |
see #287. please merge with master. |
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.
Could you also please provide example input script and update the doc accordingly?
@@ -74,6 +79,11 @@ def _load_one_model_devi(self, fname, model_devi): | |||
model_devi.add(DeviManager.MAX_DEVI_F, dd[:, 4]) # type: ignore | |||
model_devi.add(DeviManager.MIN_DEVI_F, dd[:, 5]) # type: ignore | |||
model_devi.add(DeviManager.AVG_DEVI_F, dd[:, 6]) # type: ignore | |||
# assume the 7-9 columns are for MF | |||
if dd.shape[1] >= 10: # type: ignore |
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.
It seems to be better to judge from the lammps input if the spin model deviation is expected to be output or not.
you may implement a method like self.has_spin(self.lammps_input)
.
If the input implies spin model deviation output, then the shape[1]
of dd
must be 9 otherwise must be 6.
if self.lammps_input is not None: | ||
lammps_input_file = "lammps_input.in" | ||
Path(lammps_input_file).write_text(self.lammps_input) |
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.
What is the purpose of dumping the lammps input script?
set_f_accu = set(id_f_accu) | ||
set_f_cand = set(id_f_cand) | ||
set_f_fail = set(id_f_fail) | ||
set_v_accu = set([ii for ii in range(nframes)]) if novirial else set(id_v_accu) | ||
set_v_accu = set_full if novirial else set(id_v_accu) |
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.
dangerous to assign set_full
to set_v_acc
, as set_v_acc
will be a reference to set_full
, which would introduce some unexpected behavior. see the following code
set_full = set([1,2,3])
set_v = set_full
set_mf = set_full
set_v.add(4)
print(set_mf)
The code gives
{1, 2, 3, 4}
) | ||
|
||
|
||
class LmpSpinTaskGroup(ConfSamplingTaskGroup): |
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.
It seems that this task group generate lammps spin md tasks from templates.
I would recommend naming it as, e.g. LmpSpinTemplateTaskGroup
, and use input name like "lmp-spin-template"
self.lmp_template = Path(lmp_template_fname).read_text().split("\n") | ||
self.revisions = revisions | ||
self.lmp_set = True | ||
self.model_list = sorted([model_name_pattern % ii for ii in range(numb_models)]) |
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.
What's the difference between a spin task group and a normal template task group? It seems that the spin task group does not revise input models in the template.
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.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
dpgen2/entrypoint/submit.py
(3 hunks)dpgen2/op/run_dp_train.py
(3 hunks)tests/op/test_run_dp_train.py
(3 hunks)
🧰 Additional context used
🪛 Ruff (0.11.9)
dpgen2/entrypoint/submit.py
84-84: dpgen2.exploration.task.LmpSpinTaskGroup
imported but unused
Remove unused import
(F401)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: build (3.10)
- GitHub Check: build (3.9)
- GitHub Check: build (3.8)
🔇 Additional comments (10)
dpgen2/op/run_dp_train.py (4)
427-433
: Implementation correctly handles force prefactors for spin jobs.The conditional block adds specific handling for spin jobs by using different parameter keys in the loss dictionary. For spin jobs, it uses "start_pref_fr" and "start_pref_fm" instead of "start_pref_f", allowing separate prefactors for regular and magnetic forces.
437-441
: Consistent implementation for non-nested loss dictionary.The same conditional logic for spin jobs is correctly implemented in the case of a non-nested loss dictionary, ensuring consistent behavior regardless of the loss dictionary structure.
530-534
: Clear documentation for the magnetic force prefactor parameter.The documentation string clearly explains that this parameter is specific to spin jobs, which helps users understand its purpose and usage context.
604-617
: Well-defined new spin-related arguments.The implementation adds two new arguments to support spin jobs:
init_model_start_pref_fm
: Default value of 100 for the magnetic force prefactorspin
: Boolean flag to indicate if the job is a spin jobBoth arguments have appropriate types, defaults, and clear documentation.
dpgen2/entrypoint/submit.py (2)
322-324
: Improved constructor formatting with explicit lammps_input_file parameter.The
TrajRenderLammps
constructor has been reformatted for better readability and now explicitly includes thelammps_input_file
parameter from the configuration.
384-388
: Consistent parameter passing across different exploration scheduler functions.Similar to the previous change, the
TrajRenderLammps
constructor in this function is also reformatted to explicitly include thelammps_input_file
parameter, ensuring consistent parameter handling across different exploration scheduler functions.tests/op/test_run_dp_train.py (4)
92-102
: Appropriate spin configuration for testing.A new
config_spin
dictionary is defined with appropriate parameters for testing spin jobs, including:
"spin": True
to enable spin mode- All standard parameters from the regular config
- The new magnetic force prefactor parameter
"init_model_start_pref_fm": 100
184-211
: Well-defined expected output for spin jobs.The
expected_init_model_odict_v2_spin
dictionary correctly defines the expected output for spin jobs, using"start_pref_fr"
and"start_pref_fm"
instead of"start_pref_f"
in the loss section, which properly tests the spin-specific parameter handling.
602-607
: Good test preparation for spin-specific loss parameters.The test setup creates a modified input dictionary with the appropriate spin-specific loss parameters (
start_pref_fr
andstart_pref_fm
), ensuring the test accurately represents real-world usage.
592-660
: Comprehensive test for spin job initialization.The
test_exec_v2_init_model_spin
method thoroughly tests the spin job functionality by:
- Setting up appropriate spin configuration with init_model_policy = "yes"
- Verifying correct command calls with --init-frz-model flag
- Validating output file existence and log content
- Confirming that the generated training script contains the expected spin-specific parameters
This ensures that the spin job implementation works correctly with model initialization.
@@ -81,6 +81,7 @@ | |||
CustomizedLmpTemplateTaskGroup, | |||
ExplorationStage, | |||
ExplorationTask, | |||
LmpSpinTaskGroup, |
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.
Unused import detected.
The LmpSpinTaskGroup
import is not used within this file according to static analysis.
Consider removing this import if it's not needed or add a comment explaining why it's included for future reference.
- LmpSpinTaskGroup,
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
LmpSpinTaskGroup, |
🧰 Tools
🪛 Ruff (0.11.9)
84-84: dpgen2.exploration.task.LmpSpinTaskGroup
imported but unused
Remove unused import
(F401)
🤖 Prompt for AI Agents
In dpgen2/entrypoint/submit.py at line 84, the import LmpSpinTaskGroup is not
used anywhere in the file. Remove this import statement to clean up the code
unless there is a specific reason to keep it, in which case add a comment
explaining its purpose for future maintainers.
) | ||
with open(out["script"]) as fp: | ||
jdata = json.load(fp) | ||
print(jdata) |
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.
Remove debug print statement.
There's a debug print statement that should be removed before merging.
- print(jdata)
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
print(jdata) |
🤖 Prompt for AI Agents
In tests/op/test_run_dp_train.py at line 658, there is a debug print statement
printing jdata. Remove this print statement to clean up the code before merging.
Support the spin job:
For a spin job, most of the contents of the submit config file are same as a normal job, except for:
A lammps template file may be like:
Need replace "SEED" to a random number, the command may be like:"a=$RANDOM && sed -i "s/SEED/$a/g" in.lammps"
Summary by CodeRabbit
Summary by CodeRabbit
New Features
Documentation