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

force elapsed time test to save restart after first advance #786

Merged
merged 1 commit into from
Dec 2, 2023

Conversation

PhilipDeegan
Copy link
Member

@PhilipDeegan PhilipDeegan commented Nov 26, 2023

passing on my fork PhilipDeegan#79

Summary by CodeRabbit

  • New Features

    • Added a search functionality to the app.
  • Chores

    • Streamlined simulation configuration for better project directory management.

Copy link

coderabbitai bot commented Nov 26, 2023

Walkthrough

Walkthrough

The changes involve updates to the configuration and testing of a simulation environment. The config.py file has been modified to dynamically set the project_root based on the file's location if a placeholder is detected. In test_restarts.py, the testing logic has been altered to adjust the simulation's restart behavior, including changes to the time step number, handling of refinement boxes, and directory management for restarts and diagnostics, with added error handling for missing refinement due to regridding.

Changes

File Change Summary
tests/simulator/config.py
tests/simulator/test_restarts.py
Added conditional check to redefine project_root if it matches a placeholder string, using the file's grandparent directory. Imported time and datetime, modified restart logic and directory settings, removed _find_restart_time function, and added error handling for missing refinement boxes.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

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.

Review Status

Actionable comments generated: 1

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 501fb3b and 34e1c70.
Files selected for processing (2)
  • tests/simulator/config.py (1 hunks)
  • tests/simulator/test_restarts.py (4 hunks)
Additional comments: 7
tests/simulator/test_restarts.py (7)
  • 3-7:
    The addition of time and datetime imports aligns with the changes in the test behavior.

  • 276-276:
    The change to time_step_nbr ensures that the simulation will restart after the first time step, as intended.

  • 281-282:
    The addition of a RuntimeError to handle the absence of a refinement box version is a good practice to alert about potential regridding issues.

  • 292-294:
    Setting restart_idx to 1 correctly indicates that the restart should happen after the first advancement.

  • 303-307:
    The seconds variable and elapsed_timestamps setup align with the intended test behavior to dump diagnostics on the first advance.

  • 320-321:
    Please verify the necessity of the time.sleep(2) call, as it introduces a delay in the test execution. If it's not essential for the test logic, consider removing it to keep the code efficient, in line with your preference for minimal code.

  • 328-328:
    The removal of elapsed_timestamps from simput["restart_options"] ensures that the second simulation behaves differently from the first, which is necessary for the test's logic.

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.

Review Status

Actionable comments generated: 2

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 501fb3b and 168ca86.
Files selected for processing (2)
  • tests/simulator/config.py (1 hunks)
  • tests/simulator/test_restarts.py (5 hunks)
Additional comments: 9
tests/simulator/test_restarts.py (9)
  • 3-4: The addition of time and datetime imports is appropriate for the new time-based features introduced in the tests.

  • 140-142: The early return based on cpp.mpi_rank() is a standard practice in MPI-based parallel computing to ensure that only the master rank or a specific rank performs the diagnostics check.

  • 284-285: The addition of a RuntimeError when "refinement" is not present in simput enforces stricter input requirements for the simulation tests, which is a good practice for ensuring that necessary configuration is provided.

  • 279-279: Updating simput["time_step_nbr"] to 2 is intended to force a restart after the first advance, which is a valid test case for the restart functionality.

  • 295-295: The update of restart_idx to 1 is consistent with the test's intention to check the restart functionality after a single time step.

  • 297-297: The timestamps list now contains only one element, which is consistent with the updated test case that checks for a single restart event.

  • 306-306: The update of the seconds value to 1 is likely related to the timing of the restart test, ensuring that the simulation dumps diagnostics on the first advance.

  • 310-311: The updates to simput["restart_options"]["dir"] and simput["diag_options"]["options"]["dir"] are necessary to reflect the new directory paths used in the tests.

  • 292-314: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [270-339]

The removal of the _find_restart_time function and related code indicates a simplification of the restart time determination logic, which is a positive change for maintainability.


time.sleep(seconds + 1)
time.sleep(5)
Copy link

Choose a reason for hiding this comment

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

The time.sleep(5) call has been reduced to time.sleep(2), which may still be necessary for the test setup. However, considering the user's preference for minimal and efficient code, it's worth verifying if this delay is essential or if it can be further optimized.

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.

Review Status

Actionable comments generated: 1

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 501fb3b and 40340d5.
Files selected for processing (2)
  • tests/simulator/config.py (1 hunks)
  • tests/simulator/test_restarts.py (5 hunks)
Additional comments: 1
tests/simulator/test_restarts.py (1)
  • 325-327: Given your preference for minimal and efficient code, please verify if the time.sleep(5) is essential or if it can be further optimized.

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.

Review Status

Actionable comments generated: 1

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 501fb3b and d6b9c92.
Files selected for processing (2)
  • tests/simulator/config.py (1 hunks)
  • tests/simulator/test_restarts.py (5 hunks)
Additional comments: 8
tests/simulator/config.py (2)
  • 3-7: The at variable is still present in the code, which contradicts the previous comments about it being removed. Consider inlining the placeholder string to align with the preference for minimal and efficient code.
- at = "@" # try to work without cmake config
- if project_root == f"{at}PHARE_PROJECT_DIR{at}":
+ if project_root == "@PHARE_PROJECT_DIR@":
  • 6-6: Verify that the Path class from pathlib is not used elsewhere in the file outside of this conditional block. If it is, consider moving the import to the top of the file.
tests/simulator/test_restarts.py (6)
  • 3-4: The addition of time and datetime imports aligns with the changes made to handle timestamps and restart behavior.

  • 140-142: The early return for non-zero MPI ranks has been removed from the check_diags function. Ensure that this change is intentional and does not affect parallel execution of tests.

  • 284-285: The addition of a RuntimeError when no refinement box is present due to regridding is a good practice for early failure and clear messaging.

  • 325-325: The time.sleep(5) call has been removed, which aligns with the preference for minimal and efficient code. Confirm that this removal does not affect the test's reliability.

  • 295-296: The change in restart_idx from 4 to 1 and seconds from 1 to 9 is consistent with the summary's mention of adjustments to restart behavior.

  • 279-279: The time_step_nbr has been changed from 2 to 10 in the test_restarts function. Verify that this change is intentional and aligns with the desired test behavior.


if project_root == f"{at}PHARE_PROJECT_DIR{at}":
from pathlib import Path
project_root = Path(__file__).resolve().parent.parent.parent
Copy link

Choose a reason for hiding this comment

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

Consider adding a check to verify that the new project_root path exists to prevent potential runtime errors.

if not project_root.exists():
    raise RuntimeError(f"The project root path '{project_root}' does not exist.")

@nicolasaunai nicolasaunai merged commit 2ae567b into PHAREHUB:master Dec 2, 2023
6 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.

2 participants