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

Refactor performance for montecarlo #2792

Conversation

officialasishkumar
Copy link
Member

📝 Description

Type: refactor

  • rpacket_tracker refactor

📌 Resources

Examples, notebooks, and links to useful references.

🚦 Testing

How did you test these changes?

  • Testing pipeline
  • Other method (describe)
  • My changes can't be tested (explain why)

☑️ Checklist

  • I requested two reviewers for this pull request
  • I updated the documentation according to my changes
  • I built the documentation by applying the build_docs label

Note: If you are not allowed to perform any of these actions, ping (@) a contributor.

@officialasishkumar officialasishkumar marked this pull request as draft August 13, 2024 09:10
@tardis-bot
Copy link
Contributor

tardis-bot commented Aug 13, 2024

*beep* *bop*
Hi human,
I ran ruff on the latest commit (fd18ffd).
Here are the outputs produced.
Results can also be downloaded as artifacts here.
Summarised output:

2	PIE790	[*] Unnecessary `pass` statement
2	I001  	[*] Import block is un-sorted or un-formatted
2	D411  	[*] Missing blank line before section ("Parameters")
2	UP004 	[*] Class `RPacketLastInteractionTracker` inherits from `object`
1	RET505	[ ] Unnecessary `else` after `return` statement
1	D202  	[*] No blank lines allowed after function docstring (found 1)
1	D412  	[*] No blank lines allowed between a section header and its content ("Parameters")

Complete output(might be large):

tardis/transport/montecarlo/packet_source.py:1:1: I001 [*] Import block is un-sorted or un-formatted
tardis/transport/montecarlo/packet_source.py:228:9: D202 [*] No blank lines allowed after function docstring (found 1)
tardis/transport/montecarlo/packet_source.py:246:9: RET505 Unnecessary `else` after `return` statement
tardis/transport/montecarlo/packet_source.py:270:9: D412 [*] No blank lines allowed between a section header and its content ("Parameters")
tardis/transport/montecarlo/packet_trackers.py:1:1: I001 [*] Import block is un-sorted or un-formatted
tardis/transport/montecarlo/packet_trackers.py:36:22: UP004 [*] Class `RPacketTracker` inherits from `object`
tardis/transport/montecarlo/packet_trackers.py:39:5: D411 [*] Missing blank line before section ("Parameters")
tardis/transport/montecarlo/packet_trackers.py:226:37: UP004 [*] Class `RPacketLastInteractionTracker` inherits from `object`
tardis/transport/montecarlo/packet_trackers.py:229:5: D411 [*] Missing blank line before section ("Parameters")
tardis/transport/montecarlo/packet_trackers.py:271:9: PIE790 [*] Unnecessary `pass` statement
tardis/transport/montecarlo/packet_trackers.py:278:9: PIE790 [*] Unnecessary `pass` statement
Found 11 errors.
[*] 10 fixable with the `--fix` option.

Copy link

codecov bot commented Aug 13, 2024

Codecov Report

Attention: Patch coverage is 85.71429% with 2 lines in your changes missing coverage. Please review.

Project coverage is 69.37%. Comparing base (8a317dd) to head (fd18ffd).
Report is 34 commits behind head on master.

Files with missing lines Patch % Lines
tardis/transport/montecarlo/packet_trackers.py 83.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2792      +/-   ##
==========================================
- Coverage   69.91%   69.37%   -0.54%     
==========================================
  Files         206      206              
  Lines       15523    15524       +1     
==========================================
- Hits        10853    10770      -83     
- Misses       4670     4754      +84     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tardis-bot
Copy link
Contributor

tardis-bot commented Aug 13, 2024

*beep* *bop*
Hi human,
I ran benchmarks as you asked comparing master (8a317dd) and the latest commit (fd18ffd).
Here are the logs produced by ASV.
Results can also be downloaded as artifacts here.

Significantly changed benchmarks:

All benchmarks:

Benchmarks that have stayed the same:

| Change   | Before [8a317dd9] <master>   | After [fd18ffd8]    | Ratio   | Benchmark (Parameter)                                                                                                               |
|----------|------------------------------|---------------------|---------|-------------------------------------------------------------------------------------------------------------------------------------|
|          | 7.04±2μs                     | 9.75±2μs            | ~1.38   | transport_montecarlo_vpacket.BenchmarkMontecarloMontecarloNumbaVpacket.time_trace_vpacket_volley                                    |
|          | 45.7±20μs                    | 57.1±20μs           | ~1.25   | transport_montecarlo_interaction.BenchmarkTransportMontecarloInteraction.time_line_emission                                         |
|          | 551±200ns                    | 621±200ns           | ~1.13   | opacities_opacity.BenchmarkMontecarloMontecarloNumbaOpacities.time_photoabsorption_opacity_calculation                              |
|          | 3.35±0.3μs                   | 2.99±0.5μs          | ~0.90   | transport_montecarlo_vpacket.BenchmarkMontecarloMontecarloNumbaVpacket.time_trace_bad_vpacket                                       |
|          | 66.2±0.3ms                   | 57.2±0.4ms          | ~0.86   | transport_montecarlo_packet_trackers.BenchmarkTransportMontecarloPacketTrackers.time_rpacket_trackers_to_dataframe                  |
|          | 511±200ns                    | 561±100ns           | 1.10    | opacities_opacity.BenchmarkMontecarloMontecarloNumbaOpacities.time_compton_opacity_calculation                                      |
|          | 1.42±0.4μs                   | 1.56±0.3μs          | 1.10    | transport_geometry_calculate_distances.BenchmarkTransportGeometryCalculateDistances.time_calculate_distance_line                    |
|          | 2.69±0.02ms                  | 2.88±0.01ms         | 1.07    | opacities_opacity_state.BenchmarkOpacitiesOpacityState.time_opacity_state_initialize('scatter')                                     |
|          | 7.02±1μs                     | 7.27±1μs            | 1.04    | transport_montecarlo_vpacket.BenchmarkMontecarloMontecarloNumbaVpacket.time_trace_vpacket                                           |
|          | 31.3±0.03μs                  | 31.7±0.05μs         | 1.01    | transport_montecarlo_packet_trackers.BenchmarkTransportMontecarloPacketTrackers.time_generate_rpacket_tracker_list                  |
|          | 39.5±0.02s                   | 39.6±0.01s          | 1.00    | run_tardis.BenchmarkRunTardis.time_run_tardis                                                                                       |
|          | 2.07±0m                      | 2.07±0m             | 1.00    | spectrum_formal_integral.BenchmarkTransportMontecarloFormalIntegral.time_FormalIntegrator_functions                                 |
|          | 3.53±0.3μs                   | 3.54±0.5μs          | 1.00    | transport_montecarlo_vpacket.BenchmarkMontecarloMontecarloNumbaVpacket.time_trace_vpacket_within_shell                              |
|          | 3.63±0.05ms                  | 3.61±0.01ms         | 0.99    | opacities_opacity_state.BenchmarkOpacitiesOpacityState.time_opacity_state_initialize('macroatom')                                   |
|          | 207±0.1ns                    | 206±0.08ns          | 0.99    | spectrum_formal_integral.BenchmarkTransportMontecarloFormalIntegral.time_intensity_black_body                                       |
|          | 44.4±30μs                    | 43.8±20μs           | 0.99    | transport_montecarlo_interaction.BenchmarkTransportMontecarloInteraction.time_line_scatter                                          |
|          | 758±0.4ns                    | 751±0.9ns           | 0.99    | transport_montecarlo_interaction.BenchmarkTransportMontecarloInteraction.time_thomson_scatter                                       |
|          | 551±100ns                    | 541±200ns           | 0.98    | opacities_opacity.BenchmarkMontecarloMontecarloNumbaOpacities.time_pair_creation_opacity_calculation                                |
|          | 1.05±0m                      | 1.03±0m             | 0.98    | run_tardis.BenchmarkRunTardis.time_run_tardis_rpacket_tracking                                                                      |
|          | 2.56±0.4ms                   | 2.52±0.4ms          | 0.98    | transport_montecarlo_single_packet_loop.BenchmarkTransportMontecarloSinglePacketLoop.time_single_packet_loop                        |
|          | 1.24±0μs                     | 1.20±0μs            | 0.97    | transport_geometry_calculate_distances.BenchmarkTransportGeometryCalculateDistances.time_calculate_distance_boundary                |
|          | 2.22±2μs                     | 2.16±2μs            | 0.97    | transport_montecarlo_estimators_radfield_estimator_calcs.BenchmarkMontecarloMontecarloNumbaPacket.time_update_line_estimators       |
|          | 1.75±0.03ms                  | 1.65±0ms            | 0.94    | transport_montecarlo_main_loop.BenchmarkTransportMontecarloMontecarloMainLoop.time_montecarlo_main_loop                             |
|          | 25.3±6μs                     | 23.2±6μs            | 0.92    | transport_montecarlo_packet_trackers.BenchmarkTransportMontecarloPacketTrackers.time_generate_rpacket_last_interaction_tracker_list |

If you want to see the graph of the results, you can check it here

Signed-off-by: Asish Kumar <[email protected]>
@@ -287,9 +290,10 @@ def generate_rpacket_tracker_list(no_of_packets, length):
-------
A list containing RPacketTracker for each RPacket
"""
rPacketTracker = RPacketTracker(length)
Copy link
Member

Choose a reason for hiding this comment

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

please readup on PEP8 naming schemes

@andrewfullard
Copy link
Contributor

@officialasishkumar did you verify that this produces a significant performance improvement?

@officialasishkumar
Copy link
Member Author

@officialasishkumar did you verify that this produces a significant performance improvement?

Not significant but slight performance improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants