Commit fb7ad3de authored by Yin, Junqi's avatar Yin, Junqi

fixes torus

parent 4dc60369
......@@ -333,6 +333,7 @@ class TorusGraph(PhysicalLayout):
n_mpi_process, n_sub_process, world, comm_device, on_cuda, rank
)
self._mixing_matrix = self._define_graph(n_mpi_process)
self._normalize_mixing_matrix()
def _define_graph(self, n_mpi_process):
# get proper _width and _height.
......@@ -351,7 +352,7 @@ class TorusGraph(PhysicalLayout):
mixing_matrix = networkx.adjacency_matrix(graph).toarray()
for i in range(0, mixing_matrix.shape[0]):
mixing_matrix[i][i] = 1
mixing_matrix = mixing_matrix / 4
mixing_matrix = mixing_matrix / 5
return mixing_matrix
@property
......@@ -384,7 +385,36 @@ class TorusGraph(PhysicalLayout):
def set_matrix(self, m):
self._mixing_matrix = m
def _normalize_mixing_matrix(self):
"""
Bug fix mixing matrix to ensure each row/column sums up to 1.
"""
matrix = self._mixing_matrix
assert(matrix.shape[0] == matrix.shape[1])
size = matrix.shape[0]
for i in range(size):
for j in range(i+1, size):
assert(matrix[i][j] == matrix[j][i])
degree = 0
for i in range(size):
if matrix[0][i] > 0:
degree += 1
for i in range(1, size):
d = 0
for j in range(size):
if matrix[i][j] > 0:
d += 1
# Torus requires all vertices have the same degree
assert(d == degree)
# Add self into consideration
#degree += 1
for i in range(size):
for j in range(size):
if matrix[i][j] > 0:
matrix[i][j] = 1./degree
self._mixing_matrix = matrix
class ExpanderGraph(PhysicalLayout):
def __init__(self, n_mpi_process, n_sub_process, world, comm_device, on_cuda, rank):
super(ExpanderGraph, self).__init__(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment