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

Grids (part 3) #981

Merged
merged 18 commits into from
Feb 9, 2021
Merged

Conversation

pheuer
Copy link
Member

@pheuer pheuer commented Jan 22, 2021

I'm getting really close to a reviewable proton radiography PR, but I ended up needing some new features (and some other minor improvements) to grids. A few of these are breaking changes, I'll try to mark them below:

Major

  • Introduced 'persistent interpolators' which assume the grid has not changed between calls (as long as a keyword flag is set). Otherwise, ~25% of the interpolation cycle was being wasted constantly rebuilding some arrays. I tried to make this as elegant as possible, but maybe it can be done better? Something like this has to be done, though.

  • Introduced the grid.grid_resolution method which determines a single scalar length scale from the grid spacing. I'm using this to determine a simulation timestep. This could be defined in the proton radiography module, but it's generally applicable so I put it here.

  • Introduced grid.on_grid: a method which determines which of a list of points lies within the region bounded by the grid. Useful for the proton radiography code, likely also elsewhere so I put it here.

  • Introduced grid.vector_intersects which determines whether a line between two points intersects the grid using a ray-box intersection algorithm. This is broadly useful.

Minor

  • grid.grid and grid.grids are now dimensioned. Subsequently, grid.grids is only defined for grids with the same units on all three dims. grid.pts# are still dimensioned, their API hasn't changed. (BREAKING)

  • grid.is_uniform_grid is now just grid.is_uniform because the old name was redundant. (BREAKING)

  • Added a grid.quantities property that returns a list of all the quantities defined on the grid.

  • Other minor speed improvements to interpolators, none of which are breaking. For example, interpolation is now done without units and I was able to collapse some for loops into array ops.

Everything should have associated tests added

Here's an example of the speed enhancement achieved with the persistent keyword for 6 quantities at 5e5 positions on a (200x200x200) grid (these are times per cycle, so the extra 300 ms adds up fast).

Non-Persistent Volume-Averaged Interpolation (avg over 30)
--- 1.2901666641235352 seconds ---
Persistent Volume-Averaged Interpolation (avg over 30)
--- 1.014957102139791 seconds ---

- Made out-of-bound value detection explicit in interpolate_indices
- Also fixed a units bug for self.grids for non-uniform grids.
@pheuer pheuer self-assigned this Jan 22, 2021
@pheuer pheuer changed the title Grids improvements 3 Grids (part 3) Jan 22, 2021
@pheuer pheuer added the plasmapy.plasma Related to the plasmapy.plasma subpackage label Jan 22, 2021
@StanczakDominik StanczakDominik self-assigned this Jan 26, 2021
@StanczakDominik
Copy link
Member

StanczakDominik commented Jan 28, 2021

I took the liberty of replacing your implementation of grid_resolution for the non-uniform case with a few lines of scipy code :) I also added a very basic test for it, but it'd be great if you could double-check if it still does the same thing - or, even better, add more detailed tests! ;)

Copy link
Member

@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.

Partial review for now, I haven't dug into the persistence of interpolators yet. A couple questions! :)

plasmapy/plasma/grids.py Show resolved Hide resolved
plasmapy/plasma/grids.py Outdated Show resolved Hide resolved
@pheuer
Copy link
Member Author

pheuer commented Jan 28, 2021

@StanczakDominik Thanks for the improved grid_resolution, that looks great! Effectively the same as what I was doing, just much more efficient.

@pheuer
Copy link
Member Author

pheuer commented Jan 28, 2021

@StanczakDominik I was able to re-implement persistent interpolation with cached properties: the code is definitely cleaner and, based on a speed test, maybe even a hair faster!

Non-Persistent Volume-Averaged Interpolation (avg over 30)
--- 1.2720242420832315 seconds ---
Persistent Volume-Averaged Interpolation (avg over 30)
--- 0.9786213397979736 seconds ---

I tried to add cached-properties >= 1.5.2 to the dependencies: let me know if I put it all the right places (setup.cfg and requirements.txt)

@pheuer pheuer mentioned this pull request Jan 29, 2021
@codecov
Copy link

codecov bot commented Feb 9, 2021

Codecov Report

Merging #981 (ef0b1bd) into master (030d224) will decrease coverage by 0.05%.
The diff coverage is 95.20%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #981      +/-   ##
==========================================
- Coverage   96.68%   96.62%   -0.06%     
==========================================
  Files          64       64              
  Lines        6175     6249      +74     
==========================================
+ Hits         5970     6038      +68     
- Misses        205      211       +6     
Impacted Files Coverage Δ
plasmapy/plasma/grids.py 94.67% <95.20%> (-0.61%) ⬇️

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 030d224...ef0b1bd. Read the comment docs.

@StanczakDominik
Copy link
Member

Yay, I finally broke tests 😼

The codecov failure displays the tests lines that are not covered by tests in this code. It was supposed to pop up earlier, but I sort of missed that it wasn't working right for the last two months...

Anyway, these are minor and let's fix them later on (#895 ?), so this doesn't get stalled further. On to the final review I go!

Copy link
Member

@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.

Okay, let's get this done! :) (and hopefully go back to the minor coverage leaks in #895 :) )

@StanczakDominik StanczakDominik merged commit 6f163e0 into PlasmaPy:master Feb 9, 2021
@pheuer
Copy link
Member Author

pheuer commented Feb 9, 2021

Yay, Codecov is back!! Writing tests just isn't much fun without it...

@StanczakDominik
Copy link
Member

Yeah... sorry for that!

@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 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plasmapy.plasma Related to the plasmapy.plasma subpackage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants