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

try fallback for dl on keyerror + ruffage #916

Merged
merged 1 commit into from
Oct 24, 2024

Conversation

PhilipDeegan
Copy link
Member

@PhilipDeegan PhilipDeegan commented Oct 24, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced error handling in the Simulator class for better exception management.
    • Improved structure and organization in the test files to streamline simulation runs.
  • Bug Fixes

    • Corrected syntax in the CMake configuration for the test-tdtagged project.

Copy link

coderabbitai bot commented Oct 24, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces several modifications across multiple files. In run.py, the Run class has been updated for better handling of the times parameter and improved error management in various methods. The Simulator class in simulator.py has refined its exception handling. Changes in CMakeLists.txt correct a function call syntax, while td1dtagged.py enhances import organization and simulation management. Overall, these changes focus on improving robustness and clarity in code execution.

Changes

File Path Change Summary
pyphare/pyphare/pharesee/run/run.py - Moved glob import to the top.
- Updated _get_hierarchy to handle None for times.
- Simplified GetB, GetE, GetJ methods.
- Restructured GetDl with error handling.
- Modified all_times for better diagnostic file processing.
pyphare/pyphare/simulator/simulator.py - Refined exception handling in setup and initialize methods to catch specific exceptions.
tests/functional/tdtagged/CMakeLists.txt - Removed hyphen from phare_python3_exec function call for correct syntax.
tests/functional/tdtagged/td1dtagged.py - Added imports for AdvanceTestBase and cpp_lib.
- Initialized cpp variable.
- Updated post_advance for MPI rank check.
- Adjusted main function for simulation state management.

Possibly related PRs

Suggested reviewers

  • nicolasaunai

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

return root_cell_width / fac

except KeyError:
... # time may not be avilaable for given quantity

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.
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: 4

🧹 Outside diff range and nitpick comments (2)
tests/functional/tdtagged/td1dtagged.py (2)

Line range hint 266-273: Consider refactoring global state usage.

The function relies on the global particle_diagnostics dictionary which could make testing and maintenance more difficult. Consider:

  1. Passing the diagnostics state as a parameter
  2. Using a class to encapsulate this state

Example refactor:

-def post_advance(new_time):
+def post_advance(new_time, diagnostics):
     if (
-        particle_diagnostics["idx"] < particle_diagnostics["count"]
+        diagnostics["idx"] < diagnostics["count"]
         and cpp.mpi_rank() == 0
     ):
-        particle_diagnostics["idx"] += 1
+        diagnostics["idx"] += 1

Line range hint 275-284: Add error handling for simulation runs.

The main function could benefit from proper error handling to ensure failures are properly reported and resources are cleaned up.

 def main():
-    Simulator(noRefinement(diagdir="noRefinement")).run().reset()
-    ph.global_vars.sim = None
+    try:
+        Simulator(noRefinement(diagdir="noRefinement")).run().reset()
+    except Exception as e:
+        print(f"Error in noRefinement simulation: {e}")
+        raise
+    finally:
+        ph.global_vars.sim = None

-    Simulator(
-        withTagging(diagdir="withTagging"), post_advance=post_advance
-    ).run().reset()
-    ph.global_vars.sim = None
+    try:
+        Simulator(
+            withTagging(diagdir="withTagging"), post_advance=post_advance
+        ).run().reset()
+    except Exception as e:
+        print(f"Error in withTagging simulation: {e}")
+        raise
+    finally:
+        ph.global_vars.sim = None
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 296f0f8 and 62bf35d.

📒 Files selected for processing (4)
  • pyphare/pyphare/pharesee/run/run.py (7 hunks)
  • pyphare/pyphare/simulator/simulator.py (2 hunks)
  • tests/functional/tdtagged/CMakeLists.txt (1 hunks)
  • tests/functional/tdtagged/td1dtagged.py (1 hunks)
🧰 Additional context used
🪛 Ruff
pyphare/pyphare/simulator/simulator.py

116-116: except handlers should only be exception classes or tuples of exception classes

(B030)


140-140: except handlers should only be exception classes or tuples of exception classes

(B030)

🔇 Additional comments (4)
tests/functional/tdtagged/CMakeLists.txt (1)

13-13: LGTM! Fixed CMake function call syntax.

The removal of the hyphen corrects the function name syntax, ensuring proper recognition by CMake.

Let's verify the CMake function definition:

✅ Verification successful

Let me check the actual function definition to ensure it accepts the arguments correctly.


Function signature and usage are correct

The phare_python3_exec function is properly defined in res/cmake/def.cmake and accepts exactly 4 arguments (level, target, file, directory) which match the usage in the reviewed code. The function has two implementations based on MPI testing, but both variants support the argument pattern used in the CMakeLists.txt. The example usage comment in the definition also confirms this is the intended syntax.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the phare_python3_exec function exists in CMake files
# Expected: Find the function definition in CMake configuration

rg -l 'function.*phare_python3_exec'

Length of output: 58


Script:

#!/bin/bash
# Get the function definition with context
rg -A 10 'function.*phare_python3_exec' res/cmake/def.cmake

Length of output: 869

tests/functional/tdtagged/td1dtagged.py (1)

13-17: Verify test base class usage and cpp initialization.

Let's verify the integration of these changes with the rest of the codebase.

✅ Verification successful

Let me analyze the results and generate additional verification to understand the inheritance patterns and potential circular dependencies better.


Based on the comprehensive analysis of the results, I can now provide a final response:

The imports and cpp initialization are correctly integrated

  • AdvanceTestBase is properly used as a test base class, with multiple test files inheriting from it across the codebase
  • The cpp = cpp_lib() initialization follows a consistent pattern used in many test files
  • The imports and usage in td1dtagged.py align with the established patterns in the codebase
  • The cpp initialization is used appropriately for MPI rank checking in the post_advance function
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for other uses of AdvanceTestBase and cpp initialization patterns
echo "Checking AdvanceTestBase usage patterns..."
rg -l "AdvanceTestBase" --type py

echo "Checking cpp initialization patterns..."
rg -l "cpp = cpp_lib\(\)" --type py

echo "Checking for potential circular imports..."
rg -l "from tests.simulator.test_advance import" --type py

Length of output: 1845


Script:

#!/bin/bash
# Check the inheritance hierarchy and implementation details
echo "Checking AdvanceTestBase implementation..."
rg -A 10 "class AdvanceTestBase" tests/simulator/test_advance.py

echo "Checking td1dtagged.py implementation..."
cat tests/functional/tdtagged/td1dtagged.py

echo "Checking for cpp_lib usage patterns..."
rg -A 2 "cpp = cpp_lib\(\)" tests/functional/tdtagged/td1dtagged.py

Length of output: 7305

pyphare/pyphare/pharesee/run/run.py (2)

93-93: LGTM! Boolean condition simplification.

Good cleanup of redundant boolean comparisons in GetB, GetE, and GetJ methods. The code is now more concise while maintaining the same logic.

Also applies to: 103-103, 165-165


44-44: Verify the impact of passing None instead of empty list.

The change in behavior from passing an empty list to passing None for the times parameter could affect how hierarchy_from processes the request. Please ensure this change is compatible with all callers.

Also applies to: 55-55

✅ Verification successful

Let me gather more information about the hierarchy_from function and its usage to better understand the impact.


Let me check the implementation of hierarchy_fromh5 to understand how it handles the time parameter, since that's where the times parameter is ultimately used.


Let me check the helper functions that determine the behavior based on the time parameter.


The change from empty list to None is correct and safe

The change in behavior from passing an empty list to passing None for the times parameter is actually correct and safe. Looking at the implementation of hierarchy_fromh5 and its helper functions:

  1. When times is None, it triggers create_from_all_times which loads all available times from the H5 file
  2. When times is an empty list, it would trigger create_from_times but still process no times
  3. The change makes the intent clearer by using None to explicitly indicate "load all times" vs. an empty list which suggests "load no times"

This aligns better with the function's design and makes the behavior more explicit and intentional.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all calls to hierarchy_from to verify time parameter handling
ast-grep --pattern 'hierarchy_from($$$, times=$_)'

Length of output: 184


Script:

#!/bin/bash
# Search for hierarchy_from function definition and usage
ast-grep --pattern 'hierarchy_from($$$)'

# Also search for the function definition using ripgrep for better context
rg "def hierarchy_from" -A 5

Length of output: 8887


Script:

#!/bin/bash
# Search for the content of hierarchy_fromh5 function to see how it handles time parameter
rg "def hierarchy_fromh5" -A 20 pyphare/pyphare/pharesee/hierarchy/fromh5.py

Length of output: 871


Script:

#!/bin/bash
# Search for the helper functions that determine the behavior
rg "def create_from_times|def create_from_all_times|def load_one_time|def load_all_times" -B 1 -A 5 pyphare/pyphare/pharesee/hierarchy/fromh5.py

Length of output: 539

pyphare/pyphare/simulator/simulator.py Outdated Show resolved Hide resolved
pyphare/pyphare/simulator/simulator.py Outdated Show resolved Hide resolved
pyphare/pyphare/pharesee/run/run.py Show resolved Hide resolved
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: 0

🧹 Outside diff range and nitpick comments (1)
pyphare/pyphare/pharesee/run/run.py (1)

Line range hint 236-273: Enhance method documentation and type hints.

Consider adding:

  1. Type hints for parameters and return value
  2. More descriptive docstring including the return type and possible exceptions

Apply these improvements:

-    def GetDl(self, level="finest", time=None):
+    def GetDl(self, level: Union[str, int] = "finest", time: Optional[float] = None) -> np.ndarray:
         """
         gives the ndarray containing the grid sizes at the given time
         for the hierarchy defined in the given run, and for the given level
         (default is 'finest', but can also be a int)

         :param level: the level at which get the associated grid size
         :param time: the time because level depends on it
+        :return: numpy array containing the grid sizes
+        :raises RuntimeError: if unable to get cell width for the given time
+        :raises KeyError: if time is not available for a given quantity
         """

Don't forget to add the imports at the top:

from typing import Union, Optional
🧰 Tools
🪛 GitHub Check: CodeQL

[notice] 271-271: Statement has no effect
This statement has no effect.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 89565b6 and 6872684.

📒 Files selected for processing (4)
  • pyphare/pyphare/pharesee/run/run.py (5 hunks)
  • pyphare/pyphare/simulator/simulator.py (2 hunks)
  • tests/functional/tdtagged/CMakeLists.txt (1 hunks)
  • tests/functional/tdtagged/td1dtagged.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • pyphare/pyphare/simulator/simulator.py
  • tests/functional/tdtagged/CMakeLists.txt
  • tests/functional/tdtagged/td1dtagged.py
🧰 Additional context used
🪛 GitHub Check: CodeQL
pyphare/pyphare/pharesee/run/run.py

[notice] 271-271: Statement has no effect
This statement has no effect.

🔇 Additional comments (1)
pyphare/pyphare/pharesee/run/run.py (1)

93-93: LGTM! Good simplification of boolean conditions.

The removal of redundant == True comparisons makes the code more concise and readable while maintaining the same functionality.

Also applies to: 103-103, 165-165

@PHAREHUB PHAREHUB deleted a comment from coderabbitai bot Oct 24, 2024
@PhilipDeegan PhilipDeegan merged commit 4549dd0 into PHAREHUB:master Oct 24, 2024
12 checks passed
@PhilipDeegan PhilipDeegan deleted the rufftdtagging branch October 24, 2024 15:21
UCaromel pushed a commit to UCaromel/PHARE that referenced this pull request Nov 13, 2024
UCaromel pushed a commit to UCaromel/PHARE that referenced this pull request Nov 13, 2024
UCaromel added a commit to UCaromel/PHARE that referenced this pull request Jan 6, 2025
…putation

improved test, fixed some bugs in godunov-fluxes

better timing directory creation (PHAREHUB#914)

safer nu (PHAREHUB#911)

try fallback for dl on keyerror + ruffage (PHAREHUB#916)

convenient utils for mpi/hierarchies

keep pyattrs on compute_from_hier

nan min/max to handle possible nan ghosts (PHAREHUB#923)

* nan min/max to handle possible nan ghosts

* flatten

rm atefact file

fixed missing template keyword for macos-12 build

more explicit unwrapping in godunov fluxes with variadic arguments of unclear size

fixed lambda capture problem

fixed lambda capture problem
UCaromel added a commit to UCaromel/PHARE that referenced this pull request Jan 6, 2025
…putation

improved test, fixed some bugs in godunov-fluxes

better timing directory creation (PHAREHUB#914)

safer nu (PHAREHUB#911)

try fallback for dl on keyerror + ruffage (PHAREHUB#916)

convenient utils for mpi/hierarchies

keep pyattrs on compute_from_hier

nan min/max to handle possible nan ghosts (PHAREHUB#923)

* nan min/max to handle possible nan ghosts

* flatten

rm atefact file

fixed missing template keyword for macos-12 build

more explicit unwrapping in godunov fluxes with variadic arguments of unclear size

fixed lambda capture problem

fixed lambda capture problem
UCaromel added a commit to UCaromel/PHARE that referenced this pull request Jan 10, 2025
…putation

improved test, fixed some bugs in godunov-fluxes

better timing directory creation (PHAREHUB#914)

safer nu (PHAREHUB#911)

try fallback for dl on keyerror + ruffage (PHAREHUB#916)

convenient utils for mpi/hierarchies

keep pyattrs on compute_from_hier

nan min/max to handle possible nan ghosts (PHAREHUB#923)

* nan min/max to handle possible nan ghosts

* flatten

rm atefact file

fixed missing template keyword for macos-12 build

more explicit unwrapping in godunov fluxes with variadic arguments of unclear size

fixed lambda capture problem

fixed lambda capture problem
UCaromel added a commit to UCaromel/PHARE that referenced this pull request Jan 10, 2025
…putation

improved test, fixed some bugs in godunov-fluxes

better timing directory creation (PHAREHUB#914)

safer nu (PHAREHUB#911)

try fallback for dl on keyerror + ruffage (PHAREHUB#916)

convenient utils for mpi/hierarchies

keep pyattrs on compute_from_hier

nan min/max to handle possible nan ghosts (PHAREHUB#923)

* nan min/max to handle possible nan ghosts

* flatten

rm atefact file

fixed missing template keyword for macos-12 build

more explicit unwrapping in godunov fluxes with variadic arguments of unclear size

fixed lambda capture problem

fixed lambda capture problem
UCaromel added a commit to UCaromel/PHARE that referenced this pull request Jan 10, 2025
…putation

improved test, fixed some bugs in godunov-fluxes

better timing directory creation (PHAREHUB#914)

safer nu (PHAREHUB#911)

try fallback for dl on keyerror + ruffage (PHAREHUB#916)

convenient utils for mpi/hierarchies

keep pyattrs on compute_from_hier

nan min/max to handle possible nan ghosts (PHAREHUB#923)

* nan min/max to handle possible nan ghosts

* flatten

rm atefact file

fixed missing template keyword for macos-12 build

more explicit unwrapping in godunov fluxes with variadic arguments of unclear size

fixed lambda capture problem

fixed lambda capture problem
UCaromel added a commit to UCaromel/PHARE that referenced this pull request Jan 10, 2025
…putation

improved test, fixed some bugs in godunov-fluxes

better timing directory creation (PHAREHUB#914)

safer nu (PHAREHUB#911)

try fallback for dl on keyerror + ruffage (PHAREHUB#916)

convenient utils for mpi/hierarchies

keep pyattrs on compute_from_hier

nan min/max to handle possible nan ghosts (PHAREHUB#923)

* nan min/max to handle possible nan ghosts

* flatten

rm atefact file

fixed missing template keyword for macos-12 build

more explicit unwrapping in godunov fluxes with variadic arguments of unclear size

fixed lambda capture problem

fixed lambda capture problem
UCaromel pushed a commit to UCaromel/PHARE that referenced this pull request Jan 13, 2025
UCaromel added a commit to UCaromel/PHARE that referenced this pull request Jan 13, 2025
updated + tested mhd_state, updated mhd_model

revert back my typo on hybrid_tagger

fixed typo in test_mhd_state

preparing mhd usablevecfield

new field initialisation logic

Added end of file newline in  field_user_initializer.hpp

added mhd state fixture

wrote test for mhd_state_fixtures

added mhd yee grid, modified gridlayout to handle both hybrid and mhd

up

init_functions

MHD solver

solver mhd update

more solver updates

preparing rebase

formatting

riemann reconstruction

quick commit fix

solved conflict

more solver updates

initial branch commit: new architecture for reconstruction + flux computation

improved test, fixed some bugs in godunov-fluxes

better timing directory creation (PHAREHUB#914)

safer nu (PHAREHUB#911)

try fallback for dl on keyerror + ruffage (PHAREHUB#916)

convenient utils for mpi/hierarchies

keep pyattrs on compute_from_hier

nan min/max to handle possible nan ghosts (PHAREHUB#923)

* nan min/max to handle possible nan ghosts

* flatten

rm atefact file

fixed missing template keyword for macos-12 build

more explicit unwrapping in godunov fluxes with variadic arguments of unclear size

fixed lambda capture problem

fixed lambda capture problem

added time integration

added projection functions for centering, primitive/conservetive converter

added projection functions for centering, primitive/conservetive converter

solver ref binding in a lambda issue

added template deduction guide on for macOS compile on a struct of MHDSolver

New approach for template deduction for the struct in MHDSolver

added usable ghost cells

syntaxe fixes for Werror

full boundary conditions in solver

changed ghost cells function names to be more consistant with hybrid

corrected dummyhierarchy in testmhdsolver (operation on nullptr)

MHDMock simulator setup

added pybind wrappers and first tests

successful orszag-tang test

fixed typo

fixed typo

fixed typo

bug fixes (wrong usage of prevIndex nextIndex)
UCaromel added a commit to UCaromel/PHARE that referenced this pull request Jan 13, 2025
updated + tested mhd_state, updated mhd_model

revert back my typo on hybrid_tagger

fixed typo in test_mhd_state

preparing mhd usablevecfield

new field initialisation logic

Added end of file newline in  field_user_initializer.hpp

added mhd state fixture

wrote test for mhd_state_fixtures

added mhd yee grid, modified gridlayout to handle both hybrid and mhd

up

init_functions

MHD solver

solver mhd update

more solver updates

preparing rebase

formatting

riemann reconstruction

quick commit fix

solved conflict

more solver updates

initial branch commit: new architecture for reconstruction + flux computation

improved test, fixed some bugs in godunov-fluxes

better timing directory creation (PHAREHUB#914)

safer nu (PHAREHUB#911)

try fallback for dl on keyerror + ruffage (PHAREHUB#916)

convenient utils for mpi/hierarchies

keep pyattrs on compute_from_hier

nan min/max to handle possible nan ghosts (PHAREHUB#923)

* nan min/max to handle possible nan ghosts

* flatten

rm atefact file

fixed missing template keyword for macos-12 build

more explicit unwrapping in godunov fluxes with variadic arguments of unclear size

fixed lambda capture problem

fixed lambda capture problem

added time integration

added projection functions for centering, primitive/conservetive converter

added projection functions for centering, primitive/conservetive converter

solver ref binding in a lambda issue

added template deduction guide on for macOS compile on a struct of MHDSolver

New approach for template deduction for the struct in MHDSolver

added usable ghost cells

syntaxe fixes for Werror

full boundary conditions in solver

changed ghost cells function names to be more consistant with hybrid

corrected dummyhierarchy in testmhdsolver (operation on nullptr)

MHDMock simulator setup

added pybind wrappers and first tests

successful orszag-tang test

fixed typo

fixed typo

fixed typo

bug fixes (wrong usage of prevIndex nextIndex)
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