Skip to content

Commit

Permalink
printing packet information (#1877)
Browse files Browse the repository at this point in the history
* add print statement

* add documentation

* fix imports

* change print statement

* run in objmode
  • Loading branch information
wkerzendorf authored Jan 27, 2022
1 parent bb4304b commit ae5c17b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
5 changes: 3 additions & 2 deletions tardis/montecarlo/montecarlo_numba/calculate_distances.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)

from tardis.montecarlo.montecarlo_numba.utils import MonteCarloException

from tardis.montecarlo.montecarlo_numba.r_packet import print_r_packet_properties

@njit(**njit_dict_no_parallel)
def calculate_distance_boundary(r, mu, r_inner, r_outer):
Expand Down Expand Up @@ -98,7 +98,8 @@ def calculate_distance_line(
if nu_diff >= 0:
distance = (nu_diff / nu) * C_SPEED_OF_LIGHT * time_explosion
else:
print("WARNING: nu difference is less than 0.0")
print("WARNING: nu difference is less than 0.0; see packet information below")
print_r_packet_properties(r_packet)
raise MonteCarloException(
"nu difference is less than 0.0; for more"
" information, see print statement beforehand"
Expand Down
20 changes: 18 additions & 2 deletions tardis/montecarlo/montecarlo_numba/r_packet.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from enum import IntEnum

import numpy as np
from numba import int64, float64
from numba import int64, float64, njit, objmode
from numba.experimental import jitclass

from tardis.montecarlo.montecarlo_numba.frame_transformations import (
get_doppler_factor,
)

from tardis.montecarlo.montecarlo_numba import njit_dict_no_parallel

class InteractionType(IntEnum):
BOUNDARY = 1
Expand Down Expand Up @@ -68,3 +68,19 @@ def initialize_line_id(self, numba_plasma, numba_model):
self.next_line_id = next_line_id


@njit(**njit_dict_no_parallel)
def print_r_packet_properties(r_packet):
"""
Print all packet information
Parameters
----------
r_packet : RPacket
RPacket object
"""
print("-"*80)
print("R-Packet information:")
with objmode:
for r_packet_attribute_name, _ in rpacket_spec:
print(r_packet_attribute_name, "=", str(getattr(r_packet, r_packet_attribute_name)))
print("-"*80)

0 comments on commit ae5c17b

Please sign in to comment.