cellml/libcellml

Segmentation Fault when analysing model with an error.

Closed this issue · 13 comments

I have a model with an error. When I try to analyse this model it throws a segmentation fault instead of telling me the error

Here is the model

lung_ROM.zip

The code I use to analyse is:

model = cellml.parse_model(os.path.join(self.project_dir + 'lung_ROM.cellml'), False)
# resolve imports, in non-strict mode
importer = cellml.resolve_imports(model, self.project_dir False)
# need a flattened model for analysing
flat_model = cellml.flatten_model(model, importer)
model_string = cellml.print_model(flat_model)

# this if we want to create the flat model, for debugging
with open(os.path.join(self.output_dir, self.filename_prefix + '_flat.cellml'), 'w') as f:
    f.write(model_string)

# analyse the model
a = Analyser()

a.analyseModel(flat_model)
analysed_model = a.model() # here it segfaults.

The error when I open the model in OpenCOR is: "Error: a problem occurred during the generation of the model code (CellML Variable u_out in component pp_T_RICRI_type has in interfaces, but is not connected (directly or indirectly) to any variable with no in interfaces;)."

I'm not worried about the error in the CellML model, I am fixing that. The issue is to do with libCellML segfaulting when analysing a model with an error instead of specifying the error.

This is in the new libcellml0.6 with Python3.12

The seg fault still occurs after I have fixed the CellML model.

Fixed model:
file:///home/farg967/Documents/physiology_models/pulmonary_CVS_Alfred/patient_4/pre/generated_models/lung_ROM/lung_ROM_fixed.zip

Will look into it next week. In the meantime, @FinbarArgus, could you upload your fixed version?

Has anyone tried this with the previous version of libCellML? Does that version segfault with this model?

The previous version worked fine.

On second thought, the previous version worked fine with a very similar model, but not exactly the same. I will check with the same model on Monday.

I confirm that with the previous version and the same CellML model there is no seg fault.

agarny commented

Thanks @FinbarArgus. Will look into it once I am done with my current task (testing of generated code when tracking/untracking some variables).

agarny commented

Ok, using @hsorby, I can confirm @FinbarArgus's issue. That's indeed some code that got introduced in 0.6.x... and our tests clearly didn't catch this particular (?) case. Am on it.

agarny commented

Should be fixed either today or tomorrow and from there, @hsorby should be able to release 0.6.3.

agarny commented

I have fixed the issue and tested the fix against @FinbarArgus's CellML file and it's all good. It was an oversight on my part. My bad!

Will provide a PR tomorrow morning.

agarny commented

FWIW, the fix is very simple. I am just trying to come up with an easy to reproduce use case and this is not proving easy...

agarny commented

Ok, got some atomic tests for this issue (and some related ones!).