Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network Explorer: Replace (crashing) threads with ConcurrentMixin #261

Merged
merged 3 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions orangecontrib/network/network/layout/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,27 @@ def fruchterman_reingold(pos,
k,
init_temp=0.05,
sample_ratio=None,
callback_step=None, callback=None):

last_perc = 0

def run_iterations(n_iterations, temperatures):
nonlocal last_perc
callback_interval=0.5, callback=None):

def run_iterations(n_iterations, temperatures, callback=callback):
last_call = time.perf_counter()
for iteration in range(n_iterations):
if sample_ratio is not None:
np.random.shuffle(sample)
fruchterman_reingold_step(pos, sample[:sample_size],
edge_src, edge_dst, edge_weights,
k, temperatures[iteration], disp)
if callback is not None and iteration % callback_step == 0:
perc = iteration / n_iterations * 100
if not callback(pos, perc - last_perc):
return False
last_perc = perc
return True

if callback and \
(now := time.perf_counter()) - last_call > callback_interval:
progress = iteration / n_iterations * 100
callback(pos, progress)
last_call = now

n_nodes = len(pos)

edge_weights = edges.data if weighted else np.empty(0)
edge_src, edge_dst = edges.row, edges.col,
edge_src, edge_dst = edges.row.astype(np.int32), edges.col.astype(np.int32)

disp = np.empty((n_nodes, 2))

Expand All @@ -50,8 +46,7 @@ def run_iterations(n_iterations, temperatures):

temperatures = np.linspace(init_temp, 0.01, TEST_ITERATIONS)
start_time = time.perf_counter()
if not run_iterations(TEST_ITERATIONS, temperatures):
return
run_iterations(TEST_ITERATIONS, temperatures, callback=None)
elapsed_time = time.perf_counter() - start_time

iterations = int(allowed_time / (elapsed_time / TEST_ITERATIONS))
Expand Down
Loading
Loading