-
-
Notifications
You must be signed in to change notification settings - Fork 405
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
Restructure Trackers #2719
Restructure Trackers #2719
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2719 +/- ##
==========================================
- Coverage 69.65% 69.30% -0.36%
==========================================
Files 188 192 +4
Lines 14930 15047 +117
==========================================
+ Hits 10400 10428 +28
- Misses 4530 4619 +89 ☔ View full report in Codecov by Sentry. |
*beep* *bop* Significantly changed benchmarks: · Did not find results for commit c18503a794babddd9b54e1e3aaa89f733ced4e41
All benchmarks: · Did not find results for commit c18503a794babddd9b54e1e3aaa89f733ced4e41
If you want to see the graph of the results, you can check it here |
So you are just using pure Python to initialize the lists and passing them along to the main loop? |
Yes. That's the only way it could be initialized without dead branch pruning. |
I could move the initialization to montecarlo_globals with numba compilation. Should I go for that? |
Need to test the speed of the initialization |
Testing the speed of appending to a numba list in pure python function and function decorated with Numba. import numba
from numba.typed import List
import timeit
from tardis.transport.montecarlo.packet_trackers import RPacketTracker, RPacketLastInteractionTracker no_of_packets = 100000 @numba.njit
def return_rpacket_tracker():
aList = List()
for i in range(no_of_packets):
aList.append(RPacketTracker(10))
return aList
@numba.njit
def return_rpacket_last_interaction_tracker():
aList = List()
for i in range(no_of_packets):
aList.append(RPacketLastInteractionTracker())
return aList
def return_rpacket_tracker_pure():
aList = List()
for i in range(no_of_packets):
aList.append(RPacketTracker(10))
return aList
def return_rpacket_last_interaction_tracker_pure():
aList = List()
for i in range(no_of_packets):
aList.append(RPacketLastInteractionTracker())
return aList %timeit return_rpacket_tracker()
%timeit return_rpacket_last_interaction_tracker()
%timeit return_rpacket_tracker_pure()
%timeit return_rpacket_last_interaction_tracker_pure()
|
Testing the speed of various ways to solve the current problem. from numba.typed import List
import numba
import timeit
from tardis.transport.montecarlo.packet_trackers import RPacketTracker, RPacketLastInteractionTracker no_of_packets = 100000 appending in true pythondef aNormalFunc(flag):
aList = List()
if flag:
for i in range(no_of_packets):
aList.append(RPacketTracker(10))
else:
for i in range(100000):
aList.append(RPacketLastInteractionTracker())
return aList appending in numbaflag = True
@numba.njit
def aNumbaFunc():
aList = List()
if flag:
for i in range(no_of_packets):
aList.append(RPacketTracker(10))
else:
for i in range(no_of_packets):
aList.append(RPacketLastInteractionTracker())
return aList appending in true python with loop in numba@numba.njit
def returnRPacketTracker():
aList = List()
for i in range(no_of_packets):
aList.append(RPacketTracker(10))
return aList
@numba.njit
def returnRPacketLastInteractionTracker():
aList = List()
for i in range(no_of_packets):
aList.append(RPacketLastInteractionTracker())
return aList
def aNormalFuncWithNumbaLoop(flag):
if flag:
aList = returnRPacketTracker()
else:
aList = returnRPacketLastInteractionTracker()
return aList Checking runtime using timeit%timeit aNormalFunc(True)
%timeit aNumbaFunc()
%timeit aNormalFuncWithNumbaLoop(True);
|
8c8f186
to
ed5fbed
Compare
@atharva-2001 @andrewfullard I think this means we do not need a separate RPacketTracker test suite |
@Sumit112192 please add tests |
|
||
def test_generate_rpacket_last_interaction_tracker_list(): | ||
no_of_packets = 50 | ||
random_index = np.random.randint(0, no_of_packets) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the time usage of the random number generator
import numpy as np
no_of_packets = 50
%timeit np.random.randint(0, no_of_packets)
2.89 μs ± 199 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
Done. |
I have added benchmarks for the packet_tracker utility functions, namely, |
Also, I am parameterizing the benchmarks the way they are given in the documentation as opposed to the parameterized marker, i.e., |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to merge this if the benchmarks running can be confirmed
The benchmarks pass if we look at the first 50% of the GitHub benchmark check. It fails on the master branch commit because the utility functions are not currently available in the master branch. |
📝 Description
Type: 🎢
infrastructure
This PR brings the rpacket_trackers initialization outside the
montecarlo_main_loop
to avoid the usage of compile time constants and reduce complexity.