Ejemplo n.º 1
0
    def test_face_equality(self):
        """Test Event equality"""
        dst = space_time.generate_flat_spacetime(2, 2)
        e1 = face.Face(space_time=dst, key=0)
        e2 = face.Face(space_time=dst, key=0)
        assert e1 == e2

        # TODO uncomment the below test once equality defined for SpaceTime
        dst2 = space_time.generate_flat_spacetime(2, 3)
        e1_2 = face.Face(space_time=dst2, key=0)
        assert e1 != e1_2
Ejemplo n.º 2
0
    def test_face_repr(self):
        """Test event string representation"""
        dst = space_time.generate_flat_spacetime(2, 2)

        f = face.Face(space_time=dst, key=0)
        print(f)
        assert repr(f) == 'Face(ST4, 0, {0, 1, 3})'
Ejemplo n.º 3
0
 def test_face_init(self):
     """Test event init from spacetime and key"""
     dst = space_time.generate_flat_spacetime(2, 2)
     f = face.Face(space_time=dst, key=0)
     assert isinstance(f, face.Face)
     assert id(f.space_time) == id(dst)
Ejemplo n.º 4
0
 def test_face_safe_getattr(self):
     """Test event getattr behavior for non passthru attributes"""
     dst = space_time.generate_flat_spacetime(2, 2)
     e0 = face.Face(space_time=dst, key=0)
     assert isinstance(e0.space_time, SpaceTime)
     assert isinstance(e0.nodes, frozenset)
Ejemplo n.º 5
0
def increase(st, node, future, past):
    """
    A move should add one node and 2 faces. we can pop all the structures to be modified out of the dicts and then push
    them back in once they've been modified. This mean we need to know what could get modfified in any given move.
    """

    # remove the sub_space that is going to be modified
    layer = node.layer
    sub_space = st.pop([node])
    future_s = event.Event(sub_space, future)  # Need these two because they have been "popped" out of the original spacetime
    past_s = event.Event(sub_space, past)

    # increment the total node counter
    new_node_num = max(st.nodes.union(sub_space.nodes)) + 1
    sub_space.add_key(new_node_num, layer=layer)

    # create a node object for easy manipulation. This also automatically adds the node to the sub_space
    new_s = event.Event(sub_space, new_node_num)
    node_s = event.Event(sub_space, node)
    left_s = event.Event(sub_space, node_s.left)
    left = node_s.left
    right = node_s.right

    # spatial changes
    event.connect_spatial(new_s, node_s)  # new_s.right = node_s and node_s.left = new_s
    event.connect_spatial(left_s, new_s)  # new_s.left = left_s and left_s.right = new_s

    # future changes
    # TODO examine algorithm concept of connection vs Spacetime (e.g. after popping a node out, what does asking for "left" mean?)
    new_future_set = {future_s}
    f = future_s.left

    while f in node_s.future and not f.is_gluing_point:
        new_future_set.add(f)
        sub_space.node_future[node.key].remove(f.key)  # TODO cleanup the event key coercion by figuring out workaround for node.future.remove()
        sub_space.node_past[f.key].remove(node.key)
        f = f.left
    event.connect_temporal(new_s, future=new_future_set)
    old_future_set = node_s.future.difference(new_future_set).union({future_s})
    event.connect_temporal(node_s, future=old_future_set)
    # sub_space.node_past[future].append(new_node)

    # past changes
    new_past_set = {past_s}
    p = past_s.left
    while p in node_s.past:
        new_past_set.add(p)
        sub_space.node_past[node_s.key].remove(p.key)
        sub_space.node_future[p.key].remove(node_s.key)
        p = p.left
    event.connect_temporal(new_s, past=new_past_set)
    old_past_set = node_s.past.difference(new_past_set).union({past_s})
    event.connect_temporal(node_s, past=old_past_set)
    # sub_space.node_future[past].append(new_node)

    # face changes

    for f in face.faces(sub_space):
        if node_s.key in f.nodes:
            modified = [i.key for i in list(new_future_set | new_past_set | {node_s, left})]
            if all(item in modified for item in f.nodes):
                new_nodes = set(f.nodes)
                new_nodes.remove(node_s.key)
                new_nodes.add(new_s.key)

                sub_space.face_nodes[f.key] = frozenset(new_nodes)
                sub_space.faces_containing[node_s.key].remove(f.key)
                sub_space.faces_containing[new_s.key].add(f.key)

    f1r = face.Face(sub_space, (set(sub_space.faces_containing[new_s.key]) & set(sub_space.faces_containing[future_s.key])).pop())
    f1l = face.Face(sub_space, (set(sub_space.faces_containing[node_s.key]) & set(sub_space.faces_containing[future_s.key])).pop())
    f2r = face.Face(sub_space, (set(sub_space.faces_containing[new_s.key]) & set(sub_space.faces_containing[past_s.key])).pop())
    f2l = face.Face(sub_space, (set(sub_space.faces_containing[node_s.key]) & set(sub_space.faces_containing[past_s.key])).pop())

    new_face_key = max(st.faces.union(sub_space.faces)) + 1

    f_new_1 = face.Face(sub_space, sub_space.add_face(frozenset({new_s.key, node_s.key, future_s.key}), new_face_key))
    sub_space.face_type[f_new_1.key] = 0
    f_new_2 = face.Face(sub_space, sub_space.add_face(frozenset({new_s.key, node_s.key, past_s.key}), new_face_key + 1))
    sub_space.face_type[f_new_2.key] = 1
    face.connect_spatial(f1r, f_new_1)
    face.connect_spatial(f_new_1, f1l)

    face.connect_spatial(f2r, f_new_2)
    face.connect_spatial(f_new_2, f2l)

    #
    face.connect_temporal(f_new_1, f_new_2)

    st.push(sub_space)