def test_nested_replicators():

    dummy_schema = WorkflowSchema()

    dummy_protocol = DummyReplicableProtocol('dummy_$(rep_a)_$(rep_b)')

    dummy_protocol.replicated_value_a = ReplicatorValue('rep_a')
    dummy_protocol.replicated_value_b = ReplicatorValue('rep_b')

    dummy_schema.protocols[dummy_protocol.id] = dummy_protocol.schema

    replicator_a = ProtocolReplicator(replicator_id='rep_a')
    replicator_a.template_values = ['a', 'b']

    replicator_b = ProtocolReplicator(replicator_id='rep_b')
    replicator_b.template_values = [1, 2]

    dummy_schema.replicators = [
        replicator_a,
        replicator_b
    ]

    dummy_schema.validate_interfaces()

    dummy_property = create_dummy_property(Density)

    dummy_metadata = Workflow.generate_default_metadata(dummy_property,
                                                        'smirnoff99Frosst-1.1.0.offxml',
                                                        [])

    dummy_workflow = Workflow(dummy_property, dummy_metadata, '')
    dummy_workflow.schema = dummy_schema

    assert len(dummy_workflow.protocols) == 4

    assert dummy_workflow.protocols['dummy_0_0'].replicated_value_a == 'a'
    assert dummy_workflow.protocols['dummy_0_1'].replicated_value_a == 'a'

    assert dummy_workflow.protocols['dummy_1_0'].replicated_value_a == 'b'
    assert dummy_workflow.protocols['dummy_1_1'].replicated_value_a == 'b'

    assert dummy_workflow.protocols['dummy_0_0'].replicated_value_b == 1
    assert dummy_workflow.protocols['dummy_0_1'].replicated_value_b == 2

    assert dummy_workflow.protocols['dummy_1_0'].replicated_value_b == 1
    assert dummy_workflow.protocols['dummy_1_1'].replicated_value_b == 2

    print(dummy_workflow.schema)
def test_advanced_nested_replicators():

    dummy_schema = WorkflowSchema()

    replicator_a = ProtocolReplicator(replicator_id='replicator_a')
    replicator_a.template_values = ['a', 'b']

    replicator_b = ProtocolReplicator(replicator_id=f'replicator_b_{replicator_a.placeholder_id}')
    replicator_b.template_values = ProtocolPath(f'dummy_list[{replicator_a.placeholder_id}]', 'global')

    dummy_protocol = DummyReplicableProtocol(f'dummy_'
                                             f'{replicator_a.placeholder_id}_'
                                             f'{replicator_b.placeholder_id}')

    dummy_protocol.replicated_value_a = ReplicatorValue(replicator_a.id)
    dummy_protocol.replicated_value_b = ReplicatorValue(replicator_b.id)

    dummy_schema.protocols[dummy_protocol.id] = dummy_protocol.schema
    dummy_schema.replicators = [replicator_a, replicator_b]

    dummy_schema.validate_interfaces()

    dummy_property = create_dummy_property(Density)
    dummy_metadata = Workflow.generate_default_metadata(dummy_property, 'smirnoff99Frosst-1.1.0.offxml', [])
    dummy_metadata['dummy_list'] = [[1], [2]]

    dummy_workflow = Workflow(dummy_property, dummy_metadata, '')
    dummy_workflow.schema = dummy_schema

    assert len(dummy_workflow.protocols) == 2

    assert dummy_workflow.protocols['dummy_0_0'].replicated_value_a == 'a'
    assert dummy_workflow.protocols['dummy_0_0'].replicated_value_b == 1

    assert dummy_workflow.protocols['dummy_1_0'].replicated_value_a == 'b'
    assert dummy_workflow.protocols['dummy_1_0'].replicated_value_b == 2

    print(dummy_workflow.schema)
def test_index_replicated_protocol():

    dummy_schema = WorkflowSchema()

    dummy_replicator = ProtocolReplicator('dummy_replicator')
    dummy_replicator.template_values = ['a', 'b', 'c', 'd']
    dummy_schema.replicators = [dummy_replicator]

    replicated_protocol = DummyInputOutputProtocol(f'protocol_{dummy_replicator.placeholder_id}')
    replicated_protocol.input_value = ReplicatorValue(dummy_replicator.id)
    dummy_schema.protocols[replicated_protocol.id] = replicated_protocol.schema

    for index in range(len(dummy_replicator.template_values)):

        indexing_protocol = DummyInputOutputProtocol(f'indexing_protocol_{index}')
        indexing_protocol.input_value = ProtocolPath('output_value', f'protocol_{index}')
        dummy_schema.protocols[indexing_protocol.id] = indexing_protocol.schema

    dummy_schema.validate_interfaces()

    dummy_property = create_dummy_property(Density)

    dummy_workflow = Workflow(dummy_property, {})
    dummy_workflow.schema = dummy_schema
def test_nested_replicators():

    dummy_schema = WorkflowSchema()

    dummy_protocol = DummyReplicableProtocol('dummy_$(rep_a)_$(rep_b)')

    dummy_protocol.replicated_value_a = ReplicatorValue('rep_a')
    dummy_protocol.replicated_value_b = ReplicatorValue('rep_b')

    dummy_schema.protocols[dummy_protocol.id] = dummy_protocol.schema

    dummy_schema.final_value_source = ProtocolPath('final_value',
                                                   dummy_protocol.id)

    replicator_a = ProtocolReplicator(replicator_id='rep_a')

    replicator_a.template_values = ['a', 'b']
    replicator_a.protocols_to_replicate = [ProtocolPath('', dummy_protocol.id)]

    replicator_b = ProtocolReplicator(replicator_id='rep_b')

    replicator_b.template_values = [1, 2]
    replicator_b.protocols_to_replicate = [ProtocolPath('', dummy_protocol.id)]

    dummy_schema.replicators = [replicator_a, replicator_b]

    dummy_schema.validate_interfaces()

    dummy_property = create_dummy_property(Density)

    dummy_metadata = Workflow.generate_default_metadata(
        dummy_property,
        get_data_filename('forcefield/smirnoff99Frosst.offxml'),
        PropertyEstimatorOptions())

    dummy_workflow = Workflow(dummy_property, dummy_metadata)
    dummy_workflow.schema = dummy_schema

    assert len(dummy_workflow.protocols) == 4

    assert dummy_workflow.protocols[dummy_workflow.uuid +
                                    '|dummy_0_0'].replicated_value_a == 'a'
    assert dummy_workflow.protocols[dummy_workflow.uuid +
                                    '|dummy_0_1'].replicated_value_a == 'a'

    assert dummy_workflow.protocols[dummy_workflow.uuid +
                                    '|dummy_1_0'].replicated_value_a == 'b'
    assert dummy_workflow.protocols[dummy_workflow.uuid +
                                    '|dummy_1_1'].replicated_value_a == 'b'

    assert dummy_workflow.protocols[dummy_workflow.uuid +
                                    '|dummy_0_0'].replicated_value_b == 1
    assert dummy_workflow.protocols[dummy_workflow.uuid +
                                    '|dummy_0_1'].replicated_value_b == 2

    assert dummy_workflow.protocols[dummy_workflow.uuid +
                                    '|dummy_1_0'].replicated_value_b == 1
    assert dummy_workflow.protocols[dummy_workflow.uuid +
                                    '|dummy_1_1'].replicated_value_b == 2

    print(dummy_workflow.schema)