def test_state_idx(self): ados = HierarchyADOs(self.mk_exponents([2, 3]), max_depth=2) assert ados.idx((0, 0)) == 0 assert ados.idx((0, 1)) == 1 assert ados.idx((0, 2)) == 2 assert ados.idx((1, 0)) == 3 assert ados.idx((1, 1)) == 4
def test_next(self): ados = HierarchyADOs(self.mk_exponents([2, 3]), max_depth=2) assert ados.next((0, 0), 0) == (1, 0) assert ados.next((0, 0), 1) == (0, 1) assert ados.next((1, 0), 0) is None assert ados.next((1, 0), 1) == (1, 1) assert ados.next((1, 1), 1) is None
def test_filter_by_nothing(self): ados = HierarchyADOs(self.mk_exponents([2, 3]), max_depth=2) assert ados.filter() == [ (0, 0), (0, 1), (0, 2), (1, 0), (1, 1), ]
def test_exps(self): ados = HierarchyADOs(self.mk_exponents([3, 3, 2]), max_depth=4) assert ados.exps((0, 0, 0)) == () assert ados.exps((1, 0, 0)) == (ados.exponents[0], ) assert ados.exps((2, 0, 0)) == ( ados.exponents[0], ados.exponents[0], ) assert ados.exps((1, 2, 1)) == ( ados.exponents[0], ados.exponents[1], ados.exponents[1], ados.exponents[2], )
def test_filter_by_level(self): ados = HierarchyADOs(self.mk_exponents([2, 3]), max_depth=2) assert ados.filter(level=0) == [ (0, 0), ] assert ados.filter(level=1) == [ (0, 1), (1, 0), ] assert ados.filter(level=2) == [ (0, 2), (1, 1), ] assert ados.filter(level=3) == []
def test_create(self): exponents = self.mk_exponents([2, 3]) ados = HierarchyADOs(exponents, max_depth=2) assert ados.exponents == exponents assert ados.max_depth == 2 assert ados.dims == [2, 3] assert ados.vk == [2.0, 2.0] assert ados.ck == [1.0, 1.0] assert ados.ck2 == [None, None] assert ados.sigma_bar_k_offset == [None, None] assert ados.labels == [ (0, 0), (0, 1), (0, 2), (1, 0), (1, 1), ]
def mk_ados(self, bath_dims, max_depth): exponents = [ BathExponent("I", dim, Q=None, ck=1.0, vk=2.0) for dim in bath_dims ] ados = HierarchyADOs(exponents, max_depth=max_depth) return ados
def test_filter_by_exponents(self): ados = HierarchyADOs(self.mk_exponents([2, 3]), max_depth=2) assert ados.filter(dims=[]) == [ (0, 0), ] assert ados.filter(dims=[2]) == [ (1, 0), ] assert ados.filter(level=1, dims=[2]) == [ (1, 0), ] assert ados.filter(dims=[3]) == [ (0, 1), ] assert ados.filter(dims=[2, 3]) == [ (1, 1), ] assert ados.filter(level=2, dims=[2, 3]) == [ (1, 1), ] assert ados.filter(dims=[3, 3]) == [ (0, 2), ] assert ados.filter(types=["I"]) == [ (0, 1), (1, 0), ] assert ados.filter(types=["I", "I"]) == [ (0, 2), (1, 1), ] with pytest.raises(ValueError) as err: ados.filter(types=[], dims=[2]) assert str(err.value) == ( "The tags, dims and types filters must all be the same length.") with pytest.raises(ValueError) as err: ados.filter(dims=[2, 2, 2]) assert str(err.value) == ( "The maximum depth for the hierarchy is 2 but 3 levels of" " excitation filters were given.") with pytest.raises(ValueError) as err: ados.filter(level=0, dims=[2]) assert str(err.value) == ( "The level parameter is 0 but 1 levels of excitation filters" " were given.")