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

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

Open
wants to merge 5 commits into
base: devel
Choose a base branch
from

Conversation

dulinhan
Copy link

@dulinhan dulinhan commented May 28, 2024

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.

Copy link

coderabbitai bot commented May 28, 2024

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

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4214d77 and 01581e9.

Files selected for processing (1)
  • dpgen/generator/run.py (1 hunks)
Additional comments not posted (4)
dpgen/generator/run.py (4)

4500-4500: Initialize log_file_path before usage

The log_file_path is initialized correctly to store paths for logging SCF failures.


4501-4502: Proper Initialization of all_sys

The all_sys object is correctly instantiated as dpdata.MultiSystems with the type map from jdata.


4503-4504: Correctly reading file content

The file content is read correctly for checking SCF convergence.


4508-4511: Appending to all_sys and incrementing icount

Appending the system and incrementing icount is correctly placed after ensuring SCF convergence.


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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

@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: 2

dpgen/generator/run.py Outdated Show resolved Hide resolved
dpgen/generator/run.py Outdated Show resolved Hide resolved
@njzjz njzjz requested a review from robinzyb May 28, 2024 17:41
Copy link

codecov bot commented Jun 7, 2024

Codecov Report

Attention: Patch coverage is 62.50000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 49.60%. Comparing base (30bc1e5) to head (01581e9).

Files Patch % Lines
dpgen/generator/run.py 62.50% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            devel    #1562   +/-   ##
=======================================
  Coverage   49.59%   49.60%           
=======================================
  Files          83       83           
  Lines       14844    14852    +8     
=======================================
+ Hits         7362     7367    +5     
- Misses       7482     7485    +3     

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

@njzjz njzjz closed this Jul 2, 2024
@njzjz njzjz reopened this Jul 2, 2024
for oo in sys_output:
_sys = dpdata.LabeledSystem(oo, fmt="cp2k/output")
Copy link
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

all_sys.append(_sys)
with open(oo, 'r') as file:
content = file.read()
if 'SCF run NOT converged' in content:
Copy link
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
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 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
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

Copy link

@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: 2

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

icount += len(all_sys)
Copy link

Choose a reason for hiding this comment

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

Duplicate icount increment

icount is incremented twice. Remove the duplicate increment.

-        icount += len(all_sys)

Committable suggestion was skipped due to low confidence.

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants