-
Notifications
You must be signed in to change notification settings - Fork 24
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
bug #913
base: master
Are you sure you want to change the base?
bug #913
Conversation
📝 Walkthrough📝 WalkthroughWalkthroughThe changes include the addition of a new Python script, Changes
Sequence Diagram(s)sequenceDiagram
participant CMake as CMakeLists.txt
participant Python as harris.py
CMake->>Python: Call phare_python3_exec(9, harris2d, harris.py, ${CMAKE_CURRENT_BINARY_DIR})
Python->>Python: Initialize MPI
Python->>Python: Execute config()
Python->>Python: Run simulation and diagnostics
Python->>Python: Perform post-advance checks
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 8
🧹 Outside diff range and nitpick comments (1)
tests/simulator/refinement/CMakeLists.txt (1)
12-12
: Consider adding a comment to explain the purpose of this execution.To improve maintainability and clarity, it would be helpful to add a brief comment explaining the purpose of this new test execution. For example:
# Execute harris.py to test the Maxwellian fluid model simulation phare_python3_exec(9 harris2d harris.py ${CMAKE_CURRENT_BINARY_DIR})
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (2)
- tests/simulator/refinement/CMakeLists.txt (1 hunks)
- tests/simulator/refinement/harris.py (1 hunks)
🧰 Additional context used
🪛 Ruff
tests/simulator/refinement/harris.py
9-9:
pyphare.pharein.ParticleDiagnostics
imported but unusedRemove unused import:
pyphare.pharein.ParticleDiagnostics
(F401)
12-12:
pyphare.pharein.MetaDiagnostics
imported but unusedRemove unused import:
pyphare.pharein.MetaDiagnostics
(F401)
17-17:
sys
imported but unusedRemove unused import:
sys
(F401)
19-19:
matplotlib.pyplot
imported but unusedRemove unused import:
matplotlib.pyplot
(F401)
72-72: Ambiguous variable name:
l
(E741)
189-189: Loop control variable
ilvl
not used within loop bodyRename unused
ilvl
to_ilvl
(B007)
213-213: Local variable
errors
is assigned to but never usedRemove assignment to unused variable
errors
(F841)
🔇 Additional comments (2)
tests/simulator/refinement/CMakeLists.txt (2)
12-12
: LGTM: New test execution added.The addition of
phare_python3_exec(9 harris2d harris.py ${CMAKE_CURRENT_BINARY_DIR})
looks good. It correctly integrates the newharris.py
script into the test suite when the HighFive condition is met.
17-17
: LGTM: Improved readability with blank line.The addition of a blank line here improves the readability of the CMake file by clearly separating the new execution from the subsequent
if(testMPI)
block.
from pyphare.simulator.simulator import Simulator, startMPI | ||
from pyphare.pharein import global_vars as gv | ||
from pyphare.pharein import LoadBalancer | ||
import sys |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unused import sys
.
The sys
module is imported but not utilized in the script.
Apply this diff to remove the unused import:
-import sys
📝 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.
import sys |
🧰 Tools
🪛 Ruff
17-17:
sys
imported but unusedRemove unused import:
sys
(F401)
datahier = check_hier( | ||
get_hier("/home/aunai/Documents/code/phare/phare_jobs/run104/diags_master") | ||
) | ||
errors = test.base_test_overlaped_fields_are_equal(datahier, new_time) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove assignment to unused variable errors
.
The variable errors
is assigned but never used, which may lead to confusion.
If the variable is not needed, remove the assignment:
-errors = test.base_test_overlaped_fields_are_equal(datahier, new_time)
+test.base_test_overlaped_fields_are_equal(datahier, new_time)
Alternatively, if errors
is significant, consider utilizing it appropriately in the code.
📝 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.
errors = test.base_test_overlaped_fields_are_equal(datahier, new_time) | |
test.base_test_overlaped_fields_are_equal(datahier, new_time) |
🧰 Tools
🪛 Ruff
213-213: Local variable
errors
is assigned to but never usedRemove assignment to unused variable
errors
(F841)
from pyphare.pharein import LoadBalancer | ||
import sys | ||
import numpy as np | ||
import matplotlib.pyplot as plt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unused import matplotlib.pyplot as plt
.
matplotlib.pyplot
is imported as plt
but is not used in the code.
Apply this diff to remove the unused import:
-import matplotlib.pyplot as plt
📝 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.
import matplotlib.pyplot as plt |
🧰 Tools
🪛 Ruff
19-19:
matplotlib.pyplot
imported but unusedRemove unused import:
matplotlib.pyplot
(F401)
from pyphare.pharein import ( | ||
ElectromagDiagnostics, | ||
FluidDiagnostics, | ||
ParticleDiagnostics, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unused import ParticleDiagnostics
.
According to the static analysis hints, ParticleDiagnostics
is imported but not used in the code.
Apply this diff to remove the unused import:
ElectromagDiagnostics,
FluidDiagnostics,
- ParticleDiagnostics,
InfoDiagnostics,
📝 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.
ParticleDiagnostics, | |
ElectromagDiagnostics, | |
FluidDiagnostics, | |
InfoDiagnostics, |
🧰 Tools
🪛 Ruff
9-9:
pyphare.pharein.ParticleDiagnostics
imported but unusedRemove unused import:
pyphare.pharein.ParticleDiagnostics
(F401)
ParticleDiagnostics, | ||
InfoDiagnostics, | ||
) | ||
from pyphare.pharein import MetaDiagnostics |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unused import MetaDiagnostics
.
MetaDiagnostics
is imported but not used in the code.
Apply this diff to remove the unused import:
-from pyphare.pharein import MetaDiagnostics
📝 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.
from pyphare.pharein import MetaDiagnostics |
🧰 Tools
🪛 Ruff
12-12:
pyphare.pharein.MetaDiagnostics
imported but unusedRemove unused import:
pyphare.pharein.MetaDiagnostics
(F401)
+ 1.0 / np.cosh((y - Ly * 0.7) / L) ** 2 | ||
) | ||
|
||
def S(y, y0, l): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename ambiguous variable l
to improve clarity.
Using l
(lowercase 'L') as a variable name can be confused with the digit 1
. It's recommended to use a more descriptive name.
Apply this diff to rename the variable:
-def S(y, y0, l):
+def S(y, y0, length):
Also, update all occurrences of l
within the function to length
:
-return 0.5 * (1.0 + np.tanh((y - y0) / l))
+return 0.5 * (1.0 + np.tanh((y - y0) / length))
Committable suggestion was skipped due to low confidence.
🧰 Tools
🪛 Ruff
72-72: Ambiguous variable name:
l
(E741)
|
||
|
||
def check_hier(hier): | ||
for ilvl, lvl in hier.levels().items(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename unused loop variable ilvl
to _
to indicate it's unused.
The loop variable ilvl
is not used within the loop body. Renaming it to _
improves readability by indicating it's intentionally unused.
Apply this diff:
-for ilvl, lvl in hier.levels().items():
+for _, lvl in hier.levels().items():
📝 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.
for ilvl, lvl in hier.levels().items(): | |
for _, lvl in hier.levels().items(): |
🧰 Tools
🪛 Ruff
189-189: Loop control variable
ilvl
not used within loop bodyRename unused
ilvl
to_ilvl
(B007)
tests/simulator/refinement/harris.py
Outdated
|
||
def post_advance(new_time): | ||
datahier = check_hier( | ||
get_hier("/home/aunai/Documents/code/phare/phare_jobs/run104/diags_master") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid hardcoding absolute file paths for better portability.
Using absolute paths like "/home/aunai/Documents/code/phare/phare_jobs/run104/diags_master"
makes the code less portable and harder to maintain. Consider using relative paths or configuration variables.
Apply this diff to use a relative path or a variable:
-get_hier("/home/aunai/Documents/code/phare/phare_jobs/run104/diags_master")
+data_directory = "/path/to/diags_master" # Define a variable or obtain from configuration
+get_hier(data_directory)
This change enhances portability and maintainability of the code.
Committable suggestion was skipped due to low confidence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
🧹 Outside diff range and nitpick comments (1)
tests/simulator/refinement/harris.py (1)
62-139
: Add documentation for complex mathematical formulasThe functions
density()
,bx()
,by()
, andbz()
contain complex mathematical formulas. Consider adding docstrings to explain the physical meaning of these formulas and their parameters.Here's an example of how you could document the
density()
function:def density(x, y): """ Calculate the plasma density distribution. This function creates a density profile with two peaks using hyperbolic secant functions. Parameters: x (float): x-coordinate (not used in this implementation) y (float): y-coordinate Returns: float: Plasma density at the given (x, y) position """ from pyphare.pharein.global_vars import sim Ly = sim.simulation_domain()[1] return ( 0.4 + 1.0 / np.cosh((y - Ly * 0.3) / L) ** 2 + 1.0 / np.cosh((y - Ly * 0.7) / L) ** 2 )Consider adding similar documentation for other complex functions.
🧰 Tools
🪛 Ruff
72-72: Ambiguous variable name:
l
(E741)
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
- tests/simulator/refinement/harris.py (1 hunks)
🧰 Additional context used
🪛 Ruff
tests/simulator/refinement/harris.py
9-9:
pyphare.pharein.ParticleDiagnostics
imported but unusedRemove unused import:
pyphare.pharein.ParticleDiagnostics
(F401)
12-12:
pyphare.pharein.MetaDiagnostics
imported but unusedRemove unused import:
pyphare.pharein.MetaDiagnostics
(F401)
17-17:
sys
imported but unusedRemove unused import:
sys
(F401)
19-19:
matplotlib.pyplot
imported but unusedRemove unused import:
matplotlib.pyplot
(F401)
72-72: Ambiguous variable name:
l
(E741)
189-189: Loop control variable
ilvl
not used within loop bodyRename unused
ilvl
to_ilvl
(B007)
211-211: Local variable
errors
is assigned to but never usedRemove assignment to unused variable
errors
(F841)
🔇 Additional comments (1)
tests/simulator/refinement/harris.py (1)
1-223
: Overall assessment: Well-structured simulation setup with minor improvements neededThe
harris.py
file implements a comprehensive simulation setup for a Maxwellian fluid model using the PyPhare framework. The code is generally well-structured, with clear separation of concerns between configuration, utility functions, and the main execution flow.Key strengths:
- Detailed configuration of simulation parameters
- Complex mathematical models for physical properties
- Clear organization of diagnostic setups
Areas for improvement:
- Cleanup of unused imports
- Better documentation for complex mathematical functions
- Minor code clarity improvements in utility functions
Consider addressing these points to enhance the overall quality and maintainability of the code. Additionally, it may be beneficial to add high-level comments explaining the purpose and methodology of the simulation for future readers and maintainers.
🧰 Tools
🪛 Ruff
9-9:
pyphare.pharein.ParticleDiagnostics
imported but unusedRemove unused import:
pyphare.pharein.ParticleDiagnostics
(F401)
12-12:
pyphare.pharein.MetaDiagnostics
imported but unusedRemove unused import:
pyphare.pharein.MetaDiagnostics
(F401)
17-17:
sys
imported but unusedRemove unused import:
sys
(F401)
19-19:
matplotlib.pyplot
imported but unusedRemove unused import:
matplotlib.pyplot
(F401)
72-72: Ambiguous variable name:
l
(E741)
189-189: Loop control variable
ilvl
not used within loop bodyRename unused
ilvl
to_ilvl
(B007)
211-211: Local variable
errors
is assigned to but never usedRemove assignment to unused variable
errors
(F841)
def check_hier(hier): | ||
for ilvl, lvl in hier.levels().items(): | ||
for patch in lvl.patches: | ||
assert all(patch.box.shape > 5) | ||
return hier |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use underscore for unused loop variable
In the check_hier()
function, the loop variable ilvl
is not used within the loop body. It's a good practice to use an underscore _
for unused variables to make the intention clear.
Apply this diff to improve code clarity:
-def check_hier(hier):
- for ilvl, lvl in hier.levels().items():
+def check_hier(hier):
+ for _, lvl in hier.levels().items():
for patch in lvl.patches:
assert all(patch.box.shape > 5)
return hier
📝 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.
def check_hier(hier): | |
for ilvl, lvl in hier.levels().items(): | |
for patch in lvl.patches: | |
assert all(patch.box.shape > 5) | |
return hier | |
def check_hier(hier): | |
for _, lvl in hier.levels().items(): | |
for patch in lvl.patches: | |
assert all(patch.box.shape > 5) | |
return hier |
🧰 Tools
🪛 Ruff
189-189: Loop control variable
ilvl
not used within loop bodyRename unused
ilvl
to_ilvl
(B007)
|
||
def post_advance(new_time): | ||
datahier = check_hier(get_hier("diags_master")) | ||
errors = test.base_test_overlaped_fields_are_equal(datahier, new_time) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove or use the assigned errors
variable
In the post_advance()
function, the errors
variable is assigned but never used. Either remove the assignment or use the variable if it's intended for future use.
If the errors
variable is not needed, apply this diff:
def post_advance(new_time):
datahier = check_hier(get_hier("diags_master"))
- errors = test.base_test_overlaped_fields_are_equal(datahier, new_time)
+ test.base_test_overlaped_fields_are_equal(datahier, new_time)
If the errors
variable is intended for future use, consider adding a TODO comment explaining its purpose.
📝 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.
def post_advance(new_time): | |
datahier = check_hier(get_hier("diags_master")) | |
errors = test.base_test_overlaped_fields_are_equal(datahier, new_time) | |
def post_advance(new_time): | |
datahier = check_hier(get_hier("diags_master")) | |
test.base_test_overlaped_fields_are_equal(datahier, new_time) |
🧰 Tools
🪛 Ruff
211-211: Local variable
errors
is assigned to but never usedRemove assignment to unused variable
errors
(F841)
def S(y, y0, l): | ||
return 0.5 * (1.0 + np.tanh((y - y0) / l)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename ambiguous variable for better readability
The variable name l
in the S()
function is ambiguous and could be confused with the number 1. Consider renaming it to a more descriptive name.
Apply this diff to improve readability:
-def S(y, y0, l):
- return 0.5 * (1.0 + np.tanh((y - y0) / l))
+def S(y, y0, scale_length):
+ return 0.5 * (1.0 + np.tanh((y - y0) / scale_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.
def S(y, y0, l): | |
return 0.5 * (1.0 + np.tanh((y - y0) / l)) | |
def S(y, y0, scale_length): | |
return 0.5 * (1.0 + np.tanh((y - y0) / scale_length)) |
🧰 Tools
🪛 Ruff
72-72: Ambiguous variable name:
l
(E741)
#!/usr/bin/env python3 | ||
|
||
import pyphare.pharein as ph # lgtm [py/import-and-import-from] | ||
from pyphare.pharein import Simulation | ||
from pyphare.pharein import MaxwellianFluidModel | ||
from pyphare.pharein import ( | ||
ElectromagDiagnostics, | ||
FluidDiagnostics, | ||
ParticleDiagnostics, | ||
InfoDiagnostics, | ||
) | ||
from pyphare.pharein import MetaDiagnostics | ||
from pyphare.pharein import ElectronModel | ||
from pyphare.simulator.simulator import Simulator, startMPI | ||
from pyphare.pharein import global_vars as gv | ||
from pyphare.pharein import LoadBalancer | ||
import sys | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
import matplotlib as mpl | ||
from tests.simulator.test_advance import AdvanceTestBase | ||
|
||
mpl.use("Agg") | ||
from pyphare.cpp import cpp_lib | ||
|
||
cpp = cpp_lib() | ||
startMPI() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clean up imports and improve consistency
There are several unused imports in the file. Consider removing them to improve code clarity:
- Remove the unused import of
ParticleDiagnostics
(line 9). - Remove the unused import of
MetaDiagnostics
(line 12). - Remove the unused import of
sys
(line 17). - Remove the unused import of
matplotlib.pyplot as plt
(line 19).
Additionally, consider grouping related imports and using a consistent import style throughout the file.
Apply this diff to clean up the imports:
-from pyphare.pharein import (
- ElectromagDiagnostics,
- FluidDiagnostics,
- ParticleDiagnostics,
- InfoDiagnostics,
-)
-from pyphare.pharein import MetaDiagnostics
+from pyphare.pharein import (
+ ElectromagDiagnostics,
+ FluidDiagnostics,
+ InfoDiagnostics,
+)
from pyphare.pharein import ElectronModel
from pyphare.simulator.simulator import Simulator, startMPI
from pyphare.pharein import global_vars as gv
from pyphare.pharein import LoadBalancer
-import sys
import numpy as np
-import matplotlib.pyplot as plt
import matplotlib as mpl
📝 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.
#!/usr/bin/env python3 | |
import pyphare.pharein as ph # lgtm [py/import-and-import-from] | |
from pyphare.pharein import Simulation | |
from pyphare.pharein import MaxwellianFluidModel | |
from pyphare.pharein import ( | |
ElectromagDiagnostics, | |
FluidDiagnostics, | |
ParticleDiagnostics, | |
InfoDiagnostics, | |
) | |
from pyphare.pharein import MetaDiagnostics | |
from pyphare.pharein import ElectronModel | |
from pyphare.simulator.simulator import Simulator, startMPI | |
from pyphare.pharein import global_vars as gv | |
from pyphare.pharein import LoadBalancer | |
import sys | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import matplotlib as mpl | |
from tests.simulator.test_advance import AdvanceTestBase | |
mpl.use("Agg") | |
from pyphare.cpp import cpp_lib | |
cpp = cpp_lib() | |
startMPI() | |
#!/usr/bin/env python3 | |
import pyphare.pharein as ph # lgtm [py/import-and-import-from] | |
from pyphare.pharein import Simulation | |
from pyphare.pharein import MaxwellianFluidModel | |
from pyphare.pharein import ( | |
ElectromagDiagnostics, | |
FluidDiagnostics, | |
InfoDiagnostics, | |
) | |
from pyphare.pharein import ElectronModel | |
from pyphare.simulator.simulator import Simulator, startMPI | |
from pyphare.pharein import global_vars as gv | |
from pyphare.pharein import LoadBalancer | |
import numpy as np | |
import matplotlib as mpl | |
from tests.simulator.test_advance import AdvanceTestBase | |
mpl.use("Agg") | |
from pyphare.cpp import cpp_lib | |
cpp = cpp_lib() | |
startMPI() |
🧰 Tools
🪛 Ruff
9-9:
pyphare.pharein.ParticleDiagnostics
imported but unusedRemove unused import:
pyphare.pharein.ParticleDiagnostics
(F401)
12-12:
pyphare.pharein.MetaDiagnostics
imported but unusedRemove unused import:
pyphare.pharein.MetaDiagnostics
(F401)
17-17:
sys
imported but unusedRemove unused import:
sys
(F401)
19-19:
matplotlib.pyplot
imported but unusedRemove unused import:
matplotlib.pyplot
(F401)
is this something that should be logged in ISSUES.md, as more of a context dependent thing (i.e. too many cores for too small a problem, or not that) |
Summary by CodeRabbit
New Features
Bug Fixes
Documentation