def test_factory(): # Generate the network & experiment. # This should generally be done in a separate script network = pyphi.examples.basic_network() state = (1, 0, 0) experiment = Experiment('test_factory', '1.0', network, state) experiment.initialize() port = 10030 mechanisms = pyphi.utils.powerset(network.node_indices, nonempty=True) with WorkerFactory(experiment) as factory: start_master(experiment, mechanisms, port) # Load CES ces = experiment.load_ces() print(ces) # Check results reference_ces = pyphi.compute.ces(pyphi.Subsystem(network, state)) assert ces.phis == reference_ces.phis assert ces.mechanisms == reference_ces.mechanisms print('All good!')
def test_simple(): network = pyphi.examples.basic_network() state = (1, 0, 0) experiment = Experiment('test_simple', '1.0', network, state) experiment.initialize() mechanisms = pyphi.utils.powerset(network.node_indices, nonempty=True) print('Starting worker...') worker = subprocess.Popen([ 'work_queue_worker', '-N', experiment.project_name, '-P', experiment.password_file, # '-d', 'all' ]) try: print('Starting master...') start_master(experiment, mechanisms, port=10021, timeout=0, n_divisions=2) except: raise finally: print('Killing worker...') worker.kill() worker.wait() print('Done.') ces = experiment.load_ces() print(ces) reference_ces = pyphi.compute.ces(pyphi.Subsystem(network, state)) assert ces.phis == reference_ces.phis assert ces.mechanisms == reference_ces.mechanisms print('All good!')
import itertools import pyphi from utils import Experiment from master import WorkerFactory, start_master if __name__ == '__main__': elements = list(range(20)) state = [0 for x in elements] experiment = Experiment('iv_manet', '5.0', None, state) # fourth = mechanisms_for_order(elements, 4) # random.shuffle(fourth) def mechanisms_for_order(elements, n): return pyphi.utils.combs(elements, n).tolist() mechanisms = itertools.chain( mechanisms_for_order(elements, 3), mechanisms_for_order(elements, 2), mechanisms_for_order(elements, 1), # fourth ) port = 10010 with WorkerFactory(experiment, memory=10024) as f: start_master(experiment, mechanisms, port=port, n_divisions=10)
from master import WorkerFactory, Experiment, start_master if __name__ == '__main__': state = (0, ) * 20 # TODO: pull from experiment elements = list(range(20)) def mechanisms_for_order(elements, n): return pyphi.utils.combs(elements, n).tolist() fourth = mechanisms_for_order(elements, 4) random.shuffle(fourth) mechanisms = itertools.chain(mechanisms_for_order(elements, 1), mechanisms_for_order(elements, 2), mechanisms_for_order(elements, 3), fourth) # Already has a saved network file experiment = Experiment('largepyr', '2.1', None, state) port = 10006 with WorkerFactory(experiment) as factory: start_master(experiment, mechanisms, port)
def master() -> None: """Runs the master daemon""" click.echo("Hello from master") start_master()