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

Increase speed of get_unique_bias for Characteristic objects #2236

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

LeoMurphyWM24
Copy link
Contributor

Description

I streamlined the get_unique_bias function on Characteristic objects in plasmapy.diagnostics.langmuir.py. According to a (very basic) TimeIt, creating 200 Characteristic objects now takes 0.59 seconds instead of 12.02 seconds, a 20-fold improvement in speed. The primary change is restricting get_unique_bias to averaging only duplicated bias values, instead of taking averages for all data points, even redundant single-point averages on already-unique bias values.

Motivation and context

The get_unique_bias function in plasmapy.diagnostics.langmuir.py runs every time a new Characteristic object is created, which appears to include heavily-used operations like subtraction between existing Characteristics. Streamlining get_unique_bias saves a lot of time when calculating plasma diagnostics on thousands of shots (according to my Python profiler, get_unique_bias was responsible for 88% of my program's twelve-minute runtime, and it now completes in two minutes!)

Note: my very basic TimeIt is found on a Google Colaboratory document here. If anyone catches an error in my code, I will fix it and be eternally grateful. I have not yet created a changelog entry in case any further edits are suggested.

Replace for loop with list comprehension; eliminate redundant averaging for non-duplicated biases
Add "return None" statement to get_unique_bias
@github-actions
Copy link

github-actions bot commented Jul 3, 2023

Thank you for submitting a pull request (PR) to PlasmaPy! ✨ The future of the project depends on contributors like you, so we deeply appreciate it! 🌱

Our contributor guide has information on:

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. 🌸 You can find us in our chat room or weekly community meeting & office hours. Here are some tips:

  • Try fixing CI / Python 3.11 test failures first.
  • Most pre-commit.ci - pr failures can be automagically fixed by commenting pre-commit.ci autofix below, followed by a git pull to bring the changes back to your computer.
  • If pre-commit.ci - pr says that a function is too long or complex, try breaking up that function into multiple short functions that each do one thing. See also these tips on writing clean scientific software.
  • If the CI / Documentation check ends with a cryptic error message, check out our documentation troubleshooting guide.
  • For a documentation preview, click on Details next to docs/readthedocs.org:plasmapy.

If this PR is marked as ready for review, someone should stop by to provide a code review and offer suggestions soon. ✅ If you don't get a review within a few days, please feel free to send us a reminder.

Please also use SI units within PlasmaPy, except when there is strong justification otherwise or in some examples.

We thank you once again!

@github-actions github-actions bot added the plasmapy.diagnostics Related to the plasmapy.diagnostics subpackage label Jul 3, 2023
@namurphy namurphy added this to the Future milestone Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plasmapy.diagnostics Related to the plasmapy.diagnostics subpackage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants