-
Notifications
You must be signed in to change notification settings - Fork 339
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
Create custom list for particles #1017
Conversation
They're not passing right now, but that seems to be a problem with like 61 of the test file.
As an attempt at computational efficiency, I'm trying to store retrieved attributes so that they can be used later, so long as the contents of the list does not change. This could help with computationally intensive things where there are lots of particles, and the arrays of masses or charges get used repeatedly. |
I've been starting to think that caching this could lead to some weird and unexpected behaviors later on, so I'm going to drop the caching part here. The issues are:
Suppose one element of |
True, though people changing particle masses after creation seems like a rare use case. Dusty plasmas, maybe... But for e.g. impurity studies I'd just want a bunch of completely static particle types. Then we can take advantage of caching without issues. But keeping PRs small is also a great idea 👍 |
Suppose one element of ParticleList is a CustomParticle. Then suppose someone modifies the mass of that CustomParticle directly, without modifying the identities of the particles within the list. Then the cached values of mass would no longer be valid. This will probably not be a common issue, but it could cause unexpected and difficult to track down problems. It'll be safer and cleaner to avoid caching. We can revisit caching if/when there's a situation where it ends up being needed.
The tests still need to be cleaned up and expanded more.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1017 +/- ##
==========================================
+ Coverage 96.82% 96.86% +0.04%
==========================================
Files 69 70 +1
Lines 6737 6856 +119
==========================================
+ Hits 6523 6641 +118
- Misses 214 215 +1 ☔ View full report in Codecov by Sentry. |
…ergy I believe this idea came from Stuart Mumford several years ago.
Ahhhhhhh scope creep on this pull request 🙀 but check this out 🐍 >>> α = Particle("alpha")
>>> D = Particle("D+")
>>> T = Particle("T+")
>>> n = Particle("n")
>>> D + T > n + α # gets nuclear reaction energy
<Quantity 2.81810898e-12 J> I've been meaning to implement this for bleeping years. I think the idea originally came from @Cadair. I hereby dedicate the use of unicode characters to @rocco8773. 😬 |
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.
Good stuff! I have mostly minor comments about testing, and one more important note about documentation for the nuclear reaction energy feature.
Oh yeah, and that last one should go into the changelog!
except (InvalidParticleError, TypeError): | ||
raise InvalidParticleError(f"Cannot cast {other} into a ParticleList") |
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.
Missing tests here for this edge case (and a couple such edge cases below)!
Co-authored-by: Dominik Stańczak <[email protected]>
Co-authored-by: Dominik Stańczak <[email protected]>
These were not showing up correctly in the rendered docs.
Right now it shows up as typing.Union[blah].
Co-authored-by: Dominik Stańczak <[email protected]>
Examples | ||
-------- | ||
A `ParticleList` can be created by calling it with a `list`, `tuple`, | ||
or other iterable that provides `~plasmapy.particles.ParticleLike` |
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.
So I'm guessing the doc test glitches out on this reference, because it can't find ParticleLike. Do we have it in particles/__init__.py
?
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.
Turns out we do. Note, however, that...
/home/runner/work/PlasmaPy/PlasmaPy/docs/particles/index.rst.rst:64:autosummary: stub file not found 'plasmapy.particles.ParticleLike'. Check your autosummary_generate setting.
double .rst
extension for some reason?
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.
Something with https://github.com/namurphy/PlasmaPy/tree/particle-collection/docs/api_static (which I still don't quite get?) ? @rocco8773 do you see anything concerning here?
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.
It seems the current problem was related to me setting ParticleLike.__name__
for some reason. I just removed that line and I'm getting the tests to pass. I'm going to raise a different issue about the docs for ParticleLike
, since I started going beyond the scope of the current PR.
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.
That is pretty wack, indeed. Looks ready to merge, then!
…to particle-collection
I'm wondering if this might be causing doc build errors related to finding `ParticleLike`.
This pull request creates
ParticleList
, which inherits fromcollections.UserList
. The purpose ofParticleList
is to simplify gettingQuantity
arrays for things likeparticles.mass
andparticles.charge
, and lists likeparticles.symbols
. The purpose of this pull request is to establish the essential architecture, rather than make this list fully featured. In particular, I'm adding the features that I expect to need inIonizationState
,IonizationStateCollection
, and PlasmaPy-NEI more generally. I'll probably useParticleList
a lot in those places, in particular to get rid of some code that I keep having to rewrite.I'd also like to enable the formulary to be used like:
and then get an array of gyrofrequencies back.
Later on, I'd like to add subclasses for different categories of particles. For example, an
IonicLevels
list would contain attributes shared by all ions. It'd be really helpful to have an easy way to create a list of all of the ionic levels of a particular element or isotope...likeIonicLevels("He-4")
. Or alternatively, all isotopes (common, stable, or unstable) of a particular element.Closes #948. Related to #687.