def test_redis_pw_protection(): sampler = RedisEvalParallelSamplerServerStarter( # noqa: S106 password="******", port=8888) def simulate_one(): accepted = np.random.randint(2) return Particle(0, {}, 0.1, [], [], accepted) sample = sampler.sample_until_n_accepted(10, simulate_one) assert 10 == len(sample.get_accepted_population()) sampler.cleanup()
def test_redis_multiprocess(): sampler = RedisEvalParallelSamplerServerStarter( batch_size=3, workers=1, processes_per_worker=1) def simulate_one(): accepted = np.random.randint(2) return Particle(0, {}, 0.1, [], [], accepted) sample = sampler.sample_until_n_accepted(10, simulate_one) assert 10 == len(sample.get_accepted_population()) sampler.cleanup()
def test_redis_pw_protection(): def simulate_one(): accepted = np.random.randint(2) return pyabc.Particle(0, {}, 0.1, [], [], accepted) sampler = RedisEvalParallelSamplerServerStarter( # noqa: S106 password="******") try: # needs to be always set sampler.set_analysis_id("ana_id") sample = sampler.sample_until_n_accepted(10, simulate_one, 0) assert 10 == len(sample.get_accepted_population()) finally: sampler.shutdown()
def test_redis_multiprocess(): def simulate_one(): accepted = np.random.randint(2) return pyabc.Particle(0, {}, 0.1, [], [], accepted) sampler = RedisEvalParallelSamplerServerStarter(batch_size=3, workers=1, processes_per_worker=2) try: # id needs to be set sampler.set_analysis_id("ana_id") sample = sampler.sample_until_n_accepted(10, simulate_one, 0) assert 10 == len(sample.get_accepted_population()) finally: sampler.shutdown()