Commit 7a1c2af5 authored by sfritschi's avatar sfritschi
Browse files

Overlapped communication with computing best candidates for each throat simultaneously

parent 56bb03f9
......@@ -15,7 +15,7 @@ def main():
print("Min. number of throats per pore: %d" % min(pore_throat_counts))
print("Avg. number of throats per pore: %f" % (sum(pore_throat_counts) / len(pore_throat_counts)))
target = [2, 1, 2]
target = [2, 2, 2]
print("Target size: {}".format(target))
cutoff = 0.5 * max([basenet.ub[i] - basenet.lb[i] \
for i in range(len(basenet.ub))])
......
gen/plots/dendro.png

104 KB | W: | H:

gen/plots/dendro.png

131 KB | W: | H:

gen/plots/dendro.png
gen/plots/dendro.png
gen/plots/dendro.png
gen/plots/dendro.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -731,42 +731,62 @@ def generate_dendrogram(basenet: Network, targetsize: List[int], \
avg_throat_diff = 0.
count = 0
next_best_count = 0
for poreIdx, pore in enumerate(pores[:n]):
if (not mute):
print(f"progress {((poreIdx+1) / n)*100.:.1f}%", end="\r", flush=True)
if (len(pore.throats) == 0): continue # no further connection needed
# TODO: Search neighboring cells in parallel
#candidates = cellList.find_candidates(poreIdx)
neighborhood = cellList.nbor_indices(poreIdx)
for nborCellIdx in neighborhood:
in_q.put((poreIdx, cellList.poresSorted[nborCellIdx]))
# Compute throat lengths and radii
throatLens = []
throatR = []
for throat in pore.throats:
throatLens.append(distance(*throat_ends(throat,
[ub-lb for lb,ub in zip(basenet.lb,basenet.ub)])))
throatR.append(throat.r)
# (index, throatLen)
bestMatches = [(-1, basenet.Lmax)] * len(throatLens)
candidates = {}
for _ in range(len(neighborhood)):
cellCandidates = out_q.get()
# Compute best match for each throat
# (index, throatLen)
if (len(cellCandidates) != 0):
matches = [min(cellCandidates.items(), key=lambda il: abs(il[1] - lt)) \
for lt in throatLens]
# Update global best matches based on current (local) best matches
bestMatches = [min(m, b, key=lambda il: abs(il[1] - lt)) \
for m, b, lt in zip(matches, bestMatches, throatLens)]
# Add cell candidates to global candidates
candidates = {**candidates, **cellCandidates}
# establish throat connections between pore and best candidate
# TODO: Perform this for all throats simultaneously
#conpores = set()
while (len(pore.throats) > 0):
for i, match in enumerate(bestMatches):
nborIdx, lt = match
if (nborIdx == -1):
k = k+1; continue # no candidates left for this throat
throat = pore.throats.pop()
lt = distance(*throat_ends(throat,
[ub-lb for lb,ub in zip(basenet.lb,basenet.ub)])) # target len.
# Check if best matching nbor is still available
if nborIdx not in candidates:
if (len(candidates) == 0):
k = k+1; continue # no further candidates available
# Find next best available candidate (expensive)
next_best_count += 1
nborIdx, lt = min(candidates.items(), key=lambda pl: abs(pl[1] - lt))
if (len(candidates) == 0):
k = k+1; continue # no candidates left
nborIdx, ltc = min(candidates.items(), key=lambda pl: abs(pl[1] - lt))
nbor = pores[nborIdx]
diff = abs(lt - ltc)
diff = abs(lt - throatLens[i])
avg_throat_diff += diff
count += 1
lt = ltc
nborc = nbor # memorize potential periodic copy
# find original of buffer layer pore
if (nbor.label != LABELS[0]):
......@@ -788,19 +808,22 @@ def generate_dendrogram(basenet: Network, targetsize: List[int], \
del candidates[cpore.index]
# connect pore to nbor
throats.append([pore, nbor, lbl, throat.r])
throats.append([pore, nbor, lbl, throatR[i]])
# remove most similar throat of nbor
ranking = [(distance(*throat_ends(nthroat,
[ub-lb for lb,ub in zip(basenet.lb,basenet.ub)])),
nthroat) for nthroat in nbor.throats]
_, nthroat = min(ranking, key=lambda lth: abs(lth[0] - lt))
nbor.throats.remove(nthroat)
# remove fully connected nbor from search neighborhood
if (len(nbor.throats) == 0):
cellList.expel(nbor)
for cpore in copies[nbor]:
cellList.expel(cpore)
# remove fully connected pore from search neighborhood
cellList.expel(pore)
......@@ -819,6 +842,7 @@ def generate_dendrogram(basenet: Network, targetsize: List[int], \
avg_throat_diff /= count
print("Avg. throat length difference: %e" % avg_throat_diff)
print("Relative to Lmax: %.1f%%" % (avg_throat_diff / basenet.Lmax * 100.))
print("Percentage of finding next best candidate: %.1f%%" % (next_best_count / count * 100.))
# assemble and return network
network = Network(lb=[0.0 for k in range(d)],
......
Supports Markdown
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