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

use P as control variable in Gibbs free energy for hti #74

Merged
merged 11 commits into from
Aug 6, 2024

Conversation

Yi-FanLi
Copy link
Collaborator

@Yi-FanLi Yi-FanLi commented Aug 6, 2024

The same as #41 but for hti.py and hti_liq.py.

Summary by CodeRabbit

  • New Features

    • Introduced an optional npt parameter for the compute_task function, allowing users to utilize external pressure-volume data from an NPT simulation directory.
    • Updated command-line argument parser to include a new --npt option for enhanced flexibility in data sourcing.
  • User Experience Enhancements

    • Improved transparency by adding print statements to inform users about the source of pressure-volume values used in calculations.

Copy link

coderabbitai bot commented Aug 6, 2024

Warning

Rate limit exceeded

@Yi-FanLi has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 16 minutes and 51 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between f64d7f3 and 4f0fb49.

Walkthrough

Walkthrough

The recent updates enhance the compute_task functions in both dpti/hti.py and dpti/hti_liq.py by introducing a new optional parameter, npt. This addition allows the integration of pressure-volume (PV) data from external NPT simulation directories, improving the accuracy of Helmholtz and Gibbs free energy calculations. The command-line interface has been updated to include this functionality, enhancing usability and flexibility for users.

Changes

Files Change Summary
dpti/hti.py, dpti/hti_liq.py Introduced npt parameter in compute_task functions to utilize external PV data. Updated command-line argument parser to include --npt option, allowing users to specify the directory for NPT data. Adjusted internal logic to prioritize npt data for calculations, ensuring backward compatibility. Added print statements for transparency regarding the sources of PV data.

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

@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

Outside diff range, codebase verification and nitpick comments (8)
dpti/hti_liq.py (4)

480-480: Add a docstring for the new parameter.

The npt parameter should be documented in the function's docstring for clarity.

def compute_task(job, free_energy_type="helmholtz", scheme="simpson", manual_pv=None, manual_pv_err=None, npt=None):
    """
    Compute the thermodynamic properties of a job.

    Parameters:
    job (str): The job directory.
    free_energy_type (str): The type of free energy to compute ('helmholtz' or 'gibbs').
    scheme (str): The numerical integration scheme.
    manual_pv (float, optional): Manual pressure-volume value.
    manual_pv_err (float, optional): Manual pressure-volume error.
    npt (str, optional): Directory of the NPT task; will use PV from NPT result, where P is the control variable and V varies.
    """

523-523: Improve logging for manual PV usage.

The print statement for manual_pv should provide more context to the user.

-            print(f"# use manual_pv={manual_pv}")
+            print(f"# Using manual PV value: manual_pv={manual_pv}")

528-528: Improve logging for manual PV error usage.

The print statement for manual_pv_err should provide more context to the user.

-            print(f"# use manual_pv_err={manual_pv_err}")
+            print(f"# Using manual PV error value: manual_pv_err={manual_pv_err}")

658-658: Add a docstring for the new parameter.

The npt parameter should be documented in the function's docstring for clarity.

def handle_compute(args):
    """
    Handle the compute command.

    Parameters:
    args: Command-line arguments.
    """
dpti/hti.py (4)

1260-1260: Add a docstring for the new parameter.

The npt parameter should be documented in the function's docstring for clarity.

def compute_task(job, free_energy_type="helmholtz", method="inte", scheme="simpson", manual_pv=None, manual_pv_err=None, npt=None):
    """
    Compute the thermodynamic properties of a job.

    Parameters:
    job (str): The job directory.
    free_energy_type (str): The type of free energy to compute ('helmholtz' or 'gibbs').
    method (str): The method of thermodynamic integration.
    scheme (str): The numerical integration scheme.
    manual_pv (float, optional): Manual pressure-volume value.
    manual_pv_err (float, optional): Manual pressure-volume error.
    npt (str, optional): Directory of the NPT task; will use PV from NPT result, where P is the control variable and V varies.
    """

1309-1309: Improve logging for manual PV usage.

The print statement for manual_pv should provide more context to the user.

-            print(f"# use manual_pv={manual_pv}")
+            print(f"# Using manual PV value: manual_pv={manual_pv}")

1314-1314: Improve logging for manual PV error usage.

The print statement for manual_pv_err should provide more context to the user.

-            print(f"# use manual_pv_err={manual_pv_err}")
+            print(f"# Using manual PV error value: manual_pv_err={manual_pv_err}")

1530-1530: Add a docstring for the new parameter.

The npt parameter should be documented in the function's docstring for clarity.

def handle_compute(args):
    """
    Handle the compute command.

    Parameters:
    args: Command-line arguments.
    """

dpti/hti_liq.py Outdated
Comment on lines 510 to 519
if npt is not None:
npt_in = json.load(open(os.path.join(npt, "jdata.json")))
npt_info = json.load(open(os.path.join(npt, "result.json")))
p = npt_in["pres"]
v = npt_info["v"]
v_err = npt_info["v_err"]
unit_cvt = 1e5 * (1e-10**3) / pc.electron_volt
pv = p * v * unit_cvt * 3
pv_err = p * v_err * unit_cvt * np.sqrt(3)
print(f"# use pv from npt task: pv = {pv:.6e} pv_err = {pv_err:.6e}")
Copy link

Choose a reason for hiding this comment

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

Ensure error handling for file operations.

The code assumes that the jdata.json and result.json files exist in the npt directory. Add error handling to manage cases where these files are missing or unreadable.

-        if npt is not None:
-            npt_in = json.load(open(os.path.join(npt, "jdata.json")))
-            npt_info = json.load(open(os.path.join(npt, "result.json")))
+        if npt is not None:
+            try:
+                npt_in = json.load(open(os.path.join(npt, "jdata.json")))
+                npt_info = json.load(open(os.path.join(npt, "result.json")))
+            except (FileNotFoundError, json.JSONDecodeError) as e:
+                raise RuntimeError(f"Error loading NPT data: {e}")

Committable suggestion was skipped due to low confidence.

dpti/hti.py Outdated
Comment on lines 1297 to 1306
if npt is not None:
npt_in = json.load(open(os.path.join(npt, "jdata.json")))
npt_info = json.load(open(os.path.join(npt, "result.json")))
p = npt_in["pres"]
v = npt_info["v"]
v_err = npt_info["v_err"]
unit_cvt = 1e5 * (1e-10**3) / pc.electron_volt
pv = p * v * unit_cvt * 3
pv_err = p * v_err * unit_cvt * np.sqrt(3)
print(f"# use pv from npt task: pv = {pv:.6e} pv_err = {pv_err:.6e}")
Copy link

Choose a reason for hiding this comment

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

Ensure error handling for file operations.

The code assumes that the jdata.json and result.json files exist in the npt directory. Add error handling to manage cases where these files are missing or unreadable.

-        if npt is not None:
-            npt_in = json.load(open(os.path.join(npt, "jdata.json")))
-            npt_info = json.load(open(os.path.join(npt, "result.json")))
+        if npt is not None:
+            try:
+                npt_in = json.load(open(os.path.join(npt, "jdata.json")))
+                npt_info = json.load(open(os.path.join(npt, "result.json")))
+            except (FileNotFoundError, json.JSONDecodeError) as e:
+                raise RuntimeError(f"Error loading NPT data: {e}")
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 npt is not None:
npt_in = json.load(open(os.path.join(npt, "jdata.json")))
npt_info = json.load(open(os.path.join(npt, "result.json")))
p = npt_in["pres"]
v = npt_info["v"]
v_err = npt_info["v_err"]
unit_cvt = 1e5 * (1e-10**3) / pc.electron_volt
pv = p * v * unit_cvt * 3
pv_err = p * v_err * unit_cvt * np.sqrt(3)
print(f"# use pv from npt task: pv = {pv:.6e} pv_err = {pv_err:.6e}")
if npt is not None:
try:
npt_in = json.load(open(os.path.join(npt, "jdata.json")))
npt_info = json.load(open(os.path.join(npt, "result.json")))
except (FileNotFoundError, json.JSONDecodeError) as e:
raise RuntimeError(f"Error loading NPT data: {e}")
p = npt_in["pres"]
v = npt_info["v"]
v_err = npt_info["v_err"]
unit_cvt = 1e5 * (1e-10**3) / pc.electron_volt
pv = p * v * unit_cvt * 3
pv_err = p * v_err * unit_cvt * np.sqrt(3)
print(f"# use pv from npt task: pv = {pv:.6e} pv_err = {pv_err:.6e}")

Copy link

codecov bot commented Aug 6, 2024

Codecov Report

Attention: Patch coverage is 0% with 38 lines in your changes missing coverage. Please review.

Project coverage is 0.00%. Comparing base (1d7b742) to head (4f0fb49).

Files Patch % Lines
dpti/hti_liq.py 0.00% 23 Missing ⚠️
dpti/hti.py 0.00% 15 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##           devel     #74   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files         24      24           
  Lines       5829    5862   +33     
=====================================
- Misses      5829    5862   +33     

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

@Yi-FanLi Yi-FanLi merged commit 66b9b3b into deepmodeling:devel Aug 6, 2024
8 checks passed
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.

1 participant