Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test_sbml_semantic_test_suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
pull_request:
paths:
- .github/workflows/test_sbml_semantic_test_suite.yml
- python/sdist/amici/de_export.py
- python/sdist/amici/exporters/sundials/de_export.py
- python/sdist/amici/de_model_components.py
- python/sdist/amici/de_model.py
- python/sdist/amici/sbml_import.py
Expand Down
38 changes: 21 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ else()
set(VENDORED_SUNDIALS_INSTALL_DIR ${VENDORED_SUNDIALS_BUILD_DIR})
endif()
set(SUNDIALS_ROOT "${VENDORED_SUNDIALS_INSTALL_DIR}/${CMAKE_INSTALL_LIBDIR}")
find_package(SUNDIALS 7.1.1 REQUIRED CONFIG PATHS "${SUNDIALS_ROOT}/cmake/sundials/" )
find_package(SUNDIALS 7.1.1 REQUIRED CONFIG PATHS
"${SUNDIALS_ROOT}/cmake/sundials/")
message(STATUS "Found SUNDIALS: ${SUNDIALS_DIR}")

set(GSL_LITE_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ThirdParty/gsl")
Expand Down Expand Up @@ -306,22 +307,25 @@ if(AMICI_PYTHON_BUILD_EXT_ONLY)
"gsl_CONFIG_NARROW_THROWS_ON_TRUNCATION=1")
endif()

# Create targets to make the sources show up in IDEs for convenience
# For template files
add_custom_target(
fileTemplates
SOURCES src/CMakeLists.template.cmake
src/main.template.cpp
src/model_header.template.h
src/model.template.cpp
src/wrapfunctions.template.h
src/wrapfunctions.template.cpp
swig/CMakeLists_model.cmake
swig/modelname.template.i
COMMENT "Dummy target for SWIG files")
set_target_properties(
fileTemplates PROPERTIES INCLUDE_DIRECTORIES
"${CMAKE_CURRENT_SOURCE_DIR}/include/")
if(NOT AMICI_PYTHON_BUILD_EXT_ONLY)
# Create targets to make the sources show up in IDEs for convenience For
# template files
set(template_dir "python/sdist/amici/exporters/sundials/templates")
add_custom_target(
fileTemplates
SOURCES ${template_dir}/CMakeLists.template.cmake
${template_dir}//main.template.cpp
${template_dir}//model_header.template.h
${template_dir}//model.template.cpp
${template_dir}//wrapfunctions.template.h
${template_dir}//wrapfunctions.template.cpp
${template_dir}//CMakeLists_model.cmake
${template_dir}//modelname.template.i
COMMENT "Dummy target for SWIG files")
set_target_properties(
fileTemplates PROPERTIES INCLUDE_DIRECTORIES
"${CMAKE_CURRENT_SOURCE_DIR}/include/")
endif()

if(NOT AMICI_PYTHON_BUILD_EXT_ONLY)
include(clang-tools)
Expand Down
2 changes: 1 addition & 1 deletion doc/python_modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ AMICI Python API
amici.petab.simulator
amici.import_utils
amici.jax
amici.de_export
amici.exporters.sundials.de_export
amici.de_model
amici.de_model_components
amici.plotting
Expand Down
1 change: 1 addition & 0 deletions python/sdist/MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ recursive-include amici/cmake *
recursive-include amici/include/amici *.h
recursive-include amici/src *
recursive-include amici/swig *
recursive-include amici/exporters/sundials/templates *
include amici/*
include version.txt
include LICENSE.md
Expand Down
1 change: 0 additions & 1 deletion python/sdist/amici/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ def get_model_dir(model_id: str | None = None, jax: bool = False) -> Path:
# These modules don't require the swig interface
from typing import Protocol, runtime_checkable

from .de_export import DEExporter # noqa: F401
from .import_utils import MeasurementChannel # noqa: F401
from .sbml_import import ( # noqa: F401
SbmlImporter,
Expand Down
25 changes: 10 additions & 15 deletions python/sdist/amici/de_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@
import sympy as sp
from sympy import ImmutableDenseMatrix, MutableDenseMatrix

from ._codegen.cxx_functions import (
nobody_functions,
sensi_functions,
sparse_functions,
var_in_function_signature,
)
from .cxxcodeprinter import csc_matrix
from .de_model_components import (
AlgebraicEquation,
AlgebraicState,
Expand All @@ -45,6 +38,13 @@
SigmaZ,
State,
)
from .exporters.sundials.cxx_functions import (
nobody_functions,
sensi_functions,
sparse_functions,
var_in_function_signature,
)
from .exporters.sundials.cxxcodeprinter import csc_matrix
from .import_utils import (
ObservableTransformation,
SBMLException,
Expand Down Expand Up @@ -1135,18 +1135,14 @@ def _generate_symbol(self, name: str) -> None:
components = sorted(
components,
key=lambda x: int(
x.get_id().replace(
"observableParameter", ""
)
x.get_id().replace("observableParameter", "")
),
)
if name == "np":
components = sorted(
components,
key=lambda x: int(
x.get_id().replace(
"noiseParameter", ""
)
x.get_id().replace("noiseParameter", "")
),
)
self._syms[name] = sp.Matrix(
Expand Down Expand Up @@ -1213,8 +1209,7 @@ def _generate_symbol(self, name: str) -> None:
[
[
sp.Symbol(
f"s{tcl.get_id()}__"
f"{par.get_id()}",
f"s{tcl.get_id()}__{par.get_id()}",
real=True,
)
for par in self._parameters
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from sympy.utilities.iterables import numbered_symbols
from toposort import toposort

from .import_utils import symbol_with_assumptions
from ...import_utils import symbol_with_assumptions


class AmiciCxxCodePrinter(CXX11CodePrinter):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,23 @@

import sympy as sp

from . import (
from ... import (
__commit__,
__version__,
amiciModulePath,
amiciSrcPath,
amiciSwigPath,
get_model_dir,
splines,
)
from ._codegen.cxx_functions import (
from ...de_model import DEModel
from ...de_model_components import *
from ...logging import get_logger, log_execution_time, set_log_level
from ...sympy_utils import (
_custom_pow_eval_derivative,
_monkeypatched,
smart_is_zero_matrix,
)
from ..template import apply_template
from .compile import build_model_extension
from .cxx_functions import (
_FunctionInfo,
event_functions,
event_sensi_functions,
Expand All @@ -44,38 +51,25 @@
sparse_functions,
sparse_sensi_functions,
)
from ._codegen.model_class import (
get_function_extern_declaration,
get_model_override_implementation,
get_sunindex_extern_declaration,
get_sunindex_override_implementation,
)
from ._codegen.template import apply_template
from .compile import build_model_extension
from .cxxcodeprinter import (
AmiciCxxCodePrinter,
get_initializer_list,
get_switch_statement,
)
from .de_model import DEModel
from .de_model_components import *
from .logging import get_logger, log_execution_time, set_log_level
from .sympy_utils import (
_custom_pow_eval_derivative,
_monkeypatched,
smart_is_zero_matrix,
from .model_class import (
get_function_extern_declaration,
get_model_override_implementation,
get_sunindex_extern_declaration,
get_sunindex_override_implementation,
)

TEMPLATE_DIR = Path(__file__).parent / "templates"
# Template for model simulation main.cpp file
CXX_MAIN_TEMPLATE_FILE = os.path.join(amiciSrcPath, "main.template.cpp")
CXX_MAIN_TEMPLATE_FILE = TEMPLATE_DIR / "main.template.cpp"
# Template for model/swig/CMakeLists.txt
SWIG_CMAKE_TEMPLATE_FILE = os.path.join(
amiciSwigPath, "CMakeLists_model.cmake"
)
SWIG_CMAKE_TEMPLATE_FILE = TEMPLATE_DIR / "CMakeLists_model.cmake"
# Template for model/CMakeLists.txt
MODEL_CMAKE_TEMPLATE_FILE = os.path.join(
amiciSrcPath, "CMakeLists.template.cmake"
)
MODEL_CMAKE_TEMPLATE_FILE = TEMPLATE_DIR / "CMakeLists.template.cmake"

IDENTIFIER_PATTERN = re.compile(r"^[a-zA-Z_]\w*$")

Expand Down Expand Up @@ -950,7 +944,7 @@ def _write_wrapfunctions_cpp(self) -> None:
"""
template_data = {"MODELNAME": self.model_name}
apply_template(
os.path.join(amiciSrcPath, "wrapfunctions.template.cpp"),
TEMPLATE_DIR / "wrapfunctions.template.cpp",
os.path.join(self.model_path, "wrapfunctions.cpp"),
template_data,
)
Expand All @@ -961,7 +955,7 @@ def _write_wrapfunctions_header(self) -> None:
"""
template_data = {"MODELNAME": str(self.model_name)}
apply_template(
os.path.join(amiciSrcPath, "wrapfunctions.template.h"),
TEMPLATE_DIR / "wrapfunctions.template.h",
os.path.join(self.model_path, "wrapfunctions.h"),
template_data,
)
Expand Down Expand Up @@ -1184,13 +1178,13 @@ def event_initializer_list() -> str:
tpl_data = {k: str(v) for k, v in tpl_data.items()}

apply_template(
os.path.join(amiciSrcPath, "model_header.template.h"),
TEMPLATE_DIR / "model_header.template.h",
os.path.join(self.model_path, f"{self.model_name}.h"),
tpl_data,
)

apply_template(
os.path.join(amiciSrcPath, "model.template.cpp"),
TEMPLATE_DIR / "model.template.cpp",
os.path.join(self.model_path, f"{self.model_name}.cpp"),
tpl_data,
)
Expand Down Expand Up @@ -1256,7 +1250,7 @@ def _write_swig_files(self) -> None:
Path(self.model_swig_path).mkdir(exist_ok=True)
template_data = {"MODELNAME": self.model_name}
apply_template(
Path(amiciSwigPath, "modelname.template.i"),
TEMPLATE_DIR / "modelname.template.i",
Path(self.model_swig_path, self.model_name + ".i"),
template_data,
)
Expand All @@ -1276,20 +1270,20 @@ def _write_module_setup(self) -> None:
"PACKAGE_VERSION": "0.1.0",
}
apply_template(
Path(amiciModulePath, "setup.template.py"),
TEMPLATE_DIR / "setup.template.py",
Path(self.model_path, "setup.py"),
template_data,
)
apply_template(
Path(amiciModulePath, "MANIFEST.template.in"),
TEMPLATE_DIR / "MANIFEST.template.in",
Path(self.model_path, "MANIFEST.in"),
{},
)
# write __init__.py for the model module
Path(self.model_path, self.model_name).mkdir(exist_ok=True)

apply_template(
Path(amiciModulePath, "__init__.template.py"),
TEMPLATE_DIR / "__init__.template.py",
Path(self.model_path, self.model_name, "__init__.py"),
template_data,
)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
import sys
from pathlib import Path

from cmake_build_extension import CMakeExtension
from setuptools import find_namespace_packages, setup

from amici import _get_amici_path
from amici.custom_commands import AmiciBuildCMakeExtension
from cmake_build_extension import CMakeExtension
from setuptools import find_namespace_packages, setup


def get_extension() -> CMakeExtension:
Expand Down
3 changes: 2 additions & 1 deletion python/sdist/amici/jax/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import jax.numpy as jnp

from amici import amiciModulePath
from amici._codegen.template import apply_template

from ..exporters.template import apply_template


class Flatten(eqx.Module):
Expand Down
4 changes: 2 additions & 2 deletions python/sdist/amici/jax/ode_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
from amici import (
amiciModulePath,
)
from amici._codegen.template import apply_template
from amici.de_export import is_valid_identifier
from amici.de_model import DEModel
from amici.exporters.sundials.de_export import is_valid_identifier
from amici.exporters.template import apply_template
from amici.jax.jaxcodeprinter import AmiciJaxCodePrinter, _jnp_array_str
from amici.jax.model import JAXModel
from amici.jax.nn import generate_equinox
Expand Down
14 changes: 10 additions & 4 deletions python/sdist/amici/pysb_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@

import amici

from .de_export import (
from .de_model import DEModel
from .de_model_components import (
Constant,
DEExporter,
DifferentialState,
Event,
Expression,
LogLikelihoodY,
NoiseParameter,
Observable,
ObservableParameter,
Parameter,
SigmaY,
)
from .de_model import DEModel
from .de_model_components import Event, NoiseParameter, ObservableParameter
from .import_utils import (
MeasurementChannel,
_default_simplify,
Expand Down Expand Up @@ -265,6 +266,11 @@ def pysb2amici(
pysb_model_has_obs_and_noise=pysb_model_has_obs_and_noise,
events=_events,
)

from .exporters.sundials.de_export import (
DEExporter,
)

exporter = DEExporter(
ode_model,
outdir=output_dir,
Expand Down
7 changes: 4 additions & 3 deletions python/sdist/amici/sbml_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@

from . import get_model_dir, has_clibs
from .constants import SymbolId
from .de_export import (
DEExporter,
)
from .de_model import DEModel
from .de_model_components import Expression, symbol_to_type
from .import_utils import (
Expand Down Expand Up @@ -401,6 +398,10 @@ def sbml2amici(

output_dir = output_dir or get_model_dir(model_name)

from .exporters.sundials.de_export import (
DEExporter,
)

exporter = DEExporter(
ode_model,
model_name=model_name,
Expand Down
2 changes: 1 addition & 1 deletion python/tests/test_cxxcodeprinter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
import sympy as sp
from amici.cxxcodeprinter import AmiciCxxCodePrinter
from amici.exporters.sundials.cxxcodeprinter import AmiciCxxCodePrinter
from amici.testing import skip_on_valgrind
from sympy.codegen.rewriting import optims_c99

Expand Down
Loading
Loading