Skip to content

Commit

Permalink
Added support for passing Configuration object in run_tardis (#1559)
Browse files Browse the repository at this point in the history
* added support to pass config objects in run_tardis

* updated docstrings

* added tests for the feature

* added docstrings
  • Loading branch information
aribalam authored May 14, 2021
1 parent 7e1a513 commit f84c1d0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
15 changes: 9 additions & 6 deletions tardis/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def run_tardis(
Parameters
----------
config : str or dict
filename of configuration yaml file or dictionary
config : str or dict or tardis.io.config_reader.Configuration
filename of configuration yaml file or dictionary or TARDIS Configuration object
atom_data : str or tardis.atomic.AtomData
if atom_data is a string it is interpreted as a path to a file storing
the atomic data. Atomic data to use for this TARDIS simulation. If set to None, the
Expand All @@ -41,10 +41,13 @@ def run_tardis(
except TypeError:
atom_data = atom_data

try:
tardis_config = Configuration.from_yaml(config)
except TypeError:
tardis_config = Configuration.from_config_dict(config)
if isinstance(config, Configuration):
tardis_config = config
else:
try:
tardis_config = Configuration.from_yaml(config)
except TypeError:
tardis_config = Configuration.from_config_dict(config)

simulation = Simulation.from_config(
tardis_config,
Expand Down
18 changes: 18 additions & 0 deletions tardis/tests/test_tardis_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@
from tardis.simulation.base import Simulation
from tardis.io.config_reader import Configuration

from tardis import run_tardis


def test_run_tardis_from_config_obj(atomic_data_fname):
"""
Tests whether the run_tardis function can take in the Configuration object
as arguments
"""
config = Configuration.from_yaml(
"tardis/io/tests/data/tardis_configv1_verysimple.yml"
)
config["atom_data"] = atomic_data_fname

try:
sim = run_tardis(config)
except Exception as e:
pytest.fail(str(e.args[0]))


class TestRunnerSimple:
"""
Expand Down

0 comments on commit f84c1d0

Please sign in to comment.