Optimizing ParticleTracker and cpr.Tracker#2911
Conversation
|
Thank you for submitting this pull request (PR)! ✨ PlasmaPy depends on contributors like you, so we deeply appreciate it! The bottom of this page shows several checks that are run for every PR. ✅ Don't worry if something broke! We break stuff all the time. 😅 Click on "Details" to learn why a check didn't pass. Please also feel free to ask for help. We do that all the time as well! 🌸 We invite you to our weekly community meeting (2 pm ET on most Tuesdays) and office hours (3 pm ET on most Thursdays). After this PR is marked as ready for review, someone should stop by to provide a code review and offer suggestions soon. 👥 If we don't provide a review within a few days, please feel free to send us a reminder. 🎗 PlasmaPy's contributor guide has information on:
Tip 📚 For a documentation preview, click on Details next to docs/readthedocs.org:plasmapy. For cryptic documentation errors, see the documentation troubleshooting guide. Tip 🧹 Automatically fix most pre-commit.ci failures by commenting We thank you once again! 🌌 |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2911 +/- ##
==========================================
- Coverage 94.75% 94.43% -0.33%
==========================================
Files 108 108
Lines 9631 9681 +50
Branches 1451 1462 +11
==========================================
+ Hits 9126 9142 +16
- Misses 324 346 +22
- Partials 181 193 +12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@namurphy I added some additional print output which is causing doctest to fail - how does one reset that to accept the new test output as 'normal'? |
That's a good question! We can do that by updating the example section of each docstring directly to have the new output rather than the old. So it'd be something like changing a docstring from >>> simulation.run()
>>> simulation.whatevs()to >>> simulation.run()
Awesomely running awesome simulation.
Finished in 4.6 gigaseconds.
>>> simulation.whatevs() |
Ah, awesome, I understand how that works now! Thanks! |
|
The error in the tests is probably coming from the fact that the test uses the EDIT: Looks like that worked! |
|
@PlasmaPy/plasmapy-reviewers Can we get this merged in the next few weeks? I've left comments trying to explain what was done - please tag me with any further questions. |
namurphy
left a comment
There was a problem hiding this comment.
Thank you for doing this! And also thank you for your patience while I was proposal writing and taking a month off of work. I have a few suggestions, and overall it's looking good.
For soften_edges, there are two things I'm wondering about.
-
If I'm understanding this correctly, the
erfformulation for the mask insoften_edgeswill change all of the values on the grid. At the center of the grid, the original values would be multiplied by a value that is really close to, but slightly less than, one. Is there a mask we could apply that doesn't affect quantities toward the center of the grid? Or alternatively, should we add an admonition to the docstring that mentions this? -
If this mask is applied to the magnetic field, I believe this would cause the resulting magnetic field to violate the divergence constraint unless
$\mathbf{B} · ∇ f = 0$ . Should we add an admonition to the docstring that mentions that the divergence constraint will not be preserved?I got the condition using the vector identity that
$∇ · \left(f \mathbf{B}\right) ≡ f ∇ · \mathbf{B} + \mathbf{B} · ∇f$ , and noting that$∇ · \mathbf{B} = 0$ so the first term goes away. My first vector calculus of 2025! 😹
Thank you again!
src/plasmapy/diagnostics/charged_particle_radiography/synthetic_radiography.py
Outdated
Show resolved
Hide resolved
|
|
||
| return Tmin < Tmax | ||
|
|
||
| def soften_edges(self, width: u.Quantity | None = None) -> None: |
There was a problem hiding this comment.
If the grid has a sharp edge, that gradient can mess up the tracking results, so this is a nice pre-filter to run before particle tracing.
This is helpful information! If this information isn't already included somewhere in the documentation, it would be good to add it. I'm not sure if it would go best here and/or somewhere else.
|
@namurphy I'm working on addressing these, but I think one of the recent changes has broken pre-commit on windows. It works for me on old branches (not up to date with main), but on main now I get: With the unhelpful log: pre-commit version: 4.0.1 An unexpected error has occurred: CalledProcessError: command: ('rbenv', 'init', '-') Traceback (most recent call last): |
Co-authored-by: Nick Murphy <[email protected]>
|
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
|
Hi @namurphy
Yes, I don't see a clean way to fix this and it's a very minor problem since the ERF is very close to one away from the edge, so I've just mentioned it in the docstring.
Yes, good point, I've added a note to that effect. |
|
Ok, I think all the comments are addressed - my pre-commit is still broken locally, but I was able to run it through the comment bot, so it's passing now. |
namurphy
left a comment
There was a problem hiding this comment.
I have one final optional suggestion for one of the tests which you can consider, and I'd say it's ready to go! Thank you for doing this!
|
pre-commit.ci autofix |
This PR contains a long list of mostly minor improvements to the ParticleTracker and charged particle radiography Tracker focused on reducing unnecessary repetitive calculations.
Major changes
Minor changes (no changelog necessary)