Ejemplo n.º 1
0
def test_load_string1(test_yaml1: str) -> None:
    configuration = load(test_yaml1)
    assert isinstance(configuration, PartialConfiguration)
    assert not isinstance(configuration, Configuration)
    settings = configuration.settings
    assert settings is not None
    assert len(settings) == 3
    assert isinstance(settings['test_list'], list)
    assert settings['test_list'][1] == 1.3

    configuration = load(test_yaml1)
    assert configuration.settings is not None
    assert configuration.settings['test_str'] == 'value'
    assert configuration.settings['test_int'] == 13
    assert configuration.settings['test_list'] == [12.3, 1.3]
Ejemplo n.º 2
0
def run_muscle_dist_local(config, ymmsl_name="main.ymmsl", **args):
    """
    Run a distributed MUSCLE3 example locally.
    """

    scripts = ["muscle_manager {}".format(ymmsl_name)]

    with_config(config)

    with open("{}/{}".format(env.job_config_path_local, ymmsl_name), 'r') as f:
        config = ymmsl.load(f)

    for ce in config.model.compute_elements:
        print(ce.name, ce.implementation)

        print("python3 ./{}.py --muscle-instance={}".format(
            ce.implementation, ce.name))
        scripts.append("python3 ./{}.py --muscle-instance={}".format(
            ce.implementation, ce.name))

    exec_string = "cd {} ; ".format(env.job_config_path_local)
    for s in scripts:
        exec_string += "{} & ".format(s)
    exec_string += " wait"
    print(exec_string)
    local(exec_string)
Ejemplo n.º 3
0
def test_load_path(test_yaml1: str, tmpdir_path: Path) -> None:
    test_file = tmpdir_path / 'test_yaml1.ymmsl'
    with test_file.open('w') as f:
        f.write(test_yaml1)

    configuration = load(test_file)
    assert configuration.settings is not None
Ejemplo n.º 4
0
def test_load_string5(test_yaml5: str) -> None:
    configuration = load(test_yaml5)
    assert isinstance(configuration, Configuration)
    assert len(configuration.model.components) == 5
    assert len(configuration.model.conduits) == 5
    assert len(configuration.implementations) == 5
    assert len(configuration.resources) == 5
Ejemplo n.º 5
0
def mmp_server(yatiml_log_warning):
    ymmsl_text = ('ymmsl_version: v0.1\n'
                  'model:\n'
                  '  name: test_model\n'
                  '  compute_elements:\n'
                  '    macro: macro_implementation\n'
                  '    micro:\n'
                  '      implementation: micro_implementation\n'
                  '      multiplicity: [10]\n'
                  '  conduits:\n'
                  '    macro.out: micro.in\n'
                  '    micro.out: macro.in\n'
                  'settings:\n'
                  '  test1: 13\n'
                  '  test2: 13.3\n'
                  '  test3: testing\n'
                  '  test4: True\n'
                  '  test5: [2.3, 5.6]\n'
                  '  test6:\n'
                  '    - [1.0, 2.0]\n'
                  '    - [3.0, 1.0]\n')
    ymmsl_doc = ymmsl.load(ymmsl_text)

    server = make_server(ymmsl_doc)
    yield server
    server.stop()
Ejemplo n.º 6
0
def manage_simulation(ymmsl_file: str) -> None:
    with open(ymmsl_file) as f:
        configuration = ymmsl.load(f)

    server = start_server(configuration)
    print(server.get_location())
    server.wait()
Ejemplo n.º 7
0
def InputRead(path):

    filename = os.path.join(path, ('input_stage4.ymmsl'))
    with open(filename) as f:
        ymmsl_data = ymmsl.load(f)

    settings = ymmsl_data.settings
    return settings
Ejemplo n.º 8
0
def read_ymmsl_file(path, filename):
    final_path = path + filename
    with open(final_path) as f:
        ymmsl_data = ymmsl.load(f)

    with open(final_path) as f:
        yaml_data = yaml.load(f, Loader=yaml.FullLoader)

    return ymmsl_data, yaml_data
Ejemplo n.º 9
0
def test_load_string4(test_yaml4: str) -> None:
    configuration = load(test_yaml4)
    assert isinstance(configuration, PartialConfiguration)
    assert not isinstance(configuration, Configuration)
    assert len(configuration.implementations) == 5
    impls = configuration.implementations
    ic = Reference('isr2d.initial_conditions')
    bf2smc = Reference('isr2d.bf2smc')
    assert impls[ic].name == 'isr2d.initial_conditions'
    assert impls[bf2smc].script == 'isr2d/bin/bf2smc.py'

    assert len(configuration.resources) == 5
    assert configuration.resources[ic].num_cores == 4
    assert configuration.resources[bf2smc].num_cores == 1
Ejemplo n.º 10
0
def test_load_string2(test_yaml2: str) -> None:
    configuration = load(test_yaml2)
    assert isinstance(configuration, PartialConfiguration)
    assert not isinstance(configuration, Configuration)
    model = configuration.model
    assert isinstance(model, Model)
    assert str(model.name) == 'test_model'
    assert len(model.components) == 5
    assert str(model.components[4].name) == 'bf2smc'
    assert str(model.components[2].implementation) == 'isr2d.blood_flow'
    assert len(model.conduits) == 5
    assert str(model.conduits[0].sender) == 'ic.out'
    assert str(model.conduits[1].sending_port()) == 'cell_positions'
    assert str(model.conduits[3].receiving_component()) == 'bf2smc'
Ejemplo n.º 11
0
def do_logging_test(caplog):
    ymmsl_text = (
            'ymmsl_version: v0.1\n'
            'model:\n'
            '  name: test_model\n'
            '  compute_elements:\n'
            '    macro: macro_implementation\n'
            '    micro:\n'
            '      implementation: micro_implementation\n'
            '      multiplicity: [10]\n'
            '  conduits:\n'
            '    macro.out: micro.in\n'
            '    micro.out: macro.in\n'
            'settings:\n'
            '  test1: 13\n'
            '  test2: 13.3\n'
            '  test3: testing\n'
            '  test4: True\n'
            '  test5: [2.3, 5.6]\n'
            '  test6:\n'
            '    - [1.0, 2.0]\n'
            '    - [3.0, 1.0]\n'
            )

    # create server
    logger = Logger()
    ymmsl_doc = ymmsl.load(ymmsl_text)
    expected_elements = elements_for_model(ymmsl_doc.model)
    instance_registry = InstanceRegistry(expected_elements)
    topology_store = TopologyStore(ymmsl_doc)
    server = MMPServer(logger, ymmsl_doc.settings, instance_registry,
                       topology_store)

    # create client
    client = MMPClient('localhost:9000')
    message = LogMessage(
            instance_id='test_logging',
            timestamp=Timestamp(2.0),
            level=LogLevel.CRITICAL,
            text='Integration testing')

    # log and check
    client.submit_log_message(message)
    assert caplog.records[0].name == 'test_logging'
    assert caplog.records[0].time_stamp == '1970-01-01T00:00:02Z'
    assert caplog.records[0].levelname == 'CRITICAL'
    assert caplog.records[0].message == 'Integration testing'

    server.stop()
Ejemplo n.º 12
0
def mmp_server_process_simple(yatiml_log_warning):
    ymmsl_text = ('ymmsl_version: v0.1\n'
                  'model:\n'
                  '  name: test_model\n'
                  '  compute_elements:\n'
                  '    macro: macro_implementation\n'
                  '    micro: micro_implementation\n'
                  '  conduits:\n'
                  '    macro.out: micro.in\n'
                  '    micro.out: macro.in\n'
                  'settings:\n'
                  '  test1: 13\n'
                  '  test2: 13.3\n'
                  '  test3: testing\n'
                  '  test4: True\n'
                  '  test5: [2.3, 5.6]\n'
                  '  test6:\n'
                  '    - [1.0, 2.0]\n'
                  '    - [3.0, 1.0]\n')
    ymmsl_doc = ymmsl.load(ymmsl_text)

    yield from make_server_process(ymmsl_doc)
Ejemplo n.º 13
0
def make_muscle_ensemble(config, ymmsl_name, **args):
    """
    Creates a concurrently running MUSCLE ensemble application using a 
    variation of run_ensemble.
    """
    with_config(config)
    local("rm -rf {}/SWEEP".format(env.job_config_path_local))

    # Make MUSCLE Manager directory.
    local("mkdir -p {}/SWEEP/muscle_manager".format(env.job_config_path_local))
    local("cp {}/{} {}/SWEEP/muscle_manager/".format(
        env.job_config_path_local, ymmsl_name, env.job_config_path_local))

    with open("{}/{}".format(env.job_config_path_local, ymmsl_name), 'r') as f:
        config = ymmsl.load(f)

    # Make directories for MUSCLE submodel instances.
    for ce in config.model.compute_elements:

        print(ce.name, ce.implementation)
        local("mkdir {}/SWEEP/{}".format(env.job_config_path_local, ce.name))
        local("cp {}/{}.py {}/SWEEP/{}/model.py".format(
            env.job_config_path_local, ce.implementation,
            env.job_config_path_local, ce.name))
Ejemplo n.º 14
0
def test_load_string3(test_yaml3: str) -> None:
    configuration = load(test_yaml3)
    assert isinstance(configuration, PartialConfiguration)
    assert not isinstance(configuration, Configuration)
    assert isinstance(configuration.model, ModelReference)
    assert str(configuration.model.name) == 'test_model'
Ejemplo n.º 15
0
def do_mmp_client_test(caplog):
    ymmsl_text = ('ymmsl_version: v0.1\n'
                  'model:\n'
                  '  name: test_model\n'
                  '  compute_elements:\n'
                  '    macro: macro_implementation\n'
                  '    micro:\n'
                  '      implementation: micro_implementation\n'
                  '      multiplicity: [10]\n'
                  '  conduits:\n'
                  '    macro.out: micro.in\n'
                  '    micro.out: macro.in\n'
                  'settings:\n'
                  '  test1: 13\n'
                  '  test2: 13.3\n'
                  '  test3: testing\n'
                  '  test4: True\n'
                  '  test5: [2.3, 5.6]\n'
                  '  test6:\n'
                  '    - [1.0, 2.0]\n'
                  '    - [3.0, 1.0]\n')

    # create server
    logger = Logger()
    ymmsl_doc = ymmsl.load(ymmsl_text)
    expected_elements = elements_for_model(ymmsl_doc.model)
    instance_registry = InstanceRegistry(expected_elements)
    topology_store = TopologyStore(ymmsl_doc)
    server = MMPServer(logger, ymmsl_doc.settings, instance_registry,
                       topology_store)

    # mock the deregistration
    removed_instance = None

    def mock_remove(name: Reference):
        nonlocal removed_instance
        removed_instance = name

    instance_registry.remove = mock_remove

    # add some peers
    instance_registry.add(Reference('macro'), ['tcp:test3', 'tcp:test4'],
                          [Port('out', Operator.O_I),
                           Port('in', Operator.S)])

    # create C++ client
    # it runs through the various RPC calls
    # see libmuscle/cpp/src/libmuscle/tests/mmp_client_test.cpp
    cpp_build_dir = Path(__file__).parents[1] / 'libmuscle' / 'cpp' / 'build'
    lib_paths = [
        cpp_build_dir / 'grpc' / 'c-ares' / 'c-ares' / 'lib',
        cpp_build_dir / 'grpc' / 'zlib' / 'zlib' / 'lib',
        cpp_build_dir / 'grpc' / 'openssl' / 'openssl' / 'lib',
        cpp_build_dir / 'protobuf' / 'protobuf' / 'lib',
        cpp_build_dir / 'grpc' / 'grpc' / 'lib',
        cpp_build_dir / 'msgpack' / 'msgpack' / 'lib'
    ]
    env = {'LD_LIBRARY_PATH': ':'.join(map(str, lib_paths))}
    cpp_test_dir = cpp_build_dir / 'libmuscle' / 'tests'
    cpp_test_client = cpp_test_dir / 'mmp_client_test'
    result = subprocess.run([str(cpp_test_client)], env=env)

    # check that C++-side checks were successful
    print(result.stderr, flush=True)
    assert result.returncode == 0

    # check submit_log_message
    assert caplog.records[0].name == 'test_logging'
    assert caplog.records[0].time_stamp == '1970-01-01T00:00:02Z'
    assert caplog.records[0].levelname == 'CRITICAL'
    assert caplog.records[0].message == 'Integration testing'

    # check register_instance
    assert (instance_registry.get_locations('micro[3]') == [
        'tcp:test1', 'tcp:test2'
    ])
    ports = instance_registry.get_ports('micro[3]')
    assert ports[0].name == 'out'
    assert ports[0].operator == Operator.O_F
    assert ports[1].name == 'in'
    assert ports[1].operator == Operator.F_INIT

    # check deregister_instance
    assert removed_instance == 'micro[3]'

    server.stop()