Example #1
0
def test_force_dump_tmp_dir():
    with tempfile.TemporaryDirectory(prefix="sge") as tmp:
        dummy.init_queue_state(path=dummy.QUEUE_STATE_PATH)
        results = qmr.map(
            function=GOOD_FUNCTION,
            jobs=GOOD_JOBS,
            work_dir=os.path.join(tmp, "my_work_dir"),
            keep_work_dir=True,
            polling_interval_qstat=1e-3,
            qsub_path=dummy.QSUB_PATH,
            qstat_path=dummy.QSTAT_PATH,
            qdel_path=dummy.QDEL_PATH,
        )

        assert os.path.exists(os.path.join(tmp, "my_work_dir"))
Example #2
0
def test_minimal_example():
    dummy.init_queue_state(path=dummy.QUEUE_STATE_PATH)
    results = qmr.map(
        function=numpy.sum,
        jobs=[numpy.arange(i, 100 + i) for i in range(10)],
        polling_interval_qstat=1e-3,
        qsub_path=dummy.QSUB_PATH,
        qstat_path=dummy.QSTAT_PATH,
        qdel_path=dummy.QDEL_PATH,
    )

    assert len(results) == 10
    jobs = [numpy.arange(i, 100 + i) for i in range(10)]
    for idx in range(len(results)):
        assert results[idx] == numpy.sum(jobs[idx])
Example #3
0
def test_bad_function_creating_stderr():
    with tempfile.TemporaryDirectory(prefix="sge") as tmp:
        dummy.init_queue_state(path=dummy.QUEUE_STATE_PATH)
        results = qmr.map(
            function=BAD_FUNCTION,
            jobs=GOOD_JOBS,
            work_dir=os.path.join(tmp, "my_work_dir"),
            polling_interval_qstat=1e-3,
            qsub_path=dummy.QSUB_PATH,
            qstat_path=dummy.QSTAT_PATH,
            qdel_path=dummy.QDEL_PATH,
        )

        assert len(results) == NUM_JOBS
        for r in results:
            assert r is None
        assert os.path.exists(os.path.join(tmp, "my_work_dir"))
Example #4
0
def test_full_chain():
    function = GOOD_FUNCTION
    jobs = GOOD_JOBS

    with tempfile.TemporaryDirectory(prefix="sge") as tmp:
        dummy.init_queue_state(path=dummy.QUEUE_STATE_PATH)
        results = qmr.map(
            function=function,
            jobs=jobs,
            work_dir=os.path.join(tmp, "my_work_dir"),
            polling_interval_qstat=1e-3,
            qsub_path=dummy.QSUB_PATH,
            qstat_path=dummy.QSTAT_PATH,
            qdel_path=dummy.QDEL_PATH,
        )

        assert len(results) == NUM_JOBS
        for i in range(NUM_JOBS):
            assert results[i] == function(jobs[i])
Example #5
0
def test_one_bad_job_creating_stderr():
    with tempfile.TemporaryDirectory(prefix="sge") as tmp:
        bad_jobs = GOOD_JOBS.copy()
        bad_jobs.append("np.sum will not work for me.")

        dummy.init_queue_state(path=dummy.QUEUE_STATE_PATH)
        results = qmr.map(
            function=GOOD_FUNCTION,
            jobs=bad_jobs,
            work_dir=os.path.join(tmp, "my_work_dir"),
            polling_interval_qstat=1e-3,
            qsub_path=dummy.QSUB_PATH,
            qstat_path=dummy.QSTAT_PATH,
            qdel_path=dummy.QDEL_PATH,
        )

        assert len(results) == NUM_JOBS + 1
        for idx in range(NUM_JOBS):
            assert results[idx] == GOOD_FUNCTION(GOOD_JOBS[idx])
        assert results[idx + 1] is None
        assert os.path.exists(os.path.join(tmp, "my_work_dir"))
def test_run_with_failing_job():
    """
    The dummy_qsub will run the jobs.
    It will intentionally bring idx == 13 into error-state 'E' five times.
    This tests if qmr.map can recover this error using 10 trials.
    """
    with tempfile.TemporaryDirectory(prefix="sge") as tmp_dir:
        qsub_tmp_dir = os.path.join(tmp_dir, "qsub_tmp")

        dummy_queue.init_queue_state(
            path=dummy_queue.QUEUE_STATE_PATH,
            evil_jobs=[{
                "idx": 13,
                "num_fails": 0,
                "max_num_fails": 5
            }],
        )

        NUM_JOBS = 30

        jobs = []
        for i in range(NUM_JOBS):
            job = np.arange(0, 100)
            jobs.append(job)

        results = qmr.map(
            function=np.sum,
            jobs=jobs,
            polling_interval_qstat=0.1,
            work_dir=qsub_tmp_dir,
            keep_work_dir=True,
            max_num_resubmissions=10,
            qsub_path=dummy_queue.QSUB_PATH,
            qstat_path=dummy_queue.QSTAT_PATH,
            qdel_path=dummy_queue.QDEL_PATH,
            error_state_indicator="E",
        )

        for i in range(NUM_JOBS):
            assert results[i] == np.sum(jobs[i])