Ejemplo n.º 1
0
    def test_checks(self):
        with pytest.raises(ValueError):
            Crop(name='custom', save_fn=True)

        with pytest.raises(TypeError):
            c = Crop(fn=foo_add, save_fn=False, batchsize=0.5)
            c.choose_batch_settings([('a', [1, 2])])

        with pytest.raises(ValueError):
            c = Crop(fn=foo_add, save_fn=False, batchsize=-1)
            c.choose_batch_settings([('a', [1, 2])])

        with pytest.raises(ValueError):
            c = Crop(fn=foo_add, save_fn=False, batchsize=1, num_batches=2)
            c.choose_batch_settings([('a', [1, 2, 3])])

        with pytest.raises(ValueError):
            c = Crop(fn=foo_add, save_fn=False, batchsize=2, num_batches=3)
            c.choose_batch_settings([('a', [1, 2, 3])])

        c = Crop(fn=foo_add, save_fn=False, batchsize=1, num_batches=3)
        c.choose_batch_settings([('a', [1, 2, 3])])

        c = Crop(fn=foo_add, save_fn=False, batchsize=2, num_batches=2)
        c.choose_batch_settings([('a', [1, 2, 3])])

        c = Crop(fn=foo_add, save_fn=False, batchsize=3, num_batches=1)
        c.choose_batch_settings([('a', [1, 2, 3])])

        with pytest.raises(XYZError):
            grow(1)

        print(c)
        repr(c)
Ejemplo n.º 2
0
    def test_field_name_and_overlapping(self):
        combos1 = [('a', [10, 20, 30]),
                   ('b', [4, 5, 6, 7])]
        expected1 = combo_runner(foo_add, combos1, constants={'c': True})

        combos2 = [('a', [40, 50, 60]),
                   ('b', [4, 5, 6, 7])]
        expected2 = combo_runner(foo_add, combos2, constants={'c': True})

        with TemporaryDirectory() as tdir:
            # sow seeds
            c1 = Crop(name='run1', fn=foo_add, parent_dir=tdir, batchsize=5)
            c1.sow_combos(combos1, constants={'c': True})
            c2 = Crop(name='run2', fn=foo_add, parent_dir=tdir, batchsize=5)
            c2.sow_combos(combos2, constants={'c': True})

            # grow seeds
            for i in range(1, 4):
                grow(i, Crop(parent_dir=tdir, name='run1'))
                grow(i, Crop(parent_dir=tdir, name='run2'))

            # reap results
            assert not c1.check_bad()
            assert not c2.check_bad()
            results1 = c1.reap()
            results2 = c2.reap()

        assert results1 == expected1
        assert results2 == expected2
Ejemplo n.º 3
0
 def test_sow_reap_seperate(self, fn3_fba_runner, fn3_fba_ds):
     with tempfile.TemporaryDirectory() as tmpdir:
         r = fn3_fba_runner
         crop = r.Crop(parent_dir=tmpdir, num_batches=2)
         crop.sow_combos((('a', (1, 2)), ('b', (3, 4))))
         for i in [1, 2]:
             grow(i, crop)
         crop.reap()
         assert r.last_ds.identical(fn3_fba_ds)
Ejemplo n.º 4
0
 def test_sow_reap_seperate(self, fn3_fba_runner, fn3_fba_ds):
     with tempfile.TemporaryDirectory() as tmpdir:
         r = fn3_fba_runner
         crop = r.Crop(parent_dir=tmpdir, num_batches=2)
         crop.sow_combos((('a', (1, 2)),
                          ('b', (3, 4))))
         for i in [1, 2]:
             grow(i, crop)
         crop.reap()
         assert r.last_ds.identical(fn3_fba_ds)
Ejemplo n.º 5
0
    def test_harvest_combos_new_sow_reap_separate(self, fn3_fba_runner,
                                                  fn3_fba_ds):
        with tempfile.TemporaryDirectory() as tmpdir:
            fl_pth = os.path.join(tmpdir, 'test.h5')
            h = Harvester(fn3_fba_runner, fl_pth)
            crop = h.Crop(parent_dir=tmpdir, num_batches=2)

            crop.sow_combos((('a', (1, 2)), ('b', (3, 4))))

            for i in [1, 2]:
                grow(i, crop)
            crop.reap()

            hds = load_ds(fl_pth)

            assert h.last_ds.identical(fn3_fba_ds)
            assert h.full_ds.identical(fn3_fba_ds)
            assert hds.identical(fn3_fba_ds)
Ejemplo n.º 6
0
    def test_harvest_combos_new_sow_reap_separate(self, fn3_fba_runner,
                                                  fn3_fba_ds):
        with tempfile.TemporaryDirectory() as tmpdir:
            fl_pth = os.path.join(tmpdir, 'test.h5')
            h = Harvester(fn3_fba_runner, fl_pth)
            crop = h.Crop(parent_dir=tmpdir, num_batches=2)

            crop.sow_combos((('a', (1, 2)), ('b', (3, 4))))

            for i in [1, 2]:
                grow(i, crop)
            crop.reap()

            hds = load_ds(fl_pth)

            assert h.last_ds.identical(fn3_fba_ds)
            assert h.full_ds.identical(fn3_fba_ds)
            assert hds.identical(fn3_fba_ds)
Ejemplo n.º 7
0
    def test_batch(self):

        combos = [
            ('a', [10, 20, 30]),
            ('b', [4, 5, 6, 7]),
        ]
        expected = combo_runner(foo_add, combos, constants={'c': True})

        with TemporaryDirectory() as tdir:

            # sow seeds
            crop = Crop(fn=foo_add, parent_dir=tdir, batchsize=5)

            assert not crop.is_prepared()
            assert crop.num_sown_batches == crop.num_results == -1

            crop.sow_combos(combos, constants={'c': True})

            assert crop.is_prepared()
            assert crop.num_sown_batches == 3
            assert crop.num_results == 0

            # grow seeds
            for i in range(1, 4):
                grow(i, Crop(parent_dir=tdir, name='foo_add'))

                if i == 1:
                    assert crop.missing_results() == (2, 3,)

                    with pytest.raises(XYZError):
                        crop.reap()

            assert crop.is_ready_to_reap()
            assert not crop.check_bad()
            # reap results
            results = crop.reap()

        assert results == expected
Ejemplo n.º 8
0
 def concurrent_grow():
     # wait for cases to be sown
     time.sleep(0.5)
     for i in [1, 2]:
         grow(i, crop)
Ejemplo n.º 9
0
 def concurrent_grow():
     # wait for cases to be sown
     time.sleep(0.5)
     for i in [1, 2]:
         grow(i, crop)