Beispiel #1
0
def setup():
    global ts1, ts2, sim
    testing.init_blank_db_for_testing()
    db.config.base = os.path.dirname(os.path.abspath(__file__)) + "/"

    session = db.core.get_default_session()

    sim = tangos.core.simulation.Simulation("test_stat_files")
    session.add(sim)

    ts1 = tangos.core.timestep.TimeStep(sim,
                                        "pioneer50h128.1536gst1.bwK1.000832")
    ts1.time_gyr = 6  # unimportant
    ts1.redshift = 2.323  # matters for AHF filename

    ts2 = tangos.core.timestep.TimeStep(
        sim, "h242.cosmo50PLK.1536g1bwK1C52.004096")
    ts2.time_gyr = 10
    ts2.redshift = 0

    session.add_all([ts1, ts2])

    session.commit()

    parallel_tasks.use('null')
Beispiel #2
0
def test_parallel_writing(fresh_database):
    parallel_tasks.use('multiprocessing')
    try:
        parallel_tasks.launch(run_writer_with_args, 3, ["dummy_property"])
    finally:
        parallel_tasks.use('null')
    _assert_properties_as_expected()
Beispiel #3
0
def test_parallel_writing():
    init_blank_simulation()
    parallel_tasks.use('multiprocessing')
    try:
        parallel_tasks.launch(run_writer_with_args,3,["dummy_property"])
    finally:
        parallel_tasks.use('null')
    _assert_properties_as_expected()
Beispiel #4
0
def setup_func():
    parallel_tasks.use('null')

    testing.init_blank_db_for_testing()
    db.config.base = os.path.join(os.path.dirname(__file__), "test_simulations")
    manager = add_simulation.SimulationAdderUpdater(output_testing.TestInputHandler("dummy_sim_1"))
    with log.LogCapturer():
        manager.scan_simulation_and_add_all_descendants()
Beispiel #5
0
def setup():
    pt.use("multiprocessing")
    testing.init_blank_db_for_testing(timeout=5.0, verbose=False)

    generator = tangos.testing.simulation_generator.TestSimulationGenerator()
    generator.add_timestep()
    generator.add_objects_to_timestep(9)

    tangos.core.get_default_session().commit()
def test_property_import():
    importer = tools.property_importer.PropertyImporter()
    importer.parse_command_line(
        "X Y Z Mvir --for test_gadget_rockstar".split())
    with log.LogCapturer():
        parallel_tasks.use('multiprocessing')
        parallel_tasks.launch(importer.run_calculation_loop, 2)

    Mvir_test, = tangos.get_timestep(
        "test_gadget_rockstar/snapshot_013").calculate_all("Mvir")
    npt.assert_allclose(
        Mvir_test, [1.160400e+13, 8.341900e+12, 5.061400e+12, 5.951900e+12])
Beispiel #7
0
def test_property_import():
    importer = tools.property_importer.PropertyImporter()
    importer.parse_command_line(
        "Xc Yc Zc Mvir --for test_ahf_merger_tree".split())
    with log.LogCapturer():
        parallel_tasks.use('multiprocessing')
        parallel_tasks.launch(importer.run_calculation_loop, 2)

    Mvir_test, = tangos.get_timestep(
        "test_ahf_merger_tree/tiny_000832").calculate_all("Mvir")
    npt.assert_allclose(Mvir_test, [
        2.34068e+11, 4.94677e+10, 4.58779e+10, 4.24798e+10, 2.31297e+10,
        2.1545e+10, 1.85704e+10, 1.62538e+10, 1.28763e+10
    ])
def setup_func():
    parallel_tasks.use('null')
    testing.init_blank_db_for_testing()
    db.config.base = os.path.join(os.path.dirname(__file__),
                                  "test_simulations")
    manager = add_simulation.SimulationAdderUpdater(
        output_testing.TestInputHandler("dummy_sim_1"))
    manager2 = add_simulation.SimulationAdderUpdater(
        output_testing.TestInputHandler("dummy_sim_2"))
    with log.LogCapturer():
        manager.scan_simulation_and_add_all_descendants()
        manager2.scan_simulation_and_add_all_descendants()
        writer = property_writer.PropertyWriter()
        writer.parse_command_line(['dummy_property'])
        writer.run_calculation_loop()
Beispiel #9
0
def setup():
    pt.use("multiprocessing")
    testing.init_blank_db_for_testing(timeout=0.1, verbose=False)

    session = db.core.get_default_session()

    sim = tangos.core.simulation.Simulation("sim")
    session.add(sim)

    ts1 = tangos.core.timestep.TimeStep(sim, "ts1")
    session.add(ts1)

    halo_1 = tangos.core.halo.Halo(ts1, 1, 0, 0, 0, 0)
    session.add_all([halo_1])

    session.commit()
Beispiel #10
0
def test_writer_handles_sim_properties(fresh_database):
    """Test for issue where simulation properties could be queried from within a calculation.

    This could lead to unexpected database locks. Tangos 1.3 provides a safe route to doing this.
    The test ensures that the results are cached to prevent hammering the database

    However it does not directly test that the parallel_tasks locking mechanism is called,
    which is hard. Ideally this test would therefore be completed at some point..."""

    parallel_tasks.use('multiprocessing')
    try:
        parallel_tasks.launch(run_writer_with_args, 3, ["dummy_property_accessing_simulation_property"])
    finally:
        parallel_tasks.use('null')

    for i in range(1,3):
        ts = db.get_timestep("dummy_sim_1/step.%d"%i)
        x, = ts.calculate_all("dummy_property_accessing_simulation_property")
        npt.assert_equal(x,[1]*ts.halos.count())
Beispiel #11
0
def setup_module():
    if testing_db_backend != "sqlite":
        skip("This test is only relevant for sqlite databases")

    pt.use("multiprocessing")
    testing.init_blank_db_for_testing(timeout=0.1, verbose=False)

    session = db.core.get_default_session()

    sim = tangos.core.simulation.Simulation("sim")
    session.add(sim)

    ts1 = tangos.core.timestep.TimeStep(sim, "ts1")
    session.add(ts1)

    halo_1 = tangos.core.halo.Halo(ts1, 1, 1, 1, 0, 0, 0, 0)
    session.add_all([halo_1])

    session.commit()
Beispiel #12
0
#!/usr/bin/env python

import sys
import time

import tangos.parallel_tasks as pt


def test_function():
    lock = pt.ExclusiveLock("hello")

    print("Hello from rank", pt.backend.rank())
    for i in pt.distributed(range(10)):
        with lock:
            print("Task", i)
            time.sleep(0.1)

    if pt.backend.rank() == 1:
        print()
        print("OK")


if len(sys.argv) != 2:
    print("Syntax: test_mpi.py [backend name]")
else:
    pt.use(sys.argv[1])
    pt.launch(test_function, 8)
Beispiel #13
0
def setup():
    parallel_tasks.use('null')
Beispiel #14
0
def setup_module():
    global handler
    pt.use("multiprocessing")
    tangos.config.base = os.path.dirname(__file__) + "/"
    handler = _TestHandler("test_simulations/test_tipsy")