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

Parametrize the Slow Test class with two setups. #600

Merged
merged 11 commits into from
Jun 29, 2016
4 changes: 2 additions & 2 deletions tardis/tests/setup_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ def get_package_data():
return {
_ASTROPY_PACKAGE_NAME_ + '.tests': ['coveragerc', 'data/*.h5',
'data/*.dat', 'data/*.npy',
'tests_slow/w7/*.yml',
'tests_slow/w7/*.dat']}
'tests_slow/*/*.yml',
'tests_slow/*/*.dat']}
22 changes: 22 additions & 0 deletions tardis/tests/tests_slow/at/abundances.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#Index Z=1 - Z=32
0 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 6.9280e-06 6.2377e-01 5.0460e-09 1.2570e-05 2.9230e-07 6.0000e-02 5.5630e-07 1.8000e-01 5.8250e-08 3.0000e-02 8.2020e-08 7.3410e-07 3.0650e-08 3.0000e-03 4.6460e-10 3.1210e-06 3.1720e-09 1.6600e-04 1.0820e-07 5.0000e-03 5.2010e-02 4.6180e-02 7.2000e-09 1.7370e-08 0.0000e+00 0.0000e+00
1 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 6.9280e-06 6.2377e-01 5.0460e-09 1.2570e-05 2.9230e-07 6.0000e-02 5.5630e-07 1.8000e-01 5.8250e-08 3.0000e-02 8.2020e-08 7.3410e-07 3.0650e-08 3.0000e-03 4.6460e-10 3.1210e-06 3.1720e-09 1.6600e-04 1.0820e-07 5.0000e-03 5.2010e-02 4.6180e-02 7.2000e-09 1.7370e-08 0.0000e+00 0.0000e+00
2 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 6.9280e-06 6.2377e-01 5.0460e-09 1.2570e-05 2.9230e-07 6.0000e-02 5.5630e-07 1.8000e-01 5.8250e-08 3.0000e-02 8.2020e-08 7.3410e-07 3.0650e-08 3.0000e-03 4.6460e-10 3.1210e-06 3.1720e-09 1.6600e-04 1.0820e-07 5.0000e-03 5.2010e-02 4.6180e-02 7.2000e-09 1.7370e-08 0.0000e+00 0.0000e+00
3 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 6.9280e-06 6.2377e-01 5.0460e-09 1.2570e-05 2.9230e-07 6.0000e-02 5.5630e-07 1.8000e-01 5.8250e-08 3.0000e-02 8.2020e-08 7.3410e-07 3.0650e-08 3.0000e-03 4.6460e-10 3.1210e-06 3.1720e-09 1.6600e-04 1.0820e-07 5.0000e-03 5.2010e-02 4.6180e-02 7.2000e-09 1.7370e-08 0.0000e+00 0.0000e+00
4 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 6.9280e-06 6.2377e-01 5.0460e-09 1.2570e-05 2.9230e-07 6.0000e-02 5.5630e-07 1.8000e-01 5.8250e-08 3.0000e-02 8.2020e-08 7.3410e-07 3.0650e-08 3.0000e-03 4.6460e-10 3.1210e-06 3.1720e-09 1.6600e-04 1.0820e-07 5.0000e-03 5.2010e-02 4.6180e-02 7.2000e-09 1.7370e-08 0.0000e+00 0.0000e+00
5 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 6.9280e-06 6.2377e-01 5.0460e-09 1.2570e-05 2.9230e-07 6.0000e-02 5.5630e-07 1.8000e-01 5.8250e-08 3.0000e-02 8.2020e-08 7.3410e-07 3.0650e-08 3.0000e-03 4.6460e-10 3.1210e-06 3.1720e-09 1.6600e-04 1.0820e-07 5.0000e-03 5.2010e-02 4.6180e-02 7.2000e-09 1.7370e-08 0.0000e+00 0.0000e+00
6 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 6.9280e-06 6.2377e-01 5.0460e-09 1.2570e-05 2.9230e-07 6.0000e-02 5.5630e-07 1.8000e-01 5.8250e-08 3.0000e-02 8.2020e-08 7.3410e-07 3.0650e-08 3.0000e-03 4.6460e-10 3.1210e-06 3.1720e-09 1.6600e-04 1.0820e-07 5.0000e-03 5.2010e-02 4.6180e-02 7.2000e-09 1.7370e-08 0.0000e+00 0.0000e+00
7 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 2.7585e-02 6.9280e-06 8.8141e-01 5.0460e-09 1.2570e-05 2.9230e-07 2.3220e-02 5.5630e-07 2.3687e-02 5.8250e-08 5.1738e-03 8.2020e-08 7.3410e-07 3.0650e-08 3.0000e-03 4.6460e-10 2.7997e-07 3.1720e-09 1.3517e-05 1.0820e-07 5.2687e-04 1.2043e-02 2.3331e-02 7.2000e-09 1.7370e-08 0.0000e+00 0.0000e+00
8 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 3.0000e-02 6.9280e-06 9.0397e-01 5.0460e-09 1.2570e-05 2.9230e-07 2.0000e-02 5.5630e-07 1.0000e-02 5.8250e-08 3.0000e-03 8.2020e-08 7.3410e-07 3.0650e-08 3.0000e-03 4.6460e-10 3.1210e-08 3.1720e-09 1.6600e-07 1.0820e-07 1.3520e-04 8.5440e-03 2.1330e-02 7.2000e-09 1.7370e-08 0.0000e+00 0.0000e+00
9 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 3.0000e-02 6.9280e-06 9.0397e-01 5.0460e-09 1.2570e-05 2.9230e-07 2.0000e-02 5.5630e-07 1.0000e-02 5.8250e-08 3.0000e-03 8.2020e-08 7.3410e-07 3.0650e-08 3.0000e-03 4.6460e-10 3.1210e-08 3.1720e-09 1.6600e-07 1.0820e-07 1.3520e-04 8.5440e-03 2.1330e-02 7.2000e-09 1.7370e-08 0.0000e+00 0.0000e+00
10 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 3.0000e-02 6.9280e-06 9.0397e-01 5.0460e-09 1.2570e-05 2.9230e-07 2.0000e-02 5.5630e-07 1.0000e-02 5.8250e-08 3.0000e-03 8.2020e-08 7.3410e-07 3.0650e-08 3.0000e-03 4.6460e-10 3.1210e-08 3.1720e-09 1.6600e-07 1.0820e-07 1.3520e-04 8.5440e-03 2.1330e-02 7.2000e-09 1.7370e-08 0.0000e+00 0.0000e+00
11 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 3.0000e-02 6.9280e-06 9.0397e-01 5.0460e-09 1.2570e-05 2.9230e-07 2.0000e-02 5.5630e-07 1.0000e-02 5.8250e-08 3.0000e-03 8.2020e-08 7.3410e-07 3.0650e-08 3.0000e-03 4.6460e-10 3.1210e-08 3.1720e-09 1.6600e-07 1.0820e-07 1.3520e-04 8.5440e-03 2.1330e-02 7.2000e-09 1.7370e-08 0.0000e+00 0.0000e+00
12 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 3.0000e-02 6.9280e-06 9.0397e-01 5.0460e-09 1.2570e-05 2.9230e-07 2.0000e-02 5.5630e-07 1.0000e-02 5.8250e-08 3.0000e-03 8.2020e-08 7.3410e-07 3.0650e-08 3.0000e-03 4.6460e-10 3.1210e-08 3.1720e-09 1.6600e-07 1.0820e-07 1.3520e-04 8.5440e-03 2.1330e-02 7.2000e-09 1.7370e-08 0.0000e+00 0.0000e+00
13 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 3.0000e-02 6.9280e-06 9.0397e-01 5.0460e-09 1.2570e-05 2.9230e-07 2.0000e-02 5.5630e-07 1.0000e-02 5.8250e-08 3.0000e-03 8.2020e-08 7.3410e-07 3.0650e-08 3.0000e-03 4.6460e-10 3.1210e-08 3.1720e-09 1.6600e-07 1.0820e-07 1.3520e-04 8.5440e-03 2.1330e-02 7.2000e-09 1.7370e-08 0.0000e+00 0.0000e+00
14 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 3.0000e-02 6.9280e-06 9.0397e-01 5.0460e-09 1.2570e-05 2.9230e-07 2.0000e-02 5.5630e-07 1.0000e-02 5.8250e-08 3.0000e-03 8.2020e-08 7.3410e-07 3.0650e-08 3.0000e-03 4.6460e-10 3.1210e-08 3.1720e-09 1.6600e-07 1.0820e-07 1.3520e-04 8.5440e-03 2.1330e-02 7.2000e-09 1.7370e-08 0.0000e+00 0.0000e+00
15 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 3.0000e-02 6.9280e-06 9.0397e-01 5.0460e-09 1.2570e-05 2.9230e-07 2.0000e-02 5.5630e-07 1.0000e-02 5.8250e-08 3.0000e-03 8.2020e-08 7.3410e-07 3.0650e-08 3.0000e-03 4.6460e-10 3.1210e-08 3.1720e-09 1.6600e-07 1.0820e-07 1.3520e-04 8.5440e-03 2.1330e-02 7.2000e-09 1.7370e-08 0.0000e+00 0.0000e+00
16 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 3.0000e-02 6.9280e-06 9.0397e-01 5.0460e-09 1.2570e-05 2.9230e-07 2.0000e-02 5.5630e-07 1.0000e-02 5.8250e-08 3.0000e-03 8.2020e-08 7.3410e-07 3.0650e-08 3.0000e-03 4.6460e-10 3.1210e-08 3.1720e-09 1.6600e-07 1.0820e-07 1.3520e-04 8.5440e-03 2.1330e-02 7.2000e-09 1.7370e-08 0.0000e+00 0.0000e+00
17 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 3.0000e-02 6.9280e-06 9.0397e-01 5.0460e-09 1.2570e-05 2.9230e-07 2.0000e-02 5.5630e-07 1.0000e-02 5.8250e-08 3.0000e-03 8.2020e-08 7.3410e-07 3.0650e-08 3.0000e-03 4.6460e-10 3.1210e-08 3.1720e-09 1.6600e-07 1.0820e-07 1.3520e-04 8.5440e-03 2.1330e-02 7.2000e-09 1.7370e-08 0.0000e+00 0.0000e+00
18 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 3.0000e-02 6.9280e-06 9.0397e-01 5.0460e-09 1.2570e-05 2.9230e-07 2.0000e-02 5.5630e-07 1.0000e-02 5.8250e-08 3.0000e-03 8.2020e-08 7.3410e-07 3.0650e-08 3.0000e-03 4.6460e-10 3.1210e-08 3.1720e-09 1.6600e-07 1.0820e-07 1.3520e-04 8.5440e-03 2.1330e-02 7.2000e-09 1.7370e-08 0.0000e+00 0.0000e+00
19 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 3.0000e-02 6.9280e-06 9.0397e-01 5.0460e-09 1.2570e-05 2.9230e-07 2.0000e-02 5.5630e-07 1.0000e-02 5.8250e-08 3.0000e-03 8.2020e-08 7.3410e-07 3.0650e-08 3.0000e-03 4.6460e-10 3.1210e-08 3.1720e-09 1.6600e-07 1.0820e-07 1.3520e-04 8.5440e-03 2.1330e-02 7.2000e-09 1.7370e-08 0.0000e+00 0.0000e+00
20 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 3.0000e-02 6.9280e-06 9.0397e-01 5.0460e-09 1.2570e-05 2.9230e-07 2.0000e-02 5.5630e-07 1.0000e-02 5.8250e-08 3.0000e-03 8.2020e-08 7.3410e-07 3.0650e-08 3.0000e-03 4.6460e-10 3.1210e-08 3.1720e-09 1.6600e-07 1.0820e-07 1.3520e-04 8.5440e-03 2.1330e-02 7.2000e-09 1.7370e-08 0.0000e+00 0.0000e+00
49 changes: 49 additions & 0 deletions tardis/tests/tests_slow/at/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
atom_data: kurucz_cd23_chianti_H_He.h5
model:
abundances:
filename: abundances.dat
filetype: simple_ascii
type: file
structure:
filename: densities.dat
filetype: simple_ascii
type: file
v_inner_boundary: 12000.000 km/s
v_outer_boundary: 35000.000 km/s
montecarlo:
black_body_sampling:
num: 1000000
start: 1 angstrom
stop: 1000000 angstrom
convergence_strategy:
damping_constant: 1.0
fraction: 0.8
hold_iterations: 3
t_inner:
damping_constant: 1.0
threshold: 0.05
type: specific
iterations: 20
# originally 5.0e+5
last_no_of_packets: 5.0e+3
# originally 5.0e+4
no_of_packets: 5.0e+2
no_of_virtual_packets: 3
nthreads: 16
seed: 23111963
plasma:
disable_electron_scattering: false
excitation: dilute-lte
ionization: nebular
line_interaction_type: downbranch
radiative_rates_type: dilute-blackbody
spectrum:
num: 10000
start: 500 angstrom
stop: 20000 angstrom
supernova:
luminosity_requested: 8.675 log_lsun
luminosity_wavelength_end: 6500.000 angstrom
luminosity_wavelength_start: 3500.000 angstrom
time_explosion: 6.800 day
tardis_config_version: v1.0
23 changes: 23 additions & 0 deletions tardis/tests/tests_slow/at/densities.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
6.800000 day
#Index Velocities [km/s] Densities [g/cm^3]
0 1.2000e+04 9.652102e-13
1 1.2408e+04 3.659182e-13
2 1.2844e+04 3.932164e-13
3 1.3312e+04 3.900119e-13
4 1.3816e+04 3.090009e-13
5 1.4359e+04 3.108902e-13
6 1.4947e+04 2.463674e-13
7 1.5584e+04 5.468102e-14
8 1.6279e+04 3.228778e-14
9 1.7039e+04 2.211246e-14
10 1.7872e+04 1.542880e-14
11 1.8792e+04 1.264987e-14
12 1.9811e+04 8.297541e-15
13 2.0948e+04 4.517051e-15
14 2.2222e+04 5.480575e-16
15 2.3662e+04 8.695515e-18
16 2.5301e+04 4.354394e-18
17 2.7184e+04 2.150320e-18
18 2.9371e+04 1.040788e-18
19 3.1939e+04 4.580299e-19
20 3.5000e+04 1.893468e-19
53 changes: 23 additions & 30 deletions tardis/tests/tests_slow/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import glob
import os
import shutil
import tempfile
import yaml
import numpy as np
import pytest
Expand All @@ -26,18 +25,12 @@ def pytest_configure(config):
config.dokureport = DokuReport(
config.option.integration_tests_config['dokuwiki'])
config.pluginmanager.register(config.dokureport)
# A common tempdir for storing plots / PDFs and other slow test related data
# generated during execution.
tempdir_session = tempfile.mkdtemp()
config.option.tempdir = tempdir_session


def pytest_unconfigure(config):
integration_tests_configpath = config.getvalue("integration-tests")
if integration_tests_configpath is not None:
config.pluginmanager.unregister(config.dokureport)
# Remove tempdir by recursive deletion
shutil.rmtree(config.option.tempdir)


@pytest.mark.hookwrapper
Expand All @@ -57,25 +50,24 @@ def plot_object(request):
return PlotUploader(request)


@pytest.fixture(scope="session")
def integration_tests_config(request):
return request.config.option.integration_tests_config


@pytest.fixture(scope="session")
def reference_datadir(integration_tests_config):
return os.path.expandvars(
os.path.expanduser(integration_tests_config["reference"])
)


@pytest.fixture(scope="session")
def data_path():
return os.path.join(os.path.dirname(os.path.realpath(__file__)), "w7")


@pytest.fixture(scope="session")
def reference(request, reference_datadir):
@pytest.fixture(scope="class", params=[
path for path in glob.glob(os.path.join(
os.path.dirname(os.path.realpath(__file__)), "*")) if os.path.isdir(path)
])
def data_path(request):
integration_tests_config = request.config.option.integration_tests_config
setup_name = os.path.basename(request.param)
return {
'config_dirpath': request.param,
'reference_dirpath': os.path.join(os.path.expandvars(
os.path.expanduser(integration_tests_config["reference"])), setup_name
),
'setup_name': setup_name
}


@pytest.fixture(scope="class")
def reference(data_path):
"""
Fixture to ingest reference data for slow test from already available
compressed binaries (.npz). All data is collected in one dict and
Expand All @@ -100,11 +92,12 @@ def reference(request, reference_datadir):
* luminosity_density_nu | * wavelength
* delta_frequency | * luminosity_density_lambda
"""
reference_dirpath = data_path['reference_dirpath']

# TODO: make this fixture ingest data from an HDF5 file.
ndarrays = dict(np.load(os.path.join(reference_datadir, "ndarrays.npz")))
quantities = dict(np.load(os.path.join(reference_datadir, "quantities.npz")))
spectrum = dict(np.load(os.path.join(reference_datadir, "spectrum.npz")))
ndarrays = dict(np.load(os.path.join(reference_dirpath, "ndarrays.npz")))
quantities = dict(np.load(os.path.join(reference_dirpath, "quantities.npz")))
spectrum = dict(np.load(os.path.join(reference_dirpath, "spectrum.npz")))

# Associate CGS units to ndarrays of reference quantities.
ndarrays.update(
Expand Down
4 changes: 2 additions & 2 deletions tardis/tests/tests_slow/plot_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
thumbnail_html = """
<div class="image" style="float: left">
<a href="#">
<img src= "{dokuwiki_url}lib/exe/fetch.php?media=plots:{githash}_{name}.png" />
<img src= "{dokuwiki_url}lib/exe/fetch.php?media=reports:{githash}:{name}.png" />
</a>
</div>
"""
Expand Down Expand Up @@ -62,7 +62,7 @@ def upload(self, report):
plot.savefig(plot_file.name)

self.request.config.dokureport.doku_conn.medias.add(
"plots:{0}_{1}.png".format(tardis.__githash__[0:7], name),
"reports:{0}:{1}.png".format(tardis.__githash__[0:7], name),
plot_file.name
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,29 @@
from astropy.tests.helper import assert_quantity_allclose

from tardis.atomic import AtomData
from tardis.io.util import yaml_load_config_file
from tardis.simulation.base import Simulation
from tardis.model import Radial1DModel
from tardis.io.config_reader import Configuration


@pytest.mark.skipif(not pytest.config.getvalue("integration-tests"),
reason="integration tests are not included in this run")
class TestW7(object):
"""
Slow integration test for Stratified W7 setup.
class TestIntegration(object):
"""Slow integration test for various setups present in subdirectories of
``tardis/tests/tests_slow``.
"""

@classmethod
@pytest.fixture(scope="class", autouse=True)
def setup(self, request, reference, data_path, atomic_data_fname,
reference_datadir):
def setup(self, reference, data_path, atomic_data_fname):
"""
This method does initial setup of creating configuration and performing
a single run of integration test.
"""
self.config_file = os.path.join(data_path, "config.yml")
# The last component in dirpath can be extracted as name of setup.
self.name = data_path['setup_name']

self.config_file = os.path.join(data_path['config_dirpath'], "config.yml")

# Load atom data file separately, pass it for forming tardis config.
self.atom_data = AtomData.from_hdf5(atomic_data_fname)
Expand All @@ -49,12 +50,6 @@ def setup(self, request, reference, data_path, atomic_data_fname,
# Get the reference data through the fixture.
self.reference = reference

# Form a base directory to save plots for `W7` setup.
# TODO: Rough prototyping, parametrize this as more setups are added.
self.name = "w7"
self.base_plot_dir = os.path.join(request.config.option.tempdir, self.name)
os.makedirs(self.base_plot_dir)

def test_j_estimators(self):
assert_allclose(
self.reference['j_estimators'],
Expand Down Expand Up @@ -102,7 +97,7 @@ def test_luminosity_inner(self):
self.result.luminosity_inner)

def test_spectrum(self, plot_object):
plot_object.add(self.plot_spectrum(), "spectrum")
plot_object.add(self.plot_spectrum(), "{0}_spectrum".format(self.name))

assert_quantity_allclose(
self.reference['luminosity_density_nu'],
Expand Down Expand Up @@ -154,7 +149,7 @@ def test_montecarlo_properties(self):
self.result.montecarlo_nu)

def test_shell_temperature(self, plot_object):
plot_object.add(self.plot_t_rads(), "t_rads")
plot_object.add(self.plot_t_rads(), "{0}_t_rads".format(self.name))

assert_quantity_allclose(
self.reference['t_rads'],
Expand All @@ -172,7 +167,6 @@ def plot_t_rads(self):
marker=".", label="Result")
reference_line = ax.plot(self.reference['t_rads'], color="green",
marker=".", label="Reference")
ax.axis([0, 28, 5000, 10000])

error_ax = ax.twinx()
error_line = error_ax.plot((1 - self.result.t_rads / self.reference['t_rads']),
Expand Down
2 changes: 1 addition & 1 deletion tardis/tests/tests_slow/w7/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ montecarlo:
iterations: 20
# originally 2.0e+5
last_no_of_packets: 2.0e+3
# originally 4.0e+2
# originally 4.0e+4
no_of_packets: 4.0e+2
no_of_virtual_packets: 10
nthreads: 2
Expand Down