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

Lb stats #94

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Lb stats #94

wants to merge 11 commits into from

Conversation

PhilipDeegan
Copy link
Owner

@PhilipDeegan PhilipDeegan commented May 29, 2024

Summary by CodeRabbit

  • New Features

    • Introduced load balancing capabilities with a LoadBalancer class for simulations.
    • Added functions to write system state statistics and manage load balancing settings.
    • Enhanced integrator with rebalancing logic based on workload computation.
  • Bug Fixes

    • Improved handling of magnetic and electric field ghosts during regridding.
  • Refactor

    • Updated Python test commands to use ${Python_EXECUTABLE} for consistency.
  • Documentation

    • Added comments and TODO notes for better understanding and future improvements.
  • Chores

    • Added psutil package to requirements.txt for system state monitoring.

Copy link

coderabbitai bot commented May 29, 2024

Walkthrough

Walkthrough

The recent updates to the pyphare project include the addition of system state statistics tracking, integration of dynamic load balancing using the LoadBalancer class, enhancements to simulation and particle handling, improved error handling in plotting functions, and updates to project configurations and commenting style. Overall, these changes aim to improve performance, maintainability, and functionality.

Changes

File/Directory Change Summary
pyphare/.../phare_utilities.py Added functions write_system_state_stats for system statistics and deep_copy for deep copying with exclusions.
pyphare/.../pharein/__init__.py Imported LoadBalancer, added new functions for load balancer settings, and reordered dictionary parameters.
pyphare/.../pharein/load_balancer.py Introduced LoadBalancer class with settings for balancing simulations.
pyphare/.../maxwellian_fluid_model.py Added density_cut_off parameter to add_population function.
pyphare/.../simulation.py Modified check_time and wrapper functions, added check_system_state_writes function, and updated __init__ method.
pyphare/.../hierarchy.py Added equality methods, getters, return statements, and a hierarchy_compare function for PatchData and Patch classes.
pyphare/.../particles.py Added single_patch_per_level_per_pop_from function for particle data aggregation.
pyphare/.../simulator/simulator.py Added functions print_rank0 and plot_timestep_time, new attribute write_system_state_time, and expanded run method.
requirements.txt Added psutil package requirement.
res/cmake/def.cmake Updated commands to use ${Python_EXECUTABLE} for Python tests.
src/amr/CMakeLists.txt Included new headers for load balancing and updated target_link_directories.
src/amr/.../particles_data.hpp Updated indentation and commenting style.
src/amr/.../hybrid_level_initializer.hpp Refactored and reorganized regridding logic and added comments.
src/amr/.../..._strategy_homogeneous.hpp Added ConcreteLoadBalancerHybridStrategyHomogeneous class for load balancing in homogeneous systems.
src/amr/.../load_balancer_estimator.hpp Introduced LoadBalancerEstimator class for load balancing estimation.
src/amr/.../load_balancer_estimator_hybrid.hpp Added LoadBalancerEstimatorHybrid class for hybrid load balancing strategies.
src/amr/.../load_balancer_hybrid_strategy.hpp Added LoadBalancerHybridStrategy class template for hybrid simulations.
src/amr/.../load_balancer_hybrid_strategy_factory.hpp Added LoadBalancerHybridStrategyFactory for creating load balancing strategies.
src/amr/.../load_balancer_manager.hpp Added methods to LoadBalancerManager for estimator management, patch allocation, and workload estimation.
src/amr/.../hybrid_hybrid_messenger_strategy.hpp Added includes, updated strategy naming, and refined field ghost handling logic.
src/amr/.../multiphysics_integrator.hpp Enhanced load balancer manager integration and added new methods and logging.
src/amr/.../integrator.hpp Introduced new includes, methods, and rebalancing logic adjustments to advance and initialize.
tools/python3/plotting.py Refactored plot_run_timer_data for better error handling using new internal function _plot_run_timer_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 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.

void ConcreteLoadBalancerHybridStrategyNPPC<PHARE_T>::compute(
level_t& level, PHARE::solver::IPhysicalModel<amr_types>& model)
{
bool static constexpr c_ordering = false;

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable c_ordering is not used.
auto& E = hybridModel.state.electromag.E;
// magSharedNodesRefiners_.fill(B, levelNumber, initDataTime);
magGhostsRefiners_.fill(B, levelNumber, initDataTime);
// elecSharedNodesRefiners_.fill(E, levelNumber, initDataTime);

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
{
auto& B = hybridModel.state.electromag.B;
auto& E = hybridModel.state.electromag.E;
// magSharedNodesRefiners_.fill(B, levelNumber, initDataTime);

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
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: 41

Outside diff range and nitpick comments (15)
tools/config/config.py (1)

Line range hint 150-150: The local variable mpi_type is assigned but never used within the scope of config_mpi_version. This could be an oversight or dead code.

- mpi_type = deduce_mpi_type_from(version)
+ # mpi_type = deduce_mpi_type_from(version)  # Uncomment if used later
pyphare/pyphare/simulator/simulator.py (1)

Line range hint 108-108: Avoid using bare except statements.

Using bare except statements can catch unexpected exceptions and make debugging difficult. Specify the exception types to improve error handling.

- except:
+ except Exception as e:

Also applies to: 131-131

pyphare/pyphare/pharein/maxwellian_fluid_model.py (2)

Line range hint 4-4: Remove unused import.

The import yee_element_is_primal is unused in this file and should be removed to clean up the code.

- from pyphare.core.gridlayout import GridLayout, yee_element_is_primal
+ from pyphare.core.gridlayout import GridLayout

Line range hint 75-127: Add parameter documentation for density_cut_off.

The parameter density_cut_off is added to the add_population method but is not documented in the method's docstring. Update the docstring to include this parameter.

-        anisotropy  : Pperp/Ppara of the species, float (default = 1)
+        anisotropy  : Pperp/Ppara of the species, float (default = 1)
+        density_cut_off : The cutoff density below which particles are ignored, float (default = 1e-16)
tests/simulator/__init__.py (2)

Line range hint 77-77: Replace lambda expression with a named function for better readability.

- _ = lambda i: 0.1 * np.cos(2 * np.pi * xyz[i] / L[i])
+ def compute_value(i):
+     return 0.1 * np.cos(2 * np.pi * xyz[i] / L[i])
Tools
Ruff

4-4: Multiple imports on one line (E401)


Line range hint 178-178: Undefined name 'Box' used.

Please ensure that Box is defined or imported in this file.

Also applies to: 184-184, 191-191

Tools
Ruff

4-4: Multiple imports on one line (E401)

pyphare/pyphare/pharesee/particles.py (1)

Line range hint 88-88: Remove unnecessary f-string.

- print(f"particles.py:Particles::eq failed with:", ex)
+ print("particles.py:Particles::eq failed with:", ex)
src/core/data/ndarray/ndarray_vector.hpp (1)

216-220: Consider adding documentation for the make_array_view functions.

The make_array_view functions are crucial for creating views over data arrays, but they lack documentation. Adding comments explaining the parameters, the function's purpose, and any side effects would improve code maintainability and readability.

Also applies to: 222-226

pyphare/pyphare/pharein/__init__.py (1)

Line range hint 32-46: Remove unused imports or justify their presence.

- from .uniform_model import UniformModel
- from .maxwellian_fluid_model import MaxwellianFluidModel
- from .electron_model import ElectronModel
- from .diagnostics import (
-    FluidDiagnostics,
-    ElectromagDiagnostics,
-    ParticleDiagnostics,
-    MetaDiagnostics,
-    InfoDiagnostics,
- )
- from .simulation import (
-    Simulation,
-    serialize as serialize_sim,
-    deserialize as deserialize_sim,
- )

Several modules are imported but not used within this file. If these are not needed, consider removing them to clean up the codebase. If they are used indirectly (e.g., by being re-exported or dynamically accessed), consider adding them to an __all__ list to clarify their purpose.

Tools
Ruff

47-47: Module level import not at top of file (E402)

src/simulator/simulator.hpp (1)

Line range hint 392-401: Ensure that the logging scope is correctly set and used within the advance method.

Consider refactoring to avoid duplicate logging scope entries.

- PHARE_LOG_SCOPE(1, "Simulator::advance");
- PHARE_LOG_SCOPE(1, "Simulator::advance");
+ PHARE_LOG_SCOPE(1, "Simulator::advance - full");
src/amr/multiphysics_integrator.hpp (2)

33-33: Consider organizing related imports together for better readability.

Grouping related headers can improve the readability and maintainability of the code. For instance, all load_balancing related headers could be grouped together.

Also applies to: 36-37


603-607: Properly document the purpose and usage of setLoadBalancerManager.

Adding documentation for public methods is a best practice that enhances code maintainability and readability. Consider adding a brief comment explaining what this method does, its parameters, and when it should be called.

src/amr/messengers/hybrid_hybrid_messenger_strategy.hpp (2)

166-166: Clarify the purpose of the conditional logic in registerLevel.

Consider adding a detailed comment explaining why the schedules are not created if levelNumber is rootLevelNumber. This will help future maintainers understand the decision-making process behind this conditional logic.


341-341: Improve logging detail.

Consider enhancing the log message in fillIonGhostParticles to include more context about the operation being performed, such as the level number and the specific ions being processed. This can aid in debugging and understanding the flow of data.

pyphare/pyphare/pharesee/hierarchy.py (1)

Line range hint 668-668: Comparison to None should be cond is None.

- if select is not None:
+ if select is not None:

This change ensures that the comparison to None is done using is instead of ==, which is the recommended practice in Python for comparing singletons.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 415855c and 29cee7e.

Files selected for processing (47)
  • pyphare/pyphare/core/phare_utilities.py (2 hunks)
  • pyphare/pyphare/pharein/init.py (5 hunks)
  • pyphare/pyphare/pharein/load_balancer.py (1 hunks)
  • pyphare/pyphare/pharein/maxwellian_fluid_model.py (2 hunks)
  • pyphare/pyphare/pharein/simulation.py (7 hunks)
  • pyphare/pyphare/pharesee/hierarchy.py (6 hunks)
  • pyphare/pyphare/pharesee/particles.py (1 hunks)
  • pyphare/pyphare/simulator/simulator.py (8 hunks)
  • pyphare/pyphare_tests/test_pharesee/test_geometry_3d.py (1 hunks)
  • requirements.txt (1 hunks)
  • res/cmake/def.cmake (4 hunks)
  • res/cmake/dep/samrai.cmake (1 hunks)
  • src/amr/CMakeLists.txt (2 hunks)
  • src/amr/data/particles/particles_data.hpp (1 hunks)
  • src/amr/level_initializer/hybrid_level_initializer.hpp (2 hunks)
  • src/amr/load_balancing/concrete_load_balancer_hybrid_strategy_homogeneous.hpp (1 hunks)
  • src/amr/load_balancing/concrete_load_balancer_hybrid_strategy_nppc.hpp (1 hunks)
  • src/amr/load_balancing/load_balancer_details.hpp (1 hunks)
  • src/amr/load_balancing/load_balancer_estimator.hpp (1 hunks)
  • src/amr/load_balancing/load_balancer_estimator_hybrid.hpp (1 hunks)
  • src/amr/load_balancing/load_balancer_hybrid_strategy.hpp (1 hunks)
  • src/amr/load_balancing/load_balancer_hybrid_strategy_factory.hpp (1 hunks)
  • src/amr/load_balancing/load_balancer_manager.hpp (1 hunks)
  • src/amr/messengers/hybrid_hybrid_messenger_strategy.hpp (11 hunks)
  • src/amr/multiphysics_integrator.hpp (13 hunks)
  • src/amr/wrappers/integrator.hpp (4 hunks)
  • src/core/data/ions/particle_initializers/maxwellian_particle_initializer.hpp (6 hunks)
  • src/core/data/ions/particle_initializers/particle_initializer_factory.hpp (2 hunks)
  • src/core/data/ndarray/ndarray_vector.hpp (1 hunks)
  • src/core/data/particles/particle_array.hpp (1 hunks)
  • src/core/utilities/box/box.hpp (1 hunks)
  • src/hdf5/detail/h5/h5_file.hpp (2 hunks)
  • src/initializer/data_provider.hpp (1 hunks)
  • src/initializer/dictator.cpp (1 hunks)
  • src/simulator/simulator.hpp (6 hunks)
  • tests/core/data/ions/test_ions.cpp (1 hunks)
  • tests/diagnostic/init.py (1 hunks)
  • tests/functional/harris/CMakeLists.txt (1 hunks)
  • tests/functional/harris/harris_2d.py (4 hunks)
  • tests/functional/harris/harris_2d_lb.py (1 hunks)
  • tests/simulator/CMakeLists.txt (1 hunks)
  • tests/simulator/init.py (2 hunks)
  • tests/simulator/test_load_balancing.py (1 hunks)
  • tests/simulator/test_tagging.py.off (1 hunks)
  • tools/config/config.py (1 hunks)
  • tools/python3/init.py (2 hunks)
  • tools/python3/caliper.py (1 hunks)
Files skipped from review due to trivial changes (6)
  • requirements.txt
  • res/cmake/dep/samrai.cmake
  • src/amr/data/particles/particles_data.hpp
  • src/amr/load_balancing/load_balancer_details.hpp
  • tests/core/data/ions/test_ions.cpp
  • tests/simulator/test_tagging.py.off
Additional context used
Path-based instructions (19)
src/amr/load_balancing/load_balancer_hybrid_strategy.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

src/amr/load_balancing/load_balancer_estimator.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

src/amr/load_balancing/load_balancer_hybrid_strategy_factory.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

src/amr/load_balancing/load_balancer_estimator_hybrid.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

src/initializer/data_provider.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

src/amr/load_balancing/concrete_load_balancer_hybrid_strategy_homogeneous.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

src/amr/load_balancing/load_balancer_manager.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

src/core/data/ions/particle_initializers/particle_initializer_factory.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

src/amr/load_balancing/concrete_load_balancer_hybrid_strategy_nppc.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

src/core/utilities/box/box.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

src/core/data/ions/particle_initializers/maxwellian_particle_initializer.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

src/amr/level_initializer/hybrid_level_initializer.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

src/hdf5/detail/h5/h5_file.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

src/core/data/particles/particle_array.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

src/amr/wrappers/integrator.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

src/core/data/ndarray/ndarray_vector.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

src/simulator/simulator.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

src/amr/multiphysics_integrator.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

src/amr/messengers/hybrid_hybrid_messenger_strategy.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

Learnings (2)
pyphare/pyphare/pharein/load_balancer.py (1)
User: PhilipDeegan
PR: PhilipDeegan/PHARE#87
File: pyphare/pyphare/pharein/__init__.py:177-177
Timestamp: 2024-01-16T16:42:31.598Z
Learning: The user has clarified that the validation for the `loadbalancing` parameter is handled within the `simulation.py` file through the `check_loadbalancing` function, which checks for supported types.
pyphare/pyphare/pharein/__init__.py (1)
User: PhilipDeegan
PR: PhilipDeegan/PHARE#87
File: pyphare/pyphare/pharein/__init__.py:177-177
Timestamp: 2024-01-16T16:42:31.598Z
Learning: The user has clarified that the validation for the `loadbalancing` parameter is handled within the `simulation.py` file through the `check_loadbalancing` function, which checks for supported types.
Ruff
pyphare/pyphare_tests/test_pharesee/test_geometry_3d.py

1-1: Undefined name test_geometry_3d (F821)

tests/diagnostic/__init__.py

16-16: Multiple imports on one line (E401)


16-16: numpy imported but unused; consider removing, adding to __all__, or using a redundant alias (F401)

pyphare/pyphare/pharein/load_balancer.py

36-36: f-string without any placeholders (F541)


53-53: f-string without any placeholders (F541)


56-56: f-string without any placeholders (F541)

tools/python3/__init__.py

72-72: Module level import not at top of file (E402)

pyphare/pyphare/core/phare_utilities.py

159-159: Multiple imports on one line (E401)


181-181: Multiple imports on one line (E401)

tests/functional/harris/harris_2d.py

60-60: Ambiguous variable name: l (E741)


153-153: Undefined name Run (F821)


156-156: Undefined name plot_file_for_qty (F821)


162-162: Undefined name plot_file_for_qty (F821)


166-166: Undefined name plot_file_for_qty (F821)


171-171: Undefined name plot_file_for_qty (F821)


176-176: Undefined name plot_file_for_qty (F821)

tools/python3/caliper.py

6-6: tools.python3.run imported but unused (F401)


20-20: subprocess imported but unused (F401)

tests/functional/harris/harris_2d_lb.py

74-74: Ambiguous variable name: l (E741)

tools/config/config.py

150-150: Local variable mpi_type is assigned to but never used (F841)

pyphare/pyphare/simulator/simulator.py

108-108: Do not use bare except (E722)


131-131: Do not use bare except (E722)


143-143: pyphare.cpp.cpp_lib imported but unused (F401)


162-162: Comparison to None should be cond is not None (E711)

tests/simulator/test_load_balancing.py

73-73: Ambiguous variable name: l (E741)


218-218: Local variable diag_dir is assigned to but never used (F841)

pyphare/pyphare/pharein/maxwellian_fluid_model.py

4-4: pyphare.core.gridlayout.yee_element_is_primal imported but unused (F401)

tests/simulator/__init__.py

4-4: Multiple imports on one line (E401)


77-77: Do not assign a lambda expression, use a def (E731)


178-178: Undefined name Box (F821)


184-184: Undefined name Box (F821)


191-191: Undefined name Box (F821)


217-217: Local variable rank is assigned to but never used (F841)


218-218: Local variable env is assigned to but never used (F841)

pyphare/pyphare/pharesee/particles.py

88-88: f-string without any placeholders (F541)

pyphare/pyphare/pharein/__init__.py

32-32: Module level import not at top of file (E402)


32-32: .uniform_model.UniformModel imported but unused; consider removing, adding to __all__, or using a redundant alias (F401)


33-33: Module level import not at top of file (E402)


33-33: .maxwellian_fluid_model.MaxwellianFluidModel imported but unused; consider removing, adding to __all__, or using a redundant alias (F401)


34-34: Module level import not at top of file (E402)


34-34: .electron_model.ElectronModel imported but unused; consider removing, adding to __all__, or using a redundant alias (F401)


35-41: Module level import not at top of file (E402)


36-36: .diagnostics.FluidDiagnostics imported but unused; consider removing, adding to __all__, or using a redundant alias (F401)


37-37: .diagnostics.ElectromagDiagnostics imported but unused; consider removing, adding to __all__, or using a redundant alias (F401)


38-38: .diagnostics.ParticleDiagnostics imported but unused; consider removing, adding to __all__, or using a redundant alias (F401)


39-39: .diagnostics.MetaDiagnostics imported but unused; consider removing, adding to __all__, or using a redundant alias (F401)


40-40: .diagnostics.InfoDiagnostics imported but unused; consider removing, adding to __all__, or using a redundant alias (F401)


42-46: Module level import not at top of file (E402)


43-43: .simulation.Simulation imported but unused; consider removing, adding to __all__, or using a redundant alias (F401)


47-47: Module level import not at top of file (E402)

pyphare/pyphare/pharein/simulation.py

335-335: Comparison to None should be cond is not None (E711)


355-355: Ambiguous variable name: l (E741)


561-561: f-string without any placeholders (F541)


569-569: f-string without any placeholders (F541)


588-588: psutil imported but unused; consider using importlib.util.find_spec to test for availability (F401)


589-589: Local variable e is assigned to but never used (F841)


691-691: Comparison to None should be cond is not None (E711)


954-954: Multiple imports on one line (E401)


960-960: Multiple imports on one line (E401)

pyphare/pyphare/pharesee/hierarchy.py

668-668: Comparison to None should be cond is None (E711)

Additional comments not posted (36)
tests/functional/harris/CMakeLists.txt (1)

16-19: Correct implementation of conditional MPI testing.

The addition of the else() block for non-MPI testing is a logical extension and correctly implemented. Ensure that the phare_python3_exec function is properly defined and works as expected in the non-MPI context.

src/amr/load_balancing/load_balancer_hybrid_strategy.hpp (1)

14-25: Well-designed abstract base class for load balancing strategies.

The LoadBalancerHybridStrategy class is well-designed as an abstract base class with a pure virtual function compute, which is a common and recommended practice in C++ for defining interfaces.

src/amr/load_balancing/load_balancer_estimator.hpp (1)

17-34: Properly structured base class for load balancing estimation.

The LoadBalancerEstimator class is correctly structured with a constructor for initialization, a virtual destructor for safe polymorphic use, and a pure virtual function estimate for derived classes to implement specific behaviors.

src/amr/load_balancing/load_balancer_estimator_hybrid.hpp (1)

17-37: Well-implemented decorator pattern in load balancing estimation.

The LoadBalancerEstimatorHybrid class effectively uses the decorator pattern to enhance the functionality of LoadBalancerEstimator by delegating computation to a strategy object. Ensure that the strategy creation in the constructor handles potential errors or null returns gracefully.

tests/simulator/CMakeLists.txt (1)

27-27: LGTM! Ensure the new MPI test for load balancing runs as expected.

tests/diagnostic/__init__.py (2)

23-27: Ensure the new InfoDiagnostics class is integrated correctly in the diagnostic pipeline.


23-23: Remove unnecessary f-string as there are no placeholders.

- raise RuntimeError(f"LoadBalancer cannot work with both 'every' and 'auto'")
+ raise RuntimeError("LoadBalancer cannot work with both 'every' and 'auto'")

Likely invalid or redundant comment.

src/initializer/data_provider.hpp (1)

51-53: LGTM! The new PHAREDict type is defined correctly and includes all necessary types.

src/amr/load_balancing/concrete_load_balancer_hybrid_strategy_homogeneous.hpp (1)

45-66: Ensure the compute method integrates correctly with the load balancing system and performs as expected.

tools/python3/__init__.py (1)

14-17: Ensure proper error handling for subprocess calls.

The use of subprocess.run with check=True and proper exception handling for CalledProcessError is a good practice as it ensures that any subprocess errors are caught and handled appropriately.

src/amr/load_balancing/load_balancer_manager.hpp (2)

23-32: Review initialization of class members in constructor.

The constructor of LoadBalancerManager is well-organized, initializing class members in the initializer list. This is efficient as it directly constructs members with their final values rather than default-constructing them first and then assigning to them.


69-74: Ensure correct handling of levels in addLoadBalancerEstimator.

The method correctly handles the range of levels from iLevel_min to iLevel_max. Using a loop to assign the LoadBalancerEstimator to each level is appropriate and clear.

src/amr/CMakeLists.txt (2)

68-74: Ensure new files are correctly integrated into the build system.

The addition of new header files for load balancing strategies in the CMakeLists.txt is correctly done. This ensures that these files are recognized by the build system and included in the compilation process.


87-87: Verify the correct setting of MPI_LIBRARY_PATH.

Ensure that MPI_LIBRARY_PATH is correctly set to link against the MPI libraries. This is crucial for ensuring that the project links correctly against the required MPI libraries.

src/amr/load_balancing/concrete_load_balancer_hybrid_strategy_nppc.hpp (1)

53-53: Skip commenting on unused local variable c_ordering.

The previous comment regarding the unused local variable c_ordering is still valid and does not need to be repeated.

pyphare/pyphare/core/phare_utilities.py (1)

181-196: Ensure proper handling of file operations and system resource queries.

The function write_system_state_stats correctly handles file operations and queries system resources using psutil. The use of json.dump to write data to a file is appropriate and follows good practices for data handling.

Tools
Ruff

181-181: Multiple imports on one line (E401)

tests/functional/harris/harris_2d.py (2)

29-30: The calculation of timestamps using final_time / 3 may not include the final time due to floating-point precision issues. Consider using np.linspace for more precise control over the range and endpoint inclusion.
[REFACTOR_SUGGESTion]

- timestamps = np.arange(0, final_time + time_step, final_time / 3)
+ timestamps = np.linspace(0, final_time, num=4, endpoint=True)

36-36: The final_time parameter is directly passed to the Simulation constructor. Ensure that this aligns with the simulation's expected behavior and that final_time is appropriately validated elsewhere in the code.

Verification successful

The final_time parameter is validated within the check_time function in pyphare/pyphare/pharein/simulation.py. This function ensures that final_time is used correctly in conjunction with time_step and time_step_nbr, raising a ValueError if the parameters are not specified correctly.

  • pyphare/pyphare/pharein/simulation.py, check_time function:
    • Validates final_time in combination with time_step and time_step_nbr.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that `final_time` is validated before being used in the simulation.
# Test: Search for validation logic. Expect: Validation logic for `final_time`.
rg --type python $'final_time' --context 5

Length of output: 72



Script:

#!/bin/bash
# Description: Verify that `final_time` is validated before being used in the simulation.
# Test: Search for validation logic. Expect: Validation logic for `final_time`.
rg --type py 'final_time' --context 5

Length of output: 50535



Script:

#!/bin/bash
# Description: Verify that `final_time` is validated in the `Simulation` class.
# Test: Search for the `Simulation` class definition and its initialization logic.
ast-grep --lang python --pattern $'class Simulation {
  $$$
  def __init__($$$):
    $$$
}' --context 10

Length of output: 583



Script:

#!/bin/bash
# Description: Verify that `final_time` is validated in the `Simulation` class.
# Test: Search for the `Simulation` class definition and its initialization logic.
ast-grep --lang python --pattern 'class Simulation:
  def __init__($$$):
    $$$'

Length of output: 83



Script:

#!/bin/bash
# Description: Locate the file containing the `Simulation` class and search for its `__init__` method.
# Step 1: Locate the file containing the `Simulation` class.
fd -e py 'Simulation' | xargs rg 'class Simulation'

# Step 2: Search for the `__init__` method within the located file(s).
fd -e py 'Simulation' | xargs -I {} rg 'def __init__' {}

Length of output: 176



Script:

#!/bin/bash
# Description: Display the contents of the `pyphare/pyphare/pharein/simulation.py` file, focusing on the `__init__` method.
# Step 1: Display the `Simulation` class definition and its `__init__` method.
rg --context 10 'class Simulation' pyphare/pyphare/pharein/simulation.py
rg --context 10 'def __init__' pyphare/pyphare/pharein/simulation.py

Length of output: 1654



Script:

#!/bin/bash
# Description: Search for the `checker` decorator and any validation logic related to `final_time`.
# Step 1: Locate the `checker` decorator definition.
rg --context 10 'def checker' pyphare/pyphare/pharein/simulation.py

# Step 2: Search for validation logic related to `final_time`.
rg --context 10 'final_time' pyphare/pyphare/pharein/simulation.py

Length of output: 4786

tools/python3/caliper.py (1)

79-79: The query string is overwritten without being used in its initial form. This could be an error or unnecessary code. Verify if the initial assignment is required.

Verification successful

The initial query assignment is commented out and not used in the code.

  • tools/python3/caliper.py: Commented out lines with the initial query assignment.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Check if the initial query assignment is used elsewhere in the code.
# Test: Search for the initial query usage. Expect: No usage found.
rg --type python $'select function,%s group by %s format json-split'

Length of output: 100



Script:

#!/bin/bash
# Description: Check if the initial query assignment is used elsewhere in the code.
# Test: Search for the initial query usage. Expect: No usage found.
rg --type py $'select function,%s group by %s format json-split'

Length of output: 345

src/core/utilities/box/box.hpp (1)

161-162: The use of auto in the iterator's dereference operators is clear and appropriate here, providing flexibility with the type of index_.

src/amr/level_initializer/hybrid_level_initializer.hpp (1)

55-55: Ensure proper error handling for dynamic_cast.

Dynamic casting can fail and return nullptr if the cast is not valid. It's crucial to verify that hybMessenger is not a nullptr after this cast to prevent potential dereferencing of a null pointer.

src/hdf5/detail/h5/h5_file.hpp (1)

72-72: Ensure method consistency.

The method file() correctly provides access to the h5file_ member. This is consistent with the encapsulation practices in C++.

pyphare/pyphare/pharein/__init__.py (1)

229-247: Ensure proper initialization and handling of the LoadBalancer instance.

The initialization of LoadBalancer with active=False and _register=False is crucial for its behavior. Verify that these flags are handled correctly throughout the class to ensure that the load balancing functionality can be safely toggled on and off.

Verification successful

The LoadBalancer class in pyphare/pyphare/pharein/load_balancer.py correctly initializes and handles the active and _register flags. The active flag is initialized with a default value of True, and the _register flag is also initialized with a default value of True. Additionally, there is a conditional check for _register within the class.

  • pyphare/pyphare/pharein/load_balancer.py
    • active: bool = field(default_factory=lambda: True)
    • _register: bool = field(default_factory=lambda: True)
    • if self._register:
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the LoadBalancer class handles the 'active' and '_register' flags correctly.

# Test: Search for the LoadBalancer class definition and its handling of the 'active' and '_register' flags.
rg --type python $'class LoadBalancer'

Length of output: 70



Script:

#!/bin/bash
# Description: Verify that the LoadBalancer class handles the 'active' and '_register' flags correctly.

# Test: Search for the LoadBalancer class definition and its handling of the 'active' and '_register' flags.
rg 'class LoadBalancer'

Length of output: 558



Script:

#!/bin/bash
# Description: Verify that the LoadBalancer class handles the 'active' and '_register' flags correctly.

# Test: Search for the handling of the 'active' and '_register' flags within the LoadBalancer class definition.
rg 'active' pyphare/pyphare/pharein/load_balancer.py
rg '_register' pyphare/pyphare/pharein/load_balancer.py

Length of output: 346

src/simulator/simulator.hpp (3)

16-18: Ensure that the newly included headers are necessary and correctly placed.

Verification successful

The newly included headers are necessary and correctly placed as their entities are used in the file.

  • amr::LoadBalancerDetails is used.
  • amr::LoadBalancerManager is used.
  • amr::LoadBalancerEstimatorHybrid is used.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the newly included headers are used in the file.

# Test: Search for usage of entities from the headers. Expect: At least one usage per header.
rg --type cpp 'LoadBalancerDetails|LoadBalancerManager|LoadBalancerEstimatorHybrid' src/simulator/simulator.hpp

Length of output: 462


266-293: Review the initialization and usage of load balancing classes. Ensure that the LoadBalancerDetails and LoadBalancerManager are correctly configured and used.

Verification successful

The initialization and usage of LoadBalancerDetails and LoadBalancerManager appear to be correctly configured and used in the codebase. The parameters passed during their initialization and the methods called on these objects are appropriate and consistent with their definitions.

  • LoadBalancerDetails is initialized using amr::LoadBalancerDetails::FROM(dict["simulation"]["AMR"]["loadbalancing"]).
  • LoadBalancerManager is initialized with std::make_unique<amr::LoadBalancerManager<dim>>(dict) and used with multiphysInteg_->setLoadBalancerManager(std::move(lbm_)).
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct configuration and usage of load balancing classes.

# Test: Search for the configuration of `LoadBalancerDetails` and `LoadBalancerManager`. Expect: Correct parameters and methods calls.
rg --type cpp 'LoadBalancerDetails|LoadBalancerManager' src/simulator/simulator.hpp

Length of output: 341



Script:

#!/bin/bash
# Description: Verify the correct configuration and usage of load balancing classes.

# Search for the definition and methods of `LoadBalancerDetails`.
ast-grep --lang cpp --pattern 'class LoadBalancerDetails { $$$ }'

# Search for the definition and methods of `LoadBalancerManager`.
ast-grep --lang cpp --pattern 'class LoadBalancerManager { $$$ }'

Length of output: 825



Script:

#!/bin/bash
# Description: Verify the correct configuration and usage of load balancing classes.

# Refined search for the definition and methods of `LoadBalancerDetails`.
ast-grep --lang cpp --pattern 'class LoadBalancerDetails { $$$ }'

# Refined search for the definition and methods of `LoadBalancerManager`.
ast-grep --lang cpp --pattern 'class LoadBalancerManager { $$$ }'

# Search for the initialization and method calls related to `LoadBalancerDetails` and `LoadBalancerManager` in the entire codebase.
rg --type cpp 'LoadBalancerDetails|LoadBalancerManager'

Length of output: 2881


297-299: Ensure that the Integrator constructor is correctly receiving all necessary parameters.

pyphare/pyphare/pharein/simulation.py (2)

Line range hint 127-151: Ensure that the check_time function correctly calculates time_step_nbr, time_step, and final_time based on the provided arguments.

This modification correctly handles different scenarios for time calculation based on the provided keyword arguments.


Line range hint 631-706: Review the wrapper function to ensure that it correctly processes simulation parameters and handles errors appropriately.

The function effectively validates and sets up simulation parameters, handling various configurations and defaults.

src/amr/multiphysics_integrator.hpp (2)

107-107: Ensure load_balancer_manager_ is properly initialized in all constructors.

Verification successful

The constructor for MultiPhysicsIntegrator in src/amr/multiphysics_integrator.hpp does initialize load_balancer_manager_ to nullptr.

  • load_balancer_manager_ is properly initialized in the constructor found.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that `load_balancer_manager_` is initialized in all constructors.
# Test: Search for all constructors in the file and check initialization of `load_balancer_manager_`.
rg --type cpp 'MultiPhysicsIntegrator\(' multiphysics_integrator.hpp

Length of output: 138



Script:

#!/bin/bash
# Locate the `multiphysics_integrator.hpp` file
fd multiphysics_integrator.hpp

# If the file is found, search for all constructors of the `MultiPhysicsIntegrator` class in the file
if [ -f "$(fd multiphysics_integrator.hpp)" ]; then
  rg --type cpp 'MultiPhysicsIntegrator\(' "$(fd multiphysics_integrator.hpp)"
else
  echo "multiphysics_integrator.hpp file not found"
fi

Length of output: 338



Script:

#!/bin/bash
# Extract the constructor definition from the file
rg --type cpp --context 10 'MultiPhysicsIntegrator\(' src/amr/multiphysics_integrator.hpp

Length of output: 1165


369-369: Verify that load_balancer_manager_ is properly initialized before use.

Verification successful

The setLoadBalancerManager method is called in src/simulator/simulator.hpp before any method calls on load_balancer_manager_. This ensures that load_balancer_manager_ is properly initialized before use.

  • setLoadBalancerManager is called before the Integrator is created and before any other operations that might use load_balancer_manager_.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that `load_balancer_manager_` is initialized before use in `estimate`.
# Test: Search for all uses of `load_balancer_manager_` and ensure it's initialized.
rg --type cpp 'load_balancer_manager_' multiphysics_integrator.hpp

Length of output: 134



Script:

#!/bin/bash
# Locate the file `multiphysics_integrator.hpp` in the repository
file_path=$(fd multiphysics_integrator.hpp)

# If the file is found, search for the initialization of `load_balancer_manager_`
if [[ -n "$file_path" ]]; then
  echo "File found at: $file_path"
  rg --type cpp 'load_balancer_manager_' "$file_path"
else
  echo "File not found"
fi

Length of output: 851



Script:

#!/bin/bash
# Extract the relevant code blocks to verify the order of initialization and method calls for `load_balancer_manager_`
file_path="src/amr/multiphysics_integrator.hpp"

# Extract the class definition and constructor to check initialization
rg --type cpp -A 20 'class' "$file_path"
rg --type cpp -A 20 'multiphysics_integrator' "$file_path"

Length of output: 1267



Script:

#!/bin/bash
# Search for the assignment of `load_balancer_manager_` and verify the order of operations
file_path="src/amr/multiphysics_integrator.hpp"

# Search for the assignment of `load_balancer_manager_`
rg --type cpp 'load_balancer_manager_ = std::move' "$file_path" -A 10 -B 10

Length of output: 830



Script:

#!/bin/bash
# Search for calls to `setLoadBalancerManager` and ensure they occur before any method calls on `load_balancer_manager_`
file_path="src/amr/multiphysics_integrator.hpp"

# Search for calls to `setLoadBalancerManager`
rg --type cpp 'setLoadBalancerManager' "$file_path" -A 10 -B 10

Length of output: 680



Script:

#!/bin/bash
# Search the entire codebase for calls to `setLoadBalancerManager`
rg --type cpp 'setLoadBalancerManager'

Length of output: 258



Script:

#!/bin/bash
# Extract the relevant code from `src/simulator/simulator.hpp` to verify the order of operations
rg --type cpp 'setLoadBalancerManager' src/simulator/simulator.hpp -A 20 -B 20

Length of output: 1933

src/amr/messengers/hybrid_hybrid_messenger_strategy.hpp (1)

222-224: Remove commented-out code.

As previously noted by the GitHub Advanced Security bot, commented-out code should be removed unless there is a specific reason to keep it for documentation or future use.

pyphare/pyphare/pharesee/hierarchy.py (5)

13-13: Added import for dataclass from the dataclasses module.

This is a standard import necessary for using dataclasses in Python, which are used later in the file.


91-92: Added equality method for FieldData class.

This method correctly compares field_name and the contents of dataset arrays. Ensure that dataset comparison is intended to be element-wise.


229-230: Added equality method for ParticleData class.

This method ensures that two ParticleData instances are considered equal if they have the same name and dataset. This is a straightforward and effective way to compare these data structures.


258-259: Added __getitem__ method to the Patch class.

This method allows for direct indexing into patch_datas using keys, which is a useful feature for accessing data more conveniently.


1809-1861: Added EqualityReport dataclass and hierarchy_compare function.

The EqualityReport dataclass is well-defined and used effectively in the hierarchy_compare function to provide detailed comparison results between two PatchHierarchy instances. This function thoroughly checks for mismatches in class types, dimensions, timesteps, levels, and data keys, ensuring a comprehensive comparison.

@@ -44,6 +44,7 @@
serialize as serialize_sim,
deserialize as deserialize_sim,
)
from .load_balancer import LoadBalancer
Copy link

Choose a reason for hiding this comment

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

Address the module level import issue.

- from .load_balancer import LoadBalancer
+ # from .load_balancer import LoadBalancer

The import of LoadBalancer is flagged as not being at the top of the file. Consider moving all imports to the top to comply with PEP 8 standards, unless there's a specific reason they are delayed (e.g., to prevent circular dependencies).

Committable suggestion was skipped due to low confidence.

Tools
Ruff

47-47: Module level import not at top of file (E402)

@@ -319,17 +323,25 @@ namespace solver
model.allocate(*patch, initDataTime);
solver.allocate(model, *patch, initDataTime);
messenger.allocate(*patch, initDataTime);
load_balancer_manager_->allocate(*patch, initDataTime);
Copy link

Choose a reason for hiding this comment

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

Ensure that load_balancer_manager_ is not null before calling allocate.

if (load_balancer_manager_) {
    load_balancer_manager_->allocate(*patch, initDataTime);
}

This modification ensures that the program does not crash if load_balancer_manager_ is null.

@@ -195,11 +197,15 @@ namespace amr
{
auto& hybridModel = dynamic_cast<HybridModel&>(model);
auto level = hierarchy->getPatchLevel(levelNumber);

bool isRegriddingL0 = levelNumber == 0 and oldLevel;
Copy link

Choose a reason for hiding this comment

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

Handle potential null pointer dereference.

- bool isRegriddingL0 = levelNumber == 0 and oldLevel;
+ bool isRegriddingL0 = levelNumber == 0 && oldLevel != nullptr;

Ensure that oldLevel is checked for nullity before usage to prevent runtime errors.

@@ -349,7 +365,7 @@
void fillIonPopMomentGhosts(IonsT& ions, SAMRAI::hier::PatchLevel& level,
double const afterPushTime) override
{
PHARE_LOG_SCOPE(3, "HybridHybridMessengerStrategy::fillIonMomentGhosts");
PHARE_LOG_SCOPE(1, "HybridHybridMessengerStrategy::fillIonMomentGhosts");
Copy link

Choose a reason for hiding this comment

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

Validate alpha values rigorously.

if (level.getLevelNumber() > 0 && (alpha < 0.0 || alpha > 1.0))

Ensure that alpha is within the expected range (0 to 1) to prevent logical errors in time interpolation calculations. This validation is crucial for maintaining the integrity of the simulation data.

@@ -81,7 +82,7 @@
using DefaultCoarsenOp = BaseCoarsenOp<DefaultFieldCoarsener<dimension>>;

public:
static const std::string stratName;
static const inline std::string stratName = "HybridModel-HybridModel";
Copy link

Choose a reason for hiding this comment

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

Consider using constexpr for stratName if it does not need to be modified.

- static const inline std::string stratName    = "HybridModel-HybridModel";
+ static constexpr auto stratName    = "HybridModel-HybridModel";

This change ensures that stratName is evaluated at compile time, potentially improving performance and reducing memory usage.

Comment on lines +38 to +58
def print_rank0(*args, **kwargs):
from pyphare.cpp import cpp_lib

if cpp_lib().mpi_rank() == 0:
print(*args, **kwargs)


def plot_timestep_time(timestep_times):
from pyphare.cpp import cpp_lib

if cpp_lib().mpi_rank() == 0:
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.plot(timestep_times)
plt.ylabel("timestep time")
plt.xlabel("timestep")
fig.savefig("timestep_times.png")

cpp_lib().mpi_barrier()

Copy link

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The functions print_rank0 and plot_timestep_time involve MPI operations but do not have specific error handling for potential MPI errors. Consider adding error handling mechanisms to ensure robustness against MPI failures.

  • print_rank0 function
  • plot_timestep_time function
Analysis chain

Ensure proper error handling in MPI-related functions.

The functions print_rank0 and plot_timestep_time involve MPI operations but do not handle potential MPI errors. It's important to ensure that these functions are robust against MPI failures.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify error handling in MPI-related functions in `simulator.py`.

# Test: Search for MPI error handling. Expect: Proper error handling mechanisms.
rg --type py $'cpp_lib().mpi_rank()' pyphare/pyphare/simulator/simulator.py

Length of output: 76



Script:

#!/bin/bash
# Description: Verify error handling in MPI-related functions in `simulator.py`.

# Test: Search for try-except blocks that might handle MPI errors.
rg --type py 'try:' pyphare/pyphare/simulator/simulator.py

Length of output: 97



Script:

#!/bin/bash
# Description: Extract lines containing try-except blocks and their surrounding context in `simulator.py`.

# Test: Display lines with try-except blocks and 5 lines before and after each occurrence.
rg --type py --context 5 'try:' pyphare/pyphare/simulator/simulator.py

Length of output: 1136

return

with self.assertRaises(RuntimeError):
diag_dir = self.run_sim(
Copy link

Choose a reason for hiding this comment

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

Remove unused local variable.

The local variable diag_dir is assigned but never used, which can lead to confusion and clutter in the code.

- diag_dir = self.run_sim(
+ self.run_sim(
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.

Suggested change
diag_dir = self.run_sim(
self.run_sim(
Tools
Ruff

218-218: Local variable diag_dir is assigned to but never used (F841)

rho[np.where(np.isclose(y, 10, atol=0.1))] = 0
return rho

def S(y, y0, l):
Copy link

Choose a reason for hiding this comment

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

Avoid ambiguous variable names.

The variable name l is ambiguous and can be confused with the number 1. Use a more descriptive name.

- def S(y, y0, l):
+ def S(y, y0, length):
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.

Suggested change
def S(y, y0, l):
def S(y, y0, length):
Tools
Ruff

73-73: Ambiguous variable name: l (E741)

@@ -45,6 +45,7 @@ PYBIND11_MODULE(dictator, m)
m.def("add_size_t", add<std::size_t>, "add_size_t");
m.def("add_optional_size_t", add<std::optional<std::size_t>>, "add_optional_size_t");

m.def("add_bool", add<bool>, "add");
Copy link

Choose a reason for hiding this comment

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

Consider improving the documentation strings for each binding to reflect the specific type being added.

- m.def("add_bool", add<bool>, "add");
+ m.def("add_bool", add<bool>, "add boolean value");
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.

Suggested change
m.def("add_bool", add<bool>, "add");
m.def("add_bool", add<bool>, "add boolean value");



def write_system_state_stats(file_path):
import json, psutil, pathlib, datetime
Copy link

Choose a reason for hiding this comment

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

Separate imports onto individual lines.

- import json, psutil, pathlib, datetime
+ import json
+ import psutil
+ import pathlib
+ import datetime

For better readability and to comply with PEP 8 standards, place each import on a separate line.

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.

Suggested change
import json, psutil, pathlib, datetime
import json
import psutil
import pathlib
import datetime
Tools
Ruff

181-181: Multiple imports on one line (E401)

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)
tests/functional/harris/harris_2d.py (1)

Line range hint 66-66: Consider renaming the variable l to length or another descriptive name to avoid confusion with the number 1.

- def S(y, y0, l):
+ def S(y, y0, length):
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 29cee7e and 2d65858.

Files selected for processing (3)
  • res/cmake/dep/phlop.cmake (1 hunks)
  • tests/functional/harris/CMakeLists.txt (1 hunks)
  • tests/functional/harris/harris_2d.py (4 hunks)
Files skipped from review due to trivial changes (1)
  • res/cmake/dep/phlop.cmake
Files skipped from review as they are similar to previous changes (1)
  • tests/functional/harris/CMakeLists.txt
Additional context used
Ruff
tests/functional/harris/harris_2d.py

66-66: Ambiguous variable name: l (E741)

Additional comments not posted (4)
tests/functional/harris/harris_2d.py (4)

45-45: Consider making the cells tuple configurable or validating it against expected simulation parameters to ensure it meets the necessary conditions for the simulation's spatial resolution.


163-164: Function plot_file_for_qty correctly generates file paths for plots.


168-196: The function plot is now correctly using defined names for plotting, addressing previous issues.


198-212: Function main correctly handles simulation execution and potential errors, ensuring robust operation.

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 (9)
tests/functional/shock/shock.py (2)

25-26: Consider removing or uncommenting the smallest_patch_size and largest_patch_size if they are not intended for future use.


Line range hint 49-49: Consider renaming the variable l to length to avoid ambiguity with the number 1.

tests/functional/alfven_wave/alfven_wave1d.py (1)

27-28: Consider removing or uncommenting the smallest_patch_size and largest_patch_size if they are not intended for future use.

tests/functional/translation/translat1d.py (2)

23-24: Consider removing or uncommenting the smallest_patch_size and largest_patch_size if they are not intended for future use.


Line range hint 131-131: Consider renaming the variable l to length to avoid ambiguity with the number 1.

tests/functional/harris/harris_2d.py (2)

40-41: Consider removing or uncommenting the smallest_patch_size and largest_patch_size if they are not intended for future use.


Line range hint 66-66: Consider renaming the variable l to length to avoid ambiguity with the number 1.

tests/functional/ionIonBeam/ion_ion_beam1d.py (1)

26-27: Consider removing or uncommenting the smallest_patch_size and largest_patch_size if they are not intended for future use.

tests/functional/conservation/conserv.py (1)

25-26: Consider removing or uncommenting the smallest_patch_size and largest_patch_size if they are not intended for future use.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2d65858 and b3a3822.

Files selected for processing (15)
  • tests/functional/alfven_wave/CMakeLists.txt (1 hunks)
  • tests/functional/alfven_wave/alfven_wave1d.py (1 hunks)
  • tests/functional/conservation/CMakeLists.txt (1 hunks)
  • tests/functional/conservation/conserv.py (1 hunks)
  • tests/functional/dispersion/dispersion.py (1 hunks)
  • tests/functional/harris/CMakeLists.txt (1 hunks)
  • tests/functional/harris/harris_2d.py (4 hunks)
  • tests/functional/ionIonBeam/CMakeLists.txt (1 hunks)
  • tests/functional/ionIonBeam/ion_ion_beam1d.py (1 hunks)
  • tests/functional/shock/CMakeLists.txt (1 hunks)
  • tests/functional/shock/shock.py (1 hunks)
  • tests/functional/td/td1d.py (1 hunks)
  • tests/functional/tdtagged/CMakeLists.txt (1 hunks)
  • tests/functional/translation/CMakeLists.txt (1 hunks)
  • tests/functional/translation/translat1d.py (1 hunks)
Files skipped from review due to trivial changes (2)
  • tests/functional/tdtagged/CMakeLists.txt
  • tests/functional/translation/CMakeLists.txt
Files skipped from review as they are similar to previous changes (1)
  • tests/functional/harris/CMakeLists.txt
Additional context used
Ruff
tests/functional/td/td1d.py

7-7: matplotlib.pyplot imported but unused (F401)


41-41: Ambiguous variable name: l (E741)

tests/functional/dispersion/dispersion.py

7-7: matplotlib.pyplot imported but unused (F401)

tests/functional/shock/shock.py

49-49: Ambiguous variable name: l (E741)

tests/functional/translation/translat1d.py

7-7: matplotlib.pyplot imported but unused (F401)


131-131: Ambiguous variable name: l (E741)

tests/functional/harris/harris_2d.py

66-66: Ambiguous variable name: l (E741)

tests/functional/ionIonBeam/ion_ion_beam1d.py

8-8: tests.diagnostic.all_timestamps imported but unused (F401)


15-15: pyphare.pharesee.plotting imported but unused (F401)


16-16: pathlib.Path imported but unused (F401)

tests/functional/conservation/conserv.py

8-8: os imported but unused (F401)

Additional comments not posted (10)
tests/functional/shock/CMakeLists.txt (2)

10-10: Condition correctly checks for necessary components for the test.


13-13: Execution command correctly configured for MPI environment.

tests/functional/conservation/CMakeLists.txt (2)

10-10: Condition correctly checks for necessary components for the test.


13-13: Execution command correctly configured for MPI environment.

tests/functional/alfven_wave/CMakeLists.txt (2)

10-10: Condition correctly checks for necessary components for the test.


13-13: Execution command correctly configured for MPI environment.

tests/functional/ionIonBeam/CMakeLists.txt (2)

10-10: Condition correctly checks for necessary components for the test.


13-13: Execution command correctly configured for MPI environment.

tests/functional/td/td1d.py (1)

21-22: Changes in simulation configuration appear to be for testing different scenarios.

tests/functional/dispersion/dispersion.py (1)

20-21: Changes in simulation configuration appear to be for testing different scenarios.

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b3a3822 and 451024b.

Files selected for processing (7)
  • src/core/CMakeLists.txt (1 hunks)
  • tests/functional/alfven_wave/CMakeLists.txt (1 hunks)
  • tests/functional/conservation/CMakeLists.txt (1 hunks)
  • tests/functional/dispersion/CMakeLists.txt (1 hunks)
  • tests/functional/harris/CMakeLists.txt (1 hunks)
  • tests/functional/ionIonBeam/CMakeLists.txt (1 hunks)
  • tests/functional/shock/CMakeLists.txt (1 hunks)
Files skipped from review as they are similar to previous changes (5)
  • tests/functional/alfven_wave/CMakeLists.txt
  • tests/functional/conservation/CMakeLists.txt
  • tests/functional/harris/CMakeLists.txt
  • tests/functional/ionIonBeam/CMakeLists.txt
  • tests/functional/shock/CMakeLists.txt
Additional comments not posted (2)
tests/functional/dispersion/CMakeLists.txt (1)

10-12: Ensure phare_python3_exec is correctly defined and used.

Verification successful

Verify the correctness of the phare_python3_exec function definition in res/cmake/def.cmake.


Re-verify the definition of phare_python3_exec in res/cmake/def.cmake with increased context lines.


Re-verify the definition of phare_python3_exec in res/cmake/def.cmake by extracting a larger portion of the file.


The phare_python3_exec function is correctly defined in res/cmake/def.cmake and matches the expected usage in tests/functional/dispersion/CMakeLists.txt.

  • The function phare_python3_exec is defined to execute a Python file identified by the target in a specified directory, with or without MPI based on the testMPI condition.
  • The usage in tests/functional/dispersion/CMakeLists.txt is consistent with this definition.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the definition and usage of `phare_python3_exec`.

# Test: Search for the definition of `phare_python3_exec`. Expect: Definition should exist and match expected usage.
rg --type cmake $'phare_python3_exec'

Length of output: 2095



Script:

#!/bin/bash
# Description: Verify the definition of `phare_python3_exec` in `res/cmake/def.cmake`.

# Test: Extract the definition of `phare_python3_exec` function.
rg --type cmake --context 10 $'function(phare_python3_exec level target file directory)' res/cmake/def.cmake

Length of output: 109



Script:

#!/bin/bash
# Description: Verify the definition of `phare_python3_exec` in `res/cmake/def.cmake`.

# Test: Extract the definition of `phare_python3_exec` function with increased context lines.
rg --type cmake --context 20 $'function(phare_python3_exec level target file directory)' res/cmake/def.cmake

Length of output: 109



Script:

#!/bin/bash
# Description: Verify the definition of `phare_python3_exec` in `res/cmake/def.cmake`.

# Test: Extract a larger portion of the file containing the `phare_python3_exec` function definition.
rg --type cmake --context 50 'phare_python3_exec' res/cmake/def.cmake

Length of output: 7422

src/core/CMakeLists.txt (1)

73-73: Verify the condition for skipping mpicxx in the compile command.

Verification successful

The condition for skipping mpicxx in the compile command is controlled by the phare_configurator option. The search results show that phare_configurator is defined and used in multiple CMake files, including src/core/CMakeLists.txt.

  • tools/config/CMakeLists.txt: Defines the phare_configurator project.
  • src/core/CMakeLists.txt: Contains the condition if (NOT phare_configurator).
  • res/cmake/options.cmake: Defines the phare_configurator option.
  • res/cmake/def.cmake: Uses the phare_configurator condition.

The condition appears to be correctly used in the project. Therefore, the review comment regarding the condition for skipping mpicxx in the compile command is verified.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the condition for skipping `mpicxx`.

# Test: Search for the usage of `phare_configurator`. Expect: Condition should be correctly used in the project.
rg --type cmake $'phare_configurator'

Length of output: 371

@PhilipDeegan PhilipDeegan force-pushed the lb_stats branch 2 times, most recently from ff4f07e to af0a74f Compare June 6, 2024 19:48
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: 10

Outside diff range and nitpick comments (17)
tests/diagnostic/__init__.py (1)

Line range hint 16-16: Refactor imports to follow best practices.

- import pyphare.pharein as ph, numpy as np
+ import pyphare.pharein as ph
+ import numpy as np

Also, ensure that numpy is used if it's being imported, or remove it if it's not necessary.

tests/functional/td/td1d.py (2)

Line range hint 7-7: Remove unused import to clean up the code.

- import matplotlib.pyplot as plt

Line range hint 41-41: Clarify ambiguous variable name.

- def S(x, x0, l):
+ def S(x, x0, length):

Replace l with length to improve readability and avoid confusion with the number 1.

tests/functional/dispersion/dispersion.py (1)

Line range hint 7-7: Remove unused import to clean up the code.

- import matplotlib.pyplot as plt
tests/functional/shock/shock.py (1)

Line range hint 49-49: Rename the variable l to a more descriptive name to avoid confusion with the number 1.

- def S(x, x0, l):
+ def S(x, x0, length):
tests/functional/translation/translat1d.py (2)

Line range hint 7-7: Remove unused import to clean up the code.

- import matplotlib.pyplot as plt

Line range hint 131-131: Rename the variable l to a more descriptive name to avoid confusion with the number 1.

- def S(x, x0, l):
+ def S(x, x0, length):
tests/functional/harris/harris_2d.py (1)

Line range hint 66-66: The variable name l is ambiguous and could be confused with the number 1. Consider renaming it for clarity.

- def S(y, y0, l):
+ def S(y, y0, length):
tests/functional/ionIonBeam/ion_ion_beam1d.py (3)

Line range hint 8-8: Remove unused import tests.diagnostic.all_timestamps to clean up the code.

- from tests.diagnostic import all_timestamps

Line range hint 15-15: Remove unused import pyphare.pharesee.plotting to clean up the code.

- from pyphare.pharesee import plotting

Line range hint 16-16: Remove unused import pathlib.Path to clean up the code.

- from pathlib import Path
tests/functional/conservation/conserv.py (1)

Line range hint 8-8: Remove unused import os to clean up the code.

- import os
pyphare/pyphare/pharein/simulation.py (4)

Line range hint 127-150: Refactor the handling of start_time in check_time function.

- start_time = kwargs.get("restart_options", {}).get("restart_time", 0)
+ start_time = kwargs.get("restart_options", {}).get("restart_time", None)
+ if start_time is None:
+     start_time = 0

This change ensures that start_time is explicitly checked for None before defaulting to 0, aligning with best practices for clarity and error handling.


631-631: Ensure the new keyword system_state_write_every_t is documented.

It would be beneficial to add a comment or documentation string explaining the purpose and usage of the new keyword system_state_write_every_t to aid future maintainers and users of the code.


854-854: Initialization of load_balancer should be documented.

Consider adding a comment here to explain why load_balancer is initialized to None. This could help in understanding the flow and usage of load balancing within the simulation.


Line range hint 954-954: Correct the style of imports to adhere to best practices.

- import dill, codecs
+ import dill
+ import codecs

Splitting the imports into separate lines enhances readability and adheres to Python's PEP 8 style guide.

Also applies to: 960-960

pyphare/pyphare/pharesee/hierarchy.py (1)

Line range hint 668-668: Comparison to None should be cond is None.

- if select is not None:
+ if select is not None:

This change ensures that the comparison to None is done using the recommended Pythonic way, which is more readable and can prevent subtle bugs.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 451024b and af0a74f.

Files selected for processing (57)
  • pyphare/pyphare/core/phare_utilities.py (2 hunks)
  • pyphare/pyphare/pharein/init.py (5 hunks)
  • pyphare/pyphare/pharein/load_balancer.py (1 hunks)
  • pyphare/pyphare/pharein/maxwellian_fluid_model.py (2 hunks)
  • pyphare/pyphare/pharein/simulation.py (7 hunks)
  • pyphare/pyphare/pharesee/hierarchy.py (6 hunks)
  • pyphare/pyphare/pharesee/particles.py (1 hunks)
  • pyphare/pyphare/simulator/simulator.py (8 hunks)
  • pyphare/pyphare_tests/test_pharesee/test_geometry_3d.py (1 hunks)
  • requirements.txt (1 hunks)
  • res/cmake/def.cmake (4 hunks)
  • res/cmake/dep/phlop.cmake (1 hunks)
  • res/cmake/dep/samrai.cmake (1 hunks)
  • src/amr/CMakeLists.txt (2 hunks)
  • src/amr/data/particles/particles_data.hpp (1 hunks)
  • src/amr/level_initializer/hybrid_level_initializer.hpp (2 hunks)
  • src/amr/load_balancing/concrete_load_balancer_hybrid_strategy_homogeneous.hpp (1 hunks)
  • src/amr/load_balancing/concrete_load_balancer_hybrid_strategy_nppc.hpp (1 hunks)
  • src/amr/load_balancing/load_balancer_details.hpp (1 hunks)
  • src/amr/load_balancing/load_balancer_estimator.hpp (1 hunks)
  • src/amr/load_balancing/load_balancer_estimator_hybrid.hpp (1 hunks)
  • src/amr/load_balancing/load_balancer_hybrid_strategy.hpp (1 hunks)
  • src/amr/load_balancing/load_balancer_hybrid_strategy_factory.hpp (1 hunks)
  • src/amr/load_balancing/load_balancer_manager.hpp (1 hunks)
  • src/amr/messengers/hybrid_hybrid_messenger_strategy.hpp (11 hunks)
  • src/amr/multiphysics_integrator.hpp (13 hunks)
  • src/amr/wrappers/integrator.hpp (4 hunks)
  • src/core/CMakeLists.txt (1 hunks)
  • src/core/data/ions/particle_initializers/maxwellian_particle_initializer.hpp (6 hunks)
  • src/core/data/ions/particle_initializers/particle_initializer_factory.hpp (2 hunks)
  • src/core/data/ndarray/ndarray_vector.hpp (1 hunks)
  • src/core/data/particles/particle_array.hpp (1 hunks)
  • src/core/utilities/box/box.hpp (1 hunks)
  • src/hdf5/detail/h5/h5_file.hpp (2 hunks)
  • src/initializer/data_provider.hpp (1 hunks)
  • src/initializer/dictator.cpp (1 hunks)
  • src/simulator/simulator.hpp (6 hunks)
  • tests/core/data/ions/test_ions.cpp (1 hunks)
  • tests/diagnostic/init.py (1 hunks)
  • tests/functional/alfven_wave/CMakeLists.txt (1 hunks)
  • tests/functional/alfven_wave/alfven_wave1d.py (1 hunks)
  • tests/functional/conservation/CMakeLists.txt (1 hunks)
  • tests/functional/conservation/conserv.py (1 hunks)
  • tests/functional/dispersion/CMakeLists.txt (1 hunks)
  • tests/functional/dispersion/dispersion.py (1 hunks)
  • tests/functional/harris/CMakeLists.txt (1 hunks)
  • tests/functional/harris/harris_2d.py (4 hunks)
  • tests/functional/harris/harris_2d_lb.py (1 hunks)
  • tests/functional/ionIonBeam/CMakeLists.txt (1 hunks)
  • tests/functional/ionIonBeam/ion_ion_beam1d.py (1 hunks)
  • tests/functional/shock/CMakeLists.txt (1 hunks)
  • tests/functional/shock/shock.py (1 hunks)
  • tests/functional/td/td1d.py (1 hunks)
  • tests/functional/tdtagged/CMakeLists.txt (1 hunks)
  • tests/functional/translation/CMakeLists.txt (1 hunks)
  • tests/functional/translation/translat1d.py (1 hunks)
  • tests/simulator/CMakeLists.txt (1 hunks)
Files not processed due to max files limit (10)
  • tests/simulator/init.py
  • tests/simulator/refinement/CMakeLists.txt
  • tests/simulator/refinement/test_2d_10_core.py
  • tests/simulator/refinement/test_2d_2_core.py
  • tests/simulator/test_diagnostic_timestamps.py
  • tests/simulator/test_load_balancing.py
  • tests/simulator/test_tagging.py.off
  • tools/config/config.py
  • tools/python3/init.py
  • tools/python3/caliper.py
Files skipped from review due to trivial changes (1)
  • src/core/CMakeLists.txt
Files skipped from review as they are similar to previous changes (37)
  • requirements.txt
  • res/cmake/def.cmake
  • res/cmake/dep/phlop.cmake
  • res/cmake/dep/samrai.cmake
  • src/amr/CMakeLists.txt
  • src/amr/data/particles/particles_data.hpp
  • src/amr/level_initializer/hybrid_level_initializer.hpp
  • src/amr/load_balancing/concrete_load_balancer_hybrid_strategy_homogeneous.hpp
  • src/amr/load_balancing/concrete_load_balancer_hybrid_strategy_nppc.hpp
  • src/amr/load_balancing/load_balancer_details.hpp
  • src/amr/load_balancing/load_balancer_estimator.hpp
  • src/amr/load_balancing/load_balancer_estimator_hybrid.hpp
  • src/amr/load_balancing/load_balancer_hybrid_strategy.hpp
  • src/amr/load_balancing/load_balancer_hybrid_strategy_factory.hpp
  • src/amr/load_balancing/load_balancer_manager.hpp
  • src/amr/messengers/hybrid_hybrid_messenger_strategy.hpp
  • src/amr/multiphysics_integrator.hpp
  • src/core/data/ions/particle_initializers/maxwellian_particle_initializer.hpp
  • src/core/data/ions/particle_initializers/particle_initializer_factory.hpp
  • src/core/data/ndarray/ndarray_vector.hpp
  • src/core/data/particles/particle_array.hpp
  • src/core/utilities/box/box.hpp
  • src/hdf5/detail/h5/h5_file.hpp
  • src/initializer/data_provider.hpp
  • src/initializer/dictator.cpp
  • src/simulator/simulator.hpp
  • tests/core/data/ions/test_ions.cpp
  • tests/functional/alfven_wave/CMakeLists.txt
  • tests/functional/alfven_wave/alfven_wave1d.py
  • tests/functional/conservation/CMakeLists.txt
  • tests/functional/dispersion/CMakeLists.txt
  • tests/functional/harris/CMakeLists.txt
  • tests/functional/ionIonBeam/CMakeLists.txt
  • tests/functional/shock/CMakeLists.txt
  • tests/functional/tdtagged/CMakeLists.txt
  • tests/functional/translation/CMakeLists.txt
  • tests/simulator/CMakeLists.txt
Additional context used
Path-based instructions (1)
src/amr/wrappers/integrator.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

Learnings (2)
pyphare/pyphare/pharein/load_balancer.py (1)
User: PhilipDeegan
PR: PhilipDeegan/PHARE#87
File: pyphare/pyphare/pharein/__init__.py:177-177
Timestamp: 2024-01-16T16:42:31.598Z
Learning: The user has clarified that the validation for the `loadbalancing` parameter is handled within the `simulation.py` file through the `check_loadbalancing` function, which checks for supported types.
pyphare/pyphare/pharein/__init__.py (1)
User: PhilipDeegan
PR: PhilipDeegan/PHARE#87
File: pyphare/pyphare/pharein/__init__.py:177-177
Timestamp: 2024-01-16T16:42:31.598Z
Learning: The user has clarified that the validation for the `loadbalancing` parameter is handled within the `simulation.py` file through the `check_loadbalancing` function, which checks for supported types.
Ruff
pyphare/pyphare_tests/test_pharesee/test_geometry_3d.py

1-1: Undefined name test_geometry_3d (F821)

tests/diagnostic/__init__.py

16-16: Multiple imports on one line (E401)


16-16: numpy imported but unused; consider removing, adding to __all__, or using a redundant alias (F401)

pyphare/pyphare/pharein/load_balancer.py

36-36: f-string without any placeholders (F541)


53-53: f-string without any placeholders (F541)


56-56: f-string without any placeholders (F541)

tests/functional/td/td1d.py

7-7: matplotlib.pyplot imported but unused (F401)


41-41: Ambiguous variable name: l (E741)

tests/functional/dispersion/dispersion.py

7-7: matplotlib.pyplot imported but unused (F401)

pyphare/pyphare/core/phare_utilities.py

159-159: Multiple imports on one line (E401)


181-181: Multiple imports on one line (E401)

tests/functional/shock/shock.py

49-49: Ambiguous variable name: l (E741)

tests/functional/translation/translat1d.py

7-7: matplotlib.pyplot imported but unused (F401)


131-131: Ambiguous variable name: l (E741)

tests/functional/harris/harris_2d.py

66-66: Ambiguous variable name: l (E741)

tests/functional/harris/harris_2d_lb.py

74-74: Ambiguous variable name: l (E741)

tests/functional/ionIonBeam/ion_ion_beam1d.py

8-8: tests.diagnostic.all_timestamps imported but unused (F401)


15-15: pyphare.pharesee.plotting imported but unused (F401)


16-16: pathlib.Path imported but unused (F401)

tests/functional/conservation/conserv.py

8-8: os imported but unused (F401)

pyphare/pyphare/simulator/simulator.py

108-108: Do not use bare except (E722)


131-131: Do not use bare except (E722)


143-143: pyphare.cpp.cpp_lib imported but unused (F401)


162-162: Comparison to None should be cond is not None (E711)

pyphare/pyphare/pharein/maxwellian_fluid_model.py

4-4: pyphare.core.gridlayout.yee_element_is_primal imported but unused (F401)

pyphare/pyphare/pharesee/particles.py

88-88: f-string without any placeholders (F541)

pyphare/pyphare/pharein/__init__.py

32-32: Module level import not at top of file (E402)


32-32: .uniform_model.UniformModel imported but unused; consider removing, adding to __all__, or using a redundant alias (F401)


33-33: Module level import not at top of file (E402)


33-33: .maxwellian_fluid_model.MaxwellianFluidModel imported but unused; consider removing, adding to __all__, or using a redundant alias (F401)


34-34: Module level import not at top of file (E402)


34-34: .electron_model.ElectronModel imported but unused; consider removing, adding to __all__, or using a redundant alias (F401)


35-41: Module level import not at top of file (E402)


36-36: .diagnostics.FluidDiagnostics imported but unused; consider removing, adding to __all__, or using a redundant alias (F401)


37-37: .diagnostics.ElectromagDiagnostics imported but unused; consider removing, adding to __all__, or using a redundant alias (F401)


38-38: .diagnostics.ParticleDiagnostics imported but unused; consider removing, adding to __all__, or using a redundant alias (F401)


39-39: .diagnostics.MetaDiagnostics imported but unused; consider removing, adding to __all__, or using a redundant alias (F401)


40-40: .diagnostics.InfoDiagnostics imported but unused; consider removing, adding to __all__, or using a redundant alias (F401)


42-46: Module level import not at top of file (E402)


43-43: .simulation.Simulation imported but unused; consider removing, adding to __all__, or using a redundant alias (F401)


47-47: Module level import not at top of file (E402)

pyphare/pyphare/pharein/simulation.py

335-335: Comparison to None should be cond is not None (E711)


355-355: Ambiguous variable name: l (E741)


561-561: f-string without any placeholders (F541)


569-569: f-string without any placeholders (F541)


588-588: psutil imported but unused; consider using importlib.util.find_spec to test for availability (F401)


589-589: Local variable e is assigned to but never used (F841)


691-691: Comparison to None should be cond is not None (E711)


954-954: Multiple imports on one line (E401)


960-960: Multiple imports on one line (E401)

pyphare/pyphare/pharesee/hierarchy.py

668-668: Comparison to None should be cond is None (E711)

Additional comments not posted (16)
pyphare/pyphare_tests/test_pharesee/test_geometry_3d.py (1)

1-1: Skip: The previous comment about the undefined name test_geometry_3d still applies.

Tools
Ruff

1-1: Undefined name test_geometry_3d (F821)

tests/functional/dispersion/dispersion.py (1)

20-20: The simulation setup in fromNoise and prescribedModes functions appears correctly implemented.

Also applies to: 21-21

pyphare/pyphare/core/phare_utilities.py (1)

181-181: This comment is still valid and should be addressed:
coderabbitai[bot]: Separate imports onto individual lines.

- import json, psutil, pathlib, datetime
+ import json
+ import psutil
+ import pathlib
+ import datetime

For better readability and to comply with PEP 8 standards, place each import on a separate line.

Tools
Ruff

181-181: Multiple imports on one line (E401)

tests/functional/harris/harris_2d_lb.py (1)

74-74: The variable name l is ambiguous and could be confused with the number 1. Consider renaming it for clarity.

Tools
Ruff

74-74: Ambiguous variable name: l (E741)

pyphare/pyphare/pharein/maxwellian_fluid_model.py (1)

Line range hint 75-127: Addition of density_cut_off parameter approved.

The addition of the density_cut_off parameter to the add_population function is a sensible enhancement for handling low-density scenarios.

src/amr/wrappers/integrator.hpp (5)

36-41: Refactor to improve readability of conditional logic.


166-167: Clarify the necessity of setting SAMRAI MPI.


94-99: Ensure that the rebalance check logic is correctly implemented.

Verification successful

The cadence_rebalance_check method is used as part of the _rebalance_check function, which is called within the _should_rebalance_now method. The logic in cadence_rebalance_check appears to be correctly implemented, as it checks for rebalancing conditions based on time_step_idx and lb_info_.

  • The method checks if time_step_idx is 0 and lb_info_.on_init is true.
  • It also checks if lb_info_.every is greater than 0, time_step_idx is greater than 0, and time_step_idx is a multiple of lb_info_.every.

These conditions seem appropriate for determining when to perform a rebalance.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the rebalance check logic in `cadence_rebalance_check` method is correctly implemented.

# Test: Search for the method usage. Expect: Correct handling of rebalance checks.
rg --type cpp $'bool cadence_rebalance_check()'

Length of output: 115



Script:

#!/bin/bash
# Description: Search for the usage of the `cadence_rebalance_check` method in the codebase.

# Test: Find all occurrences of `cadence_rebalance_check` to understand its usage context.
rg 'cadence_rebalance_check' --type cpp

Length of output: 237



Script:

#!/bin/bash
# Description: Extract the relevant code around the `std::bind` call to understand how `cadence_rebalance_check` is used.

# Test: Print lines around the `std::bind` call to understand the context.
rg 'std::bind(&Integrator::cadence_rebalance_check' -A 5 -B 5 --type cpp

Length of output: 181



Script:

#!/bin/bash
# Description: Extract the relevant code around the `std::bind` call to understand how `cadence_rebalance_check` is used.

# Test: Print lines around the `std::bind` call to understand the context.
rg 'std::bind\(&Integrator::cadence_rebalance_check' -A 5 -B 5 --type cpp

Length of output: 1055



Script:

#!/bin/bash
# Description: Search for the usage of `_rebalance_check` within the `Integrator` class to understand its role.

# Test: Find all occurrences of `_rebalance_check` to understand its usage context.
rg '_rebalance_check' --type cpp

Length of output: 574



Script:

#!/bin/bash
# Description: Extract the relevant code around the `_rebalance_check` call to understand its usage.

# Test: Print lines around the `_rebalance_check` call to understand the context.
rg '_rebalance_check\(\)' -A 5 -B 5 --type cpp

Length of output: 1682


47-53: Ensure that the method advance correctly handles the rebalancing logic.

Verification successful

The _should_rebalance_now method is implemented as follows:

template<std::size_t _dimension>
bool Integrator<_dimension>::_should_rebalance_now()
{
    if (is_tagging_refinement and lb_info_.active)
        return _rebalance_check();

    return false;
}

The advanceHierarchy method is used in the advance method of the Integrator class:

double advance(double dt)
{
    bool rebalance_coarsest_now = _should_rebalance_now();
    auto new_time = timeRefIntegrator_->advanceHierarchy(dt, rebalance_coarsest_now);
    ++time_step_idx;
    return new_time;
}

The _should_rebalance_now method checks if rebalancing is needed based on the conditions is_tagging_refinement and lb_info_.active. If both conditions are met, it calls _rebalance_check() to determine if rebalancing should occur. The result is then used as a parameter in the advanceHierarchy method.

Based on the gathered information, the rebalancing logic in the advance method appears to be correctly implemented.

  • _should_rebalance_now method correctly checks conditions for rebalancing.
  • The result of _should_rebalance_now is used in advanceHierarchy.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the rebalancing logic in `advance` method is correctly implemented.

# Test: Search for the method usage. Expect: Correct handling of rebalancing.
rg --type cpp $'bool rebalance_coarsest_now = _should_rebalance_now();'

Length of output: 72



Script:

#!/bin/bash
# Description: Verify the implementation of `_should_rebalance_now` method.

# Search for the `_should_rebalance_now` method definition.
ast-grep --lang cpp --pattern $'bool _should_rebalance_now() { $$$ }'

# Search for the `advanceHierarchy` method definition.
ast-grep --lang cpp --pattern $'$_ timeRefIntegrator_->advanceHierarchy($_, $_) { $$$ }'

Length of output: 160



Script:

#!/bin/bash
# Description: Verify the implementation of `_should_rebalance_now` method and `advanceHierarchy` method.

# Search for the `_should_rebalance_now` method definition.
rg --type cpp --pcre2 'bool\s+_should_rebalance_now\s*\(\s*\)\s*\{'

# Search for the `advanceHierarchy` method definition.
rg --type cpp --pcre2 'advanceHierarchy\s*\(\s*double\s+\w+\s*,\s*bool\s+\w+\s*\)\s*\{'

Length of output: 159



Script:

#!/bin/bash
# Description: Verify the implementation of `_should_rebalance_now` method and `advanceHierarchy` method.

# Search for the `_should_rebalance_now` method definition.
fd -e cpp -e h -e hpp -e cxx -e cc -e c | xargs rg 'bool\s+_should_rebalance_now\s*\(\s*\)\s*\{'

# Search for the `advanceHierarchy` method definition.
fd -e cpp -e h -e hpp -e cxx -e cc -e c | xargs rg 'advanceHierarchy\s*\(\s*double\s+\w+\s*,\s*bool\s+\w+\s*\)\s*\{'

Length of output: 217



Script:

#!/bin/bash
# Description: Verify the implementation of `_should_rebalance_now` method and `advanceHierarchy` method.

# Search for the `_should_rebalance_now` method definition.
fd -e cpp -e h -e hpp -e cxx -e cc -e c | xargs rg '_should_rebalance_now'

# Search for the `advanceHierarchy` method definition.
fd -e cpp -e h -e hpp -e cxx -e cc -e c | xargs rg 'advanceHierarchy'

Length of output: 707



Script:

#!/bin/bash
# Description: Retrieve the full implementation of `_should_rebalance_now` and `advanceHierarchy` methods.

# Get the full implementation of `_should_rebalance_now` method.
rg --context 10 'bool Integrator<_dimension>::_should_rebalance_now()' src/amr/wrappers/integrator.hpp

# Get the full implementation of `advanceHierarchy` method.
rg --context 10 'advanceHierarchy' src/amr/wrappers/integrator.hpp tests/amr/messengers/test_messengers.cpp

Length of output: 3763


101-127: Review the logic for automatic rebalancing to ensure it adheres to the specified tolerance and backoff settings.

pyphare/pyphare/pharein/__init__.py (1)

47-47: Address the module level import issue.

- from .load_balancer import LoadBalancer
+ # from .load_balancer import LoadBalancer

The import of LoadBalancer is flagged as not being at the top of the file. Consider moving all imports to the top to comply with PEP 8 standards, unless there's a specific reason they are delayed (e.g., to prevent circular dependencies).

Tools
Ruff

47-47: Module level import not at top of file (E402)

pyphare/pyphare/pharesee/hierarchy.py (5)

13-13: Added import for dataclass from the dataclasses module.

This is a standard Python import necessary for using dataclasses, which are used later in the file.


91-93: Added equality method __eq__ for FieldData.

This method correctly compares field_name and the contents of dataset arrays. It ensures that two FieldData instances are considered equal if they have the same field name and identical data.


229-231: Added equality method __eq__ for ParticleData.

This method ensures that two ParticleData instances are considered equal if they have the same name and identical datasets. This is crucial for operations that require comparison of particle data across different simulations or time steps.


258-260: Added method __getitem__ to the Patch class.

This method allows for direct indexing into patch_datas using keys, which simplifies access to data within a patch. It enhances the usability of the Patch class by allowing it to behave more like a dictionary.


1809-1861: Added EqualityReport dataclass and hierarchy_compare function.

The EqualityReport dataclass is well-defined and provides a structured way to report equality checks. The hierarchy_compare function is comprehensive and checks various aspects of PatchHierarchy objects to ensure they are equivalent. This is useful for validating the consistency of hierarchies across different parts of the application or in different states of computation.

Comment on lines +79 to +90
auto computeNonUniformWorkLoadForLevel0() const
{
auto const& L0 = *timeRefIntegrator_->getPatchHierarchy()->getPatchLevel(0);
double load = 0.0;
for (SAMRAI::hier::PatchLevel::iterator ip(L0.begin()); ip != L0.end(); ++ip)
{
std::shared_ptr<SAMRAI::hier::Patch> const& patch = *ip;
load += SAMRAI::mesh::BalanceUtilities::computeNonUniformWorkload(
patch, loadBalancerPatchId_, patch->getBox());
}
return load;
}
Copy link

Choose a reason for hiding this comment

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

Optimize the computation of non-uniform workload.

- auto const& L0 = *timeRefIntegrator_->getPatchHierarchy()->getPatchLevel(0);
- double load    = 0.0;
- for (SAMRAI::hier::PatchLevel::iterator ip(L0.begin()); ip != L0.end(); ++ip)
- {
-     std::shared_ptr<SAMRAI::hier::Patch> const& patch = *ip;
-     load += SAMRAI::mesh::BalanceUtilities::computeNonUniformWorkload(
-         patch, loadBalancerPatchId_, patch->getBox());
- }
- return load;
+ return std::accumulate(L0.begin(), L0.end(), 0.0, [this](double load, auto& patch) {
+     return load + SAMRAI::mesh::BalanceUtilities::computeNonUniformWorkload(
+         patch, loadBalancerPatchId_, patch->getBox());
+ });
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.

Suggested change
auto computeNonUniformWorkLoadForLevel0() const
{
auto const& L0 = *timeRefIntegrator_->getPatchHierarchy()->getPatchLevel(0);
double load = 0.0;
for (SAMRAI::hier::PatchLevel::iterator ip(L0.begin()); ip != L0.end(); ++ip)
{
std::shared_ptr<SAMRAI::hier::Patch> const& patch = *ip;
load += SAMRAI::mesh::BalanceUtilities::computeNonUniformWorkload(
patch, loadBalancerPatchId_, patch->getBox());
}
return load;
}
auto computeNonUniformWorkLoadForLevel0() const
{
auto const& L0 = *timeRefIntegrator_->getPatchHierarchy()->getPatchLevel(0);
return std::accumulate(L0.begin(), L0.end(), 0.0, [this](double load, auto& patch) {
return load + SAMRAI::mesh::BalanceUtilities::computeNonUniformWorkload(
patch, loadBalancerPatchId_, patch->getBox());
});
}


def __post_init__(self):
if self.auto and self.every:
raise RuntimeError(f"LoadBalancer cannot work with both 'every' and 'auto'")
Copy link

Choose a reason for hiding this comment

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

Remove unnecessary f-strings as there are no placeholders.

- raise RuntimeError(f"LoadBalancer cannot work with both 'every' and 'auto'")
+ raise RuntimeError("LoadBalancer cannot work with both 'every' and 'auto'")
- raise RuntimeError(f"LoadBalancer cannot be registered as no simulation exists")
+ raise RuntimeError("LoadBalancer cannot be registered as no simulation exists")
- raise RuntimeError(f"LoadBalancer is already registered to simulation")
+ raise RuntimeError("LoadBalancer is already registered to simulation")

Also applies to: 53-53, 56-56

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.

Suggested change
raise RuntimeError(f"LoadBalancer cannot work with both 'every' and 'auto'")
raise RuntimeError("LoadBalancer cannot work with both 'every' and 'auto'")
Tools
Ruff

36-36: f-string without any placeholders (F541)

Comment on lines +38 to +43
def print_rank0(*args, **kwargs):
from pyphare.cpp import cpp_lib

if cpp_lib().mpi_rank() == 0:
print(*args, **kwargs)

Copy link

Choose a reason for hiding this comment

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

Add error handling for MPI operations.

Consider adding error handling mechanisms to ensure robustness against MPI failures in the print_rank0 function.

Comment on lines +259 to +275
def write_system_state_stats(self):
import pyphare.core.phare_utilities as pu
from pyphare.cpp import cpp_lib

if self.simulation.system_state_write_every_t == 0:
return
diff_time = self.cpp_sim.currentTime() - self.write_system_state_time
if (
pu.fp_equal(diff_time, self.simulation.system_state_write_every_t)
or diff_time > self.simulation.system_state_write_every_t
):
self.write_system_state_time = self.cpp_sim.currentTime()
time = "{:.10f}".format(self.cpp_sim.currentTime())
pu.write_system_state_stats(
f".phare/sys/stats/{cpp_lib().mpi_rank()}/{time}"
)

Copy link

Choose a reason for hiding this comment

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

Add file path validation and exception handling.

The method write_system_state_stats does not include file path validation or exception handling. Consider adding these to ensure robustness and correctness.

Comment on lines +45 to +58
def plot_timestep_time(timestep_times):
from pyphare.cpp import cpp_lib

if cpp_lib().mpi_rank() == 0:
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.plot(timestep_times)
plt.ylabel("timestep time")
plt.xlabel("timestep")
fig.savefig("timestep_times.png")

cpp_lib().mpi_barrier()

Copy link

Choose a reason for hiding this comment

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

Add error handling for MPI operations.

Consider adding error handling mechanisms to ensure robustness against MPI failures in the plot_timestep_time function.

Comment on lines +277 to +303
def single_patch_per_level_per_pop_from(hier, only_keep_L0=True): # dragons
for tidx in hier.times():
if only_keep_L0:
hier.time_hier[tidx] = {0: hier.time_hier[tidx][0]}

patch_levels = hier.time_hier[tidx]

for level_idx in patch_levels.keys():
patch_level = patch_levels[level_idx]

patch0 = patch_level.patches[0]
particles = {} # str:[]

for key in patch0.patch_datas.keys():
if isinstance(patch0[key].dataset, Particles):
particles[key] = []

for patch in patch_level.patches:
for patch_data_key in patch.patch_datas.keys():
particles[key] += [patch[patch_data_key].dataset]

for key in particles.keys():
patch0[key].dataset = aggregate(particles[key])

patch_levels[level_idx].patches = [patch0] # just one patch

return hier
Copy link

Choose a reason for hiding this comment

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

Handle empty patches in single_patch_per_level_per_pop_from.

The function single_patch_per_level_per_pop_from does not explicitly handle empty patches. Please add a check to handle empty patches to ensure the function works correctly in all scenarios.

@@ -1,11 +1,13 @@
#!/usr/bin/env python3
import os
import numpy as np
from pathlib import Path
Copy link

Choose a reason for hiding this comment

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

Consider removing unused import Path to clean up the code.

- from pathlib import Path
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.

Suggested change
from pathlib import Path

Comment on lines +584 to +594
def check_system_state_writes(**kwargs):
write_time = kwargs.get("system_state_write_every_t", 0)
if write_time > 0:
try:
import psutil
except ImportError as e:
raise ValueError(
"psutil is not available for writing system usage information"
)
return write_time

Copy link

Choose a reason for hiding this comment

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

Handle the import of psutil more gracefully and remove unused variable.

- import psutil
- except ImportError as e:
+ except ImportError:
+     psutil = None

This modification ensures that if psutil is not available, the function can still proceed without crashing, and it removes the unused variable e.

Committable suggestion was skipped due to low confidence.

Tools
Ruff

588-588: psutil imported but unused; consider using importlib.util.find_spec to test for availability (F401)


589-589: Local variable e is assigned to but never used (F841)

@PhilipDeegan PhilipDeegan force-pushed the lb_stats branch 3 times, most recently from 6fbf63e to 204f53e Compare June 6, 2024 22:29
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 (2)
tests/simulator/test_run.py (1)

Line range hint 60-60: Rename variable l to length to avoid ambiguity with the number 1.

- def S(y, y0, l):
+ def S(y, y0, length):
tools/config/config.py (1)

Line range hint 150-150: Remove the unused local variable mpi_type.

- mpi_type = "unknown"
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between af0a74f and 204f53e.

Files selected for processing (12)
  • tests/diagnostic/CMakeLists.txt (1 hunks)
  • tests/diagnostic/job_1d_1core.py (1 hunks)
  • tests/diagnostic/job_1d_2core.py (1 hunks)
  • tests/diagnostic/job_2d_1core.py (1 hunks)
  • tests/diagnostic/job_2d_2core.py (1 hunks)
  • tests/diagnostic/test-diagnostics_1d.cpp (1 hunks)
  • tests/diagnostic/test-diagnostics_2d.cpp (1 hunks)
  • tests/simulator/refinement/CMakeLists.txt (1 hunks)
  • tests/simulator/refinement/test_2d_10_core.py (2 hunks)
  • tests/simulator/test_diagnostic_timestamps.py (6 hunks)
  • tests/simulator/test_run.py (6 hunks)
  • tools/config/config.py (1 hunks)
Files skipped from review due to trivial changes (2)
  • tests/diagnostic/job_2d_2core.py
  • tests/simulator/refinement/CMakeLists.txt
Additional context used
Ruff
tests/simulator/refinement/test_2d_10_core.py

132-132: Module level import not at top of file (E402)


134-134: Module level import not at top of file (E402)

tests/simulator/test_diagnostic_timestamps.py

6-6: Module level import not at top of file (E402)


7-7: Module level import not at top of file (E402)


9-9: Module level import not at top of file (E402)


10-10: Module level import not at top of file (E402)


11-11: Module level import not at top of file (E402)


12-12: Module level import not at top of file (E402)


13-13: Module level import not at top of file (E402)


14-14: Module level import not at top of file (E402)


15-15: Module level import not at top of file (E402)


16-16: Module level import not at top of file (E402)


17-17: Module level import not at top of file (E402)

tests/simulator/test_run.py

60-60: Ambiguous variable name: l (E741)

tools/config/config.py

150-150: Local variable mpi_type is assigned to but never used (F841)

Additional comments not posted (8)
tests/diagnostic/job_1d_1core.py (1)

8-8: Change in output directory is appropriate for organizing diagnostic outputs.

tests/diagnostic/job_2d_1core.py (1)

8-8: Change in output directory is consistent with the 2D diagnostic setup.

tests/diagnostic/job_1d_2core.py (1)

8-8: Change in output directory is tailored for a 2-core setup, aligning with scaling tests or similar scenarios.

tests/diagnostic/test-diagnostics_1d.cpp (1)

6-8: Dynamic configuration of job file and output directory based on the number of cores enhances test flexibility and robustness.

tests/diagnostic/test-diagnostics_2d.cpp (1)

6-7: Ensure that the dynamically generated job_file and out_dir are correctly handled in all contexts where they are used.

Verification successful

The job_file and out_dir variables are used in multiple test functions within test-diagnostics_2d.cpp and test-diagnostics_1d.cpp. Specifically, they are used in the following functions in test-diagnostics_2d.cpp:

  • fluid_test(TypeParam{job_file}, out_dir);
  • particles_test(TypeParam{job_file}, out_dir);
  • electromag_test(TypeParam{job_file}, out_dir);
  • allFromPython_test(TypeParam{job_file}, out_dir);

These functions are expected to handle the dynamically generated job_file and out_dir correctly. The same pattern is observed in test-diagnostics_1d.cpp.

Based on the results, it appears that the variables are consistently used across the test functions. There are no indications of mishandling or incorrect usage.

  • tests/diagnostic/test-diagnostics_2d.cpp: fluid_test(TypeParam{job_file}, out_dir);

  • tests/diagnostic/test-diagnostics_2d.cpp: particles_test(TypeParam{job_file}, out_dir);

  • tests/diagnostic/test-diagnostics_2d.cpp: electromag_test(TypeParam{job_file}, out_dir);

  • tests/diagnostic/test-diagnostics_2d.cpp: allFromPython_test(TypeParam{job_file}, out_dir);

  • tests/diagnostic/test-diagnostics_1d.cpp: fluid_test(TypeParam{job_file}, out_dir);

  • tests/diagnostic/test-diagnostics_1d.cpp: particles_test(TypeParam{job_file}, out_dir);

  • tests/diagnostic/test-diagnostics_1d.cpp: electromag_test(TypeParam{job_file}, out_dir);

  • tests/diagnostic/test-diagnostics_1d.cpp: allFromPython_test(TypeParam{job_file}, out_dir);

The review comment is verified, and the dynamically generated job_file and out_dir are correctly handled in all contexts where they are used.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that `job_file` and `out_dir` are correctly handled.
# Test: Search for usages of `job_file` and `out_dir`. Expect: Proper handling in all contexts.
rg --type cpp $'job_file|out_dir'

Length of output: 1336

tests/diagnostic/CMakeLists.txt (1)

5-8: Ensure that the conditional copying of Python files does not lead to missing dependencies during the build process.

tests/simulator/refinement/test_2d_10_core.py (1)

200-200: Ensure that the refinement_boxes dictionary is correctly structured and used within the simulation configuration.

Verification successful

The refinement_boxes dictionary is used extensively throughout the codebase, particularly in various test files and simulation configurations. The structure and usage appear consistent with the intended design.

  • tests/simulator/refinement/test_2d_10_core.py: The refinement_boxes dictionary is correctly structured and used within the simulation configuration.

No issues were found with the structure or usage of refinement_boxes.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the structure and usage of `refinement_boxes`.
# Test: Search for usages of `refinement_boxes`. Expect: Correct structure and usage.
rg --type python $'refinement_boxes'

Length of output: 66



Script:

#!/bin/bash
# Description: Verify the structure and usage of `refinement_boxes`.
# Test: Search for usages of `refinement_boxes`. Expect: Correct structure and usage.
rg 'refinement_boxes' --type py

Length of output: 16778

tests/simulator/test_diagnostic_timestamps.py (1)

17-17: Ensure that the SimulatorTest import is correctly utilized in the test suite.

Verification successful

The SimulatorTest class is correctly utilized in the test suite, as evidenced by its usage in multiple test files.

  • tests/simulator/test_diagnostic_timestamps.py: SimulatorTest is imported and used as a base class for DiagnosticsTest.

Other files also show similar usage, confirming that the import is appropriate and consistent across the test suite.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of `SimulatorTest`.
# Test: Search for usages of `SimulatorTest`. Expect: Correct utilization in the test suite.
rg --type python $'SimulatorTest'

Length of output: 63



Script:

#!/bin/bash
# Description: Verify the usage of `SimulatorTest`.
# Test: Search for usages of `SimulatorTest`. Expect: Correct utilization in the test suite.
rg 'SimulatorTest' --type py

Length of output: 1588

Tools
Ruff

17-17: Module level import not at top of file (E402)

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 204f53e and 4f43003.

Files selected for processing (7)
  • tests/diagnostic/CMakeLists.txt (2 hunks)
  • tests/diagnostic/job_1d_1core.py (1 hunks)
  • tests/diagnostic/job_1d_2core.py (1 hunks)
  • tests/diagnostic/job_2d_1core.py (1 hunks)
  • tests/diagnostic/job_2d_2core.py (1 hunks)
  • tests/diagnostic/test-diagnostics_1d.cpp (1 hunks)
  • tests/diagnostic/test-diagnostics_2d.cpp (1 hunks)
Files skipped from review as they are similar to previous changes (7)
  • tests/diagnostic/CMakeLists.txt
  • tests/diagnostic/job_1d_1core.py
  • tests/diagnostic/job_1d_2core.py
  • tests/diagnostic/job_2d_1core.py
  • tests/diagnostic/job_2d_2core.py
  • tests/diagnostic/test-diagnostics_1d.cpp
  • tests/diagnostic/test-diagnostics_2d.cpp

@PhilipDeegan PhilipDeegan force-pushed the lb_stats branch 2 times, most recently from 4b4fc76 to 4d75f9c Compare June 7, 2024 07:46
@PhilipDeegan PhilipDeegan force-pushed the lb_stats branch 2 times, most recently from 9b81fa8 to 7080605 Compare June 7, 2024 11:12
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: 1

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4f43003 and 8c77fdf.

Files selected for processing (10)
  • tests/diagnostic/CMakeLists.txt (2 hunks)
  • tests/diagnostic/job_1d_1core.py (1 hunks)
  • tests/diagnostic/job_1d_2core.py (1 hunks)
  • tests/diagnostic/job_2d_1core.py (1 hunks)
  • tests/diagnostic/job_2d_2core.py (1 hunks)
  • tests/diagnostic/test-diagnostics_1d.cpp (1 hunks)
  • tests/diagnostic/test-diagnostics_2d.cpp (1 hunks)
  • tests/functional/alfven_wave/CMakeLists.txt (1 hunks)
  • tests/functional/harris/CMakeLists.txt (1 hunks)
  • tools/config/config.py (1 hunks)
Files skipped from review as they are similar to previous changes (9)
  • tests/diagnostic/CMakeLists.txt
  • tests/diagnostic/job_1d_1core.py
  • tests/diagnostic/job_1d_2core.py
  • tests/diagnostic/job_2d_1core.py
  • tests/diagnostic/job_2d_2core.py
  • tests/diagnostic/test-diagnostics_1d.cpp
  • tests/diagnostic/test-diagnostics_2d.cpp
  • tests/functional/alfven_wave/CMakeLists.txt
  • tests/functional/harris/CMakeLists.txt
Additional context used
Ruff
tools/config/config.py

150-150: Local variable mpi_type is assigned to but never used (F841)

@PhilipDeegan PhilipDeegan force-pushed the lb_stats branch 2 times, most recently from 5c1ac06 to 9aacbfe Compare June 9, 2024 09:54
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: 5

Outside diff range and nitpick comments (8)
tests/functional/td/td1d.py (1)

Line range hint 41-41: Ambiguous variable name: l.

Consider renaming l to length or another descriptive name to improve code readability.

tests/functional/dispersion/dispersion.py (1)

Line range hint 7-7: Unused import: matplotlib.pyplot.

Consider removing the unused import to clean up the code.

tests/functional/shock/shock.py (1)

Line range hint 49-49: Ambiguous variable name: l.

Consider renaming l to length or another descriptive name to improve code readability.

tests/functional/translation/translat1d.py (1)

Line range hint 131-131: Ambiguous variable name l used in the function S. Consider renaming it to something more descriptive to improve code readability.

tests/functional/harris/harris_2d.py (1)

Line range hint 67-67: Ambiguous variable name l used in the function S. Consider renaming it to something more descriptive to improve code readability.

tests/simulator/test_run.py (1)

Line range hint 60-60: Consider renaming the variable l to something more descriptive to avoid ambiguity.

tests/functional/ionIonBeam/ion_ion_beam1d.py (1)

Line range hint 8-8: Remove unused imports to clean up the code.

- from tests.diagnostic import all_timestamps
- from pyphare.pharesee.plotting import plotting
- from pathlib import Path

Also applies to: 15-15, 16-16

tests/functional/conservation/conserv.py (1)

Line range hint 8-8: Remove the unused import to clean up the code.

- import os
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8c77fdf and 9aacbfe.

Files selected for processing (31)
  • res/cmake/dep/phlop.cmake (1 hunks)
  • tests/diagnostic/CMakeLists.txt (2 hunks)
  • tests/diagnostic/job_1d_1core.py (1 hunks)
  • tests/diagnostic/job_1d_2core.py (1 hunks)
  • tests/diagnostic/job_2d_1core.py (1 hunks)
  • tests/diagnostic/job_2d_2core.py (1 hunks)
  • tests/diagnostic/test-diagnostics_1d.cpp (1 hunks)
  • tests/diagnostic/test-diagnostics_2d.cpp (1 hunks)
  • tests/functional/alfven_wave/CMakeLists.txt (1 hunks)
  • tests/functional/alfven_wave/alfven_wave1d.py (1 hunks)
  • tests/functional/conservation/CMakeLists.txt (1 hunks)
  • tests/functional/conservation/conserv.py (1 hunks)
  • tests/functional/dispersion/CMakeLists.txt (1 hunks)
  • tests/functional/dispersion/dispersion.py (1 hunks)
  • tests/functional/harris/CMakeLists.txt (1 hunks)
  • tests/functional/harris/harris_2d.py (4 hunks)
  • tests/functional/ionIonBeam/CMakeLists.txt (1 hunks)
  • tests/functional/ionIonBeam/ion_ion_beam1d.py (1 hunks)
  • tests/functional/shock/CMakeLists.txt (1 hunks)
  • tests/functional/shock/shock.py (1 hunks)
  • tests/functional/td/td1d.py (1 hunks)
  • tests/functional/tdtagged/CMakeLists.txt (1 hunks)
  • tests/functional/translation/CMakeLists.txt (1 hunks)
  • tests/functional/translation/translat1d.py (1 hunks)
  • tests/simulator/CMakeLists.txt (1 hunks)
  • tests/simulator/refinement/CMakeLists.txt (1 hunks)
  • tests/simulator/refinement/test_2d_10_core.py (2 hunks)
  • tests/simulator/test_diagnostic_timestamps.py (6 hunks)
  • tests/simulator/test_run.py (6 hunks)
  • tools/config/config.py (1 hunks)
  • tools/python3/plotting.py (1 hunks)
Files skipped from review due to trivial changes (1)
  • tests/functional/shock/CMakeLists.txt
Files skipped from review as they are similar to previous changes (18)
  • res/cmake/dep/phlop.cmake
  • tests/diagnostic/CMakeLists.txt
  • tests/diagnostic/job_1d_1core.py
  • tests/diagnostic/job_1d_2core.py
  • tests/diagnostic/job_2d_1core.py
  • tests/diagnostic/job_2d_2core.py
  • tests/diagnostic/test-diagnostics_1d.cpp
  • tests/diagnostic/test-diagnostics_2d.cpp
  • tests/functional/alfven_wave/CMakeLists.txt
  • tests/functional/alfven_wave/alfven_wave1d.py
  • tests/functional/conservation/CMakeLists.txt
  • tests/functional/dispersion/CMakeLists.txt
  • tests/functional/harris/CMakeLists.txt
  • tests/functional/ionIonBeam/CMakeLists.txt
  • tests/functional/tdtagged/CMakeLists.txt
  • tests/functional/translation/CMakeLists.txt
  • tests/simulator/CMakeLists.txt
  • tests/simulator/refinement/CMakeLists.txt
Additional context used
Ruff
tests/functional/td/td1d.py

7-7: matplotlib.pyplot imported but unused (F401)


41-41: Ambiguous variable name: l (E741)

tests/functional/dispersion/dispersion.py

7-7: matplotlib.pyplot imported but unused (F401)

tests/functional/shock/shock.py

49-49: Ambiguous variable name: l (E741)

tests/simulator/refinement/test_2d_10_core.py

132-132: Module level import not at top of file (E402)


134-134: Module level import not at top of file (E402)

tests/functional/translation/translat1d.py

7-7: matplotlib.pyplot imported but unused (F401)


131-131: Ambiguous variable name: l (E741)

tests/functional/harris/harris_2d.py

67-67: Ambiguous variable name: l (E741)

tests/simulator/test_diagnostic_timestamps.py

6-6: Module level import not at top of file (E402)


7-7: Module level import not at top of file (E402)


9-9: Module level import not at top of file (E402)


10-10: Module level import not at top of file (E402)


11-11: Module level import not at top of file (E402)


12-12: Module level import not at top of file (E402)


13-13: Module level import not at top of file (E402)


14-14: Module level import not at top of file (E402)


15-15: Module level import not at top of file (E402)


16-16: Module level import not at top of file (E402)


17-17: Module level import not at top of file (E402)

tests/simulator/test_run.py

60-60: Ambiguous variable name: l (E741)

tests/functional/ionIonBeam/ion_ion_beam1d.py

8-8: tests.diagnostic.all_timestamps imported but unused (F401)


15-15: pyphare.pharesee.plotting imported but unused (F401)


16-16: pathlib.Path imported but unused (F401)

tools/config/config.py

150-150: Local variable mpi_type is assigned to but never used (F841)

tests/functional/conservation/conserv.py

8-8: os imported but unused (F401)

Additional comments not posted (5)
tools/python3/plotting.py (1)

18-26: Improved exception handling in plot_run_timer_data.

Consider adding more specific logging details for each exception type to aid in debugging.

tests/simulator/refinement/test_2d_10_core.py (1)

200-200: Added refinement_boxes to the simulation configuration. Ensure that the specified refinement boxes are appropriate for the simulation's domain and resolution requirements.

tests/simulator/test_run.py (2)

186-186: The plotting functionality appears to be correctly implemented.


206-209: The file existence and size check are implemented correctly.

tools/config/config.py (1)

247-247: Remove the unused local variable mpi_type as it is assigned but never used.

- mpi_type = deduce_mpi_type_from(mpi_results["MPI_Get_library_version"])

Likely invalid or redundant comment.

Comment on lines +21 to +22
# smallest_patch_size=20,
# largest_patch_size=20,
Copy link

Choose a reason for hiding this comment

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

Commented-out patch size settings.

Consider removing or explaining these commented-out lines to maintain code clarity.

Comment on lines +25 to +26
# smallest_patch_size=10,
# largest_patch_size=20,
Copy link

Choose a reason for hiding this comment

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

The commented-out parameters for smallest_patch_size, largest_patch_size, and boundary_types are removed. If these are intentional and permanent removals, consider cleaning up by removing these commented lines to avoid confusion.

Comment on lines +23 to +24
# smallest_patch_size=20,
# largest_patch_size=20,
Copy link

Choose a reason for hiding this comment

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

The commented-out parameters for smallest_patch_size and largest_patch_size are removed. If these are intentional and permanent removals, consider cleaning up by removing these commented lines to avoid confusion.

time_step=time_step,
# boundary_types="periodic",
cells=(200, 400),
dl=(0.2, 0.2),
cells=(400, 400),
Copy link

Choose a reason for hiding this comment

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

The hardcoded cell size (400, 400) might not be flexible for different simulation scenarios. Consider making this configurable.

- cells=(400, 400),
+ cells=configurable_cells,  # Ensure `configurable_cells` is defined and validated elsewhere
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
cells=(400, 400),
cells=configurable_cells, # Ensure `configurable_cells` is defined and validated elsewhere

@PhilipDeegan PhilipDeegan force-pushed the lb_stats branch 2 times, most recently from 99392ed to feb7855 Compare June 13, 2024 11:55
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: 11

Outside diff range and nitpick comments (20)
tests/simulator/CMakeLists.txt (1)

27-27: Add a comment explaining why the phare_mpi_python3_exec for load balancing is not applicable in serial mode.

tests/functional/td/td1d.py (2)

21-22: Remove or clarify the commented-out patch size settings to enhance code clarity and maintainability.


Line range hint 41-41: Replace ambiguous variable name 'l' with a more descriptive name to improve code readability and avoid potential confusion with the number '1'.

-    def S(x, x0, l):
+    def S(x, x0, length):
tests/functional/dispersion/dispersion.py (1)

Line range hint 7-7: Remove the unused import matplotlib.pyplot to clean up the code and adhere to best practices.

- import matplotlib.pyplot as plt
tests/functional/shock/shock.py (3)

Line range hint 39-39: Convert to f-string for consistency and modern Python practices.

-            "options": {"dir": "shock_{}".format(interp_order), "mode": "overwrite"},
+            "options": {"dir": f"shock_{interp_order}", "mode": "overwrite"},

Line range hint 49-49: Consider renaming the variable l to length to avoid ambiguity with the number 1.

-    def S(x, x0, l):
+    def S(x, x0, length):

Line range hint 138-138: Convert to f-string for consistency and modern Python practices across multiple lines.

-    "ffmpeg -r 10 -y -pattern_type glob -i 'shock_{}/shock_By_{}_*.png' -c:v libx264 -crf 0 shock_interp{}.mp4".format(
-        interp_order, interp_order, interp_order
+    f"ffmpeg -r 10 -y -pattern_type glob -i 'shock_{interp_order}/shock_By_{interp_order}_*.png' -c:v libx264 -crf 0 shock_interp{interp_order}.mp4"

Also applies to: 142-142, 150-152, 156-158, 178-178

tests/simulator/refinement/test_2d_10_core.py (4)

Line range hint 21-21: Avoid using mutable default arguments for function parameters to prevent unexpected behavior.

- def config(diag_outputs, model_init={}, refinement_boxes=None):
+ def config(diag_outputs, model_init=None, refinement_boxes=None):
+     if model_init is None:
+         model_init = {}

Line range hint 120-120: Convert to f-string for consistency and modern Python practices.

-        time = "{:.10f}".format(time)
+        time = f"{time:.10f}"

Line range hint 142-142: Avoid using mutable default arguments for function parameters to prevent unexpected behavior.

- def make_fig(hier, fig_name, ilvl, extra_collections=[]):
+ def make_fig(hier, fig_name, ilvl, extra_collections=None):
+     if extra_collections is None:
+         extra_collections = []

Line range hint 166-166: Rename unused loop control variable to underscore to indicate it's intentionally unused.

-    for ilvl, lvl in hier.levels().items():
+    for _ilvl, lvl in hier.levels().items():
tests/functional/alfven_wave/alfven_wave1d.py (1)

Line range hint 188-188: Convert to f-string for consistency and modern Python practices.

-        ax.set_title(r"$V_\phi = {:6.4f}$".format(vphi.mean()))
+        ax.set_title(rf"$V_\phi = {vphi.mean():6.4f}$")
tests/functional/translation/translat1d.py (2)

Line range hint 7-7: Remove unused import to clean up the code.

- import matplotlib.pyplot as plt

Line range hint 131-131: Consider renaming the variable l to length to avoid ambiguity with the number 1.

-    def S(x, x0, l):
+    def S(x, x0, length):
tests/simulator/test_run.py (2)

Line range hint 214-214: Use super() instead of super(RunTest, self) for simplicity and modern Python style.

- super(RunTest, self).__init__(*args, **kwargs)
+ super().__init__(*args, **kwargs)
- super(RunTest, self).tearDown()
+ super().tearDown()

Also applies to: 218-218


Line range hint 60-60: Ambiguous variable name: l. Consider renaming it to length for clarity.

- def S(y, y0, l):
+ def S(y, y0, length):
tests/functional/ionIonBeam/ion_ion_beam1d.py (1)

26-27: Ensure that the commented out smallest_patch_size and largest_patch_size are intentionally left out or should be removed if not needed.

tools/config/config.py (1)

Line range hint 262-262: Rename the unused loop control variable k to _k to indicate it is intentionally unused.

- for k, v in GENERATED_CONFIGS.items():
+ for _k, v in GENERATED_CONFIGS.items():
tests/functional/conservation/conserv.py (2)

Line range hint 34-34: Convert the format call to an f-string for improved readability and performance.

- "options": {"dir": "vth{}dx{}".format(vth, dl), "mode": "overwrite"},
+ "options": {"dir": f"vth{vth}dx{dl}", "mode": "overwrite"},

Line range hint 137-137: Rename the unused loop control variable ip to _ip to indicate it is intentionally unused.

- for ip, patch in enumerate(lvl.patches):
+ for _ip, patch in enumerate(lvl.patches):

Also applies to: 157-157

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9aacbfe and 821c71e.

Files selected for processing (32)
  • res/cmake/dep/phlop.cmake (1 hunks)
  • tests/diagnostic/CMakeLists.txt (2 hunks)
  • tests/diagnostic/job_1d_1core.py (1 hunks)
  • tests/diagnostic/job_1d_2core.py (1 hunks)
  • tests/diagnostic/job_2d_1core.py (1 hunks)
  • tests/diagnostic/job_2d_2core.py (1 hunks)
  • tests/diagnostic/test-diagnostics_1d.cpp (1 hunks)
  • tests/diagnostic/test-diagnostics_2d.cpp (1 hunks)
  • tests/functional/alfven_wave/CMakeLists.txt (1 hunks)
  • tests/functional/alfven_wave/alfven_wave1d.py (1 hunks)
  • tests/functional/conservation/CMakeLists.txt (1 hunks)
  • tests/functional/conservation/conserv.py (1 hunks)
  • tests/functional/dispersion/CMakeLists.txt (1 hunks)
  • tests/functional/dispersion/dispersion.py (1 hunks)
  • tests/functional/harris/CMakeLists.txt (1 hunks)
  • tests/functional/harris/harris_2d.py (4 hunks)
  • tests/functional/harris/harris_2d_lb.py (1 hunks)
  • tests/functional/ionIonBeam/CMakeLists.txt (1 hunks)
  • tests/functional/ionIonBeam/ion_ion_beam1d.py (1 hunks)
  • tests/functional/shock/CMakeLists.txt (1 hunks)
  • tests/functional/shock/shock.py (1 hunks)
  • tests/functional/td/td1d.py (1 hunks)
  • tests/functional/tdtagged/CMakeLists.txt (1 hunks)
  • tests/functional/translation/CMakeLists.txt (1 hunks)
  • tests/functional/translation/translat1d.py (1 hunks)
  • tests/simulator/CMakeLists.txt (1 hunks)
  • tests/simulator/refinement/CMakeLists.txt (1 hunks)
  • tests/simulator/refinement/test_2d_10_core.py (2 hunks)
  • tests/simulator/test_diagnostic_timestamps.py (6 hunks)
  • tests/simulator/test_run.py (6 hunks)
  • tools/config/config.py (1 hunks)
  • tools/python3/plotting.py (1 hunks)
Files not summarized due to errors (9)
  • tests/diagnostic/job_2d_1core.py: Error: Server error. Please try again later.
  • tests/functional/td/td1d.py: Error: Server error. Please try again later.
  • tests/functional/shock/CMakeLists.txt: Error: Server error. Please try again later.
  • tests/simulator/refinement/test_2d_10_core.py: Error: Server error. Please try again later.
  • tests/simulator/CMakeLists.txt: Error: Server error. Please try again later.
  • tools/config/config.py: Error: Server error. Please try again later.
  • res/cmake/dep/phlop.cmake: Error: Server error. Please try again later.
  • tests/diagnostic/CMakeLists.txt: Error: Server error. Please try again later.
  • tests/functional/shock/shock.py: Error: Server error. Please try again later.
Files skipped from review as they are similar to previous changes (13)
  • tests/diagnostic/job_1d_1core.py
  • tests/diagnostic/job_1d_2core.py
  • tests/diagnostic/job_2d_2core.py
  • tests/diagnostic/test-diagnostics_1d.cpp
  • tests/diagnostic/test-diagnostics_2d.cpp
  • tests/functional/alfven_wave/CMakeLists.txt
  • tests/functional/conservation/CMakeLists.txt
  • tests/functional/dispersion/CMakeLists.txt
  • tests/functional/harris/CMakeLists.txt
  • tests/functional/ionIonBeam/CMakeLists.txt
  • tests/functional/tdtagged/CMakeLists.txt
  • tests/functional/translation/CMakeLists.txt
  • tests/simulator/refinement/CMakeLists.txt
Additional context used
Ruff
tools/python3/plotting.py

18-18: tools.python3.phloping imported but unused; consider using importlib.util.find_spec to test for availability (F401)

tests/functional/td/td1d.py

7-7: matplotlib.pyplot imported but unused (F401)

Remove unused import: matplotlib.pyplot


41-41: Ambiguous variable name: l (E741)

tests/functional/dispersion/dispersion.py

7-7: matplotlib.pyplot imported but unused (F401)

Remove unused import: matplotlib.pyplot

tests/functional/shock/shock.py

39-39: Use f-string instead of format call (UP032)

Convert to f-string


49-49: Ambiguous variable name: l (E741)


138-138: Use f-string instead of format call (UP032)

Convert to f-string


142-142: Use f-string instead of format call (UP032)

Convert to f-string


150-152: Use f-string instead of format call (UP032)

Convert to f-string


156-158: Use f-string instead of format call (UP032)

Convert to f-string


178-178: Use f-string instead of format call (UP032)

Convert to f-string

tests/simulator/refinement/test_2d_10_core.py

21-21: Do not use mutable data structures for argument defaults (B006)

Replace with None; initialize within function


120-120: Use f-string instead of format call (UP032)

Convert to f-string


132-132: Module level import not at top of file (E402)


134-134: Module level import not at top of file (E402)


142-142: Do not use mutable data structures for argument defaults (B006)

Replace with None; initialize within function


166-166: Loop control variable ilvl not used within loop body (B007)

Rename unused ilvl to _ilvl

tests/functional/alfven_wave/alfven_wave1d.py

188-188: Use f-string instead of format call (UP032)

Convert to f-string

tests/functional/translation/translat1d.py

7-7: matplotlib.pyplot imported but unused (F401)

Remove unused import: matplotlib.pyplot


131-131: Ambiguous variable name: l (E741)

tests/functional/harris/harris_2d.py

67-67: Ambiguous variable name: l (E741)

tests/simulator/test_diagnostic_timestamps.py

6-6: Module level import not at top of file (E402)


7-7: Module level import not at top of file (E402)


9-9: Module level import not at top of file (E402)


10-10: Module level import not at top of file (E402)


11-11: Module level import not at top of file (E402)


12-12: Module level import not at top of file (E402)


13-13: Module level import not at top of file (E402)


14-14: Module level import not at top of file (E402)


15-15: Module level import not at top of file (E402)


16-16: Module level import not at top of file (E402)


17-17: Module level import not at top of file (E402)


87-87: Use super() instead of super(__class__, self) (UP008)

Remove __super__ parameters


104-104: Use f-string instead of format call (UP032)

Convert to f-string


131-131: Use f-string instead of format call (UP032)

Convert to f-string


133-133: Loop control variable diagname not used within loop body (B007)

Rename unused diagname to _diagname


178-178: Loop control variable diagname not used within loop body (B007)

Rename unused diagname to _diagname

tests/simulator/test_run.py

60-60: Ambiguous variable name: l (E741)


214-214: Use super() instead of super(__class__, self) (UP008)

Remove __super__ parameters


218-218: Use super() instead of super(__class__, self) (UP008)

Remove __super__ parameters

tests/functional/harris/harris_2d_lb.py

77-77: Ambiguous variable name: l (E741)


191-191: Use super() instead of super(__class__, self) (UP008)

Remove __super__ parameters


195-195: Use super() instead of super(__class__, self) (UP008)

Remove __super__ parameters

tests/functional/ionIonBeam/ion_ion_beam1d.py

8-8: tests.diagnostic.all_timestamps imported but unused (F401)

Remove unused import: tests.diagnostic.all_timestamps


15-15: pyphare.pharesee.plotting imported but unused (F401)

Remove unused import: pyphare.pharesee.plotting


16-16: pathlib.Path imported but unused (F401)

Remove unused import: pathlib.Path


209-211: Use f-string instead of format call (UP032)

Convert to f-string


247-247: Use f-string instead of format call (UP032)

Convert to f-string

tools/config/config.py

150-150: Local variable mpi_type is assigned to but never used (F841)

Remove assignment to unused variable mpi_type


262-262: Loop control variable k not used within loop body (B007)

Rename unused k to _k

tests/functional/conservation/conserv.py

8-8: os imported but unused (F401)

Remove unused import: os


34-34: Use f-string instead of format call (UP032)

Convert to f-string


137-137: Loop control variable ip not used within loop body (B007)

Rename unused ip to _ip


157-157: Loop control variable ip not used within loop body (B007)

Rename unused ip to _ip

Additional comments not posted (11)
tests/functional/shock/CMakeLists.txt (1)

10-13: The condition checks for both HighFive and testMPI, which is appropriate for the required diagnostics. Consider adding a comment to explain why both of these dependencies are necessary for these tests.

tests/diagnostic/job_2d_1core.py (1)

8-8: Ensure the output directory exists or is created before running the simulation to avoid runtime errors.

res/cmake/dep/phlop.cmake (1)

2-7: Clear instructions are provided for enabling phlop. Consider adding a brief description of what phlop does or why it might be beneficial to enable it, to help future developers make informed decisions.

tests/diagnostic/CMakeLists.txt (1)

5-8: The copying of Python files is essential for ensuring that the tests have access to the necessary scripts. Ensure that this step is well-documented in the project's README or developer documentation to clarify its importance.

tests/simulator/CMakeLists.txt (1)

30-30: Ensure that the diagnostic timestamps test is adequately covered by unit tests, especially given its importance highlighted by the added specific version.

Verification successful

The search results indicate that there are indeed test functions related to test_diagnostic_timestamps.py, specifically test_dump_diags_timestamps and test_hierarchy_timestamp_cadence.

  • tests/simulator/test_diagnostic_timestamps.py: def test_dump_diags_timestamps(self)
  • tests/simulator/test_diagnostic_timestamps.py: def test_hierarchy_timestamp_cadence(self, refinement_boxes)

These functions suggest that the diagnostic timestamps are being tested, addressing the concern about adequate coverage.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify unit test coverage for `test_diagnostic_timestamps.py`.

# Test: Search for unit tests covering this file. Expect: At least one test case.
rg --type python $'test_diagnostic_timestamps.py' tests/

Length of output: 86



Script:

#!/bin/bash
# Description: Verify unit test coverage for `test_diagnostic_timestamps.py`.

# Test: Search for unit tests covering this file. Expect: At least one test case.
rg 'test_diagnostic_timestamps' tests/

Length of output: 179



Script:

#!/bin/bash
# Description: Search for Python test functions that might indirectly cover `test_diagnostic_timestamps.py`.

# Test: Search for test functions in the `tests/` directory.
rg -t py 'def test_' tests/

Length of output: 7025

tools/python3/plotting.py (1)

17-29: Refactor the exception handling to avoid redundancy and improve clarity. Consider merging the two separate except blocks into a single one with enhanced logging that differentiates the exceptions based on their type.
[REFACTOR_Suggestion]

-    except (ImportError, FileNotFoundError) as e:
-        if rank == 0:
-            logger.info(
-                f"Phlop timings are not active, see: res/cmake/dep/phlop.cmake`: \n{e}"
-            )
-    except Exception as e:
-        if rank == 0:
-            logger.error(f"Unknown exception handled during timer plotting: {e}")
+    except Exception as e:
+        if rank == 0:
+            if isinstance(e, (ImportError, FileNotFoundError)):
+                logger.info(f"Phlop timings are not active, see: res/cmake/dep/phlop.cmake`: \n{e}")
+            else:
+                logger.error(f"Unknown exception handled during timer plotting: {e}")
Tools
Ruff

18-18: tools.python3.phloping imported but unused; consider using importlib.util.find_spec to test for availability (F401)

tests/simulator/refinement/test_2d_10_core.py (1)

25-26: Remove commented-out code for clarity unless there's a specific reason to keep it.

tests/functional/translation/translat1d.py (1)

23-24: Remove commented-out code for clarity unless there's a specific reason to keep it.

tests/functional/harris/harris_2d.py (2)

46-46: The hardcoded cell size (400, 400) might not be flexible for different simulation scenarios. Consider making this configurable.

- cells=(400, 400),
+ cells=configurable_cells,  # Ensure `configurable_cells` is defined and validated elsewhere

Likely invalid or redundant comment.


4-4: Consider removing the unused import Path to clean up the code.

- from pathlib import Path

Likely invalid or redundant comment.

tests/functional/ionIonBeam/ion_ion_beam1d.py (1)

Line range hint 209-211: Replace format calls with f-strings for better readability and performance.
[REFACTOR_SUGGESTion]

- "dir": "vth{}dx{}".format(vth, dl)
+ "dir": f"vth{vth}dx{dl}"
- title="t = {:.1f}".format(t)
+ title=f"t = {t:.1f}"

Also applies to: 247-247

Comment on lines +25 to +26
# smallest_patch_size=20,
# largest_patch_size=20,
Copy link

Choose a reason for hiding this comment

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

Consider removing commented-out code to improve code cleanliness.

-        # smallest_patch_size=20,
-        # largest_patch_size=20,
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
# smallest_patch_size=20,
# largest_patch_size=20,


def plot_run_timer_data(diag_dir=None, rank=0):
try:
import tools.python3.phloping as phloping # check if available
Copy link

Choose a reason for hiding this comment

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

Consider using importlib.util.find_spec instead of importing tools.python3.phloping directly to check for its availability, as suggested by static analysis.

-        import tools.python3.phloping as phloping  # check if available
+        from importlib import util
+        phloping_spec = util.find_spec("tools.python3.phloping")
+        if phloping_spec is None:
+            logger.info("Phlop timings module not available.")
+        else:
+            import tools.python3.phloping as phloping
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
import tools.python3.phloping as phloping # check if available
from importlib import util
phloping_spec = util.find_spec("tools.python3.phloping")
if phloping_spec is None:
logger.info("Phlop timings module not available.")
else:
import tools.python3.phloping as phloping
Tools
Ruff

18-18: tools.python3.phloping imported but unused; consider using importlib.util.find_spec to test for availability (F401)

Comment on lines +27 to +28
# smallest_patch_size=50,
# largest_patch_size=50,
Copy link

Choose a reason for hiding this comment

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

Consider removing commented-out code to improve code cleanliness.

-        # smallest_patch_size=50,
-        # largest_patch_size=50,
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
# smallest_patch_size=50,
# largest_patch_size=50,

@@ -244,7 +244,7 @@ def write_local_cmake_file(mpi_results):
if mpi_type == "OMPI":
# work around for https://github.com/open-mpi/ompi/issues/10761#issuecomment-1236909802
file.write(
"""set (PHARE_MPIRUN_POSTFIX "${PHARE_MPIRUN_POSTFIX} -q --bind-to none")
"""set (PHARE_MPIRUN_POSTFIX "${PHARE_MPIRUN_POSTFIX} --bind-to none ")
Copy link

Choose a reason for hiding this comment

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

Remove the unused local variable mpi_type as it is assigned but never used.

- mpi_type = deduce_mpi_type_from(mpi_results["MPI_Get_library_version"])

Committable suggestion was skipped due to low confidence.



def plot(diag_dir):
run = Run(diag_dir)
Copy link

Choose a reason for hiding this comment

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

Multiple undefined names such as Run and plot_file_for_qty are used. These need to be defined or imported to avoid runtime errors.

+ from pyphare.pharesee.run import Run
+ def plot_file_for_qty(qty, time):
+     return f"some_directory/{qty}_{time}.png"
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
run = Run(diag_dir)
from pyphare.pharesee.run import Run
def plot_file_for_qty(qty, time):
return f"some_directory/{qty}_{time}.png"
run = Run(diag_dir)

@@ -102,6 +103,11 @@
def test_dump_diags_timestamps(self):
print("test_dump_diags dim/interp:{}/{}".format(1, 1))
Copy link

Choose a reason for hiding this comment

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

Use f-string instead of format call for better readability and performance.

- print("test_dump_diags dim/interp:{}/{}".format(1, 1))
+ print(f"test_dump_diags dim/interp:{1}/{1}")
- return "{:.10f}".format(stamp)
+ return f"{stamp:.10f}"

Also applies to: 131-131

Tools
Ruff

104-104: Use f-string instead of format call (UP032)

Convert to f-string

@@ -125,7 +131,7 @@
return "{:.10f}".format(stamp)

for diagname, diagInfo in ph.global_vars.sim.diagnostics.items():
Copy link

Choose a reason for hiding this comment

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

Loop control variable diagname not used within loop body. Consider renaming it to _ if it's intentionally unused.

- for diagname, diagInfo in ph.global_vars.sim.diagnostics.items():
+ for _, diagInfo in ph.global_vars.sim.diagnostics.items():

Also applies to: 178-178

Tools
Ruff

133-133: Loop control variable diagname not used within loop body (B007)

Rename unused diagname to _diagname

@@ -81,7 +82,7 @@


@ddt
class DiagnosticsTest(unittest.TestCase):
class DiagnosticsTest(SimulatorTest):
def __init__(self, *args, **kwargs):
super(DiagnosticsTest, self).__init__(*args, **kwargs)
Copy link

Choose a reason for hiding this comment

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

Use super() instead of super(DiagnosticsTest, self) for simplicity and modern Python style.

- super(DiagnosticsTest, self).__init__(*args, **kwargs)
+ super().__init__(*args, **kwargs)
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
super(DiagnosticsTest, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
Tools
Ruff

87-87: Use super() instead of super(__class__, self) (UP008)

Remove __super__ parameters


class HarrisTest(SimulatorTest):
def __init__(self, *args, **kwargs):
super(HarrisTest, self).__init__(*args, **kwargs)
Copy link

Choose a reason for hiding this comment

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

Use super() instead of super(HarrisTest, self) for simplicity and modern Python style.

- super(HarrisTest, self).__init__(*args, **kwargs)
+ super().__init__(*args, **kwargs)
- super(HarrisTest, self).tearDown()
+ super().tearDown()

Also applies to: 195-195

Tools
Ruff

191-191: Use super() instead of super(__class__, self) (UP008)

Remove __super__ parameters

+ 1.0 / np.cosh((y - Ly * 0.7) / L) ** 2
)

def S(y, y0, l):
Copy link

Choose a reason for hiding this comment

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

The variable name l is ambiguous and could be confused with the number 1. Consider renaming it for clarity.

- def S(y, y0, l):
+ def S(y, y0, length):
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
def S(y, y0, l):
def S(y, y0, length):
Tools
Ruff

77-77: Ambiguous variable name: l (E741)

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