Skip to content

Comments

GSoC:Fix vpacket energy histogram race condition in prange loop#3424

Open
remo-lab wants to merge 1 commit intotardis-sn:masterfrom
remo-lab:fix/vpacket-histogram-race-condition
Open

GSoC:Fix vpacket energy histogram race condition in prange loop#3424
remo-lab wants to merge 1 commit intotardis-sn:masterfrom
remo-lab:fix/vpacket-histogram-race-condition

Conversation

@remo-lab
Copy link

📝 Description

Type: 🪲 bugfix

Summary: Fixed race condition in virtual packet energy histogram accumulation inside prange parallel loop. The += operation on shared array v_packets_energy_hist caused non-deterministic energy loss scaling with thread count. Moved histogram binning to sequential post-processing loop.

Impact: Multi-threaded virtual packet spectra were systematically low in luminosity. Now matches single-threaded results.


🚦 Testing

  • Testing pipeline
  • Compare single vs multi-threaded virtual packet spectra
  • Verify luminosity conservation

☑️ 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

Copy link
Contributor

@tardis-bot tardis-bot left a comment

Choose a reason for hiding this comment

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

👋 Welcome @remo-lab! Thank you for your first contribution to this repository!

Before asking for reviews, please fill out the PR description template and ensure that all checks are passing.

If you are applying to GSoC, please read our AI Usage Policy and make sure to add GSoC to the PR title like so:

GSoC: <title of your pull request>

Please mark the pull request as draft if you are not ready for review yet or if there are things you will be adding.

@tardis-bot
Copy link
Contributor

*beep* *bop*

Hi, human.

I'm the @tardis-bot and couldn't find your records in my database. I think we don't know each other, or you changed your credentials recently.

Please add your name and email to .mailmap in your current branch and push the changes to this pull request.

In case you need to map an existing alias, follow this example.

@tardis-bot
Copy link
Contributor

*beep* *bop*

Hi, human.

I'm the @tardis-bot and I noticed that your email is not associated with an ORCID ID in our database.

Please add your email and ORCID ID to the .orcid.csv file in your current branch and push the changes to this pull request.

If you don't have an ORCID ID yet, you can create one for free at orcid.org. ORCID IDs help ensure you get proper credit for your scientific contributions.

The format should be:

email,orcid
your.email@example.com,0000-0000-0000-0000

@tardis-bot
Copy link
Contributor

tardis-bot commented Feb 11, 2026

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

Details
805	      	[ ] syntax-error
8	G004  	[ ] logging-f-string
6	I001  	[*] unsorted-imports
5	F401  	[*] unused-import
4	E902  	[ ] io-error
3	W291  	[ ] trailing-whitespace
3	F821  	[ ] undefined-name
3	RET505	[*] superfluous-else-return
2	UP006 	[*] non-pep585-annotation
2	UP035 	[ ] deprecated-import
1	E701  	[ ] multiple-statements-on-one-line-colon
1	W293  	[*] blank-line-with-whitespace
1	B017  	[ ] assert-raises-exception
1	F811  	[ ] redefined-while-unused
1	INP001	[ ] implicit-namespace-package
1	PIE804	[*] unnecessary-dict-kwargs
1	RET506	[*] superfluous-else-raise
1	RUF021	[*] parenthesize-chained-operators
1	UP032 	[*] f-string
Found 850 errors.
[*] 23 fixable with the `--fix` option.

Complete output(might be large):

Details
tardis/energy_input/tests/test_gamma_ray_packet_source_minimal.py:3:1: I001 [*] Import block is un-sorted or un-formatted
tardis/energy_input/tests/test_gamma_ray_packet_source_minimal.py:5:17: F401 [*] `numpy` imported but unused
tardis/io/configuration/config_reader.py:1:1: I001 [*] Import block is un-sorted or un-formatted
tardis/io/configuration/config_reader.py:54:29: G004 Logging statement uses f-string
tardis/io/configuration/config_reader.py:118:9: RET505 [*] Unnecessary `else` after `return` statement
tardis/io/configuration/config_reader.py:142:13: RET505 [*] Unnecessary `else` after `return` statement
tardis/io/configuration/config_reader.py:219:29: G004 Logging statement uses f-string
tardis/io/model/csvy/__init__.py:1:1: E902 No such file or directory (os error 2)
tardis/io/model/csvy/data.py:1:1: E902 No such file or directory (os error 2)
tardis/io/model/csvy/readers.py:1:1: E902 No such file or directory (os error 2)
tardis/io/model/parse_density_configuration.py:2:1: UP035 `typing.Tuple` is deprecated, use `tuple` instead
tardis/io/model/parse_density_configuration.py:20:6: UP006 [*] Use `tuple` instead of `Tuple` for type annotation
tardis/io/model/parse_mass_fraction_configuration.py:4:25: F401 [*] `astropy.units` imported but unused
tardis/io/model/parse_radiation_field_configuration.py:1:1: I001 [*] Import block is un-sorted or un-formatted
tardis/io/model/readers/generic_readers.py:1:1: UP035 `typing.Tuple` is deprecated, use `tuple` instead
tardis/io/model/readers/generic_readers.py:20:6: UP006 [*] Use `tuple` instead of `Tuple` for type annotation
tardis/io/model/readers/generic_readers.py:51:72: W291 [*] Trailing whitespace
tardis/io/model/readers/tests/test_csvy_reader.py:1:1: INP001 File `tardis/io/model/readers/tests/test_csvy_reader.py` is part of an implicit namespace package. Add an `__init__.py`.
tardis/io/model/readers/tests/test_csvy_reader.py:47:10: B017 Do not assert blind exception: `Exception`
tardis/model/base.py:1:1: I001 [*] Import block is un-sorted or un-formatted
tardis/model/base.py:368:21: G004 Logging statement uses f-string
tardis/transport/montecarlo/montecarlo_main_loop.py:9:55: F401 [*] `tardis.transport.montecarlo.configuration.montecarlo_globals` imported but unused
tardis/transport/montecarlo/montecarlo_main_loop.py:20:5: F401 [*] `tardis.transport.montecarlo.packets.packet_collections.initialize_last_interaction_tracker` imported but unused
tardis/transport/montecarlo/montecarlo_main_loop.py:170:1: W293 [*] Blank line contains whitespace
tardis/visualization/widgets/custom_abundance.py:3:1: I001 [*] Import block is un-sorted or un-formatted
tardis/visualization/widgets/custom_abundance.py:741:16: RUF021 [*] Parenthesize `a and b` expressions when chaining `and` and `or` together, to make the precedence clear
tardis/visualization/widgets/custom_abundance.py:1131:9: RET505 [*] Unnecessary `else` after `return` statement
tardis/visualization/widgets/custom_abundance.py:1422:9: RET506 [*] Unnecessary `else` after `raise` statement
tardis/visualization/widgets/custom_abundance.py:1725:9: F811 Redefinition of unused `input_d_time_0_eventhandler` from line 1714
tardis/visualization/widgets/custom_abundance.py:1755:13: F821 Undefined name `display`
tardis/visualization/widgets/custom_abundance.py:1757:13: F821 Undefined name `display`
tardis/visualization/widgets/custom_abundance.py:1759:13: F821 Undefined name `display`
tardis/workflows/simple_tardis_workflow.py:269:17: G004 Logging statement uses f-string
tardis/workflows/simple_tardis_workflow.py:525:17: G004 Logging statement uses f-string
tardis/workflows/type_iip_workflow.py:155:13: PIE804 [*] Unnecessary `dict` kwargs
tardis/workflows/type_iip_workflow.py:357:13: G004 Logging statement uses f-string
tardis/workflows/type_iip_workflow.py:411:17: G004 Logging statement uses f-string
tardis/workflows/type_iip_workflow.py:518:15: UP032 [*] Use f-string instead of `format` call
tardis/workflows/type_iip_workflow.py:883:17: G004 Logging statement uses f-string
Found 39 errors.
[*] 20 fixable with the `--fix` option.

@remo-lab remo-lab changed the title Fix vpacket energy histogram race condition in prange loop GSoC:Fix vpacket energy histogram race condition in prange loop Feb 11, 2026
@remo-lab
Copy link
Author

remo-lab commented Feb 11, 2026

Hi @atharva-2001 @wkerzendorf , I think I found a race condition in the montecarlo loop where virtual packet energies weren't being accumulated correctly in multi-threaded runs. I moved the histogram binning outside the prange loop . would appreciate a review whenever you have time!

@atharva-2001
Copy link
Member

Hi, please read the instructions mentioned here- https://tardis-sn.github.io/summer_of_code/pr_checklist/

@codecov
Copy link

codecov bot commented Feb 11, 2026

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.53%. Comparing base (57ded6b) to head (dd02768).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...ardis/transport/montecarlo/montecarlo_main_loop.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3424      +/-   ##
==========================================
- Coverage   70.73%   70.53%   -0.21%     
==========================================
  Files         213      213              
  Lines       17259    17261       +2     
==========================================
- Hits        12209    12175      -34     
- Misses       5050     5086      +36     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@remo-lab remo-lab force-pushed the fix/vpacket-histogram-race-condition branch from dd02768 to ba351bd Compare February 12, 2026 01:56
@tardis-bot
Copy link
Contributor

*beep* *bop*

Hi, human.

I'm the @tardis-bot and couldn't find your records in my database. I think we don't know each other, or you changed your credentials recently.

Please add your name and email to .mailmap in your current branch and push the changes to this pull request.

In case you need to map an existing alias, follow this example.

Signed-off-by: remo-lab <remopanda7@gmail.com>
@remo-lab remo-lab force-pushed the fix/vpacket-histogram-race-condition branch from ba351bd to 3c550f9 Compare February 12, 2026 02:01
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