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

Add status to r packet last interaction tracker #2796

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Sumit112192
Copy link
Contributor

📝 Description

Type: 🚀 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
Copy link
Contributor

tardis-bot commented Aug 14, 2024

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

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

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

Copy link

codecov bot commented Aug 14, 2024

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 ⚠️
Additional details and impacted files
@@            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     

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

@tardis-bot
Copy link
Contributor

tardis-bot commented Aug 14, 2024

*beep* *bop*
Hi human,
I ran benchmarks as you asked comparing master (5fe6806) and the latest commit (8578799).
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 [b79b61ed] <master>   | 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
Copy link
Contributor

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

@Sumit112192
Copy link
Contributor Author

Sumit112192 commented Aug 20, 2024

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.

@Sumit112192 Sumit112192 force-pushed the AddStatusToRPacketLastInteractionTracker branch from 90beeb4 to 21614fa Compare August 20, 2024 10:13
andrewfullard
andrewfullard previously approved these changes Aug 20, 2024
@Sumit112192
Copy link
Contributor Author

Sumit112192 commented Sep 23, 2024

@DeerWhale There is some issue with the current logic, so I have to change the current code in the PR. But it will need some discussion. The current code will always show the packet status to be IN_PROCESS since the track function is invoked only when it is Line Interaction or Escatter interaction but not boundary interaction, so it misses the last boundary interaction.

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

Successfully merging this pull request may close these issues.

4 participants