Exemplo n.º 1
0
    def test_flatten(self):
        from libcellml import Importer, Parser

        parser = Parser()
        importer = Importer()

        model = parser.parseModel(file_contents('importer/diamond.cellml'))

        importer.resolveImports(model, resource_path('importer/'))

        flattenedModel = importer.flattenModel(model)
        self.assertEqual(2, flattenedModel.componentCount())
    print('   STEP 2: Resolve the imports and flatten                ')
    print('----------------------------------------------------------')

    import_path = os.path.dirname(model_file)
    #  2.a
    #      Create an Importer instance and use it to resolve the imports in your model.
    importer = Importer()
    importer.resolveImports(model, import_path)

    #  2.b
    #      Check that the importer has not raised any issues.
    print_issues(importer)

    #  2.c
    #      Use the importer to create a flattened version of the model.
    flatModel = importer.flattenModel(model)

    #  end 2

    print('----------------------------------------------------------')
    print('   STEP 3: Validate and analyse the flattened model       ')
    print('----------------------------------------------------------')

    #  3.a
    #      Create a Validator instance, pass in the flattened model, and check that
    #      there are no issues raised.
    validator = Validator()
    validator.validateModel(flatModel)
    print_issues(validator)

    #  3.b
Exemplo n.º 3
0
    analyser.analyseModel(model)

    #  6.b
    #      Retrieve and print the issues from the analysis to the screen.  We expect to see
    #      messages related to un-computed variables, since anything which is imported is
    #      missing from this model.
    print_issues(analyser)

    print()
    #  6.c
    #      Create a flattened version of the model print it to the screen.
    #      Notice that any comments indicating that a component was an import have been
    #      removed as these components have been instantiated in the flattened model.
    #      Useful functions:
    #          - Importer.flattenModel(Model) will return a flattened copy.
    flat_model = importer.flattenModel(model)
    print_model(flat_model)

    #  6.d
    #      Analyse the flattened model and print the issues to the screen.
    analyser.analyseModel(flat_model)
    print_issues(analyser)

    #  end 6.d

    #      The issue returned from the analyser says that we're trying to use two different variables
    #      as the base variable of integration, and the CellML code generation facility (which the analyser
    #      is tied to) does not support this yet. It's still valid CellML though! In this example, the real
    #      problem is that these two variables are talking about the same thing, but haven't been connected
    #      to one another yet.
Exemplo n.º 4
0
    validator.validateModel(original_model)

    print('Investigating the original model:')
    print(' - the validator found {} issues'.format(validator.issueCount()))
    for i in range(0, validator.issueCount()):
        print('    - {}'.format(validator.issue(i).description()))
    
    analyser = Analyser()
    analyser.analyseModel(original_model)
    print(' - the analyser found {} issues'.format(analyser.issueCount()))
    for i in range(0, analyser.issueCount()):
        print('    - {}'.format(analyser.issue(i).description()))
    print()

    # Create a flattened version for diagnostics.
    flat_model = importer.flattenModel(original_model)

    # Repeat the validation and analysis above on the flattened model.
    validator.validateModel(flat_model)
    print('Investigating the flattened model:')
    print(' - the validator found {} issues'.format(validator.issueCount()))
    for i in range(0, validator.issueCount()):
        print('    - {}'.format(validator.issue(i).description()))
    
    analyser.analyseModel(flat_model)
    print(' - the analyser found {} issues'.format(analyser.issueCount()))
    for i in range(0, analyser.issueCount()):
        print('    - {}'.format(analyser.issue(i).description()))
    print()

    # STEP 4