Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

amici.import_utils.SBMLexception #2651

Open
PHvanLent opened this issue Feb 28, 2025 · 1 comment
Open

amici.import_utils.SBMLexception #2651

PHvanLent opened this issue Feb 28, 2025 · 1 comment
Assignees
Labels
bug SBML SBML import related

Comments

@PHvanLent
Copy link

PHvanLent commented Feb 28, 2025

Hi AMICI developers,

I am trying to compile a model using amici.assignmentRules2observables with a spline interpolation on some observable.

import amici
import pandas as pd
import libsbml
import numpy as np

domain=np.array([0.0, 5.0, 10.0, 15.0, 20.0, 30.0, 60.0, 90.0, 150.0, 180.0, 220.0, 250.0, 300.0, 350.0, 400.0])
drange=np.array([0.09436668 0.20660086 0.32938346 0.39271404 0.46033645 0.43051466
 0.38017434 0.31141232 0.22630089 0.18609768 0.14751637 0.12343035
 0.10829366 0.09658453 0.09436668])

spline = amici.splines.CubicHermiteSpline(
    sbml_id="ECglucose",
    evaluate_at=amici.sbml_utils.amici_time_symbol,  # the spline function is evaluated at the current time point
    nodes=domain,
    values_at_nodes=drange,)

spline.add_to_sbml_model(sbml_model)

libsbml.writeSBMLToFile(sbml_model.getSBMLDocument(),
                        f"models/manual_implementations/sbml_export/{model_name_spline}.xml")`

When I try to load this and run

sbml_file = f"{sbml_file_dir}/{model_name_spline}.xml"
# Create an SbmlImporter instance for our SBML model
sbml_importer = amici.SbmlImporter(sbml_file)

# Retrieve model output names and formulae from AssignmentRules and remove the respective rules
observables = amici.assignmentRules2observables(
    sbml_importer.sbml,  # the libsbml model object
    filter_function=lambda variable: variable.getId() == "ECglucose")

I receive the error

amici.import_utils.SBMLException: AMICI can not parse piecewise/event trigger functions with argument lt(time, 5).

Do you have an idea what I can do to solve this?

Best,

Paul

@dweindl dweindl self-assigned this Mar 4, 2025
dweindl added a commit to dweindl/AMICI that referenced this issue Mar 4, 2025
dweindl added a commit to dweindl/AMICI that referenced this issue Mar 4, 2025
@dweindl
Copy link
Member

dweindl commented Mar 4, 2025

Hi @PHvanLent, after modifying the example a bit, I was able to reproduce the issue. It is fixed in #2652. Thanks for reporting.

Reproducer

import libsbml
import numpy as np
import amici.sbml_utils
import amici.splines

sbml_doc = libsbml.SBMLDocument()
sbml_model = sbml_doc.createModel()
p = sbml_model.createParameter()
p.setId("ECglucose")
p.setConstant(False)


domain=np.array([0.0, 5.0, 10.0, 15.0, 20.0, 30.0, 60.0, 90.0, 150.0, 180.0, 220.0, 250.0, 300.0, 350.0, 400.0])
drange=np.array([0.09436668, 0.20660086, 0.32938346, 0.39271404, 0.46033645, 0.43051466,
 0.38017434, 0.31141232, 0.22630089, 0.18609768, 0.14751637, 0.12343035,
 0.10829366, 0.09658453, 0.09436668])

spline = amici.splines.CubicHermiteSpline(
    sbml_id="ECglucose",
    evaluate_at=amici.sbml_utils.amici_time_symbol,
    nodes=domain,
    values_at_nodes=drange,)

spline.add_to_sbml_model(sbml_model)

sbml_importer = amici.SbmlImporter(sbml_model)

observables = amici.assignmentRules2observables(
    sbml_importer.sbml,  # the libsbml model object
    filter_function=lambda variable: variable.getId() == "ECglucose")

sbml_importer.sbml2amici("gh2651", observables=observables)

EDIT: After #2652 is merged, you can install the latest unreleased version with pip3 install -e git+https://github.com/AMICI-dev/amici.git@develop#egg=amici\&subdirectory=python/sdist.

@dweindl dweindl added bug SBML SBML import related labels Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug SBML SBML import related
Projects
None yet
Development

No branches or pull requests

2 participants