Ejemplo n.º 1
0
def test_filter_aux_list_triangular():
    """
    This functions checks that the TRIANGULAR filter is being properly applied
    """
    # initializing hops_hierarchy class
    hierarchy_param = {
        "MAXHIER": 2,
        "STATIC_FILTERS": [("Triangular", [[False, True], [1, 1]])],
    }
    system_param = {"N_HMODES": 2}
    HH = HHier(hierarchy_param, system_param)
    aux_list = [
        AuxVec([], 2),
        AuxVec([(0, 1)], 2),
        AuxVec([(1, 1)], 2),
        AuxVec([(0, 2)], 2),
        AuxVec([(0, 1), (1, 1)], 2),
        AuxVec([(1, 2)], 2),
    ]
    aux_list = HH.filter_aux_list(aux_list)
    # known result filtered triangular list
    known_triangular_tuple = [
        AuxVec([], 2),
        AuxVec([(0, 1)], 2),
        AuxVec([(1, 1)], 2),
        AuxVec([(0, 2)], 2),
    ]
    assert aux_list == known_triangular_tuple
    assert HH.param["STATIC_FILTERS"] == [("Triangular", [[False, True], [1, 1]])]
Ejemplo n.º 2
0
    def initialize(self, flag_adaptive):
        """
        This function will initialize the hierarchy.

        PARAMETERS
        ----------
        1. flag_adaptive : boolean
                           boolean describing whether the calculation is adaptive or not

        RETURNS
        -------
        None
        """
        # Prepare the hierarchy
        # ---------------------
        if not flag_adaptive:
            self.auxiliary_list = self.define_triangular_hierarchy(
                self.n_hmodes, self.param["MAXHIER"])
            self.auxiliary_list = self.filter_aux_list(self.auxiliary_list)

        else:
            # Initialize Guess for the hierarchy
            # NOTE: The first thing a hierarchy does is start expanding from the
            #       zero index. It might, at some point, be more efficient to
            #       initialize the hierarchy with an explicit guess (in combination
            #       with a restriction that no auxiliary nodes are removed until after
            #       Nsteps). At the moment, though, I'm skipping this and allowing
            #       the hierarchy to control its own growth.
            self.auxiliary_list = [AuxVec([], self.n_hmodes)]
Ejemplo n.º 3
0
    def define_triangular_hierarchy(n_hmodes, maxhier):
        """
        This function creates a triangular hierarchy

        PARAMETERS
        ----------
        1. n_hmodes : int
                      number of modes that appear in the hierarchy
        2. maxhier : int
                     the max single value of the hierarchy

        RETURNS
        -------
        1. list_aux : list
                      list of auxiliaries in the new triangular hierarchy
        """
        list_aux = []
        # first loop over hierarchy depth
        for k in range(maxhier + 1):
            # Second loop over
            for aux_raw in it.combinations_with_replacement(
                    range(n_hmodes), k):
                count = Counter(aux_raw)
                list_aux.append(
                    AuxVec([(key, count[key]) for key in count.keys()],
                           n_hmodes))
        return list_aux
Ejemplo n.º 4
0
def map_to_auxvec(list_aux):
    list_aux_vec = []
    for aux_values in list_aux:
        aux_key = np.where(aux_values)[0]
        list_aux_vec.append(
            AuxVec([tuple([key, aux_values[key]]) for key in aux_key], 4))
    return list_aux_vec
Ejemplo n.º 5
0
def test_const_aux_edge():
    """
     This function test whether const_aux_edge is properly creating an auxiliary index
     tuple for an edge node at a particular depth along a given mode.
    """
    hierarchy_param = {"MAXHIER": 4}
    system_param = {"N_HMODES": 4}
    HH = HHier(hierarchy_param, system_param)
    HH.initialize(True)
    tmp = HH._const_aux_edge(2, 1, 4)
    known_index_tuple = AuxVec([(2, 1)], 4)
    assert tmp == known_index_tuple
Ejemplo n.º 6
0
def test_hierarchy_initialize_true():
    """
    This test checks whether an adaptive calculation (True) creates a list of tuples
    n_hmodes long
    """
    # initializing hops_hierarchy class
    hierarchy_param = {"MAXHIER": 4}
    system_param = {"N_HMODES": 4}
    HH = HHier(hierarchy_param, system_param)
    HH.initialize(True)  # makes the calculation adaptive
    aux_list = HH.auxiliary_list
    known_tuple = [AuxVec([], 4)]
    assert known_tuple == aux_list
Ejemplo n.º 7
0
def test_aux_index_true():
    """
    This function test the case where _aux_index returns the absolute index of a
    specific auxiliary member
    """
    hierarchy_param = {"MAXHIER": 4}
    system_param = {"N_HMODES": 4}
    HH = HHier(hierarchy_param, system_param)
    abs_index = HH._aux_index(
        AuxVec([(0, 1), (2, 1)], 4), True
    )  # True = absolute index
    # known result based on alpha numeric ordering
    known_index = 7
    assert abs_index == known_index
Ejemplo n.º 8
0
def test_check_markovian():
    """
    checks to make sure an auxiliary is non markovian or an allowed markovian aux
    """
    aux_0000 = AuxVec([], 4)
    aux_1000 = AuxVec([(0, 1)], 4)
    aux_0100 = AuxVec([(1, 1)], 4)
    aux_1010 = AuxVec([(0, 1), (2, 1)], 4)
    aux_2000 = AuxVec([(0, 2)], 4)
    aux_0101 = AuxVec([(1, 1), (3, 1)], 4)
    aux_1001 = AuxVec([(0, 1), (3, 1)], 4)
    aux_1111 = AuxVec([(0, 1), (1, 1), (2, 1), (3, 1)], 4)
    list_bool = [False, True, False, True]
    # aux_1000 check
    markov_bool = HF.check_markovian(aux_0000, list_bool)
    known_bool = True
    assert markov_bool == known_bool
    # aux_1000 check
    markov_bool = HF.check_markovian(aux_1000, list_bool)
    known_bool = True
    assert markov_bool == known_bool
    # aux_0100 check
    markov_bool = HF.check_markovian(aux_0100, list_bool)
    known_bool = True
    assert markov_bool == known_bool
    # aux_1010 check
    markov_bool = HF.check_markovian(aux_1010, list_bool)
    known_bool = True
    assert markov_bool == known_bool
    # aux_2000 check
    markov_bool = HF.check_markovian(aux_2000, list_bool)
    known_bool = True
    assert markov_bool == known_bool
    # aux_0101 check
    markov_bool = HF.check_markovian(aux_0101, list_bool)
    known_bool = False
    assert markov_bool == known_bool
    # aux_1001 check
    markov_bool = HF.check_markovian(aux_1001, list_bool)
    known_bool = False
    assert markov_bool == known_bool
    # aux_1111 check
    markov_bool = HF.check_markovian(aux_1111, list_bool)
    known_bool = False
    assert markov_bool == known_bool
Ejemplo n.º 9
0
    def _const_aux_edge(absindex_mode, depth, n_hmodes):
        """
        This function creates an auxiliary object for an edge node at
        a particular depth along a given mode. 

        PARAMETERS
        ----------
        1. absindex_mode : int
                           absolute index of the edge mode
        2. depth : int
                   the depth of the edge auxiliary
        3. n_hmodes : int
                      number of modes that appear in the hierarchy

        RETURNS
        -------
        1. aux : Auxiliary object
                 the auxiliary at the the edge node

        """
        return AuxVec([(absindex_mode, depth)], n_hmodes)
Ejemplo n.º 10
0
def test_hierarchy_initialize_false():
    """
    This test checks whether a non-adaptive calculation (False) creates a list of tuples
    applied to a triangular filter
    """
    # initializing hops_hierarchy class
    hierarchy_param = {"MAXHIER": 2, "STATIC_FILTERS": []}
    system_param = {"N_HMODES": 2}
    HH = HHier(hierarchy_param, system_param)
    HH.initialize(False)
    aux_list = HH.auxiliary_list
    # known result triangular filtered list
    known_triangular_list = [
        AuxVec([], 2),
        AuxVec([(0, 1)], 2),
        AuxVec([(1, 1)], 2),
        AuxVec([(0, 2)], 2),
        AuxVec([(0, 1), (1, 1)], 2),
        AuxVec([(1, 2)], 2),
    ]
    assert known_triangular_list == aux_list
Ejemplo n.º 11
0
def test_aux_index_false():
    """
    This function test the case where _aux_index returns the relative index of a
    specific auxiliary member. It is important to note because of auxilary_list
    setter our auxiliary list gets rearranged into alpha numerical order and the
    return index is that of the relative list in alpha numerical order
    """
    hierarchy_param = {"MAXHIER": 4}
    system_param = {"N_HMODES": 4}
    HH = HHier(hierarchy_param, system_param)
    HH.auxiliary_list = [
        AuxVec([], 4),
        AuxVec([(2, 1), (3, 1)], 4),
        AuxVec([(0, 1), (1, 1)], 4),
        AuxVec([(0, 1), (2, 1)], 4),
        AuxVec([(1, 1), (3, 1)], 4),
    ]
    relative_index = HH._aux_index(AuxVec([(0, 1), (2, 1)], 4), False)
    # known result based on alpha numerical ordering
    known_index = 2
    assert relative_index == known_index
Ejemplo n.º 12
0
def test_filer_aux_list_longedge():
    hierarchy_param = {"MAXHIER": 2}
    system_param = {"N_HMODES": 2}
    HH = HHier(hierarchy_param, system_param)
    aux_list = [
        AuxVec([], 2),
        AuxVec([(0, 1)], 2),
        AuxVec([(1, 1)], 2),
        AuxVec([(0, 2)], 2),
        AuxVec([(0, 1), (1, 1)], 2),
        AuxVec([(1, 2)], 2),
    ]
    known_aux_list = [
        AuxVec([], 2),
        AuxVec([(0, 1)], 2),
        AuxVec([(1, 1)], 2),
        AuxVec([(0, 2)], 2),
        AuxVec([(1, 2)], 2),
    ]
    aux_list = HH.apply_filter(aux_list, "LongEdge", [[False, True], [2, 1]])
    assert aux_list == known_aux_list
    assert HH.param["STATIC_FILTERS"] == [("LongEdge", [[False, True], [2, 1]])]
Ejemplo n.º 13
0
def test_filter_markovian():
    """
    test to make sure filter_markovian is properly filtering auxiliaries
    """
    # Note: Does not like the zero vector
    list_bool = [False, True, False, True]
    list_aux = [
        AuxVec([], 4),
        AuxVec([(3, 1)], 4),
        AuxVec([(2, 1)], 4),
        AuxVec([(2, 1), (3, 1)], 4),
        AuxVec([(1, 1)], 4),
        AuxVec([(1, 1), (3, 1)], 4),
        AuxVec([(1, 1), (2, 1)], 4),
        AuxVec([(1, 1), (2, 1), (3, 1)], 4),
        AuxVec([(0, 1)], 4),
        AuxVec([(0, 1), (3, 1)], 4),
        AuxVec([(0, 1), (2, 1)], 4),
        AuxVec([(0, 1), (2, 1), (3, 1)], 4),
        AuxVec([(0, 1), (1, 1)], 4),
        AuxVec([(0, 1), (1, 1), (3, 1)], 4),
        AuxVec([(0, 1), (1, 1), (2, 1)], 4),
        AuxVec([(0, 1), (1, 1), (2, 1), (3, 1)], 4),
    ]
    list_markov = HF.filter_markovian(list_aux, list_bool)
    known_list = [
        AuxVec([], 4),
        AuxVec([(3, 1)], 4),
        AuxVec([(2, 1)], 4),
        AuxVec([(1, 1)], 4),
        AuxVec([(0, 1)], 4),
        AuxVec([(0, 1), (2, 1)], 4),
    ]
    assert list_markov == known_list