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

Add multiprocessing support #13

Merged
merged 2 commits into from
May 30, 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
29 changes: 15 additions & 14 deletions tests/generators/fork_choice_generated/instance_generator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from eth2spec.test.helpers.constants import ALTAIR
from eth2spec.gen_helpers.gen_base import gen_runner
from eth2spec.test.helpers.constants import MINIMAL
from eth2spec.test.helpers.constants import MINIMAL, MAINNET
from eth2spec.test.helpers.specs import spec_targets
from eth2spec.gen_helpers.gen_base.gen_typing import TestCase, TestProvider
from itertools import product
Expand Down Expand Up @@ -39,18 +39,19 @@ def prepare_fn() -> None:
bls.use_milagro()
return

def make_cases_fn() -> Iterable[TestCase]:
seeds = [initial_seed]
if number_of_variations > 1:
rnd = random.Random(initial_seed)
seeds = [rnd.randint(1, 10000) for _ in range(number_of_variations)]
seeds[0] = initial_seed

for i, solution in enumerate(solutions):
for seed in seeds:
for fork_name in forks:
for preset_name in presets:
spec = spec_targets[preset_name][fork_name]
seeds = [initial_seed]
if number_of_variations > 1:
rnd = random.Random(initial_seed)
seeds = [rnd.randint(1, 10000) for _ in range(number_of_variations)]
seeds[0] = initial_seed

for fork_name in forks:
for preset_name in presets:
spec = spec_targets[preset_name][fork_name]

for i, solution in enumerate(solutions):
def make_cases_fn() -> Iterable[TestCase]:
for seed in seeds:
mutation_generator = MutatorsGenerator(
spec, seed, number_of_mutations,
lambda: test_fn(fork_name, preset_name, seed, solution),
Expand All @@ -64,7 +65,7 @@ def make_cases_fn() -> Iterable[TestCase]:
case_name=test_name + '_' + str(i) + '_' + str(seed) + '_' + str(j),
case_fn=mutation_generator.next_test_case)

yield TestProvider(prepare=prepare_fn, make_cases=make_cases_fn)
yield TestProvider(prepare=prepare_fn, make_cases=make_cases_fn)


def _find_sm_link_solutions(anchor_epoch: int,
Expand Down
9 changes: 8 additions & 1 deletion tests/generators/fork_choice_generated/mutation_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,15 @@ def mk_mutations(spec, seed, num, test_fn, debug=False):

class MutatorsGenerator:
def __init__(self, spec, seed, num, test_fn, debug=False):
self.iterator = iter(mk_mutations(spec, seed, num, test_fn, debug))
self.spec = spec
self.seed = seed
self.num = num
self.test_fn = test_fn
self.debug = debug
self.iterator = None

def next_test_case(self):
if self.iterator is None:
self.iterator = iter(mk_mutations(self.spec, self.seed, self.num, self.test_fn, self.debug))
_, test_case = next(self.iterator)
return test_case
Loading