def test_configuration_update_model3() -> None:
    component1 = Component('macro', 'my.macro')
    model1 = Model('model1', [component1])
    base = Configuration(model1)

    model_ref2 = ModelReference('model2')
    overlay = PartialConfiguration(model_ref2)

    base.update(overlay)

    assert base.model == model1
    assert model1.name == 'model2'
    assert model1.components == [component1]
示例#2
0
def test_config5() -> Configuration:
    model = Model(
            'test_model',
            [
                Component('ic', 'isr2d.initial_conditions'),
                Component('smc', 'isr2d.smc'),
                Component('bf', 'isr2d.blood_flow'),
                Component('smc2bf', 'isr2d.smc2bf'),
                Component('bf2smc', 'isr2d.bf2smc')],
            [
                Conduit('ic.out', 'smc.initial_state'),
                Conduit('smc.cell_positions', 'smc2bf.in'),
                Conduit('smc2bf.out', 'bf.initial_domain'),
                Conduit('bf.wss_out', 'bf2smc.in'),
                Conduit('bf2smc.out', 'smc.wss_in')])
    implementations = [
            Implementation(
                Reference('isr2d.initial_conditions'), 'isr2d/bin/ic'),
            Implementation(
                Reference('isr2d.smc'), 'isr2d/bin/smc'),
            Implementation(
                Reference('isr2d.blood_flow'), 'isr2d/bin/bf'),
            Implementation(
                Reference('isr2d.smc2bf'), 'isr2d/bin/smc2bf.py'),
            Implementation(
                Reference('isr2d.bf2smc'), 'isr2d/bin/bf2smc.py')]
    resources = [
            Resources(Reference('isr2d.initial_conditions'), 4),
            Resources(Reference('isr2d.smc'), 4),
            Resources(Reference('isr2d.blood_flow'), 4),
            Resources(Reference('isr2d.smc2bf'), 1),
            Resources(Reference('isr2d.bf2smc'), 1)]

    return Configuration(model, None, implementations, resources)
def test_configuration_update_model4() -> None:
    component1 = Component('macro', 'my.macro')
    model1 = Model('model1', [component1])
    base = Configuration(model1)

    component2 = Component('micro', 'my.micro')
    model2 = Model('model2', [component2])
    overlay = Configuration(model2)

    base.update(overlay)

    assert isinstance(base.model, Model)
    assert base.model == model1
    assert base.model.name == 'model2'
    assert component1 in base.model.components
    assert component2 in base.model.components
示例#4
0
def topology_store() -> TopologyStore:
    config = Configuration(
            Model(
                'test_model',
                [
                    ComputeElement('macro', 'macro_implementation'),
                    ComputeElement(
                        'micro', 'micro_implementation', [10, 10])],
                [
                    Conduit('macro.out', 'micro.in'),
                    Conduit('micro.out', 'macro.in')
                ]))

    return TopologyStore(config)
示例#5
0
def test_duplication_mapper(log_file_in_tmpdir):
    """A positive all-up test of duplication mappers.

    This is an acyclic workflow.
    """
    elements = [
        ComputeElement('dm', 'muscle.duplication_mapper'),
        ComputeElement('first', 'receiver'),
        ComputeElement('second', 'receiver')
    ]

    conduits = [Conduit('dm.out', 'first.in'), Conduit('dm.out2', 'second.in')]

    model = Model('test_model', elements, conduits)
    settings = Settings()

    configuration = Configuration(model, settings)

    implementations = {
        'muscle.duplication_mapper': duplication_mapper,
        'receiver': receiver
    }
    run_simulation(configuration, implementations)
示例#6
0
def test_all(log_file_in_tmpdir):
    """A positive all-up test of everything.
    """
    elements = [
        ComputeElement('macro', 'macro_impl'),
        ComputeElement('micro', 'micro_impl', [10])
    ]

    conduits = [
        Conduit('macro.out', 'micro.in'),
        Conduit('micro.out', 'macro.in')
    ]

    model = Model('test_model', elements, conduits)
    settings = Settings(
        OrderedDict([('test1', 13), ('test2', 13.3), ('test3', 'testing'),
                     ('test4', True), ('test5', [2.3, 5.6]),
                     ('test6', [[1.0, 2.0], [3.0, 1.0]])]))

    configuration = Configuration(model, settings)

    implementations = {'macro_impl': macro, 'micro_impl': micro}
    run_simulation(configuration, implementations)
示例#7
0
def test_settings_overlays(log_file_in_tmpdir):
    """A positive all-up test of settings overlays.
    """
    elements = [
            ComputeElement('qmc', 'qmc'),
            ComputeElement('macro', 'macro', [10]),
            ComputeElement('relay', 'explicit_relay'),
            ComputeElement('relay2', 'explicit_relay'),
            ComputeElement('micro', 'micro', [10])]

    conduits = [
                Conduit('qmc.settings_out', 'macro.muscle_settings_in'),
                Conduit('macro.out', 'relay.in'),
                Conduit('relay.out', 'micro.in'),
                Conduit('micro.out', 'relay2.in'),
                Conduit('relay2.out', 'macro.in')]

    model = Model('test_model', elements, conduits)

    settings = Settings(OrderedDict([
                ('test1', 13),
                ('test2', 13.3),
                ('test3', 'testing'),
                ('test4', True),
                ('test5', [2.3, 5.6]),
                ('test6', [[1.0, 2.0], [3.0, 1.0]])]))

    configuration = Configuration(model, settings)

    implementations = {
            'qmc': qmc,
            'macro': macro,
            'explicit_relay': explicit_relay,
            'micro': micro}

    run_simulation(configuration, implementations)
示例#8
0
feed = np.array(feed)
kill = np.array(kill)

# Compute elements for the macro and micro model: specify the name of the python file here
elements = [ComputeElement('macro', 'macro', [n_samples]),
            ComputeElement('micro', 'micro', [n_samples])]

# connect the submodels
conduits = [Conduit('macro.state_out', 'micro.state'),
            Conduit('micro.sgs', 'macro.state_in')]

# create model instance
model = Model('gray_scott_reduced', elements, conduits)

# common settings
settings_dict = {'micro.t_max': 0.1, 'micro.dt': 0.1, 'N_Q': 2, 'N_LF': 128}

# parameter value settings, differs per run
for i in range(n_samples):
    settings_dict['macro[%d].feed' % i] = feed[i]
    settings_dict['macro[%d].kill' % i] = kill[i]
settings = Settings(settings_dict)

configuration = Configuration(model, settings)

# actual subroutines to run, imported from macro.py and micro.py
implementations = {'macro': gray_scott_macro, 'micro': reduced_sgs}

# execute ensemble on a single node
run_simulation(configuration, implementations)
示例#9
0
def test_data_error() -> None:
    config = Configuration('v0.1')
    with pytest.raises(ValueError):
        TopologyStore(config)