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

Tracking RPacket Properties in Montecarlo Single Packet Loop Function #1748

Merged
merged 23 commits into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
250989a
Added functionality to track properties for r_packets, configured fro…
DhruvSondhi Jul 26, 2021
b132079
Tried implementation of record based tracking of the r_packet properties
DhruvSondhi Jul 27, 2021
99890ae
Implemented array based packet property tracking
DhruvSondhi Jul 29, 2021
42d8f58
Added functionality to reduce the array size inside the RPacketCollec…
DhruvSondhi Jul 29, 2021
6135d12
Reverted formatting changes within montecarlo_numba/base.py
DhruvSondhi Jul 29, 2021
d61b9ae
Changed the searching implementation for finding the exact size of th…
DhruvSondhi Aug 2, 2021
d86b9cd
Added docstring for the newly added RPacketCollection Class
DhruvSondhi Aug 2, 2021
2b4eef1
Made array length for the properties in the RPacketCollection configu…
DhruvSondhi Aug 2, 2021
7d05438
Added tests for r_packet tracking
DhruvSondhi Aug 2, 2021
1cf4c3c
Changed initial_array_length to const value,
DhruvSondhi Aug 3, 2021
03683c3
Added demarcation for Setup & Teardown in tests
DhruvSondhi Aug 4, 2021
6a2fcf3
Changed set_properties func to track,
DhruvSondhi Aug 5, 2021
2c8b5de
Renamed r_packet_tracking to track_rpacket for consistency
DhruvSondhi Aug 5, 2021
daa436c
Added Documentation for RPacket Tracking
DhruvSondhi Aug 5, 2021
f110cbe
Changed formatting for the documentation
DhruvSondhi Aug 5, 2021
ff4301c
Reverted whitespace addition
DhruvSondhi Aug 10, 2021
b380bbc
Made required changes,
DhruvSondhi Aug 12, 2021
e418e11
Made changes as requested
DhruvSondhi Aug 16, 2021
4722b5a
[build docs]
DhruvSondhi Aug 16, 2021
6bfd6fd
Restructured code for multithreading
DhruvSondhi Nov 7, 2021
53d6e0c
Restructured the tracking to happen after conditionals in single_pack…
DhruvSondhi Dec 3, 2021
6a804fc
Added Docstrings to RPacketCollection JITClass
DhruvSondhi Dec 9, 2021
97216e9
Refactored original tests to be consistent with the new changes
DhruvSondhi Dec 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/io/output/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ In addition to the widgets, TARDIS can output information in several other forms
to_hdf
callback
vpacket_logging
progress_bars
progress_bars
rpacket_tracking
333 changes: 333 additions & 0 deletions docs/io/output/rpacket_tracking.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,333 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "f57cd4fe",
"metadata": {},
"source": [
"# Tracking the Properties of Real Packets"
]
},
{
"cell_type": "markdown",
"id": "c103617c",
"metadata": {},
"source": [
"**TARDIS** has the functionality to track the properties of the *RPackets* that are generated when running the Simulation. The `rpacket_tracker` can track all the interactions a packet undergoes & thus keeps a track of the various properties, a packet may have.<br>Currently, the `rpacket_tracker` tracks the properties of all the packets in the *Last Iteration of the Simulation*. "
]
},
{
"cell_type": "markdown",
"id": "ce6214b9",
"metadata": {},
"source": [
"<html>\n",
" <body>\n",
" The properties that are tracked are as follows :\n",
" <ol>\n",
" <li><b>index</b> - Index of the Packet</li>\n",
" <li><b>seed</b> - Seed of the Packet</li>\n",
" <li><b>status</b> - Current Status for the Packet Interaction</li>\n",
" <li><b>r</b> - Radius of the Current Shell</li> \n",
" <li><b>nu</b> - Packet's Frequency</li> \n",
" <li><b>mu</b> - Propagation Direction of the Packet (cosine of the angle the packet’s path makes with the radial direction)</li>\n",
" <li><b>energy</b> - Energy of the Packet</li>\n",
" <li><b>shell_id</b> - Current Shell Id where the Packet is present</li>\n",
" </ol>\n",
" </body>\n",
"</html>"
]
},
{
"cell_type": "markdown",
"id": "1686d9f1",
"metadata": {},
"source": [
"## How to Setup the Tracking for the RPackets?"
]
},
{
"cell_type": "markdown",
"id": "29e14475",
"metadata": {},
"source": [
"**TARDIS**' `rpacket_tracker` is configured via the `YAML` file. This functionality of tracking the packets is turned **off**, by default. This is due to that fact that using this property, may slow down the execution time for the Simulation. An example configuration can be seen below for setting up the *tracking*:\n",
"\n",
"```yaml\n",
"... \n",
"montecarlo:\n",
"...\n",
"tracking:\n",
" r_packet_tracking: true\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "13b6420b",
"metadata": {},
"source": [
"The `montecarlo` section of the **YAML** file now has a `tracking` sub section which holds the configuration properties for the `rpacket_tracker` & the `initial_array_length` (discussed later in the tutorial)."
]
},
{
"cell_type": "markdown",
"id": "2634c571",
"metadata": {},
"source": [
"Let us see, the new `rpacket_tracker` in action."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a0e975b6",
"metadata": {},
"outputs": [],
"source": [
"from tardis.io.config_reader import Configuration"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "adbf5f75",
"metadata": {},
"outputs": [],
"source": [
"# Reading the Configuration stored in `tardis_config_packet_tracking.yml` into config\n",
"\n",
"config = Configuration.from_yaml(\"tardis_example.yml\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "975766e9",
"metadata": {},
"outputs": [],
"source": [
"# Checking the `tracking` section via the Schema\n",
"\n",
"config[\"montecarlo\"][\"tracking\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b00bc2ca",
"metadata": {},
"outputs": [],
"source": [
"# Setting `r_packet_tracking` to True to turn on the Tracking \n",
"\n",
"config[\"montecarlo\"][\"tracking\"][\"track_rpacket\"] = True"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b25271d6",
"metadata": {},
"outputs": [],
"source": [
"from tardis import run_tardis"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f9e51fd3",
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"# Running the simulation from the config\n",
"\n",
"sim = run_tardis(config, show_cplots=False)"
]
},
{
"cell_type": "markdown",
"id": "532bfafc",
"metadata": {},
"source": [
"Now, the `tracked` properties can be accessed via the `rpacket_tracker` attribute of the `sim.runner` object. "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f8b3424f",
"metadata": {},
"outputs": [],
"source": [
"sim.runner.rpacket_tracker"
]
},
{
"cell_type": "markdown",
"id": "4771d92a",
"metadata": {},
"source": [
"It can be seen from the above code, that the `sim.runner.rpacket_tracker` is an instance of the `RPacketCollection` *Numba jitclass*. The `RPacketCollection` class has the following structure for the properties : {More information in the **TARDIS API** for `RPacketCollection` class}"
]
},
{
"cell_type": "markdown",
"id": "ce587807",
"metadata": {},
"source": [
"```python\n",
"# Basic structure for the RPacketCollection Class\n",
"class RPacketCollection:\n",
" # Properties\n",
" index\n",
" seed\n",
" status\n",
" r\n",
" nu\n",
" mu\n",
" energy\n",
" shell_id\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "411f2ef9",
"metadata": {},
"source": [
"To access these different properties, we may consider the following examples for the `rpacket_tracker`:"
]
},
{
"cell_type": "markdown",
"id": "a4772b00",
"metadata": {},
"source": [
"- Accessing the `index` property for the packets:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "de7b8877",
"metadata": {},
"outputs": [],
"source": [
"sim.runner.rpacket_tracker.index"
]
},
{
"cell_type": "markdown",
"id": "d81fbbf7",
"metadata": {},
"source": [
"- Accessing the `seed` property for the packets:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "39e2dbd2",
"metadata": {},
"outputs": [],
"source": [
"sim.runner.rpacket_tracker.seed"
]
},
{
"cell_type": "markdown",
"id": "7afe2110",
"metadata": {},
"source": [
"- Accessing the `status` property for the packets:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e82427ea",
"metadata": {},
"outputs": [],
"source": [
"sim.runner.rpacket_tracker.status"
]
},
{
"cell_type": "markdown",
"id": "ea308a55",
"metadata": {},
"source": [
"Thus, all other properties {`r`, `nu`, `mu`, `energy`, `shell_id`} can be accessed accordingly."
]
},
{
"cell_type": "markdown",
"id": "c83dd906",
"metadata": {},
"source": [
"We can also see the total number of interactions all the packets had, with the following example:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "090b1517",
"metadata": {},
"outputs": [],
"source": [
"len(sim.runner.rpacket_tracker.index)"
]
},
{
"cell_type": "markdown",
"id": "9136fba1",
"metadata": {},
"source": [
"<div class=\"alert alert-warning\">\n",
"\n",
"Warning\n",
"\n",
"If we try to access `sim.runner.rpacket_tracker` property when we have the `track_rpacket` property in the `tracking` subsection of `montecarlo` config, turned off as follows `config[\"montecarlo\"][\"tracking\"][\"track_rpacket\"] = False`, it will return `None`. Error will be raised if we try to access the properties i.e. `seed`, `index`, etc.\n",
"</div>"
]
},
{
"cell_type": "markdown",
"id": "afa3c7f4",
"metadata": {},
"source": [
"<div class=\"alert alert-info\">\n",
"\n",
"Note\n",
" \n",
"When we initialise the `RPacketCollection()` class, the properties arrays {`index`, `seed`, `status`, etc} are allocated certain length based on the `initial_array_length` parameter that can be set via the `initial_array_length` property under `montecarlo -> tracking` section of the configuration. The default size of the array is `10`. This variable is important as the number of interactions a packet may have is variable, thus we need to allocate space dynamically. This variable is used to compute the size and expand the array such that the properties are able to hold these values for the packet interaction. Higher number, allocates more space initially leading to lesser times the arrays expands and vice versa. It can be set in the following manner `config[\"montecarlo\"][\"tracking\"][\"initial_array_length\"] = {value}`.\n",
"</div>"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
14 changes: 14 additions & 0 deletions tardis/io/schemas/montecarlo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ properties:
default: false
description: Enables a more complete treatment of relativitic effects. This includes
angle aberration as well as use of the fully general Doppler formula.
tracking:
type: object
default: {}
properties:
track_rpacket:
type: boolean
default: false
description: Allows for Tracking the properties of the RPackets in Single Packet Loop
initial_array_length:
type: number
default: 10
multiple: 1
description: Configures the initial array length for the RPacketCollection Properties arrays
description: Sets up tracking for Montecarlo
debug_packets:
type: boolean
default: false
Expand Down
Loading