tardis-sn / tardis

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

Add status to r packet last interaction tracker #2796

Open Sumit112192 opened 1 month ago

Sumit112192 commented 1 month ago

:pencil: Description

Type: :rocket: feature

This PR adds a status property to the RPacketLastInteractionTracker as it can be used to determine whether the packet was reabsorbed or emitted.

tardis-bot commented 1 month ago

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

```diff 5 I001 [*] Import block is un-sorted or un-formatted 4 G004 [ ] Logging statement uses f-string 4 E999 [ ] SyntaxError: Expected ',', found ':' 3 F405 [ ] `deepcopy` may be undefined, or defined from star imports 2 PIE790 [*] Unnecessary `pass` statement 2 RET505 [ ] Unnecessary `else` after `return` statement 2 D202 [*] No blank lines allowed after function docstring (found 1) 2 D411 [*] Missing blank line before section ("Parameters") 2 UP004 [*] Class `RPacketLastInteractionTracker` inherits from `object` 1 B009 [*] Do not call `getattr` with a constant attribute value. It is not any safer than normal property access. 1 B018 [ ] Found useless expression. Either assign it to a variable or remove it. 1 G001 [ ] Logging statement uses `str.format` 1 PT020 [ ] `@pytest.yield_fixture` is deprecated, use `@pytest.fixture` 1 RET506 [ ] Unnecessary `elif` after `raise` statement 1 E902 [ ] No such file or directory (os error 2) 1 W291 [*] Trailing whitespace 1 W292 [*] No newline at end of file 1 F401 [*] `astropy.units` imported but unused 1 F403 [ ] `from tardis.tests.fixtures.atom_data import *` used; unable to detect undefined names 1 F821 [ ] Undefined name `pytest_report_header` 1 PGH004 [ ] Use specific rule codes when using `noqa` 1 UP030 [*] Use implicit references for positional format fields ```

Complete output(might be large):

```diff .zenodo.json:1:1: B018 Found useless expression. Either assign it to a variable or remove it. .zenodo.json:357:2: W292 [*] No newline at end of file CHANGELOG.md:4:15: E999 SyntaxError: Expected ',', found ':' CITATION.cff:3:1: E999 SyntaxError: Invalid annotated assignment target README.rst:1:1: E999 SyntaxError: Expected a statement docs/io/output/how_to_rpacket_tracking.ipynb:cell 12:1:62: W291 [*] Trailing whitespace docs/resources/credits.rst:1:1: E999 SyntaxError: Expected a statement tardis/conftest.py:1:1: I001 [*] Import block is un-sorted or un-formatted tardis/conftest.py:11:1: F403 `from tardis.tests.fixtures.atom_data import *` used; unable to detect undefined names tardis/conftest.py:30:49: PGH004 Use specific rule codes when using `noqa` tardis/conftest.py:32:9: F821 Undefined name `pytest_report_header` tardis/conftest.py:145:5: RET505 Unnecessary `else` after `return` statement tardis/conftest.py:169:1: PT020 `@pytest.yield_fixture` is deprecated, use `@pytest.fixture` tardis/conftest.py:240:19: F405 `deepcopy` may be undefined, or defined from star imports tardis/conftest.py:249:19: F405 `deepcopy` may be undefined, or defined from star imports tardis/conftest.py:278:19: F405 `deepcopy` may be undefined, or defined from star imports tardis/gui/tests/test_gui.py:1:1: I001 [*] Import block is un-sorted or un-formatted tardis/gui/tests/test_gui.py:5:25: F401 [*] `astropy.units` imported but unused tardis/gui/tests/test_gui.py:8:1: I001 [*] Import block is un-sorted or un-formatted tardis/io/atom_data/base.py:182:34: G004 Logging statement uses f-string tardis/io/atom_data/base.py:236:17: G004 Logging statement uses f-string tardis/io/atom_data/base.py:240:21: UP030 Use implicit references for positional format fields tardis/io/atom_data/base.py:240:21: G001 Logging statement uses `str.format` tardis/io/atom_data/base.py:670:17: G004 Logging statement uses f-string tardis/tests/test_tardis_full_formal_integral.py:61:9: RET505 Unnecessary `else` after `return` statement tardis/transport/montecarlo/packet_trackers.py:1:1: I001 [*] Import block is un-sorted or un-formatted tardis/transport/montecarlo/packet_trackers.py:37:22: UP004 [*] Class `RPacketTracker` inherits from `object` tardis/transport/montecarlo/packet_trackers.py:40:5: D411 [*] Missing blank line before section ("Parameters") tardis/transport/montecarlo/packet_trackers.py:204:48: B009 [*] Do not call `getattr` with a constant attribute value. It is not any safer than normal property access. tardis/transport/montecarlo/packet_trackers.py:225:37: UP004 [*] Class `RPacketLastInteractionTracker` inherits from `object` tardis/transport/montecarlo/packet_trackers.py:228:5: D411 [*] Missing blank line before section ("Parameters") tardis/transport/montecarlo/packet_trackers.py:276:9: PIE790 [*] Unnecessary `pass` statement tardis/transport/montecarlo/packet_trackers.py:283:9: PIE790 [*] Unnecessary `pass` statement tardis/visualization/tools/liv_plot.py:1:1: I001 [*] Import block is un-sorted or un-formatted tardis/visualization/tools/liv_plot.py:25:9: D202 [*] No blank lines allowed after function docstring (found 1) tardis/visualization/tools/liv_plot.py:48:9: D202 [*] No blank lines allowed after function docstring (found 1) tardis/visualization/tools/liv_plot.py:247:17: G004 Logging statement uses f-string tardis/visualization/tools/liv_plot.py:357:13: RET506 Unnecessary `elif` after `raise` statement tardis/visualization/tools/tests/test_liv_plot.py:1:1: E902 No such file or directory (os error 2) Found 39 errors. [*] 17 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option). ```
codecov[bot] commented 1 month ago

Codecov Report

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

Project coverage is 70.78%. Comparing base (5fe6806) to head (8578799). Report is 6 commits behind head on master.

Files with missing lines Patch % Lines
tardis/transport/montecarlo/packet_trackers.py 33.33% 2 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #2796 +/- ## ========================================== + Coverage 69.88% 70.78% +0.90% ========================================== Files 208 209 +1 Lines 15453 15641 +188 ========================================== + Hits 10799 11072 +273 + Misses 4654 4569 -85 ```

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

tardis-bot commented 1 month ago

*beep* *bop* Hi human, I ran benchmarks as you asked comparing master (5fe6806d2dc18afa155ffeb3a3cb31518637a214) and the latest commit (85787999dfd611d0d5f6799ffa02b93ef8b6e6e3). 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 [b79b61ed] | After [85787999] | Ratio | Benchmark (Parameter) | |----------|------------------------------|---------------------|---------|-------------------------------------------------------------------------------------------------------------------------------------| | | 3.57±0.01ms | 3.98±0.02ms | ~1.12 | opacities_opacity_state.BenchmarkOpacitiesOpacityState.time_opacity_state_initialize('macroatom') | | | 5.93±1μs | 6.67±0.5μs | ~1.12 | transport_montecarlo_vpacket.BenchmarkMontecarloMontecarloNumbaVpacket.time_trace_vpacket | | | 501±100ns | 551±100ns | 1.10 | opacities_opacity.BenchmarkMontecarloMontecarloNumbaOpacities.time_compton_opacity_calculation | | | 59.4±10μs | 64.7±10μs | 1.09 | transport_montecarlo_interaction.BenchmarkTransportMontecarloInteraction.time_line_emission | | | 581±200ns | 621±100ns | 1.07 | opacities_opacity.BenchmarkMontecarloMontecarloNumbaOpacities.time_pair_creation_opacity_calculation | | | 1.67±0ms | 1.76±0ms | 1.06 | transport_montecarlo_main_loop.BenchmarkTransportMontecarloMontecarloMainLoop.time_montecarlo_main_loop | | | 24.7±7μs | 26.1±7μs | 1.06 | transport_montecarlo_packet_trackers.BenchmarkTransportMontecarloPacketTrackers.time_generate_rpacket_last_interaction_tracker_list | | | 7.05±2μs | 7.47±1μs | 1.06 | transport_montecarlo_vpacket.BenchmarkMontecarloMontecarloNumbaVpacket.time_trace_vpacket_volley | | | 721±0.5ns | 748±2ns | 1.04 | transport_montecarlo_interaction.BenchmarkTransportMontecarloInteraction.time_thomson_scatter | | | 3.03±0.6μs | 3.13±0.5μs | 1.03 | transport_montecarlo_vpacket.BenchmarkMontecarloMontecarloNumbaVpacket.time_trace_bad_vpacket | | | 39.6±0.01s | 39.8±0.01s | 1.01 | run_tardis.BenchmarkRunTardis.time_run_tardis | | | 202±0ns | 203±0.1ns | 1.01 | spectrum_formal_integral.BenchmarkTransportMontecarloFormalIntegral.time_intensity_black_body | | | 2.07±0m | 2.07±0m | 1.00 | spectrum_formal_integral.BenchmarkTransportMontecarloFormalIntegral.time_FormalIntegrator_functions | | | 1.21±0μs | 1.22±0.01μs | 1.00 | transport_geometry_calculate_distances.BenchmarkTransportGeometryCalculateDistances.time_calculate_distance_boundary | | | 31.2±0.07μs | 31.3±0.02μs | 1.00 | transport_montecarlo_packet_trackers.BenchmarkTransportMontecarloPacketTrackers.time_generate_rpacket_tracker_list | | | 2.85±0.01ms | 2.81±0.01ms | 0.99 | opacities_opacity_state.BenchmarkOpacitiesOpacityState.time_opacity_state_initialize('scatter') | | | 1.06±0m | 1.05±0m | 0.99 | run_tardis.BenchmarkRunTardis.time_run_tardis_rpacket_tracking | | | 1.43±0.3μs | 1.41±0.3μs | 0.99 | transport_geometry_calculate_distances.BenchmarkTransportGeometryCalculateDistances.time_calculate_distance_line | | | 63.4±0.2ms | 62.8±0.01ms | 0.99 | transport_montecarlo_packet_trackers.BenchmarkTransportMontecarloPacketTrackers.time_rpacket_trackers_to_dataframe | | | 3.06±0.9μs | 3.02±0.6μs | 0.99 | transport_montecarlo_vpacket.BenchmarkMontecarloMontecarloNumbaVpacket.time_trace_vpacket_within_shell | | | 2.57±0.5ms | 2.53±0.4ms | 0.98 | transport_montecarlo_single_packet_loop.BenchmarkTransportMontecarloSinglePacketLoop.time_single_packet_loop | | | 45.2±20μs | 43.4±20μs | 0.96 | transport_montecarlo_interaction.BenchmarkTransportMontecarloInteraction.time_line_scatter | | | 621±100ns | 591±100ns | 0.95 | opacities_opacity.BenchmarkMontecarloMontecarloNumbaOpacities.time_photoabsorption_opacity_calculation | | | 2.24±1μs | 2.10±1μs | 0.94 | transport_montecarlo_estimators_radfield_estimator_calcs.BenchmarkMontecarloMontecarloNumbaPacket.time_update_line_estimators | ```

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

andrewfullard commented 3 weeks ago

What exactly do you mean by "emitted"? Escaped the outer boundary of the simulation?

Sumit112192 commented 3 weeks ago

What exactly do you mean by "emitted"? Escaped the outer boundary of the simulation?

class PacketStatus(IntEnum):
    IN_PROCESS = 0
    EMITTED = 1
    REABSORBED = 2
    ADIABATIC_COOLING = 4

Yes. In the end, the packet is emitted from the ejecta or reabsorbed in the photosphere.