Skip to content

Modify post_fp_cp2k, adapt to SCF not converged situation. - #1562

Open
dulinhan wants to merge 6 commits into
deepmodeling:masterfrom
dulinhan:modify_post_fp_cp2k
Open

Modify post_fp_cp2k, adapt to SCF not converged situation.#1562
dulinhan wants to merge 6 commits into
deepmodeling:masterfrom
dulinhan:modify_post_fp_cp2k

Conversation

@dulinhan

@dulinhan dulinhan commented May 28, 2024

Copy link
Copy Markdown
Contributor

Check whether "SCF run NOT converged" appears before reading the output file. Print the path of unfinished calculation to the log file. Make the icount counter work effectively

Summary by CodeRabbit

  • New Features
    • Added logging to track output files with SCF convergence issues.
    • Enhanced error handling to skip files with specific error messages.
    • Updated the system count to reflect all processed systems more accurately.

@coderabbitai

coderabbitai Bot commented May 28, 2024

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 37 minutes.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c7f00b27-e6b8-4009-a3a9-89875dc1be03

📥 Commits

Reviewing files that changed from the base of the PR and between 01581e9 and e3e6094.

📒 Files selected for processing (1)
  • dpgen/generator/run.py
📝 Walkthrough

Walkthrough

The changes to the post_fp_cp2k function in run.py enhance error handling and logging. Specifically, the function now checks for SCF convergence issues in output files, logs any occurrences, and skips the affected files. Moreover, the system count is updated based on the processed systems. These updates ensure robust handling of non-converged SCF runs, improving the reliability of the function.

Changes

File Change Summary
dpgen/generator/run.py Enhanced post_fp_cp2k to handle SCF convergence issues by logging and skipping non-converged files, and updated system processing logic to count processed systems accurately.

Sequence Diagram(s)

Old Flow

sequenceDiagram
    participant Client
    participant post_fp_cp2k
    Client->>+post_fp_cp2k: Call function with iter_index, jdata, rfailed
    post_fp_cp2k->>post_fp_cp2k: Initialize all_sys
    loop sys_output
        post_fp_cp2k->>post_fp_cp2k: Process system
    end
    post_fp_cp2k->>-Client: Return result
Loading

New Flow

sequenceDiagram
    participant Client
    participant post_fp_cp2k
    participant LogFile
    
    Client->>+post_fp_cp2k: Call function with iter_index, jdata, rfailed
    post_fp_cp2k->>post_fp_cp2k: Initialize all_sys
    loop sys_output
        post_fp_cp2k->>post_fp_cp2k: Read file content
        alt SCF run NOT converged
            post_fp_cp2k->>LogFile: Write log entry
            post_fp_cp2k->>post_fp_cp2k: Skip file
        else
            post_fp_cp2k->>post_fp_cp2k: Process system
            post_fp_cp2k->>post_fp_cp2k: Append system to all_sys
            post_fp_cp2k->>post_fp_cp2k: Increment count
        end
    end
    post_fp_cp2k->>-Client: Return result
Loading

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Comment thread dpgen/generator/run.py Outdated
Comment thread dpgen/generator/run.py Outdated
@njzjz
njzjz requested a review from robinzyb May 28, 2024 17:41
@codecov

codecov Bot commented Jun 7, 2024

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 49.81%. Comparing base (30bc1e5) to head (e3e6094).
⚠️ Report is 144 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1562      +/-   ##
==========================================
+ Coverage   49.59%   49.81%   +0.22%     
==========================================
  Files          83       83              
  Lines       14844    14993     +149     
==========================================
+ Hits         7362     7469     +107     
- Misses       7482     7524      +42     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@njzjz njzjz closed this Jul 2, 2024
@njzjz njzjz reopened this Jul 2, 2024
Comment thread dpgen/generator/run.py Outdated
log_file_path = os.path.join(work_path, f"{ss}.fp-fail.log")
all_sys = dpdata.MultiSystems(type_map=jdata["type_map"])
for oo in sys_output:
_sys = dpdata.LabeledSystem(oo, fmt="cp2k/output")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why does this fmt revert back?

dpgen/dpgen/generator/run.py

Lines 4483 to 4489 in 54e48c6

for oo in sys_output:
_sys = dpdata.LabeledSystem(
oo, fmt="cp2kdata/e_f", type_map=jdata["type_map"]
)
all_sys.append(_sys)
icount += 1

Comment thread dpgen/generator/run.py Outdated
all_sys.append(_sys)
with open(oo, 'r') as file:
content = file.read()
if 'SCF run NOT converged' in content:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

cp2kdata already checks the convergence.
if the scf is not converged, dpdata will return empty object.
https://github.com/robinzyb/cp2kdata/blob/d74c14cbf7470451af443c706d8479c8b486a68d/cp2kdata/dpdata_plugin.py#L24-L43

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, it will. But when using MultiSystems, the empty object will be added into that, for example create an empty "C0H0O0". This will raise error when save the MultiSystems to data.xxx. Maybe we should change the subroutine which you mentioned to skip instead of creating empty object.

Comment thread dpgen/generator/run.py
Comment on lines +4475 to +4480
with open(oo) as file:
content = file.read()
if "SCF run NOT converged" in content:
with open(log_file_path, "a") as log_file:
log_file.write(f"Skipping file {oo} due to SCF run NOT converged\n")
continue

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

move these lines after _sys=dpdata.LabeledSystem

Suggested change
with open(oo) as file:
content = file.read()
if "SCF run NOT converged" in content:
with open(log_file_path, "a") as log_file:
log_file.write(f"Skipping file {oo} due to SCF run NOT converged\n")
continue
if len(_sys) == 0:
with open(log_file_path, "a") as log_file:
log_file.write(f"Skipping file {oo} due to SCF run NOT converged\n")
continue

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Comment thread dpgen/generator/run.py Outdated
Comment thread dpgen/generator/run.py
Comment on lines +4505 to +4508
if "SCF run NOT converged" in content:
with open(log_file_path, "a") as log_file:
log_file.write(f"Skipping file {oo} due to SCF run NOT converged\n")
continue

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Move SCF check and logging after _sys instantiation

To ensure _sys is only instantiated if SCF converges, move these lines after _sys=dpdata.LabeledSystem.

-            if "SCF run NOT converged" in content:
-                with open(log_file_path, "a") as log_file:
-                    log_file.write(f"Skipping file {oo} due to SCF run NOT converged\n")
-                continue
            _sys = dpdata.LabeledSystem(
                oo, fmt="cp2kdata/e_f", type_map=jdata["type_map"]
            )
+            if "SCF run NOT converged" in content:
+                with open(log_file_path, "a") as log_file:
+                    log_file.write(f"Skipping file {oo} due to SCF run NOT converged\n")
+                continue
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.

Suggested change
if "SCF run NOT converged" in content:
with open(log_file_path, "a") as log_file:
log_file.write(f"Skipping file {oo} due to SCF run NOT converged\n")
continue
_sys = dpdata.LabeledSystem(
oo, fmt="cp2kdata/e_f", type_map=jdata["type_map"]
)
if "SCF run NOT converged" in content:
with open(log_file_path, "a") as log_file:
log_file.write(f"Skipping file {oo} due to SCF run NOT converged\n")
continue

@njzjz-bot njzjz-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Verdict: Changes requested. Successful tasks are counted twice, which can make the failure ratio negative and bypass ratio_failed. Matching one SCF message is also insufficient to establish that dpdata parsed a valid frame. Current master already has a more reliable empty-LabeledSystem check; a smaller logging-only PR should be based on that implementation.

Note: The Codex quota is about to reset, so I am using the remaining tokens to review all open PRs in this repository.

Coding agent: Codex
Codex version: codex-cli 0.144.6
Model: gpt-5.6-sol
Reasoning effort: xhigh

Comment thread dpgen/generator/run.py Outdated
all_sys.append(_sys)
icount += 1

icount += len(all_sys)

@njzjz-bot njzjz-bot Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Blocking] icount is already incremented once for each successful output in the inner loop, and this line adds len(all_sys) again, counting every successful task twice. For example, six successes out of ten tasks produce icount=12 and a failure ratio of -20%, bypassing ratio_failed. Remove this increment and append/count only when len(_sys) > 0. Other parse failures can also produce an empty LabeledSystem, so checking only the literal SCF run NOT converged message is insufficient.

@njzjz-bot njzjz-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Independent review C

REQUEST_CHANGES. The new non-converged-output filtering is useful, but the success counter is incremented twice for every accepted CP2K result, corrupting the completion/failure accounting.

Coding agent: Codex
Codex version: codex-cli 0.151.0
Model: gpt-5.6-sol
Reasoning effort: xhigh

Comment thread dpgen/generator/run.py Outdated
all_sys.append(_sys)
icount += 1

icount += len(all_sys)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

icount is already incremented for every system appended to all_sys in the loop above. Adding len(all_sys) here double-counts every successful output, so the later icount / tcount accounting can exceed 1 or mask skipped/non-converged tasks. Remove this second increment.

Suggested change
icount += len(all_sys)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Fixed in e3e6094 by removing the second success increment; each converged CP2K output is now counted once. Validation: Python syntax compilation passed. The historical CP2K unittest cannot import in the current environment because modern dpdata no longer exposes the dpdata.abacus API required by this old branch.

Coding agent: Codex
Codex version: codex-cli 0.151.0
Model: gpt-5.6-sol
Reasoning effort: xhigh

@njzjz-bot njzjz-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Independent review B\n\nRequesting changes because successful CP2K results are counted twice, corrupting the failure-ratio calculation.\n\nCoding agent: Codex\nCodex version: codex-cli 0.151.0\nModel: gpt-5.6-sol\nReasoning effort: xhigh

Comment thread dpgen/generator/run.py Outdated
all_sys.append(_sys)
icount += 1

icount += len(all_sys)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Each converged output already increments icount at line 4513. Adding len(all_sys) again doubles every successful frame, which can make (tcount - icount) / tcount negative and suppress the configured failure threshold. Remove this second increment.\n\nsuggestion\n

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Fixed in e3e6094 by removing the second success increment; each converged CP2K output is now counted once. Validation: Python syntax compilation passed. The historical CP2K unittest cannot import in the current environment because modern dpdata no longer exposes the dpdata.abacus API required by this old branch.

Coding agent: Codex
Codex version: codex-cli 0.151.0
Model: gpt-5.6-sol
Reasoning effort: xhigh

@njzjz-bot njzjz-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Independent review A

Blocking finding attached inline. The new failure accounting double-counts successful CP2K results and can turn the reported failed fraction negative.

Coding agent: Codex
Codex version: codex-cli 0.151.0
Model: gpt-5.6-sol
Reasoning effort: xhigh

Comment thread dpgen/generator/run.py Outdated
all_sys.append(_sys)
icount += 1

icount += len(all_sys)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

P1: Remove this second success increment. icount is already incremented once for every parsed output inside the loop above; adding len(all_sys) again counts the same successful tasks a second time. With one converged output, for example, tcount == 1 and icount == 2, producing a negative failure ratio and disabling the intended failure threshold.

Suggested change
icount += len(all_sys)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Fixed in e3e6094 by removing the second success increment; each converged CP2K output is now counted once. Validation: Python syntax compilation passed. The historical CP2K unittest cannot import in the current environment because modern dpdata no longer exposes the dpdata.abacus API required by this old branch.

Coding agent: Codex
Codex version: codex-cli 0.151.0
Model: gpt-5.6-sol
Reasoning effort: xhigh

Coding-Agent: Codex
Codex-Version: codex-cli 0.151.0
Model: gpt-5.6-sol
Reasoning-Effort: xhigh

@njzjz-bot njzjz-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The CP2K success double-count was removed in e3e6094, so every converged output contributes exactly once. The branch is mergeable and its current checks pass.

Coding agent: Codex
Codex version: codex-cli 0.151.0
Model: gpt-5.6-sol
Reasoning effort: xhigh

@njzjz-bot njzjz-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Independent re-review C

No blocking issues found; converged CP2K outputs now increment the accepted-frame count exactly once.

Coding agent: Codex
Codex version: codex-cli 0.151.0
Model: gpt-5.6-sol
Reasoning effort: xhigh

@njzjz-bot njzjz-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Independent re-review B

Reviewed the current merge result against the maintained CP2K post-processing path. The added convergence guard skips explicitly non-converged outputs before parsing, logs the skipped path, and preserves the existing empty-system and failure-ratio accounting. I found no blocking issue and approve this head.

Coding agent: Codex
Codex version: codex-cli 0.151.0
Model: gpt-5.6-sol
Reasoning effort: xhigh

@njzjz-bot njzjz-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Independent re-review A

Approved at e3e6094. I checked the CP2K non-convergence detection, success/failure accounting, emitted datasets, and passing CI.

Coding agent: Codex
Codex version: codex-cli 0.151.0
Model: gpt-5.6-sol
Reasoning effort: xhigh

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.

4 participants