Skip to content

cellml

Reading, writing and validating CellML models with libcellml.

The functions wrap the libcellml Parser, Printer, Validator and Analyser. Issues are returned instead of printed, so a caller decides what to do with them; errors filters the issues of level ERROR.

CellMLValidationError

Bases: ValueError

A CellML model has issues of level ERROR.

format_issue

format_issue(issue)

Format an issue as [LEVEL] description.

Parameters:

Name Type Description Default
issue Issue

issue of a libcellml logger.

required

Returns:

Type Description
str

The one line description of the issue.

format_issues

format_issues(issues)

Format issues as one line per issue.

Parameters:

Name Type Description Default
issues list[Issue]

issues of a libcellml logger.

required

Returns:

Type Description
str

The formatted issues joined by newlines.

errors

errors(issues)

The issues of level ERROR.

Parameters:

Name Type Description Default
issues list[Issue]

issues of a libcellml logger.

required

Returns:

Type Description
list[Issue]

The subset of issues with level ERROR.

model_to_string

model_to_string(model)

Serialize a model to CellML 2.0.

Parameters:

Name Type Description Default
model Model

CellML model.

required

Returns:

Type Description
str

The CellML xml.

write_model

write_model(model, cellml_path)

Write a model as CellML file.

Parameters:

Name Type Description Default
model Model

CellML model.

required
cellml_path Path

path of the file, overwritten if it exists.

required

read_model

read_model(cellml_path)

Read a CellML file.

Parameters:

Name Type Description Default
cellml_path Path

path of the CellML file.

required

Returns:

Type Description
Model

The parsed model.

Raises:

Type Description
CellMLValidationError

if the parser reports errors.

validate_model

validate_model(model)

Validate and analyse a model.

The validator checks the model against the CellML specification, the analyser checks that the equations define every variable exactly once.

Parameters:

Name Type Description Default
model Model

CellML model.

required

Returns:

Type Description
list[Issue]

The issues of the validator followed by the issues of the analyser,

list[Issue]

empty for a valid model.