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

Duplicated packet source initialization #2585

Open
DeerWhale opened this issue Apr 15, 2024 · 1 comment
Open

Duplicated packet source initialization #2585

DeerWhale opened this issue Apr 15, 2024 · 1 comment
Assignees

Comments

@DeerWhale
Copy link
Contributor

Describe the bug
In the tardis/model/parse_input.py, there are 2 functions contains duplicated codes for the packet source initialization, see the screenshot below:
image

Currently each of the two functions is being called somewhere else (see screenshot below), but someone should investigate carefully if the duplication is on purpose or by mistake.
image

@Sumit112192
Copy link
Contributor

Sumit112192 commented May 28, 2024

I think we should remove the reinitialization of packet_source from the function initialize_packet_source

def initialize_packet_source(
config, geometry, packet_source, legacy_mode_enabled
):
"""
Initialize the packet source based on config and geometry
Parameters
----------
config : Config
The configuration object containing the supernova and plasma settings.
geometry : Geometry
The geometry object containing the inner radius information.
packet_source : BasePacketSource
The packet source object based on the configuration and geometry.
Returns
-------
packet_source : BasePacketSource
The packet source object based on the configuration and geometry.
Raises
------
ValueError
If both t_inner and luminosity_requested are None.
"""
if config.montecarlo.enable_full_relativity:
packet_source = BlackBodySimpleSourceRelativistic(
base_seed=config.montecarlo.seed,
time_explosion=config.supernova.time_explosion,
legacy_mode_enabled=legacy_mode_enabled,
)
else:
packet_source = BlackBodySimpleSource(
base_seed=config.montecarlo.seed,
legacy_mode_enabled=legacy_mode_enabled,
)
luminosity_requested = config.supernova.luminosity_requested
if config.plasma.initial_t_inner > 0.0 * u.K:

initialize_packet_source is called two times:
1)

if config.montecarlo.enable_full_relativity:
packet_source = BlackBodySimpleSourceRelativistic(
base_seed=config.montecarlo.seed,
time_explosion=config.supernova.time_explosion,
legacy_mode_enabled=legacy_mode_enabled,
)
else:
packet_source = BlackBodySimpleSource(
base_seed=config.montecarlo.seed,
legacy_mode_enabled=legacy_mode_enabled,
)
return initialize_packet_source(
config, geometry, packet_source, legacy_mode_enabled
)

We have already initialized the packet_source before passing it to the initialize_packet_source function.

  1. if packet_source is not None:
    simulation_state.packet_source = initialize_packet_source(
    config,
    simulation_state.geometry,
    packet_source,
    legacy_mode_enabled,
    )

    The reinitialization will overwrite the custom packet_source passed to the default one, which I think is not desired as we pass a custom packet_source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants