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

ParticleTracker refactor: Bring in particle_integrators.py #953

Merged

Conversation

StanczakDominik
Copy link
Member

@StanczakDominik StanczakDominik commented Nov 22, 2020

This is (finally!) a follow-up to the closed #675. It brings in a separated implementation of the Boris algorithm, which I was hoping would solve the issue raised in https://plasmapy.discourse.group/t/e-cross-b-drift/; we're not there yet, but this is a change in the right direction and should be easier to review.

7f20252 is marked [REVERT], but I haven't yet found a way to combine astropy.units with parallel numba, and in my previious tests the parallelization did not bring huge speedups, so it's fine to keep it that way for now.

This separate implementation will also make #895 easier.

@StanczakDominik
Copy link
Member Author

black's failure gets fixed in #952.

@PlasmaPyBot
Copy link

This pull request has been mentioned on PlasmaPy Community Discourse Forum. There might be relevant details there:

https://plasmapy.discourse.group/t/e-cross-b-drift/57/4

@codecov
Copy link

codecov bot commented Nov 22, 2020

Codecov Report

Merging #953 (8d967e7) into master (95aa647) will decrease coverage by 0.39%.
The diff coverage is 44.18%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #953      +/-   ##
==========================================
- Coverage   96.29%   95.89%   -0.40%     
==========================================
  Files          62       63       +1     
  Lines        5715     5748      +33     
==========================================
+ Hits         5503     5512       +9     
- Misses        212      236      +24     
Impacted Files Coverage Δ
plasmapy/simulation/particle_integrators.py 31.42% <31.42%> (ø)
plasmapy/simulation/particletracker.py 98.27% <100.00%> (-0.06%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8beba18...d25ce97. Read the comment docs.

@pheuer pheuer linked an issue Nov 23, 2020 that may be closed by this pull request
8 tasks
@pheuer pheuer removed a link to an issue Nov 23, 2020
8 tasks
@pheuer
Copy link
Member

pheuer commented Nov 23, 2020

This PR would also address a couple of the points raised in issue #936

@StanczakDominik
Copy link
Member Author

StanczakDominik commented Dec 12, 2020

Merging this now would break Python 3.9 support, because that version broke Numba (numba/numba#6345) and we won't get that fixed until RC 2021.

For now, it is probably the best call to make Numba optional, so people can still install PlasmaPy on 3.9, and conditionally xfail the test on 3.9, so we can get this PR moving. Does that sound reasonable?

@rocco8773
Copy link
Member

Could you possibly have a numba and non-numba version by doing something like....

try:
    import numba
    _range = numba.prange
except ImportError:
    warn(
        "If running Python < 3.9 consider installing numba.  This will allow parallel "
        "computing and speed up ParticleTracker"
    )
    _range = np.arange

def foo(*args):
    # use _range for the loops so the function is automatically a numba or 
    # non-numba version
    ...

if "numba" in globals:
    foo = numba.njit()(foo)

Then we might be able to use environment markers so numba is only installed on python < 3.9. (see also https://stackoverflow.com/a/32643122) I've never done this, so I'm not sure how well it will work.

@StanczakDominik
Copy link
Member Author

It's still a for loop. If we do "optional Numba" here, the performance will suffer greatly over the current implementation.

@rocco8773
Copy link
Member

It's still a for loop. If we do "optional Numba" here, the performance will suffer greatly over the current implementation.

I get that. The idea is that, with the environmental markers we can make numba a dependency for installs on python < 3.9 and thus utilized the numba functionality you're integrating here. If someone is using python >= 3.9, then numba will not be installed, the particle tracker functionality will revert to a slower form, and the user is warned about what is happening. However, the UI is made consistent across the python versions so when the numba with python39 issue is resolved the user does not have to change anything when make the patch on our end.

@StanczakDominik
Copy link
Member Author

StanczakDominik commented Dec 14, 2020

I went without numba for now. I figure we can wait until Q1 2021 and introduce less complexity then.

In the meantime, I went with refactoring the numpy version out of the class, and lo and behold, I fixed the ExB drift direction bug. I've got the numba version backed up, but for now, this should be good.

@PlasmaPyBot
Copy link

This pull request has been mentioned on PlasmaPy Community Discourse Forum. There might be relevant details there:

https://plasmapy.discourse.group/t/e-cross-b-drift/57/5

@StanczakDominik
Copy link
Member Author

Should be good to go!

@namurphy namurphy self-assigned this Jan 5, 2021
@StanczakDominik
Copy link
Member Author

@namurphy here's the promised reminder :)

Copy link
Member

@namurphy namurphy left a comment

Choose a reason for hiding this comment

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

I like this refactoring, so thank you! My final suggestions are pretty minor and mostly aren't even necessary. I think it's ready to be merged whenever you're ready to.

docs/notebooks/particle_stepper.ipynb Outdated Show resolved Hide resolved
docs/notebooks/particle_stepper.ipynb Show resolved Hide resolved
docs/simulation/index.rst Outdated Show resolved Hide resolved
plasmapy/simulation/particle_integrators.py Show resolved Hide resolved
plasmapy/simulation/particle_integrators.py Show resolved Hide resolved
plasmapy/simulation/particle_integrators.py Show resolved Hide resolved
StanczakDominik added a commit to kjmontes/PlasmaPy that referenced this pull request Jan 12, 2021
This is to further limit the number of warnings emitted
during the doc build.
@StanczakDominik StanczakDominik merged commit 3576470 into PlasmaPy:master Jan 12, 2021
@StanczakDominik StanczakDominik deleted the fixes-from-RefactorTracker branch January 12, 2021 19:22
@StanczakDominik StanczakDominik added this to the 0.6.0 milestone Mar 12, 2021
rocco8773 added a commit to rocco8773/PlasmaPy that referenced this pull request Mar 14, 2021
@namurphy namurphy added plasmapy.simulation Related to the plasmapy.simulation subpackage refactoring ♻️ Improving an implementation without adding new functionality labels May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plasmapy.simulation Related to the plasmapy.simulation subpackage refactoring ♻️ Improving an implementation without adding new functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants