-
-
Notifications
You must be signed in to change notification settings - Fork 423
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
Adding DataFrame for the RPacket Tracking Functionality #1776
Closed
DhruvSondhi
wants to merge
35
commits into
tardis-sn:master
from
DhruvSondhi:packet_interaction_dataframe
+428
−85
Closed
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
1904924
Added functionality to track properties for r_packets, configured fro…
DhruvSondhi cabea5f
Tried implementation of record based tracking of the r_packet properties
DhruvSondhi aed2e56
Implemented array based packet property tracking
DhruvSondhi 09e7f36
Added functionality to reduce the array size inside the RPacketCollec…
DhruvSondhi 5fbf57e
Reverted formatting changes within montecarlo_numba/base.py
DhruvSondhi db2a023
Changed the searching implementation for finding the exact size of th…
DhruvSondhi 2e92303
Added docstring for the newly added RPacketCollection Class
DhruvSondhi 57c3ed8
Made array length for the properties in the RPacketCollection configu…
DhruvSondhi 580fc32
Added tests for r_packet tracking
DhruvSondhi 4ae5507
Changed initial_array_length to const value,
DhruvSondhi 96e16cc
Added demarcation for Setup & Teardown in tests
DhruvSondhi 2b2de2b
Changed set_properties func to track,
DhruvSondhi 7762fa1
Renamed r_packet_tracking to track_rpacket for consistency
DhruvSondhi 61b39bf
Added Documentation for RPacket Tracking
DhruvSondhi de7cdfb
[build docs]
DhruvSondhi d596a96
Moved tracked_rpacket outside montecarlo_main_loop,
DhruvSondhi b56fee6
Added functionality to display dataframe when accessed by sim.runner.…
DhruvSondhi 947d02b
Added functionality for single DataFrame to hold all the values for a…
DhruvSondhi dddce2f
Added functionality to append DF
DhruvSondhi bbba997
Removed redundant code,
DhruvSondhi 8d496f6
Fixed Iteration values getting converted to float from int,
DhruvSondhi b3bf9f2
Restructured code for multi threaded runs & changed the way of the ge…
DhruvSondhi cbe0b79
Added Docstring along with few changes to the way the arrays are gene…
DhruvSondhi 3d0b130
Refactored original tests to be consistent with the new changes
DhruvSondhi 5a43301
Restoring some changes which are not fixed when rebasing
DhruvSondhi 789de23
Added tests for generated tracking dataframe
DhruvSondhi 5638ac7
Added config for the rpacket tracking tests
DhruvSondhi 154abcb
Updated documentation for RPacket Tracking DataFrame feature
DhruvSondhi 3f1326a
[build docs]
DhruvSondhi ec9b478
Changed the way generation of DataFrame happens, Sped up the process …
DhruvSondhi 9d17d08
Reverted documentation positioning in index.rst
DhruvSondhi ead38b5
Changed the process of generation of the tracking dataframe into more…
DhruvSondhi 135b22f
Fixing orphaned imports from single_packet_loop when rebased
DhruvSondhi 2d6292f
Renamed `rpacket_collections` to `tracked_rpacket` for remaining occu…
DhruvSondhi 6a4ad39
Merge remote-tracking branch 'upstream/master' into packet_interactio…
DhruvSondhi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Example YAML configuration for TARDIS | ||
tardis_config_version: v1.0 | ||
|
||
supernova: | ||
luminosity_requested: 9.44 log_lsun | ||
time_explosion: 13 day | ||
|
||
atom_data: kurucz_cd23_chianti_H_He.h5 | ||
|
||
model: | ||
structure: | ||
type: specific | ||
velocity: | ||
start: 1.1e4 km/s | ||
stop: 20000 km/s | ||
num: 20 | ||
density: | ||
type: branch85_w7 | ||
|
||
abundances: | ||
type: uniform | ||
O: 0.19 | ||
Mg: 0.03 | ||
Si: 0.52 | ||
S: 0.19 | ||
Ar: 0.04 | ||
Ca: 0.03 | ||
|
||
plasma: | ||
disable_electron_scattering: no | ||
ionization: lte | ||
excitation: lte | ||
radiative_rates_type: dilute-blackbody | ||
line_interaction_type: macroatom | ||
|
||
montecarlo: | ||
seed: 23111963 | ||
no_of_packets: 100 | ||
iterations: 10 | ||
nthreads: 1 | ||
|
||
last_no_of_packets: 1000 | ||
no_of_virtual_packets: 2 | ||
|
||
convergence_strategy: | ||
type: damped | ||
damping_constant: 1.0 | ||
threshold: 0.05 | ||
fraction: 0.8 | ||
hold_iterations: 3 | ||
t_inner: | ||
damping_constant: 0.5 | ||
|
||
spectrum: | ||
start: 500 angstrom | ||
stop: 20000 angstrom | ||
num: 10000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import pytest | ||
import logging | ||
import os | ||
import pandas as pd | ||
import numpy as np | ||
|
||
from tardis.io.config_reader import Configuration | ||
from tardis.simulation import Simulation | ||
|
@@ -105,3 +108,112 @@ def test_logging_both_specified( | |
assert record.levelno == LOGGING_LEVELS[log_level.upper()] | ||
else: | ||
assert record.levelno >= LOGGING_LEVELS[log_level.upper()] | ||
|
||
|
||
@pytest.fixture | ||
def config(): | ||
return Configuration.from_yaml( | ||
"tardis/io/tests/data/tardis_configv1_verysimple_tracking.yml" | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def tracker_ref_path(tardis_ref_path): | ||
return os.path.abspath(os.path.join(tardis_ref_path, "rpacket_tracking.h5")) | ||
|
||
|
||
@pytest.fixture | ||
def tracking_refdata( | ||
config, atomic_data_fname, tracker_ref_path, generate_reference | ||
): | ||
config["atom_data"] = atomic_data_fname | ||
|
||
simulation = Simulation.from_config(config) | ||
simulation.run() | ||
|
||
track_df = simulation.runner.rpacket_tracker | ||
key = "tracking" | ||
|
||
if not generate_reference: | ||
return simulation | ||
else: | ||
track_df.to_hdf(tracker_ref_path, key=key, mode="w") | ||
pytest.skip("Reference data was generated during this run.") | ||
|
||
|
||
@pytest.fixture | ||
def read_comparison_refdata(tracker_ref_path): | ||
return pd.read_hdf(tracker_ref_path) | ||
|
||
|
||
# @pytest.mark.parametrize( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clean out these comments |
||
# ["no_of_packets", "initial_seed", "last_seed", "iterations"], | ||
# [(1200, 2850180890, 2683780343, 3)], | ||
# ) | ||
def test_tracking_dataframe( | ||
config, | ||
tracking_refdata, | ||
# no_of_packets, | ||
# initial_seed, | ||
# last_seed, | ||
# iterations, | ||
): | ||
sim = tracking_refdata | ||
|
||
# Initial Test to check if the data frame is generated or not | ||
assert config["montecarlo"]["tracking"]["track_rpacket"] == True | ||
assert isinstance(sim.runner.rpacket_tracker, pd.DataFrame) | ||
# # assert ( | ||
# # len(sim.runner.rpacket_tracker["Packet Seed"].unique()) == no_of_packets | ||
# # ) | ||
# assert sim.runner.rpacket_tracker["Packet Seed"].iloc[0] == initial_seed | ||
# assert sim.runner.rpacket_tracker["Packet Seed"].iloc[-1] == last_seed | ||
# assert len(sim.runner.rpacket_tracker["Iteration"].unique()) == iterations | ||
|
||
|
||
def test_compare_dataframe( | ||
tracking_refdata, | ||
read_comparison_refdata, | ||
): | ||
sim = tracking_refdata | ||
comparison_df = read_comparison_refdata | ||
|
||
pd.testing.assert_frame_equal( | ||
sim.runner.rpacket_tracker, | ||
comparison_df, | ||
check_dtype=True, | ||
check_column_type=True, | ||
check_exact=True, | ||
) | ||
|
||
assert isinstance(comparison_df, pd.DataFrame) | ||
assert len(comparison_df["Packet Seed"].unique()) == len( | ||
sim.runner.rpacket_tracker["Packet Seed"].unique() | ||
) | ||
assert len(comparison_df["Iteration"].unique()) == len( | ||
sim.runner.rpacket_tracker["Iteration"].unique() | ||
) | ||
|
||
|
||
def test_parallel_dataframe( | ||
config, | ||
atomic_data_fname, | ||
read_comparison_refdata, | ||
): | ||
comparison_df = read_comparison_refdata | ||
|
||
config["atom_data"] = atomic_data_fname | ||
config["montecarlo"]["nthreads"] = 3 | ||
|
||
sim = Simulation.from_config(config) | ||
sim.run() | ||
|
||
assert isinstance(sim.runner.rpacket_tracker, pd.DataFrame) | ||
assert len(comparison_df["Packet Seed"].unique()) == len( | ||
sim.runner.rpacket_tracker["Packet Seed"].unique() | ||
) | ||
assert len(comparison_df["Iteration"].unique()) == len( | ||
sim.runner.rpacket_tracker["Iteration"].unique() | ||
) | ||
|
||
config["montecarlo"]["nthreads"] = 1 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this feels like the standard example?
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.
This is not a standard example. There is changes to the number of packets so as to make it run fast for the tracking. More changes would be done in the future so as to make it very fast & not consume much time in testing.
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.
let's change this after