From ee10c4f8feffcd333cb250338a804c22f027f66f Mon Sep 17 00:00:00 2001 From: endolith Date: Thu, 20 Jul 2023 21:14:03 -0400 Subject: [PATCH] Feed batch_size to function instead of global --- examples/niemi_1968_table_1.py | 5 +++-- examples/niemi_1968_table_2.py | 5 +++-- examples/wikipedia_condorcet_paradox_likelihood.py | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/examples/niemi_1968_table_1.py b/examples/niemi_1968_table_1.py index fbc84b5..242b0b0 100644 --- a/examples/niemi_1968_table_1.py +++ b/examples/niemi_1968_table_1.py @@ -65,7 +65,7 @@ assert n_batches * batch_size == n_elections -def simulate_batch(n_voters, n_cands): +def simulate_batch(n_voters, n_cands, batch_size): condorcet_paradox_count = Counter() # Reuse the same chunk of memory to save time election = np.empty((n_voters, n_cands), dtype=np.uint8) @@ -79,7 +79,8 @@ def simulate_batch(n_voters, n_cands): jobs = [] for n_cands in n_cands_list: - jobs.extend([delayed(simulate_batch)(n_voters, n_cands)] * n_batches) + jobs.extend(n_batches * + [delayed(simulate_batch)(n_voters, n_cands, batch_size)]) print(f'{len(jobs)} tasks total:') results = Parallel(n_jobs=-3, verbose=5)(jobs) diff --git a/examples/niemi_1968_table_2.py b/examples/niemi_1968_table_2.py index a9952d5..385d726 100644 --- a/examples/niemi_1968_table_2.py +++ b/examples/niemi_1968_table_2.py @@ -41,7 +41,7 @@ assert n_batches * batch_size == n_elections -def simulate_batch(n_voters, n_cands): +def simulate_batch(n_voters, n_cands, batch_size): condorcet_paradox_count = Counter() # Reuse the same chunk of memory to save time election = np.empty((n_voters, n_cands), dtype=np.uint8) @@ -56,7 +56,8 @@ def simulate_batch(n_voters, n_cands): jobs = [] for n_voters in n_voters_list: for n_cands in n_cands_list: - jobs.extend([delayed(simulate_batch)(n_voters, n_cands)] * n_batches) + jobs.extend(n_batches * + [delayed(simulate_batch)(n_voters, n_cands, batch_size)]) print(f'{len(jobs)} tasks total:') results = Parallel(n_jobs=-3, verbose=5)(jobs) diff --git a/examples/wikipedia_condorcet_paradox_likelihood.py b/examples/wikipedia_condorcet_paradox_likelihood.py index 13cba32..8f08208 100644 --- a/examples/wikipedia_condorcet_paradox_likelihood.py +++ b/examples/wikipedia_condorcet_paradox_likelihood.py @@ -49,7 +49,7 @@ assert n_batches * batch_size == n_elections -def simulate_batch(n_voters, n_cands): +def simulate_batch(n_voters, n_cands, batch_size): condorcet_paradox_count = Counter() # Reuse the same chunk of memory to save time election = np.empty((n_voters, n_cands), dtype=np.uint8) @@ -63,7 +63,8 @@ def simulate_batch(n_voters, n_cands): jobs = [] for n_voters in WP_table: - jobs.extend([delayed(simulate_batch)(n_voters, n_cands)] * n_batches) + jobs.extend(n_batches * + [delayed(simulate_batch)(n_voters, n_cands, batch_size)]) print(f'{len(jobs)} tasks total:') results = Parallel(n_jobs=-3, verbose=5)(jobs)