def test_multiple_moves(self): dst = generate_flat_spacetime(4, 4) n1, f1, p1 = event.events(dst, [12, 0, 11]) moves.increase(dst, n1, f1, p1) n2, f2, p2 = event.events(dst, [13, 1, 9]) moves.increase(dst, n2, f2, p2) assert isinstance(dst, SpaceTime)
def test_volume_profile(self): """Test volume profile""" dst = space_time.generate_flat_spacetime(4, 4) n1, f1, p1 = event.events(dst, [12, 0, 11]) moves.increase(dst, n1, f1, p1) n2, f2, p2 = event.events(dst, [13, 1, 9]) moves.increase(dst, n2, f2, p2) vp = observables.volume_profile(dst) assert str(vp) == '[4 4 4 6]'
def test_event_hash(self): """Test Event Hash""" dst_1 = space_time.generate_flat_spacetime(2, 2) e0_1, *_ = event.events(dst_1, range(4)) dst_2 = space_time.generate_flat_spacetime(2, 2) e0_2, *_ = event.events(dst_2, range(4)) assert hash(e0_1) == hash(e0_2)
def test_event_pass_thru_getattr(self): """Test event getattr behavior for passthru attributes""" dst = space_time.generate_flat_spacetime(2, 2) e0, e1, e2, e3 = event.events(dst, range(4)) assert e0.right == e1 assert e1.left == e0 assert e0.future == {e2, e3} assert e3.past == {e0, e1}
def test_set_faces(self): dst = space_time.generate_flat_spacetime(2, 2) e0, e1, e2, e3 = event.events(dst) print(e0.faces) assert e0.faces == {0, 1, 2, 5, 6, 7} event.set_faces(e0, [2]) assert e0.faces == {2}
def test_consistent_set_left(self): """Check set .left""" dst = space_time.generate_flat_spacetime(3, 3) e0, e1, e2, e3, e4, e5, e6, e7, e8 = event.events(dst, range(9)) assert e0.right == e1 event.connect_spatial(e0, e2) assert e2.left == e0 assert e1.left is None
def test_consistent_set_future(self): """Check set .future""" dst = space_time.generate_flat_spacetime(3, 3) e0, e1, e2, e3, e4, e5, e6, e7, e8 = event.events(dst, range(9)) assert e0.future == {e3, e4} event.connect_temporal(e0, future={e4, e5}) assert e0 in e4.past assert e0 in e5.past assert e0 not in e3.past
def test_consistent_set_past(self): """Check set .past""" dst = space_time.generate_flat_spacetime(3, 3) e0, e1, e2, e3, e4, e5, e6, e7, e8 = event.events(dst, range(9)) assert e0.past == {e8, e6} event.connect_temporal(e0, past={e8, e7}) assert e0 in e7.future assert e0 in e8.future assert e0 not in e6.future
def untwist(coords, st): """ It is common for coordinates to become "twisted" meaning for example, that the past layer is left shifted while the future layer is right shifted. this occurs becouse most measures weight past and future edge lengths similarly so the minimum edge length that can be reached by adjusting a single node adds a twist. """ theta_x, theta_t = coords layers = st.get_layers() for t, layer in enumerate(layers[1:]): t += 1 offset = 0 for n in event.events(st, layer): d_offset = sum([ angular_seperation(theta_x[n.key], theta_x[c.key]) / len(layer) for c in n.past ]) offset = offset + d_offset for m in layer: theta_x[m] = (theta_x[m] + offset / 2.0) % (2 * pi) return theta_x, theta_t
def get_spring_coords(st, dt=0.015, k=1.0, b=2.0): theta_x, theta_t = get_naive_coords(st) v = {n: 0 for n in st.nodes} for i in range(500): for n in event.events(st, st.nodes): # print(n) # sums the x length of all connections to n dx = sum([ angular_seperation(theta_x[n.key], theta_x[c.key]) for c in n.temporal_neighbors ]) a = k * dx for c in n.spatial_neighbors: dx = angular_seperation(theta_x[n.key], theta_x[c.key]) sign = dx / abs(dx) a -= sign * 0.07 / (dx**2) a -= b * v[n.key] vel = v[n.key] + a * dt new_x_theta = (theta_x[n.key] + vel * dt) % (2 * pi) l = theta_x[n.left.key] r = theta_x[n.right.key] error_l = angular_seperation(new_x_theta, l) error_r = angular_seperation(new_x_theta, r) bounds_sep = angular_seperation(l, r) if is_between(l, r, new_x_theta): v[n] = vel theta_x[n.key] = new_x_theta % (2 * pi) # elif abs(error_l) < abs(error_r): # print(l, r, new_x_theta) # print(error_l, error_r) # theta_x[n] = l - error_l / abs(error_l) * bounds_sep / 10.0 # elif abs(error_r) < abs(error_l): # # print(error_l, error_r) # theta_x[n] = r - error_r / abs(error_r) * bounds_sep / 10.0 return (theta_x, theta_t) # def get_spring_coords(st, dt=0.015, k=1.0, b=2.0): theta_x, theta_t = get_naive_coords(st) v = {n: 0 for n in st.nodes} for i in range(500): for n in st.nodes: # print(n) # sums the x length of all connections to n dx = sum([ angular_seperation(theta_x[n], theta_x[c]) for c in n.temporal_neighbors ]) # dxp = sum( # [angular_seperation(theta_x[n], theta_x[c]) for c in st.node_past[n]] # ) # dxf = sum( # [angular_seperation(theta_x[n], theta_x[c]) for c in st.node_future[n]] # ) # for future_node in st.node_future[n]: # v[future_node] -= dxf * 0.02 # for past_node in st.node_past[n]: # v[past_node] -= dxp * 0.02 a = k * dx / abs(dx) * abs(dx)**0.1 a = 0.0 for c in n.spatial_neighbors: dx = angular_seperation(theta_x[n], theta_x[c]) sign = dx / abs(dx) a -= sign * 0.03 / (dx**2) a -= b * v[n] vel = v[n] + a * dt new_x_theta = (theta_x[n] + vel * dt) % (2 * pi) l = theta_x[n.left] r = theta_x[n.right] error_l = angular_seperation(new_x_theta, l) error_r = angular_seperation(new_x_theta, r) bounds_sep = angular_seperation(l, r) if is_between(l, r, new_x_theta): v[n] = vel theta_x[n] = new_x_theta elif abs(error_l) < abs(error_r): print(l, r, new_x_theta) print(error_l, error_r) theta_x[n] = l - error_l / abs(error_l) * bounds_sep / 10.0 elif abs(error_r) < abs(error_l): # print(error_l, error_r) theta_x[n] = r - error_r / abs(error_r) * bounds_sep / 10.0 return (theta_x, theta_t)
def test_neighbors(self): """Test neighbors""" dst = space_time.generate_flat_spacetime(3, 3) e0, e1, e2, e3, e4, e5, e6, e7, e8 = event.events(dst, range(9)) assert e0.neighbors == {e2, e1, e8, e6, e3, e4}
def test_events(self): """Test multiple event constructor utility""" dst = space_time.generate_flat_spacetime(2, 2) e0, e1 = event.events(dst, [0, 1]) assert isinstance(e0, event.Event) assert isinstance(e1, event.Event)
def test_move(self): """Test move""" dst = generate_flat_spacetime(3, 3) n, f, p = event.events(dst, [4, 7, 1]) moves.increase(dst, n, f, p) assert isinstance(dst, SpaceTime)