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

Track boundary interaction #2736

Merged
merged 36 commits into from
Aug 12, 2024

Conversation

Sumit112192
Copy link
Contributor

📝 Description

Type: 🚀 feature
This PR implements the functionality of tracking boundary interactions. It currently aims to track boundary interaction info in the form of (current_shell_id, next_shell_id)

Depends on PR #2719

Copy link

codecov bot commented Jul 24, 2024

Codecov Report

Attention: Patch coverage is 28.57143% with 30 lines in your changes missing coverage. Please review.

Project coverage is 69.38%. Comparing base (e1aa887) to head (1ea86d4).

Files Patch % Lines
tardis/transport/montecarlo/packet_trackers.py 13.33% 26 Missing ⚠️
tardis/transport/montecarlo/single_packet_loop.py 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2736      +/-   ##
==========================================
- Coverage   69.98%   69.38%   -0.61%     
==========================================
  Files         196      196              
  Lines       15008    15033      +25     
==========================================
- Hits        10503    10430      -73     
- Misses       4505     4603      +98     

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

@tardis-bot
Copy link
Contributor

tardis-bot commented Jul 28, 2024

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

3	I001  	[*] Import block is un-sorted or un-formatted
2	PIE790	[*] Unnecessary `pass` statement
2	D411  	[*] Missing blank line before section ("Parameters")
2	UP004 	[*] Class `RPacketLastInteractionTracker` inherits from `object`
1	ANN205	[ ] Missing return type annotation for staticmethod `get_relative_path`
1	B009  	[*] Do not call `getattr` with a constant attribute value. It is not any safer than normal property access.
1	RET506	[ ] Unnecessary `else` after `raise` statement

Complete output(might be large):

benchmarks/benchmark_base.py:29:9: ANN205 Missing return type annotation for staticmethod `get_relative_path`
benchmarks/benchmark_base.py:75:9: RET506 Unnecessary `else` after `raise` statement
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:203: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:223:37: UP004 [*] Class `RPacketLastInteractionTracker` inherits from `object`
tardis/transport/montecarlo/packet_trackers.py:226:5: D411 [*] Missing blank line before section ("Parameters")
tardis/transport/montecarlo/packet_trackers.py:268:9: PIE790 [*] Unnecessary `pass` statement
tardis/transport/montecarlo/packet_trackers.py:275:9: PIE790 [*] Unnecessary `pass` statement
tardis/transport/montecarlo/single_packet_loop.py:1:1: I001 [*] Import block is un-sorted or un-formatted
tardis/transport/montecarlo/tests/test_rpacket_tracker.py:1:1: I001 [*] Import block is un-sorted or un-formatted
Found 12 errors.
[*] 10 fixable with the `--fix` option.

@Sumit112192 Sumit112192 force-pushed the TrackBoundaryInteraction branch 2 times, most recently from 771a665 to 7506cac Compare July 29, 2024 05:31
@Sumit112192
Copy link
Contributor Author

The output currently looks like:

rpacket_tracker = sim.transport.transport_state.rpacket_tracker
rpacket_tracker[2].boundary_interaction
array([(1, -1,  0), (2,  0,  1), (3,  1,  0), (4,  0, -1)],
      dtype=[('interaction_id', '<i8'), ('current_shell_id', '<i8'), ('next_shell_id', '<i8')])
rpacket_tracker[2].boundary_interaction["interaction_id"]
array([1, 2, 3, 4])
rpacket_tracker[2].boundary_interaction["current_shell_id"]
array([-1,  0,  1,  0])
rpacket_tracker[2].boundary_interaction["next_shell_id"]
array([ 0,  1,  0, -1])

@Sumit112192 Sumit112192 marked this pull request as ready for review July 29, 2024 13:49
@@ -85,6 +86,9 @@ def single_packet_loop(
)

rpacket_tracker.track(r_packet)
rpacket_tracker.track_boundary_interaction(
PacketEjectaStatus.OUT_EJECTA, r_packet.current_shell_id
Copy link
Member

Choose a reason for hiding this comment

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

I think we should rename this @andrewfullard

Copy link
Contributor

Choose a reason for hiding this comment

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

I would personally just add to the PacketStatus Enum rather than defining a new one

@Sumit112192
Copy link
Contributor Author

Sumit112192 commented Jul 30, 2024

@wkerzendorf I have added track line interaction in this PR, to demonstrate how will the final tracker functionality might look like instead of creating a new PR.

@Sumit112192
Copy link
Contributor Author

@wkerzendorf The output the tracker displays.

rpacket_tracker[10].boundary_interaction
array([( 1, -1,  0), ( 2,  0,  1), ( 3,  1,  2), ( 4,  2,  3),
       ( 5,  3,  4), ( 6,  4,  5), ( 7,  5,  4), ( 8,  4,  3),
       ( 9,  3,  2), (11,  2,  3), (12,  3,  4), (13,  4,  5),
       (14,  5,  6), (15,  6,  7), (16,  7,  8), (17,  8,  9),
       (20,  9, 10), (23, 10, 11), (25, 11, 10), (26, 10,  9),
       (27,  9,  8), (28,  8,  7), (29,  7,  6), (30,  6,  5),
       (31,  5,  4), (32,  4,  3), (34,  3,  4), (35,  4,  5),
       (37,  5,  6), (38,  6,  7), (39,  7,  8), (40,  8,  9),
       (41,  9, 10), (42, 10, 11), (43, 11, 12), (44, 12, 13),
       (45, 13, 14), (46, 14, 15), (47, 15, 16), (48, 16, 17),
       (49, 17, 18), (50, 18, 19), (51, 19, -1)],
      dtype=[('interaction_id', '<i8'), ('current_shell_id', '<i8'), ('next_shell_id', '<i8')])
rpacket_tracker[10].line_interaction
array([(10,  2, 1.38711254e+15, 1.96697997e+15, 4424, 4424),
       (18,  9, 1.70933416e+15, 2.09341849e+15, 4456, 3515),
       (19,  9, 1.72672264e+15, 2.75476977e+15, 3517, 3276),
       (21, 10, 1.75272138e+15, 3.04074219e+15, 3283, 5399),
       (22, 10, 1.76448678e+15, 1.68038515e+15, 5406, 5406),
       (24, 11, 1.79317922e+15, 1.66948517e+15, 5431, 5431),
       (33,  3, 1.41930616e+15, 1.61094915e+15, 5501, 4273),
       (36,  5, 1.51352255e+15, 2.16048881e+15, 4285, 7272)],
      dtype=[('interaction_id', '<i8'), ('shell_id', '<i8'), ('r', '<f8'), ('in_nu', '<f8'), ('in_id', '<i8'), ('out_id', '<i8')])

We can also access the individual attributes,

rpacket_tracker[10].line_interaction["interaction_id"]
array([10, 18, 19, 21, 22, 24, 33, 36])
rpacket_tracker[10].line_interaction["shell_id"]
array([ 2,  9,  9, 10, 10, 11,  3,  5])
rpacket_tracker[10].line_interaction["r"]
array([1.38711254e+15, 1.70933416e+15, 1.72672264e+15, 1.75272138e+15,
       1.76448678e+15, 1.79317922e+15, 1.41930616e+15, 1.51352255e+15])
rpacket_tracker[10].line_interaction["in_nu"]
array([1.96697997e+15, 2.09341849e+15, 2.75476977e+15, 3.04074219e+15,
       1.68038515e+15, 1.66948517e+15, 1.61094915e+15, 2.16048881e+15])

@Sumit112192 Sumit112192 marked this pull request as draft July 30, 2024 13:25
@Sumit112192
Copy link
Contributor Author

I have converted this PR to a draft. I have to add tests, but it still can be reviewed as tests are independent.

self.event_id += 1

def track_line_interaction(self, r_packet):
if self.num_line_interactions >= self.line_interaction_array_length:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this if block, and the one in track_boundary_interaction, may be better as a separate method that performs the array extension.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. That makes sense. I will look into it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can they both be merged into a single extend function?

Copy link
Contributor

Choose a reason for hiding this comment

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

That would be ideal.

self.num_interactions = 0
self.boundary_interactions_index = 0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wkerzendorf If I keep the name num_boundary_interactions it seems similar to the variable num_interactions and can be used to obtain the number of boundary interactions whereas with the current name, it seems that it will only be used for array purposes. Should I rename it to num_boundary_interactions

Copy link
Member

Choose a reason for hiding this comment

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

It will be used for indexing purposes - essentially all of the analysis will be done on the dataframes

"""

def __init__(self, length):
self.length = length
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed this length variable, since If I kept this length, I would have to add another length variable for every track_interaction function.

@Sumit112192
Copy link
Contributor Author

why is black failing here? even though locally with the same version it says no reformat is required. @atharva-2001

@atharva-2001
Copy link
Member

atharva-2001 commented Aug 2, 2024

  1. Are you sure your black version is the same? black==22.3? What happens when you do black --version
  2. Are you running the same command locally as in the workflow? What command are you running?

@Sumit112192
Copy link
Contributor Author

  1. Are you sure your black version is the same? black==22.3? What happens when you do black --version

    1. Are you running the same command locally as in the workflow? What command are you running?

Yeah. I checked the version and the file it says to reformat, I ran black on that file.

@Sumit112192
Copy link
Contributor Author

I haven't even changed that file, black is suggesting.

@atharva-2001
Copy link
Member

Can you rebase once?

@Sumit112192
Copy link
Contributor Author

Can you rebase once?

I did that just now.

@atharva-2001
Copy link
Member

I will try replicating this in a while

@Sumit112192
Copy link
Contributor Author

I will try replicating this in a while

thanks.

@Sumit112192 Sumit112192 marked this pull request as ready for review August 2, 2024 13:35
andrewfullard
andrewfullard previously approved these changes Aug 2, 2024
@Sumit112192
Copy link
Contributor Author

Sumit112192 commented Aug 5, 2024

To replicate the benchmarking error,I started with a new branch created from the upstream/master branch, I rerun the benchmark locally of every commit, I made. First, remove the length variable, then declare the boundary_interaction datatype, and then define the track_boundary_interaction function. The benchmark failed when I added the track_boundary_interaction so the issue is this function but I can't figure it out. @officialasishkumar @andrewfullard Can you help me figure out the problem with this function?

@andrewfullard andrewfullard merged commit 63eb762 into tardis-sn:master Aug 12, 2024
23 of 25 checks passed
@Sumit112192 Sumit112192 deleted the TrackBoundaryInteraction branch September 8, 2024 13:07
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.

7 participants