cellml / libcellml

Repository for libCellML development.
https://libcellml.org
Apache License 2.0
16 stars 21 forks source link

An issue when initialising a state variable using a variable instead of a constant #1144

Closed WeiweiAi closed 1 year ago

WeiweiAi commented 1 year ago

libcellml 0.4.0

When I tried to write python code from the attached CellML model, I got the issues: The method "analyse_model" found 2 issues:

cellml.zip

agarny commented 1 year ago

Hi @WeiweiAi, could you please provide the Python script you used to get that outcome? Also, please tell us what outcome you would have expected. In other words: provide us with everything we need to reproduce your problem without having to guess what you were trying to do.

WeiweiAi commented 1 year ago

Hi @agarny If you place the following Python script in the same folder as the CellML files that I have uploaded, you should be able to reproduce the issues. The Python script needs libcellml and pathlib packages installed. I also tried a bit of debugging based on Andre's suggestion, i.e., I wrote the flattened model to a CellML file, read back, and analyzed it again. I got the same issues. I have checked the flattened CellML file and the units are defined as expected.

from libcellml import Analyser, Parser,  Importer, Printer
from pathlib import *
def _dump_issues(source_method_name, logger):
    if logger.issueCount() > 0:
        print('The method "{}" found {} issues:'.format(source_method_name, logger.issueCount()))
        for i in range(0, logger.issueCount()):
            print('    - {}'.format(logger.issue(i).description()))
strict_mode=True
filename = 'BG_initTest.cellml'
base_dir = str(Path.cwd())
# read the model
cellml_file = open(filename)
parser = Parser(strict_mode)
model = parser.parseModel(cellml_file.read())
_dump_issues("parse_model", parser)
analyser = Analyser()
# resolve imports
importer = Importer(strict_mode)
importer.resolveImports(model, base_dir)
_dump_issues("resolve_imports", importer)
# flatten the model and analyse it
flatModel = importer.flattenModel(model)
analyser.analyseModel(flatModel)
_dump_issues("analyse_model_flattend", analyser)
# write the flattened model to a cellml file
filename_flat = 'BG_initTest_flat.cellml'
printer = Printer()
serialised_model = printer.printModel(flatModel)
write_file = open(filename_flat, "w")
write_file.write(serialised_model)
write_file.close()
# read the flat model
cellml_file = open(filename_flat)
parser = Parser(strict_mode)
model_flat = parser.parseModel(cellml_file.read())
_dump_issues("parse_model", parser)
# analyse the flat model
analyser = Analyser()
analyser.analyseModel(model_flat)
_dump_issues("analyse_model_flat", analyser)
agarny commented 1 year ago

Thanks @WeiweiAi, I was able to reproduce the problem. However, while fixing it, I noticed that your variable of integration is initialised, which is not allowed by the analyser. Anyway, this is now all fixed as can be seen in PR #1147.