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

Refactoring of ParticleTracker, Plasma class #675

Closed
wants to merge 249 commits into from

Conversation

StanczakDominik
Copy link
Member

@StanczakDominik StanczakDominik commented Sep 8, 2019

Closes #636

This is going to be a pretty open-ended one. I've got a few ideas I'd like to tinker with:

  • Remove field interpolation code from ParticleTracker, as right now it's completely tied to Plasma3d on a uniform grid. That's completely idiotic and those responsible should be sacked.
  • Put field interpolation in Plasma3d, because that's reasonable.
  • Replace plasma3d with draft AnalyticalPlasma in ParticleTracker, which probably shares a whole bunch of functionality with PlasmaBlob
  • reenable some of the tests
  • optimize ParticleTracker
  • merge PlasmaBlob with AnalyticalPlasma as needed

Leftovers for future work:

@codecov
Copy link

codecov bot commented Sep 10, 2019

Codecov Report

Merging #675 into master will decrease coverage by 1.25%.
The diff coverage is 75.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #675      +/-   ##
==========================================
- Coverage   95.87%   94.61%   -1.26%     
==========================================
  Files          56       59       +3     
  Lines        5113     5353     +240     
==========================================
+ Hits         4902     5065     +163     
- Misses        211      288      +77     
Impacted Files Coverage Δ
plasmapy/simulation/particletracker.py 71.05% <71.05%> (-27.26%) ⬇️
plasmapy/classes/sources/plasma3d.py 96.36% <71.42%> (-3.64%) ⬇️
plasmapy/classes/sources/coils.py 73.84% <73.84%> (ø)
plasmapy/formulary/magnetostatics.py 98.06% <86.95%> (-1.94%) ⬇️
plasmapy/classes/sources/analyticalfields.py 95.00% <95.00%> (ø)
plasmapy/classes/sources/__init__.py 100.00% <100.00%> (ø)
plasmapy/simulation/particle_integrators.py 100.00% <100.00%> (ø)
plasmapy/formulary/relativity.py 100.00% <0.00%> (ø)
... and 1 more

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 b20e47b...aacb45d. Read the comment docs.

@pep8speaks
Copy link

pep8speaks commented Sep 10, 2019

Hello @StanczakDominik! Thanks for updating your pull request.

Line 23:9: E731 do not assign a lambda expression, use a def

Line 90:100: E501 line too long (103 > 99 characters)

Line 202:100: E501 line too long (100 > 99 characters)

Comment last updated at 2020-04-30 13:05:13 UTC

Copy link
Member Author

@StanczakDominik StanczakDominik left a comment

Choose a reason for hiding this comment

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

This has been my most productive bus trip every! The wifi is blocking ssh traffic, though, and I'm a bit bored of copypasting a personal access token to the password field, so I'll keep it as it is for now.

This is a first draft and I would really appreciate suggestions!

This is also sort of how I would imagine our numba based simulations and units usage for interfaces should look like, ideologically. Please take a look at this design pattern and see if you can optimize it (especially the multiple @propertyies, those are a pain).

docs/index.rst Outdated Show resolved Hide resolved
@@ -0,0 +1,43 @@
"""
Copy link
Member Author

Choose a reason for hiding this comment

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

This file is very much so a "get something working" quick and dirty copypaste of plasmablob that I'll be cleaning up later. I'm simply wondering, though, if this kind of functionality is better plugged into plasmablob or left here, as a generic "plug in your own functions of space" thing.

Copy link
Member

Choose a reason for hiding this comment

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

That's a good question; maybe we should talk about how to organize. It would be very useful functionality to have a class that we can use to represent plasma configurations analytically.

plasmapy/classes/sources/analyticalplasma.py Outdated Show resolved Hide resolved
plasmapy/classes/sources/plasma3d.py Outdated Show resolved Hide resolved
plasmapy/classes/sources/plasma3d.py Outdated Show resolved Hide resolved
plasmapy/simulation/tests/test_particletracker.py Outdated Show resolved Hide resolved
plasmapy/simulation/tests/test_particletracker.py Outdated Show resolved Hide resolved
plasmapy/simulation/tests/test_particletracker.py Outdated Show resolved Hide resolved
tox.ini Outdated Show resolved Hide resolved
@StanczakDominik StanczakDominik marked this pull request as ready for review September 15, 2019 05:13
Copy link
Member Author

@StanczakDominik StanczakDominik left a comment

Choose a reason for hiding this comment

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

Oh, also this one thing....

# atol=estimated_gyrofrequency_std), \
# "Gyrofrequencies don't match!"
s = ParticleTracker(test_plasma, particle_type=particle_type, dt=dt, nt=int(1e4))
s._v[:, 1] = perp_speed.si.value
Copy link
Member Author

Choose a reason for hiding this comment

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

I had some issues with directly modifying s.v[:, 1] = perp_speed, still figuring that one out

Copy link
Member Author

Choose a reason for hiding this comment

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

oh crud, https://stackoverflow.com/questions/3137685/using-property-decorator-on-dicts I think this is gonna be basically impossible

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.

Looks good so far! This is a partial review so far, and I will hopefully get a chance to look into this more in-depth soon. Thanks!

@@ -0,0 +1,43 @@
"""
Copy link
Member

Choose a reason for hiding this comment

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

That's a good question; maybe we should talk about how to organize. It would be very useful functionality to have a class that we can use to represent plasma configurations analytically.

plasmapy/classes/sources/plasma3d.py Show resolved Hide resolved
from plasmapy.atomic import atomic
from astropy import constants
from astropy import units as u
import numba
from plasmapy.utils import PhysicsError
import tqdm
Copy link
Member

Choose a reason for hiding this comment

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

Nice! I hadn't heard of tqdm, so I'll have to look into it.

plasmapy/simulation/particletracker.py Outdated Show resolved Hide resolved
plasmapy/simulation/tests/test_particletracker.py Outdated Show resolved Hide resolved
dtype=float)
self._velocity_history = np.zeros((self.NT, *self.v.shape),
dtype=float)
self._hqmdt = (self.eff_q / self.eff_m / 2 * dt).si.value
Copy link
Member

Choose a reason for hiding this comment

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

I am wondering if there is a better variable name than hqmdt.

Copy link
Member Author

Choose a reason for hiding this comment

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

There most certainly is. But if I wrote "half charge timestep over mass", line length would explode in a few places.

On the other hand, I have been reading Computer Simulation Using Particles recently, so my thinking may be contaminated by the FORTRAN examples...

@StanczakDominik
Copy link
Member Author

I'm giving up on running calculations on Quantities. We'll have to live with setting velocities and positions via _x, _v for now.

@namurphy namurphy mentioned this pull request May 1, 2020
5 tasks
StanczakDominik and others added 11 commits May 6, 2020 08:14
Co-authored-by: Erik Everson <eteverson@gmail.com>
Co-authored-by: Erik Everson <eteverson@gmail.com>
The tox environment does not use `make html-nonb`
because tox envs, by default, don't have `make`!
We call the sphinx command directly instead.

The Makefile was also broken. It's now fixed.
@StanczakDominik StanczakDominik marked this pull request as draft July 7, 2020 18:09
@StanczakDominik
Copy link
Member Author

Astropy.units might work better with numba now, so some refactoring and simplification should be possible -> back to drafting board!

@StanczakDominik
Copy link
Member Author

numba/numba#4637 (comment) would be the thing to try out when coming back to this PR.

However...

I think this has become overly bloated and basically unmergeable. I think the way to go may be to close this one down and break it up in a few smaller, separate PRs, redoing the changes. I still think it was worthwhile, because I now know what to do for this.

@rocco8773, whatcha think?

@rocco8773
Copy link
Member

@StanczakDominik I think that's a good idea. I agree with all of that.

@StanczakDominik
Copy link
Member Author

RIP this one, then!

@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/3

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rewrite particle stepper
5 participants