Beispiel #1
0
class _TestComparisonNonOperator(_TestComparison):
    valid_types = (
        # empty iterable
        set(),
        (),
        # Iterable[int]
        ProcSet(0),
        ProcInt(0),
        {0},
        pytest.param((i * i for i in range(4)), id='(i*i for i in range(4))'),
        # Iterable[ProcInt]
        (ProcInt(0), ProcInt(1)),
        # Iterable[ProcSet]
        (ProcSet(0), ProcSet(1)),
        # Iterable[Union[int, ProcInt, ProcSet]]
        (0, ProcInt(1), ProcSet(2)),
    )
    incompatible_types = (
        # not iterable
        None,
        0,
        # iterable of wrong type
        'bad-iterable',
        {None},
        (0, ProcInt(1), None),
    )
Beispiel #2
0
 def test_deepcopy_nonempty(self):
     pset = ProcSet(ProcInt(0, 3))
     dcopy_pset = copy.deepcopy(pset)
     assert dcopy_pset == pset
     assert dcopy_pset is not pset
     assert dcopy_pset._itvs is not pset._itvs
     pset |= ProcSet(ProcInt(128, 255))
     assert dcopy_pset != pset
Beispiel #3
0
 def test_disjoint(self):
     pset = ProcSet(ProcInt(0, 3), ProcInt(7, 15))
     assert str(pset) == '0-3 7-15'
     assert format(pset, ':,') == '0:3,7:15'
     assert format(pset) == str(pset)
     assert format(pset, '') == str(pset)
     assert repr(pset) == 'ProcSet((0, 3), (7, 15))'
     assert pset == eval(repr(pset))
Beispiel #4
0
    def __init__(self, df, resource_bounds=None, float_precision=6):
        # reset the index of the dataframe
        df = df.reset_index(drop=True)
        # set float round precision
        self.float_precision = float_precision
        self.df = np.round(df, float_precision)

        if resource_bounds:
            self.res_bounds = ProcInt(*resource_bounds)
        else:
            def alloc_apply(f, alloc):
                for pset in  alloc:
                    try:
                        yield f(pset)
                    except ValueError:
                        pass

            self.res_bounds = ProcInt(
                min(alloc_apply(lambda pset: pset.min, self.df.allocated_resources)),
                max(alloc_apply(lambda pset: pset.max, self.df.allocated_resources))
            )
        self.MaxProcs = len(self.res_bounds)

        self.df['proc_alloc'] = self.df.allocated_resources.apply(len)

        # Add missing columns if possible
        fillable_relative = all(
            col in self.df.columns
            for col in ['submission_time', 'waiting_time', 'execution_time']
        )
        fillable_absolute = all(
            col in self.df.columns
            for col in ['submission_time', 'starting_time', 'finish_time']
        )
        if fillable_relative:
            if 'starting_time' not in self.df.columns:
                self.df['starting_time'] = \
                    self.df['submission_time'] + self.df['waiting_time']
            if 'finish_time' not in self.df.columns:
                self.df['finish_time'] = \
                    self.df['starting_time'] + self.df['execution_time']
        elif fillable_absolute:
            if 'waiting_time' not in self.df.columns:
                self.df['waiting_time'] = \
                    self.df['starting_time'] - self.df['submission_time']
            if 'execution_time' not in self.df.columns:
                self.df['execution_time'] = \
                    self.df['finish_time'] - self.df['starting_time']

        if 'job_id' in self.df.columns:
            self.df.rename(columns={'job_id': 'jobID'}, inplace=True)

        # TODO check consistency on calculated columns...

        # init cache
        self._utilisation = None
        self._queue = None
Beispiel #5
0
 def test_copy_nested(self):
     pset = ProcSet(ProcInt(0, 3))
     nested = {0: pset, 1: [pset]}
     copy_nested = copy.copy(nested)
     assert copy_nested[0] == pset
     assert copy_nested[0] is pset
     assert copy_nested[0] == copy_nested[1][0]
     assert copy_nested[0] is copy_nested[1][0]
     pset |= ProcSet(ProcInt(128, 255))
     assert copy_nested[0] == pset
     assert copy_nested[0] == copy_nested[1][0]
Beispiel #6
0
 def test_deepcopy_nested(self):
     pset = ProcSet(ProcInt(0, 3))
     nested = {0: pset, 1: [pset]}
     dcopy_nested = copy.deepcopy(nested)
     assert dcopy_nested[0] == pset
     assert dcopy_nested[0] is not pset
     assert dcopy_nested[0] == dcopy_nested[1][0]
     assert dcopy_nested[0] is dcopy_nested[1][0]
     pset |= ProcSet(ProcInt(128, 255))
     assert dcopy_nested[0] != pset
     assert dcopy_nested[0] == dcopy_nested[1][0]
Beispiel #7
0
 def test_wide(self):
     itv = ProcInt(0, 41)
     assert str(itv) == '0-41'
     assert format(itv, ':') == '0:41'
     assert format(itv) == str(itv)
     assert repr(itv) == 'ProcInt(inf=0, sup=41)'
     assert itv == eval(repr(itv))
Beispiel #8
0
 def test_point(self):
     itv = ProcInt(0, 0)
     assert str(itv) == '0'
     assert format(itv, ':') == '0'
     assert format(itv) == str(itv)
     assert repr(itv) == 'ProcInt(inf=0, sup=0)'
     assert itv == eval(repr(itv))
Beispiel #9
0
 def test_copy_empty(self):
     pset = ProcSet()
     copy_pset = copy.copy(pset)
     assert copy_pset == pset
     assert copy_pset is not pset
     assert copy_pset._itvs is not pset._itvs
     pset |= ProcSet(ProcInt(128, 255))
     assert copy_pset != pset
Beispiel #10
0
 def test_contiguous(self):
     pset = ProcSet(ProcInt(0, 7))
     assert str(pset) == '0-7'
     assert format(pset, ':,') == '0:7'
     assert format(pset) == str(pset)
     assert format(pset, '') == str(pset)
     assert repr(pset) == 'ProcSet((0, 7))'
     assert pset == eval(repr(pset))
Beispiel #11
0
 def test_small(self):
     pset = ProcSet(ProcInt(0, 1))
     assert str(pset) == '0-1'
     assert format(pset, ':,') == '0:1'
     assert format(pset) == str(pset)
     assert format(pset, '') == str(pset)
     assert repr(pset) == 'ProcSet((0, 1))'
     assert pset == eval(repr(pset))
Beispiel #12
0
 def test_single_point(self):
     pset = ProcSet(ProcInt(0, 0))
     assert str(pset) == '0'
     assert format(pset, ':,') == '0'
     assert format(pset) == str(pset)
     assert format(pset, '') == str(pset)
     assert repr(pset) == 'ProcSet(0)'
     assert pset == eval(repr(pset))
Beispiel #13
0
    def __init__(self, df, resource_bounds=None, float_precision=6):
        # set float round precision
        self.float_precision = float_precision
        self.df = np.round(df, float_precision)

        if resource_bounds:
            self.res_bounds = ProcInt(*resource_bounds)
        else:
            self.res_bounds = ProcInt(
                min(pset.min for pset in self.df.allocated_processors),
                max(pset.max for pset in self.df.allocated_processors))

        self.MaxProcs = len(self.res_bounds)

        self.df['proc_alloc'] = self.df.allocated_processors.apply(len)

        # Add missing columns if possible
        fillable_relative = all(
            col in self.df.columns
            for col in ['submission_time', 'waiting_time', 'execution_time'])
        fillable_absolute = all(
            col in self.df.columns
            for col in ['submission_time', 'starting_time', 'finish_time'])
        if fillable_relative:
            if 'starting_time' not in self.df.columns:
                self.df['starting_time'] = \
                    self.df['submission_time'] + self.df['waiting_time']
            if 'finish_time' not in self.df.columns:
                self.df['finish_time'] = \
                    self.df['starting_time'] + self.df['execution_time']
        elif fillable_absolute:
            if 'waiting_time' not in self.df.columns:
                self.df['waiting_time'] = \
                    self.df['starting_time'] - self.df['submission_time']
            if 'execution_time' not in self.df.columns:
                self.df['execution_time'] = \
                    self.df['finish_time'] - self.df['starting_time']

        if 'job_id' in self.df.columns:
            self.df.rename(columns={'job_id': 'jobID'}, inplace=True)

        # TODO check consistency on calculated columns...

        # init cache
        self._utilisation = None
        self._queue = None
Beispiel #14
0
 def test_bad_reversed_args(self):
     with pytest.raises(ValueError, match='^Invalid interval bounds$'):
         ProcInt(42, 1)
Beispiel #15
0
 def test_assign_inf(self):
     with pytest.raises(AttributeError):
         itv = ProcInt(1, 2)
         itv.inf = 0
Beispiel #16
0
 def test_bad_type_inf_single(self):
     with pytest.raises(TypeError, match=r'^ProcInt\(\) argument inf must be int$'):
         ProcInt('dummy string')
Beispiel #17
0
 def test_bad_type_sup(self):
     with pytest.raises(TypeError, match=r'^ProcInt\(\) argument sup must be int$'):
         ProcInt(0, None)
Beispiel #18
0
 def test_reversed_args(self):
     itv = ProcInt(sup=41, inf=0)  # notice reversed arguments
     assert itv == (0, 41)
     assert len(itv) == 42
     for point in range(0, 42):
         assert point in itv
Beispiel #19
0
 def test_enforce_nonnegative(self):
     with pytest.raises(ValueError, match=r'^Invalid negative bound\(s\)$'):
         ProcInt(-1, 0)
     with pytest.raises(ValueError, match=r'^Invalid negative bound\(s\)$'):
         ProcInt(-15, -1)
Beispiel #20
0
 def test_point_single(self):
     itv = ProcInt(0)
     assert itv == (0, 0)
     assert len(itv) == 1
     assert 0 in itv
Beispiel #21
0
 def test_many_procint(self):
     pset = ProcSet(ProcInt(0, 3), ProcInt(2, 3))
     assert list(pset) == [0, 1, 2, 3]
     assert len(pset) == 4
     assert pset.count() == 1
Beispiel #22
0
 def test_bad_format_spec(self):
     with pytest.raises(ValueError, match='^Invalid format specifier$'):
         format(ProcInt(0, 2), '--')
Beispiel #23
0
 def test_deepcopy(self):
     itv = ProcInt(0, 0)
     copy_itv = copy.deepcopy(itv)
     assert copy_itv == itv
     assert copy_itv is not itv
Beispiel #24
0
 def test_contiguous(self):
     pset = ProcSet.from_str('0-3')
     assert pset == ProcSet(ProcInt(0, 3))
Beispiel #25
0
 def test_disjoint_ip(self):
     pset = ProcSet.from_str('0-1 2')
     assert pset == ProcSet(ProcInt(0, 1), 2)
Beispiel #26
0
 def test_disjoint_ii(self):
     pset = ProcSet.from_str('0-1 2-3')
     assert pset == ProcSet(ProcInt(0, 3))
Beispiel #27
0
 def test_assign_sup(self):
     with pytest.raises(AttributeError):
         itv = ProcInt(1, 2)
         itv.sup = 5
Beispiel #28
0
 def test_wide(self):
     itv = ProcInt(0, 41)
     assert itv == (0, 41)
     assert len(itv) == 42
     for point in range(0, 42):
         assert point in itv
Beispiel #29
0
 def test_mixed_itvs(self):
     pset = ProcSet(ProcInt(0, 3), (2, 3), [4, 7])
     assert list(pset) == [0, 1, 2, 3, 4, 5, 6, 7]
     assert len(pset) == 8
     assert pset.count() == 1
Beispiel #30
0
class TestGetItem:
    INT_INDEX_PSETS = (
        ProcSet(ProcInt(0)),
        ProcSet(ProcInt(0, 3)),
        ProcSet(ProcInt(0, 3), ProcInt(8, 11)),
        ProcSet(ProcInt(0, 1), ProcInt(3), ProcInt(6, 7)),
        ProcSet(ProcInt(0, 3), ProcInt(8, 11), ProcInt(14, 15)),
    )
    SLICE_INDEX_PSETS = (  # interval lengths: latin square + relatively prime numbers
        ProcSet(ProcInt(0, 3), ProcInt(5, 11)),
        ProcSet(ProcInt(0, 6), ProcInt(8, 11)),
        ProcSet(ProcInt(0), ProcInt(2, 5), ProcInt(7, 13)),
        ProcSet(ProcInt(0, 3), ProcInt(5, 11), ProcInt(13)),
        ProcSet(ProcInt(0, 6), ProcInt(8), ProcInt(10, 13)),
        ProcSet(ProcInt(0, 2), ProcInt(4, 8), ProcInt(10, 16)),
        ProcSet(ProcInt(0, 4), ProcInt(6, 12), ProcInt(14, 16)),
        ProcSet(ProcInt(0, 6), ProcInt(8, 10), ProcInt(12, 16)),
        ProcSet(ProcInt(0), ProcInt(2, 4), ProcInt(6, 10), ProcInt(12, 18)),
        ProcSet(ProcInt(0, 2), ProcInt(4, 8), ProcInt(10, 16), ProcInt(18)),
        ProcSet(ProcInt(0, 4), ProcInt(6, 12), ProcInt(14), ProcInt(16, 18)),
        ProcSet(ProcInt(0, 6), ProcInt(8), ProcInt(10, 12), ProcInt(14, 18)),
    )

    def test_bad_key_type(self):
        pset = ProcSet()
        with pytest.raises(TypeError):
            pset[None]
        with pytest.raises(ValueError):
            pset[::0]

    def test_empty(self):
        pset = ProcSet()
        with pytest.raises(IndexError):
            pset[0]
        with pytest.raises(IndexError):
            pset[-1]

    @pytest.mark.parametrize('pset', INT_INDEX_PSETS, ids=repr)
    def test_int_index_inrange(self, pset):
        lpset = list(pset)
        for i in range(len(pset)):
            assert pset[i] == lpset[i]

    @pytest.mark.parametrize('pset', INT_INDEX_PSETS, ids=repr)
    def test_int_index_outofrange(self, pset):
        with pytest.raises(IndexError):
            pset[len(pset)]

    @pytest.mark.parametrize('pset', INT_INDEX_PSETS, ids=repr)
    def test_negative_int_index_inrange(self, pset):
        lpset = list(pset)
        for i in range(-len(pset), 0):
            assert pset[i] == lpset[i]

    @pytest.mark.parametrize('pset', INT_INDEX_PSETS, ids=repr)
    def test_negative_int_index_outofrange(self, pset):
        with pytest.raises(IndexError):
            pset[-len(pset) - 1]

    @pytest.mark.parametrize('pset',
                             INT_INDEX_PSETS + SLICE_INDEX_PSETS,
                             ids=repr)
    def test_slice(self, pset):
        starts = (None, ) + tuple(range(-len(pset) - 1, len(pset) + 2))
        stops = starts
        steps = (None, ) + tuple(range(-len(pset) - 1, 0)) + tuple(
            range(1,
                  len(pset) + 2))

        for start, stop, step in itertools.product(starts, stops, steps):
            assert pset[start:stop:step] == list(pset)[start:stop:step]