def test_validate_model(self): import libcellml from libcellml import Validator # void validateModel(const ModelPtr &model) v = Validator() v.validateModel(libcellml.Model())
# 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('----------------------------------------------------------')
# 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'. model.component('validationErrors').variable('iShouldBeNamed_c').setName('c')
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())) for i in range(0, validator.issueCount()):
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 # to the combined model. Note that the membrane component's parent # must be removed before adding it to the model. membrane = membrane_model.component("membrane") membrane.removeParent() model.addComponent(membrane) # 1.c Validate the combined model. We expect to see errors from: # - missing units, as we have only added the component so far validator.validateModel(model) print_errors_to_terminal(validator) # 1.d Import the units from the membraneModel into the combined model for u in range(0, membrane_model.unitsCount()): model.addUnits(membrane_model.units(u)) # 1.e No errors expected this time :) validator.validateModel(model) print_errors_to_terminal(validator) print("\n-----------------------------------------------") print(" STEP 2: Read the sodium channel") print("-----------------------------------------------") # 2.a Read the model created in Tutorial 7 representing the sodium channel.
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. flat_model = importer.flattenModel(original_model)