예제 #1
0
    def test_validate_model(self):
        import libcellml
        from libcellml import Validator

        # void validateModel(const ModelPtr &model)
        v = Validator()
        v.validateModel(libcellml.Model())
예제 #2
0
    def test_create_destroy(self):
        from libcellml import Validator

        x = Validator()
        del (x)
        y = Validator()
        z = Validator(y)
        del (y, z)
예제 #3
0
    def test_inheritance(self):
        import libcellml
        from libcellml import Validator

        # Test inheritance
        x = Validator()
        self.assertIsInstance(x, libcellml.logger.Logger)

        # Test access to inherited methods
        self.assertIsNone(x.issue(0))
        self.assertIsNone(x.issue(-1))
        self.assertEqual(x.issueCount(), 0)
예제 #4
0
    def test_inheritance(self):
        import libcellml
        from libcellml import Validator

        # Test inheritance
        x = Validator()
        self.assertIsInstance(x, libcellml.Logger)

        # Test access to inherited methods
        self.assertIsNone(x.getError(0))
        self.assertIsNone(x.getError(-1))
        self.assertEqual(x.errorCount(), 0)
        x.addError(libcellml.Error())
        self.assertEqual(x.errorCount(), 1)
    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
    #      Create an Analyser instance, pass in the flattened model, and check that
    #      there are no issues raised.
    analyser = Analyser()
    analyser.analyseModel(flatModel)
    print_issues(analyser)

    #  end 3

    print('----------------------------------------------------------')
    print('   STEP 4: Generate code and output                       ')
    print('----------------------------------------------------------')
예제 #6
0
    # Resolve the imports.
    importer.resolveImports(model, '')

    # Check for issues.
    print('The importer found {} issues.'.format(importer.issueCount()))
    for i in range(0, importer.issueCount()):
        issue = importer.issue(i)
        print(issue.description())

    # Flatten the model.
    model = importer.flattenModel(model)

    # STEP 3
    # Create an Validator instance and pass the model to it for processing.
    validator = Validator()
    validator.validateModel(model)

    # Print any issues to the terminal.
    print('The validator found {} issues.'.format(validator.issueCount()))
    for i in range(0, validator.issueCount()):
        issue = validator.issue(i)
        print(issue.description())

    # STEP 4
    # Fix the validation errors.

    # Add units to the variable 'b' in component 'validationErrors'.
    model.component('validationErrors').variable('b').setUnits('dimensionless')

    # Change the name of the variable 'iShouldBeNamed_c' to be 'c'.
예제 #7
0
    def test_create_destroy(self):
        from libcellml import Validator

        x = Validator()
        del x
예제 #8
0
    model = parser.parseModel(content)

    #  1.c
    #      Use the print_model utility function to display the contents of the
    #      parsed model in the terminal.
    print_model(model, True)

    #  end 1

    print('----------------------------')
    print(' STEP 2: Validate the model')
    print('----------------------------')

    #  2.a
    #      Create a Validator and pass the model into it.
    validator = Validator()
    validator.validateModel(model)

    #  2.b
    #      Check the number of issues returned from the validator.
    num_validation_issues = validator.issueCount()
    print('The validator has found {} issues!'.format(num_validation_issues))

    #  2.c
    #      Retrieve the issues, and print their description, url, reference, and
    #      type of item stored to the terminal.  The type of stored item is
    #      available as an enum, which can be turned into a string for output using
    #      the utility function, getItemTypeFromEnum(type).
    for e in range(0, num_validation_issues):
        issue = validator.issue(e)
        reference = issue.referenceHeading()
        '           <ci>E_K</ci>\n'\
        '       </apply>\n'\
        '    </apply>\n'\
        '  </apply>\n'

    k_channel_equations.setMath(math_header)
    k_channel_equations.appendMath(equation_iK)
    k_channel_equations.appendMath(math_footer)
     
    #  2.c 
    #      Once the mathematics has been added to the component, and the component to the 
    #      model, we can make use of the diagnostic messages within the Validator class
    #      to tell us what else needs to be done.  
    #      Create a Validator instance, and pass it your model for processing using the 
    #      validateModel function.  
    validator = Validator()
    validator.validateModel(model)

    #  end 2.c

    #      Calling the validator does not return anything: we have to go looking for issues 
    #      that it found during processing.  When a problem is found, an Issue item is created
    #      containing:
    #          - a description string explaining the problem
    #          - a URL at which more information is available
    #          - an std.any item relevant to the problem, if available
    #          - a level indicator and
    #          - a cause indicator relevant to the stored item.
    #  We can use these issues as we need to.  The simplest way is to print the descriptions
    #  to the terminal.
예제 #10
0
 
    Tutorial 7 assumes that you are already comfortable with:
        - the concept of component hierarchy and encapsulation (Tutorial 5)
        - the use of the API to create all of the entities in a model (Tutorial 3)
        - the content MathML2 markup for mathematical equations (Tutorial 4)
        - serialisation and printing of a model to a CellML file (Tutorial 1)

"""

from libcellml import Component, Model, Printer, Units, Validator, Variable

from utilities.tutorial_utilities import print_errors_to_terminal

if __name__ == "__main__":
    #  0 Setup stuff that is used throughout
    validator = Validator()
    model = Model()
    model.setName("Tutorial7_SodiumChannelModel")

    math_header = '<math xmlns="http://www.w3.org/1998/Math/MathML" xmlns:cellml="http://www.cellml.org/cellml/2.0#">'
    math_footer = '</math>'

    print("-----------------------------------------------")
    print("  STEP 1: Creating the sodium channel")
    print("-----------------------------------------------")

    #  1.a Create the component instance, name it, and add to the model
    sodium_channel = Component()
    sodium_channel.setName("sodiumChannel")
    model.addComponent(sodium_channel)
예제 #11
0
    # ---------------------------------------------------------------------------
    #  STEP 2:  Print the contents of the model to the terminal so that we can read it more easily. This step makes
    #           use of the utilities in the 'tutorial_utilities.py' file
    print("-----------------------------------------------")
    print("       Printing the parsed model               ")
    print("-----------------------------------------------")
    print_model_to_terminal(model)

    # ---------------------------------------------------------------------------
    #  STEP 3: Check that the model meets the CellML2.0 specifications using the Validator
    #
    #  2.a   Create a Validator and pass the model into it
    print("-----------------------------------------------")
    print("       Validating the parsed model")
    print("-----------------------------------------------")
    validator = Validator()
    validator.validateModel(model)

    #  2.b   Check whether there were errors returned from the validator
    number_of_validation_errors = validator.errorCount()

    if number_of_validation_errors != 0:
        print("The validator has found {n} errors!".format(
            n=number_of_validation_errors))

        # 2.c  Retrieve the errors, and print their description and specification reference to the terminal
        for e in range(0, number_of_validation_errors):
            validator_error = validator.error(e)

            specification_heading = validator_error.specificationHeading()
예제 #12
0
    the model which can be solved in Python or C.  By the time you have worked 
    through Tutorial 6 you will be able to:
        - use the Generator functionality to create models in Python or C format
        - use the simple solver provided to run the created models.
    
    Tutorial 6 assumes that you are already comfortable with:
        - file manipulation and summarising using the utility functions
      
"""
from libcellml import Model, Parser, Validator

if __name__ == "__main__":
    #  0    Create a new model instance representing the combined model and name it.
    model = Model()
    model.setName("Tutorial8_HHModel")
    validator = Validator()
    parser = Parser()

    print("-----------------------------------------------")
    print("    STEP 1: Read the membrane component")
    print("-----------------------------------------------")

    #  1.a  Read the model provided for you in the "Tutorial8_MembraneModel.cellml"
    #       file in the resources folder.

    #  1.b  Create a temporary model for the membrane

    #  1.b  Extract the membrane component from the parsed model and add it
    #       to the combined model.  Note that the membrane component's parent
    #       must be cleared before adding it to the model.
예제 #13
0
    #      Use the parser to deserialise the contents of the string you've read and return the model.
    model = parser.parseModel(read_file.read())

    #  1.d
    #      Print the parsed model to the terminal for viewing.
    print_model(model, False)

    #  end 1

    print('----------------------------------------------------------')
    print('   STEP 2: Validate the parsed model                      ')
    print('----------------------------------------------------------')

    #  2.a
    #      Create a Validator item and validate the model.
    validator = Validator()
    validator.validateModel(model)

    #  end 2.a

    #      Each Validator issue contains:
    #          - a description of the problem
    #          - the reference heading in the normative specification which affects this issue
    #          - a URL at which the informative specification notes can be found
    #          - an std.any item storing the CellML element most relevant to the issue and
    #          - a level indication.

    #  2.b
    #      Retrieve any issues from the validator and print their descriptions and help URL to the terminal.
    #      If you're already familiar with these you can use the print_issues function instead.
    print('The validator found {} issues.'.format(validator.issueCount()))
    
    Tutorial 6 assumes that you are already comfortable with:
        - file manipulation and summarising using the utility functions
      
"""
from libcellml import Component, Model, Parser, Printer, Validator, Variable

from utilities.tutorial_utilities import print_errors_to_terminal, print_encapsulation_structure_to_terminal, \
    switch_units_in_maths, insert_into_mathml_string

if __name__ == "__main__":

    #  0.a Create a new model instance representing the combined model and name it.
    model = Model()
    model.setName("Tutorial8_HHModel")
    validator = Validator()
    parser = Parser()

    print("-----------------------------------------------")
    print("    STEP 1: Read the membrane component")
    print("-----------------------------------------------")

    #  1.a Read the model provided for you in the "Tutorial8_MembraneModel.cellml"
    #      file in the resources folder.
    read_file1 = open("../resources/tutorial8_MembraneModel.cellml", "r")

    # 1.b  Create a temporary model for the membrane
    membrane_model = parser.parseModel(read_file1.read())
    membrane_model.setName("membraneModel")

    #  1.b Extract the membrane component from the parsed model and add it
예제 #15
0
    # Check for issues.
    print('The importer found {} issues.'.format(importer.issueCount()))
    for i in range(0,importer.issueCount()):
        print(importer.issue(i).description())
    print()

    # STEP 3
    # The analysis tools - the Validator and Analyser - will read only the submitted
    # model they do not look into any of the imported items, so they can't check them.
    # In order to retain the import structure but be able to use the diagnostic tools, 
    # we can create a flattened copy of the model for testing.  This can be used to
    # identify mistakes in the unflattened model too.  

    # Create a Validator and Analyser and submit the original, unflattened model.
    # We don't expect either of these to report any issues.
    validator = Validator()
    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.