tardis-sn / tardis

TARDIS - Temperature And Radiative Diffusion In Supernovae
https://tardis-sn.github.io/tardis
204 stars 406 forks source link

Refactor performance for montecarlo #2792

Closed officialasishkumar closed 1 month ago

officialasishkumar commented 3 months ago

:pencil: Description

Type: refactor

:pushpin: Resources

Examples, notebooks, and links to useful references.

:vertical_traffic_light: Testing

How did you test these changes?

:ballot_box_with_check: Checklist

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

tardis-bot commented 3 months ago

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

```diff 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):

```diff 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. ```
codecov[bot] commented 3 months ago

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 :warning:
Additional details and impacted files ```diff @@ 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 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

tardis-bot commented 3 months ago

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

Significantly changed benchmarks:

```diff ```

All benchmarks:

```diff Benchmarks that have stayed the same: | Change | Before [8a317dd9] | 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

andrewfullard commented 2 months ago

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

officialasishkumar commented 2 months ago

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

Not significant but slight performance improvement.