From 0f961d676cbda261c32360463cc2245e957ff600 Mon Sep 17 00:00:00 2001
From: Polina Lakrisenko
Date: Mon, 4 Mar 2024 14:14:34 +0100
Subject: [PATCH 1/3] Fix missing import in `amici/petab/petab_import.py`
(#2342)
fixes
```
Traceback (most recent call last):
File "//./mnt/src/optimize.py", line 557, in
model, model_petab_problem = _model_import(
File "/mnt/src/util.py", line 44, in _model_import
model = amici.petab_import.import_petab_problem(
File "/usr/local/lib/python3.10/dist-packages/amici/petab/petab_import.py", line 79, in import_petab_problem
warn(
NameError: name 'warn' is not defined
```
---
python/sdist/amici/petab/petab_import.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/python/sdist/amici/petab/petab_import.py b/python/sdist/amici/petab/petab_import.py
index 902bf837ef..cb896b39e3 100644
--- a/python/sdist/amici/petab/petab_import.py
+++ b/python/sdist/amici/petab/petab_import.py
@@ -10,6 +10,7 @@
import shutil
from pathlib import Path
from typing import Union
+from warnings import warn
import amici
import petab
From 1ab1d555feb1162b9e5be9876ecd14bede374019 Mon Sep 17 00:00:00 2001
From: Daniel Weindl
Date: Mon, 4 Mar 2024 15:22:08 +0100
Subject: [PATCH 2/3] Fix ReturnDataView AttributeError: messages (#2341)
* Make log messages from ReturnData available through ReturnDataView.
* Add `LogItem.__repr__`
Closes #2331.
---
python/sdist/amici/numpy.py | 9 +++++++--
python/tests/test_sbml_import.py | 2 +-
swig/amici.i | 8 ++++++++
3 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/python/sdist/amici/numpy.py b/python/sdist/amici/numpy.py
index 6e2966ba4b..f75d927b7b 100644
--- a/python/sdist/amici/numpy.py
+++ b/python/sdist/amici/numpy.py
@@ -9,7 +9,7 @@
import itertools
from typing import Literal, Union
from collections.abc import Iterator
-
+from numbers import Number
import amici
import numpy as np
import sympy as sp
@@ -238,6 +238,7 @@ class ReturnDataView(SwigPtrView):
"numnonlinsolvconvfailsB",
"cpu_timeB",
"cpu_time_total",
+ "messages",
]
def __init__(self, rdata: Union[ReturnDataPtr, ReturnData]):
@@ -440,7 +441,11 @@ def _field_as_numpy(
attr = getattr(data, field)
if field_dim := field_dimensions.get(field, None):
return None if len(attr) == 0 else np.array(attr).reshape(field_dim)
- return float(attr)
+
+ if isinstance(attr, Number):
+ return float(attr)
+
+ return attr
def _entity_type_from_id(
diff --git a/python/tests/test_sbml_import.py b/python/tests/test_sbml_import.py
index 74a51d020a..ecf21f1f95 100644
--- a/python/tests/test_sbml_import.py
+++ b/python/tests/test_sbml_import.py
@@ -368,7 +368,7 @@ def test_solver_reuse(model_steadystate_module):
assert rdata1.status == amici.AMICI_SUCCESS
for attr in rdata1:
- if "time" in attr:
+ if "time" in attr or attr == "messages":
continue
val1 = getattr(rdata1, attr)
diff --git a/swig/amici.i b/swig/amici.i
index 3518b296fe..1ef076fe33 100644
--- a/swig/amici.i
+++ b/swig/amici.i
@@ -235,6 +235,14 @@ def __repr__(self):
%}
};
+%extend amici::LogItem {
+%pythoncode %{
+def __repr__(self):
+ return (f"{self.__class__.__name__}(severity={self.severity}, "
+ f"identifier={self.identifier!r}, message={self.message!r})")
+%}
+};
+
// Convert integer values to enum class
// defeats the purpose of enum class, but didn't find a better way to allow for
From e8852be21a25b9fa79fc2fa2bbd44a4c83edabb6 Mon Sep 17 00:00:00 2001
From: Daniel Weindl
Date: Mon, 4 Mar 2024 15:23:00 +0100
Subject: [PATCH 3/3] Fix swig/std_unique_ptr.i (#2343)
Fixes some `used without template arguments` errors when running swig with `-builtin` or `-keyword`.
---
swig/std_unique_ptr.i | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/swig/std_unique_ptr.i b/swig/std_unique_ptr.i
index c44513bcee..f73babfd9e 100644
--- a/swig/std_unique_ptr.i
+++ b/swig/std_unique_ptr.i
@@ -17,7 +17,7 @@ namespace std {
pointer operator-> () const;
pointer release ();
- void reset (pointer __p=pointer());
+ void reset (pointer __p=std::unique_ptr::pointer());
void swap (unique_ptr &__u);
pointer get () const;
operator bool () const;