atropy 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- atropy-0.0.1/.gitignore +18 -0
- atropy-0.0.1/.gitmodules +3 -0
- atropy-0.0.1/.pre-commit-config.yaml +29 -0
- atropy-0.0.1/LICENSE.txt +17 -0
- atropy-0.0.1/PKG-INFO +38 -0
- atropy-0.0.1/README.md +186 -0
- atropy-0.0.1/atropy/core/.clang-format +8 -0
- atropy-0.0.1/atropy/core/CMakeLists.txt +187 -0
- atropy-0.0.1/atropy/core/atropy_core/__init__.py +0 -0
- atropy-0.0.1/atropy/core/atropy_core/boolean_helper.py +133 -0
- atropy-0.0.1/atropy/core/atropy_core/examples/__init__.py +0 -0
- atropy-0.0.1/atropy/core/atropy_core/examples/boolean/__init__.py +0 -0
- atropy-0.0.1/atropy/core/atropy_core/examples/boolean/set_apoptosis.py +158 -0
- atropy-0.0.1/atropy/core/atropy_core/examples/boolean/set_pancreatic_cancer.py +158 -0
- atropy-0.0.1/atropy/core/atropy_core/examples/kinetic/__init__.py +0 -0
- atropy-0.0.1/atropy/core/atropy_core/examples/kinetic/set_bax.py +123 -0
- atropy-0.0.1/atropy/core/atropy_core/examples/kinetic/set_cascade.py +112 -0
- atropy-0.0.1/atropy/core/atropy_core/examples/kinetic/set_lambda_phage.py +175 -0
- atropy-0.0.1/atropy/core/atropy_core/examples/kinetic/set_toggle_switch.py +84 -0
- atropy-0.0.1/atropy/core/atropy_core/examples/models/__init__.py +0 -0
- atropy-0.0.1/atropy/core/atropy_core/examples/models/boolean/apoptosis.hpp +489 -0
- atropy-0.0.1/atropy/core/atropy_core/examples/models/boolean/pancreatic_cancer.hpp +195 -0
- atropy-0.0.1/atropy/core/atropy_core/examples/models/kinetic/__init__.py +0 -0
- atropy-0.0.1/atropy/core/atropy_core/examples/models/kinetic/bax.py +114 -0
- atropy-0.0.1/atropy/core/atropy_core/examples/models/kinetic/cascade.py +31 -0
- atropy-0.0.1/atropy/core/atropy_core/examples/models/kinetic/lambda_phage.py +59 -0
- atropy-0.0.1/atropy/core/atropy_core/examples/models/kinetic/toggle_switch.py +16 -0
- atropy-0.0.1/atropy/core/atropy_core/grid.py +86 -0
- atropy-0.0.1/atropy/core/atropy_core/id.py +46 -0
- atropy-0.0.1/atropy/core/atropy_core/index_functions.py +61 -0
- atropy-0.0.1/atropy/core/atropy_core/initial_condition.py +65 -0
- atropy-0.0.1/atropy/core/atropy_core/output_helper.py +220 -0
- atropy-0.0.1/atropy/core/atropy_core/reaction.py +28 -0
- atropy-0.0.1/atropy/core/atropy_core/tests/test_grid_class.py +53 -0
- atropy-0.0.1/atropy/core/atropy_core/tests/test_tree_class.py +231 -0
- atropy-0.0.1/atropy/core/atropy_core/tree.py +615 -0
- atropy-0.0.1/atropy/core/cmake-modules/FindNetCDF.cmake +119 -0
- atropy-0.0.1/atropy/core/include/bug_integrator.hpp +28 -0
- atropy-0.0.1/atropy/core/include/coeff_class.hpp +27 -0
- atropy-0.0.1/atropy/core/include/grid_class.hpp +42 -0
- atropy-0.0.1/atropy/core/include/index_functions.hpp +42 -0
- atropy-0.0.1/atropy/core/include/integration_methods.hpp +154 -0
- atropy-0.0.1/atropy/core/include/integrators.hpp +23 -0
- atropy-0.0.1/atropy/core/include/matrix.hpp +63 -0
- atropy-0.0.1/atropy/core/include/matrix_free.hpp +90 -0
- atropy-0.0.1/atropy/core/include/print_functions.hpp +49 -0
- atropy-0.0.1/atropy/core/include/ps_integrator.hpp +22 -0
- atropy-0.0.1/atropy/core/include/tree_class.hpp +172 -0
- atropy-0.0.1/atropy/core/pyproject.toml +15 -0
- atropy-0.0.1/atropy/core/src/bug_integrator.cpp +146 -0
- atropy-0.0.1/atropy/core/src/grid_class.cpp +28 -0
- atropy-0.0.1/atropy/core/src/main.cpp +177 -0
- atropy-0.0.1/atropy/core/src/matrix.cpp +13 -0
- atropy-0.0.1/atropy/core/src/print_functions.cpp +74 -0
- atropy-0.0.1/atropy/core/src/ps_integrator.cpp +143 -0
- atropy-0.0.1/atropy/core/src/tree_class.cpp +766 -0
- atropy-0.0.1/atropy/core/tests/CMakeLists.txt +96 -0
- atropy-0.0.1/atropy/core/tests/test_index_functions.cpp +53 -0
- atropy-0.0.1/atropy/core/tests/test_matrix_functions.cpp +108 -0
- atropy-0.0.1/atropy/core/tests/test_orthogonalization.cpp +260 -0
- atropy-0.0.1/atropy/core/tests/test_tree_h1.cpp +395 -0
- atropy-0.0.1/atropy/core/tests/test_tree_h2.cpp +692 -0
- atropy-0.0.1/atropy/src/__init__.py +0 -0
- atropy-0.0.1/atropy/src/examples/__init__.py +0 -0
- atropy-0.0.1/atropy/src/examples/compare_plots.py +78 -0
- atropy-0.0.1/atropy/src/examples/run_bax.py +140 -0
- atropy-0.0.1/atropy/src/examples/run_lambda_phage.py +176 -0
- atropy-0.0.1/atropy/src/examples/test_example.py +54 -0
- atropy-0.0.1/atropy/src/examples/usage.ipynb +352 -0
- atropy-0.0.1/atropy/src/generator.py +184 -0
- atropy-0.0.1/atropy/src/tests/__init__.py +0 -0
- atropy-0.0.1/atropy/src/tests/test_generator_class.py +68 -0
- atropy-0.0.1/pip-requirements.txt +10 -0
- atropy-0.0.1/pyproject.toml +61 -0
atropy-0.0.1/.gitignore
ADDED
atropy-0.0.1/.gitmodules
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# See https://pre-commit.com for more information
|
|
2
|
+
# See https://pre-commit.com/hooks.html for more hooks
|
|
3
|
+
repos:
|
|
4
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
5
|
+
rev: v4.6.0
|
|
6
|
+
hooks:
|
|
7
|
+
- id: check-executables-have-shebangs
|
|
8
|
+
- id: check-added-large-files
|
|
9
|
+
args: [--maxkb, "5000"]
|
|
10
|
+
- id: check-yaml
|
|
11
|
+
- id: check-toml
|
|
12
|
+
- id: check-merge-conflict
|
|
13
|
+
- id: end-of-file-fixer
|
|
14
|
+
- id: trailing-whitespace
|
|
15
|
+
# exclude markdown files
|
|
16
|
+
exclude: '.*\.md'
|
|
17
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
18
|
+
rev: v0.6.4
|
|
19
|
+
hooks:
|
|
20
|
+
# run the linter
|
|
21
|
+
- id: ruff
|
|
22
|
+
args: [ --fix ]
|
|
23
|
+
# run the formatter
|
|
24
|
+
- id: ruff-format
|
|
25
|
+
- repo: https://github.com/pre-commit/mirrors-clang-format
|
|
26
|
+
rev: v18.1.8
|
|
27
|
+
hooks:
|
|
28
|
+
- id: clang-format
|
|
29
|
+
types_or: [c++, c, cuda]
|
atropy-0.0.1/LICENSE.txt
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
Copyright (c) 2024 Julian Mangott, Lukas Einkemmer, Martina Prugger, Stefan Brunner
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
The above copyright notice and this permission notice shall be included in all
|
|
10
|
+
copies or substantial portions of the Software.
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
12
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
13
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
14
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
15
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
16
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
17
|
+
SOFTWARE.
|
atropy-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: atropy
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Wrapper for the atropy_core C++ library
|
|
5
|
+
Author-Email: Julian Mangott <julian.mangott@uibk.ac.at>, Lukas Einkemmer <lukas.einkemmer@uibk.ac.at>, Martina Prugger <martina.prugger@ipp.mpg.de>, Stefan Brunner <stefan.brunner@student.uibk.ac.at>
|
|
6
|
+
License: MIT License
|
|
7
|
+
Copyright (c) 2024 Julian Mangott, Lukas Einkemmer, Martina Prugger, Stefan Brunner
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
23
|
+
|
|
24
|
+
Project-URL: Homepage, https://stefanbrunner2709.github.io/kinetic-cme/
|
|
25
|
+
Project-URL: GitLab, https://git.uibk.ac.at/c7021158/kinetic-cme
|
|
26
|
+
Requires-Python: >=3.10
|
|
27
|
+
Requires-Dist: atropy_core
|
|
28
|
+
Requires-Dist: netCDF4
|
|
29
|
+
Requires-Dist: networkx
|
|
30
|
+
Requires-Dist: numba==0.60.0
|
|
31
|
+
Requires-Dist: numpy==1.26.4
|
|
32
|
+
Requires-Dist: matplotlib
|
|
33
|
+
Requires-Dist: regex
|
|
34
|
+
Requires-Dist: scipy
|
|
35
|
+
Requires-Dist: xarray==2024.9.0
|
|
36
|
+
Requires-Dist: xarray-datatree
|
|
37
|
+
Requires-Dist: sympy
|
|
38
|
+
|
atropy-0.0.1/README.md
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "README"
|
|
3
|
+
author: [Julian Mangott]
|
|
4
|
+
date: "2025-02-02"
|
|
5
|
+
keywords: [Markdown, README]
|
|
6
|
+
disable-header-and-footer: true
|
|
7
|
+
pagestyle: empty
|
|
8
|
+
header-includes:
|
|
9
|
+
- \usepackage{bm}
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# DLR approximation for the kinetic CME
|
|
13
|
+
|
|
14
|
+
- [DLR approximation for the kinetic CME](#dlr-approximation-for-the-kinetic-cme)
|
|
15
|
+
- [Objective](#objective)
|
|
16
|
+
- [Requirements](#requirements)
|
|
17
|
+
- [Installation](#installation)
|
|
18
|
+
- [Intel MKL](#intel-mkl)
|
|
19
|
+
- [OpenMP](#openmp)
|
|
20
|
+
- [Python environment](#python-environment)
|
|
21
|
+
- [Run the program](#run-the-program)
|
|
22
|
+
- [Input](#input)
|
|
23
|
+
- [Preparing input data](#preparing-input-data)
|
|
24
|
+
- [Output](#output)
|
|
25
|
+
- [Example problems](#example-problems)
|
|
26
|
+
- [References](#references)
|
|
27
|
+
|
|
28
|
+
## Objective
|
|
29
|
+
`atropy` solves the chemical master equation (CME),
|
|
30
|
+
$$\partial_t{P}(t,\mathbf{x}) = \sum_{\mu = 0}^{M-1}\left(\alpha_\mu(\mathbf{x}-\bm{\nu}_\mu)P(t,\mathbf{x}-\bm{\nu}_\mu) - \alpha_\mu(\mathbf{x})P(t,\mathbf{x})\right)$$
|
|
31
|
+
|
|
32
|
+
according to the algorithm proposed in https://arxiv.org/abs/2407.11792, which is based on the projector-splitting integrator for Tree Tensor networks \[1\].
|
|
33
|
+
|
|
34
|
+
$P(t,\mathbf{x})\,\mathrm{d}t$ is the probability of finding a population number of $\mathbf{x} = (x_0, \dots, x_{N-1})$ molecules of species $S_0, \dots, S_{N-1}$ in the time interval $[t,\,t + \mathrm{d}t]$.
|
|
35
|
+
The CME describes the time evolution of this probability distribution $P(t,\mathbf{x})$ in a chemical reaction network with $N$ different species $S_0, \dots, S_{N-1}$, which can react via $M$ reaction channels $R_0, \dots, R_{M-1}$. For a given reaction $\mu$, the stoichiometric vector $\bm{\nu}_\mu$ denotes the population change by that reaction and the propensity functions $\alpha_\mu(\mathbf{x})$ and $\alpha_\mu(\mathbf{x}-\bm{\nu}_\mu)$ are proportional to the transition probabilities $T(\mathbf{x}+\bm{\nu}_\mu|\mathbf{x})$ and $T(\mathbf{x}|\mathbf{x}-\bm{\nu}_\mu)$.
|
|
36
|
+
|
|
37
|
+
`atropy` makes use of the low-rank framework `Ensign` \[2\].
|
|
38
|
+
|
|
39
|
+
## Requirements
|
|
40
|
+
- CMake (3.22.1 or later)
|
|
41
|
+
- C++20 compatible C++ compiler
|
|
42
|
+
- Eigen 3.4 (if the implicit Euler or Crank-Nicolson integrators are used)
|
|
43
|
+
- Fortran compiler (if OpenBLAS is used)
|
|
44
|
+
- HDF5 (1.10.x)
|
|
45
|
+
- netCDF4
|
|
46
|
+
- Python (>3.8)
|
|
47
|
+
- OpenMP (optional)
|
|
48
|
+
- Intel MKL (optional)
|
|
49
|
+
|
|
50
|
+
Check via `nc-config --has-hdf5`, whether HDF5 was used in the netCDF4 build.
|
|
51
|
+
|
|
52
|
+
## Installation
|
|
53
|
+
Build the program in the project root by executing
|
|
54
|
+
```shell
|
|
55
|
+
cmake -B <build> -DCMAKE_BUILD_TYPE=Release
|
|
56
|
+
cmake --build <build>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
The generated executable `atropy` can be found in `bin`.
|
|
60
|
+
|
|
61
|
+
To enable compiler options for debugging, use `-DCMAKE_BUILD_TYPE=Debug` instead.
|
|
62
|
+
Unit tests for C++ files are provided in the `tests` folder. They can be run with
|
|
63
|
+
```shell
|
|
64
|
+
ctest --test-dir <build>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
MacOS: pybind11 might not find the `Python.h` header during the CMake build process.
|
|
68
|
+
In that case, set `export CPLUS_INCLUDE_PATH=<path/to/python/include>` accordingly.
|
|
69
|
+
|
|
70
|
+
### Intel MKL
|
|
71
|
+
If you prefer to use Intel MKL as the BLAS and LAPACK backend instead of OpenBLAS set
|
|
72
|
+
```shell
|
|
73
|
+
export MKLROOT=/path/to/intel/mkl
|
|
74
|
+
cmake -B <build> -DCMAKE_BUILD_TYPE=Release -DMKL_ENABLED=ON
|
|
75
|
+
cmake --build <build>
|
|
76
|
+
```
|
|
77
|
+
and make sure to add the MKL libraries to your `LD_LIBRARY_PATH`, i.e.
|
|
78
|
+
```shell
|
|
79
|
+
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/intel/mkl/lib/intel64_lin/
|
|
80
|
+
```
|
|
81
|
+
before running the executable.
|
|
82
|
+
|
|
83
|
+
### OpenMP
|
|
84
|
+
OpenMP can be activated via
|
|
85
|
+
```shell
|
|
86
|
+
cmake -B <build> -DCMAKE_BUILD_TYPE=Release -DOPENMP=ON
|
|
87
|
+
```
|
|
88
|
+
Make sure that the `OMP_NUM_THREADS` environment variable is in accordance with your hardware specification and run the unit tests via
|
|
89
|
+
```shell
|
|
90
|
+
ctest --test-dir <build>
|
|
91
|
+
```
|
|
92
|
+
to ensure that OpenMP and `atropy` work correctly.
|
|
93
|
+
|
|
94
|
+
MacOS: Note that XCode compilers do not support OpenMP. For using OpenMP on macOS, a manual installation (e.g. of `gcc11`) is required and the `CXX`, `CC` and `FC` environment variables have to be set accordingly.
|
|
95
|
+
|
|
96
|
+
### Python environment
|
|
97
|
+
To use the Python notebooks and programs included in `scripts`, a Python environment with external packages specified in `pip-requirements.txt` needs to be configured and enabled.
|
|
98
|
+
For Python venv:
|
|
99
|
+
```shell
|
|
100
|
+
python -m venv path/to/my_venv
|
|
101
|
+
source path/to/my_venv/bin/activate
|
|
102
|
+
pip install -r pip-requirements.txt
|
|
103
|
+
pip install -e .
|
|
104
|
+
```
|
|
105
|
+
For anaconda:
|
|
106
|
+
```shell
|
|
107
|
+
conda create -n my_venv python --file pip-requirements.txt
|
|
108
|
+
conda activate my_venv
|
|
109
|
+
pip install -e .
|
|
110
|
+
```
|
|
111
|
+
All scripts and notebooks have to be executed from the project root. When using a IDE, make sure to adjust the settings accordingly. In Microsoft Visual Studio Code one has to set the "Notebook File Root" to `{workspaceFolder}` to run the notebooks.
|
|
112
|
+
Unit tests for Python files are located in the `scripts/tests` folder. They can be run in the Python environment via
|
|
113
|
+
```shell
|
|
114
|
+
pytest scripts/tests
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Run the program
|
|
118
|
+
`atropy` has to be run with
|
|
119
|
+
```
|
|
120
|
+
./bin/atropy [OPTION...]
|
|
121
|
+
```
|
|
122
|
+
and expects the following command line arguments:
|
|
123
|
+
- `-i`, `--input`: Name of the input .nc file (default: `input/input.nc`)
|
|
124
|
+
- `-o`, `--output`: Name of the output folder, stored in `output/`
|
|
125
|
+
- `-s`, `--snapshot`: Number of steps between two snapshots
|
|
126
|
+
- `-t`, `--tau`: Time step size
|
|
127
|
+
- `-f`, `--tfinal`: Final integration time
|
|
128
|
+
- `-n`, `--substeps`: Number of integration substeps (default: `1`)
|
|
129
|
+
- `-m`, `--method`: Integration method (`e` (explicit Euler), `r` (explicit RK4), `i`
|
|
130
|
+
(implicit Euler), `c` (Crank-Nicolson)) (default: `i`)
|
|
131
|
+
- `-h`, `--help`: Print usage
|
|
132
|
+
|
|
133
|
+
## Input
|
|
134
|
+
Input netCDF files have to be stored as `input/input.nc` (the directory can be changed using the `-i` flag) and can be generated with the input scripts provided in `scripts/input_generation`.
|
|
135
|
+
|
|
136
|
+
**Caution:** As `Ensign` stores arrays in column-major (Fortran) order, it is assumed that input arrays also follow this convention.
|
|
137
|
+
<!-- TODO: Give more detais -->
|
|
138
|
+
|
|
139
|
+
<!-- TODO: ### Binning -->
|
|
140
|
+
|
|
141
|
+
### Preparing input data
|
|
142
|
+
Let us consider the input script `set_lambda_phage.py` located in the `scripts/input_generation` folder, which generates input data for the lambda phage model. It gives an example on how the initial conditions have to be set up. The `input/input.nc` file is generated via
|
|
143
|
+
```shell
|
|
144
|
+
python3 scripts/input_generation/set_lamba_phage.py --partition "(0 1)((2 3)(4))" --rank 5 4
|
|
145
|
+
```
|
|
146
|
+
and a short documentation for this script is provided by
|
|
147
|
+
```shell
|
|
148
|
+
python3 scripts/input_generation/set_lambda_phage.py --help
|
|
149
|
+
```
|
|
150
|
+
<!-- TODO: ### Describe examples in more detail -->
|
|
151
|
+
|
|
152
|
+
Note that `atropy` assumes that the propensity function is factorizable for the species in different partitions. However, the input scripts rely on the `ReactionSystem` class (cf. `scripts/reaction_class.py`), which assumes that the propensity function is factorizable in *all* species. This is a valid assumption for most scenarios. For problems where species in a partition are not factorizable, the propensity function can be adjusted manually after initializing the `Tree` with the method `initialize`.
|
|
153
|
+
|
|
154
|
+
<!-- #### Writing a model file with the `ReactionSystem` class
|
|
155
|
+
The model file contains all reactions $`R_\mu`$ ($`\mu=1,\dots,M`$) of the specific problem and has to be imported in the input scripts. -->
|
|
156
|
+
|
|
157
|
+
<!-- TODO: More detailed description. -->
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
## Output
|
|
161
|
+
`atropy` automatically creates a folder in `output/` with a name set by the `-o`/`--output` parameter.
|
|
162
|
+
The low-rank factors and coupling coefficients as well as the chosen model parameters are stored in this folder as `output_t<ts>.nc` (`<ts>` denotes the time step) in intervals according to the `-s`/`--snapshot` parameter.
|
|
163
|
+
|
|
164
|
+
<!-- TODO: Describe the structure of the .netCDF file -->
|
|
165
|
+
|
|
166
|
+
## Example problems
|
|
167
|
+
Input generation scripts for the example problems (lambda phage and reaction cascade) are provided in `scripts/input_generation` and the corresponding model files can be found in `scripts/models`.
|
|
168
|
+
|
|
169
|
+
All required output files and reference solutions for reproducing the plots in https://arxiv.org/abs/2407.11792 can be computed with the shell scripts provided in `scripts/shell`. Before generating the plots with the interactive Python notebooks provided in `scripts/output/notebooks`, a `plots` folder has to be created in the project root:
|
|
170
|
+
```shell
|
|
171
|
+
mkdir plots
|
|
172
|
+
```
|
|
173
|
+
Then, for the lambda phage example one has to run
|
|
174
|
+
```shell
|
|
175
|
+
sh scripts/shell/run_lambda_phage.sh
|
|
176
|
+
```
|
|
177
|
+
and for the cascade reaction example
|
|
178
|
+
```shell
|
|
179
|
+
sh scripts/shell/run_cascade.sh
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## References
|
|
183
|
+
\[1\]: Ceruti, G., Lubich, C., and Walach, H.: Time integration of Tree Tensor networks", SIAM J. Numer. Anal. **59** (2021)
|
|
184
|
+
<!-- Lubich, C., Oseledets, I.: "A projector-splitting integrator for dynamical low-rank approximation", BIT Numerical Mathematics **54** (2014) -->
|
|
185
|
+
|
|
186
|
+
\[2\]: Cassini, F., and Einkemmer, L.: "Efficient 6D Vlasov simulation using the dynamical low-rank framework Ensign", Comp. Phys. Comm. **280** (2022)
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.27 FATAL_ERROR)
|
|
2
|
+
project(atropy_core
|
|
3
|
+
VERSION 0.0.1
|
|
4
|
+
DESCRIPTION "Dynamical low-rank solver for the kinetic CME"
|
|
5
|
+
HOMEPAGE_URL https://git.uibk.ac.at/c7021158/kinetic-cme
|
|
6
|
+
LANGUAGES CXX)
|
|
7
|
+
enable_testing()
|
|
8
|
+
|
|
9
|
+
include(FetchContent)
|
|
10
|
+
|
|
11
|
+
set(CMAKE_CXX_STANDARD 20)
|
|
12
|
+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
13
|
+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake-modules")
|
|
14
|
+
set(CMAKE_CONFIGURATION_TYPES "Debug;Release;Profile" CACHE STRING "" FORCE)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
################################################################################
|
|
18
|
+
# General options
|
|
19
|
+
################################################################################
|
|
20
|
+
|
|
21
|
+
option("MKL_ENABLED" "Enable MKL for Ensign" OFF)
|
|
22
|
+
option("OPENMP" "Enable OpenMP" OFF)
|
|
23
|
+
option("PYBIND11_ENABLED" "Enable PYBIND" OFF)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
################################################################################
|
|
27
|
+
# Compiler options
|
|
28
|
+
################################################################################
|
|
29
|
+
|
|
30
|
+
if(CMAKE_CXX_COMPILER_ID MATCHES Intel)
|
|
31
|
+
set(CMAKE_CXX_FLAGS
|
|
32
|
+
"${CMAKE_CXX_FLAGS} -Warn all -fpic"
|
|
33
|
+
)
|
|
34
|
+
set(CMAKE_CXX_FLAGS_DEBUG
|
|
35
|
+
"-g -check all -traceback"
|
|
36
|
+
)
|
|
37
|
+
set(CMAKE_CXX_FLAGS_RELEASE
|
|
38
|
+
"-O3 -ip -xHOST"
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
else(CMAKE_CXX_COMPILER_ID MATCHES GNU)
|
|
42
|
+
set(CMAKE_CXX_FLAGS
|
|
43
|
+
"${CMAKE_CXX_FLAGS} -Wall -fPIC"
|
|
44
|
+
)
|
|
45
|
+
set(CMAKE_CXX_FLAGS_DEBUG
|
|
46
|
+
"-O0 -g3 -ggdb3 -Wall -D_GLIBCXX_DEBUG -fno-omit-frame-pointer -ftrapv"
|
|
47
|
+
)
|
|
48
|
+
set(CMAKE_CXX_FLAGS_RELEASE
|
|
49
|
+
"-O3 -DNDEBUG -march=native -mtune=native"
|
|
50
|
+
)
|
|
51
|
+
endif()
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
################################################################################
|
|
55
|
+
# External libraries
|
|
56
|
+
################################################################################
|
|
57
|
+
|
|
58
|
+
################################################################################
|
|
59
|
+
# Eigen
|
|
60
|
+
|
|
61
|
+
find_package(Eigen3 3.4 REQUIRED NO_MODULE)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
################################################################################
|
|
65
|
+
# NetCDF
|
|
66
|
+
|
|
67
|
+
find_package(NetCDF REQUIRED)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
################################################################################
|
|
71
|
+
# cxxopts
|
|
72
|
+
|
|
73
|
+
FetchContent_Declare(cxxopts
|
|
74
|
+
GIT_REPOSITORY "https://github.com/jarro2783/cxxopts.git"
|
|
75
|
+
GIT_TAG "v3.2.1"
|
|
76
|
+
GIT_SHALLOW ON
|
|
77
|
+
GIT_PROGRESS ON
|
|
78
|
+
FIND_PACKAGE_ARGS
|
|
79
|
+
)
|
|
80
|
+
FetchContent_MakeAvailable(cxxopts)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
################################################################################
|
|
84
|
+
# Ensign
|
|
85
|
+
|
|
86
|
+
FetchContent_Declare(Ensign
|
|
87
|
+
GIT_REPOSITORY https://github.com/leinkemmer/Ensign.git
|
|
88
|
+
GIT_TAG "development"
|
|
89
|
+
GIT_SHALLOW ON
|
|
90
|
+
GIT_PROGRESS ON
|
|
91
|
+
FIND_PACKAGE_ARGS
|
|
92
|
+
)
|
|
93
|
+
FetchContent_MakeAvailable(Ensign)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
################################################################################
|
|
97
|
+
# pybind 11
|
|
98
|
+
|
|
99
|
+
if (PYBIND11_ENABLED)
|
|
100
|
+
set(PYBIND11_NEWPYTHON ON)
|
|
101
|
+
find_package(pybind11 REQUIRED)
|
|
102
|
+
endif()
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
################################################################################
|
|
106
|
+
# Create short-hands
|
|
107
|
+
################################################################################
|
|
108
|
+
|
|
109
|
+
# Create `input` and `output` directories
|
|
110
|
+
file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/input)
|
|
111
|
+
file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/output)
|
|
112
|
+
|
|
113
|
+
# Define short-hands for the src directory and the files
|
|
114
|
+
set(SRC ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
|
115
|
+
set(SRC_FILES ${SRC}/bug_integrator.cpp
|
|
116
|
+
${SRC}/grid_class.cpp
|
|
117
|
+
${SRC}/matrix.cpp
|
|
118
|
+
${SRC}/print_functions.cpp
|
|
119
|
+
${SRC}/ps_integrator.cpp
|
|
120
|
+
${SRC}/tree_class.cpp)
|
|
121
|
+
set(HDR_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
################################################################################
|
|
125
|
+
# Set up the program
|
|
126
|
+
################################################################################
|
|
127
|
+
|
|
128
|
+
if(PYBIND11_ENABLED)
|
|
129
|
+
|
|
130
|
+
################################################################################
|
|
131
|
+
# pybind11
|
|
132
|
+
|
|
133
|
+
pybind11_add_module(atropy_core_pybind11
|
|
134
|
+
${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp
|
|
135
|
+
${SRC_FILES}
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
# Add SOURCE_ROOT as a preprocessor directive
|
|
139
|
+
target_compile_definitions(atropy_core_pybind11
|
|
140
|
+
PRIVATE "SOURCE_ROOT=${CMAKE_CURRENT_SOURCE_DIR}"
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
target_compile_definitions(atropy_core_pybind11 PRIVATE "__PYBIND11__")
|
|
144
|
+
|
|
145
|
+
target_include_directories(atropy_core_pybind11 PRIVATE ${HDR_DIR})
|
|
146
|
+
target_link_libraries(atropy_core_pybind11 PRIVATE Ensign::Ensign)
|
|
147
|
+
target_link_libraries(atropy_core_pybind11 PUBLIC Eigen3::Eigen)
|
|
148
|
+
target_include_directories(atropy_core_pybind11 PRIVATE ${NETCDF_INCLUDE_DIR})
|
|
149
|
+
|
|
150
|
+
if(cxxopts_FOUND)
|
|
151
|
+
target_link_libraries(atropy_core_pybind11 PRIVATE cxxopts::cxxopts)
|
|
152
|
+
else()
|
|
153
|
+
target_link_libraries(atropy_core_pybind11 PRIVATE cxxopts)
|
|
154
|
+
endif()
|
|
155
|
+
|
|
156
|
+
install(TARGETS atropy_core_pybind11 LIBRARY DESTINATION .)
|
|
157
|
+
|
|
158
|
+
else()
|
|
159
|
+
|
|
160
|
+
################################################################################
|
|
161
|
+
# atropy_core
|
|
162
|
+
|
|
163
|
+
add_executable(${PROJECT_NAME}
|
|
164
|
+
${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp
|
|
165
|
+
${SRC_FILES}
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
# Add SOURCE_ROOT as a preprocessor directive
|
|
169
|
+
target_compile_definitions(${PROJECT_NAME}
|
|
170
|
+
PRIVATE "SOURCE_ROOT=${CMAKE_CURRENT_SOURCE_DIR}"
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
target_include_directories(${PROJECT_NAME} PRIVATE ${HDR_DIR})
|
|
174
|
+
target_link_libraries(${PROJECT_NAME} PRIVATE Ensign::Ensign)
|
|
175
|
+
target_link_libraries(${PROJECT_NAME} PUBLIC Eigen3::Eigen)
|
|
176
|
+
target_include_directories(${PROJECT_NAME} PRIVATE ${NETCDF_INCLUDE_DIR})
|
|
177
|
+
|
|
178
|
+
if(cxxopts_FOUND)
|
|
179
|
+
target_link_libraries(${PROJECT_NAME} PRIVATE cxxopts::cxxopts)
|
|
180
|
+
else()
|
|
181
|
+
target_link_libraries(${PROJECT_NAME} PRIVATE cxxopts)
|
|
182
|
+
endif()
|
|
183
|
+
|
|
184
|
+
if(BUILD_TESTING)
|
|
185
|
+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests)
|
|
186
|
+
endif()
|
|
187
|
+
endif()
|
|
File without changes
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"""Helper module for Boolean reaction models."""
|
|
2
|
+
|
|
3
|
+
import ctypes
|
|
4
|
+
import inspect
|
|
5
|
+
import subprocess
|
|
6
|
+
import tempfile
|
|
7
|
+
import textwrap
|
|
8
|
+
|
|
9
|
+
import bitarray
|
|
10
|
+
import bitarray.util
|
|
11
|
+
import numpy as np
|
|
12
|
+
import regex as re
|
|
13
|
+
|
|
14
|
+
import atropy_core.reaction
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def convertRulesToReactions(filename: str):
|
|
18
|
+
"""
|
|
19
|
+
Converts a rule file of the Boolean CME integrator of
|
|
20
|
+
https://bitbucket.org/mprugger/low_rank_cme to a `ReactionSystem` instance.
|
|
21
|
+
NOTE: This method is only capable of converting systems
|
|
22
|
+
with a maximum of 64 species.
|
|
23
|
+
"""
|
|
24
|
+
with open(filename) as f:
|
|
25
|
+
line0 = f.readline()
|
|
26
|
+
f_string = f.read()
|
|
27
|
+
|
|
28
|
+
match = re.match(r"RULE_SET\((.*)\)", line0)
|
|
29
|
+
model_info = [x.split()[0] for x in match.group(1).split(",")]
|
|
30
|
+
|
|
31
|
+
model_name = model_info[0]
|
|
32
|
+
d = int(model_info[1])
|
|
33
|
+
species_names = [name[1:-1] for name in model_info[2:]]
|
|
34
|
+
|
|
35
|
+
rules = {}
|
|
36
|
+
dependencies = {}
|
|
37
|
+
|
|
38
|
+
rule_pattern = (
|
|
39
|
+
f"template<> bool {model_name}::rule<(\d+)>\(bitset<{d}> x\) " "\{([\S\s]*?)\}"
|
|
40
|
+
)
|
|
41
|
+
dependency_pattern = (
|
|
42
|
+
f"template<> vector<ind> {model_name}::depends_on<(\d+)>\(\) "
|
|
43
|
+
"\{[\s]*?return \{(.*?)\};\s*\}"
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
rule_matches = re.finditer(rule_pattern, f_string, re.MULTILINE)
|
|
47
|
+
for _, match in enumerate(rule_matches, start=1):
|
|
48
|
+
i = int(match.group(1))
|
|
49
|
+
rules[i] = match.group(2)
|
|
50
|
+
|
|
51
|
+
dependency_matches = re.finditer(dependency_pattern, f_string, re.MULTILINE)
|
|
52
|
+
for _, match in enumerate(dependency_matches, start=1):
|
|
53
|
+
i = int(match.group(1))
|
|
54
|
+
dependency = [int(d) for d in match.group(2).split(",")]
|
|
55
|
+
if i not in dependency:
|
|
56
|
+
dependency.append(i)
|
|
57
|
+
dependencies[i] = sorted(dependency)
|
|
58
|
+
|
|
59
|
+
with tempfile.TemporaryDirectory() as tmpdirname:
|
|
60
|
+
with open(tmpdirname + "/rule_set_temp.cpp", mode="w") as f:
|
|
61
|
+
str_begin = '#include <bitset>\nextern "C"\n{'
|
|
62
|
+
f.write(str_begin)
|
|
63
|
+
for k, v in rules.items():
|
|
64
|
+
str_rule = "\n\tbool rule_{}(std::bitset<{}> x)\n\t{{{}\t}}\n"
|
|
65
|
+
f.write(str_rule.format(k, d, textwrap.indent(v, "\t")))
|
|
66
|
+
str_end = "}"
|
|
67
|
+
f.write(str_end)
|
|
68
|
+
|
|
69
|
+
subprocess.run(
|
|
70
|
+
[
|
|
71
|
+
"g++",
|
|
72
|
+
"-fPIC",
|
|
73
|
+
"-shared",
|
|
74
|
+
"-o",
|
|
75
|
+
tmpdirname + "/rule_set_temp.so",
|
|
76
|
+
tmpdirname + "/rule_set_temp.cpp",
|
|
77
|
+
]
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
handle = ctypes.CDLL(tmpdirname + "/rule_set_temp.so")
|
|
81
|
+
|
|
82
|
+
def fun_x0(x):
|
|
83
|
+
return 1 - x
|
|
84
|
+
|
|
85
|
+
def fun_x1(x):
|
|
86
|
+
return x
|
|
87
|
+
|
|
88
|
+
reactions = []
|
|
89
|
+
|
|
90
|
+
for i in range(d):
|
|
91
|
+
d_dep = len(dependencies[i])
|
|
92
|
+
dx_dep = 2**d_dep
|
|
93
|
+
for j in range(dx_dep):
|
|
94
|
+
x = bitarray.bitarray(d, endian="little")
|
|
95
|
+
x.setall(0)
|
|
96
|
+
x_dep = bitarray.util.int2ba(j, length=d_dep, endian="little")
|
|
97
|
+
for k, k_dep in enumerate(dependencies[i]):
|
|
98
|
+
x[k_dep] = x_dep[k]
|
|
99
|
+
curr_rule = handle[f"rule_{i}"]
|
|
100
|
+
curr_rule.argtypes = [
|
|
101
|
+
ctypes.c_ulonglong
|
|
102
|
+
] # avoid overflow for large systems
|
|
103
|
+
x_i_prime = curr_rule(bitarray.util.ba2int(x))
|
|
104
|
+
if (
|
|
105
|
+
x[i] != x_i_prime
|
|
106
|
+
): # create a reaction only when output is different from input
|
|
107
|
+
nu = np.zeros(d)
|
|
108
|
+
nu[i] = 1 if x[i] == 0 else -1
|
|
109
|
+
propensity = {}
|
|
110
|
+
for k_dep in dependencies[i]:
|
|
111
|
+
propensity[k_dep] = fun_x0 if x[k_dep] == 0 else fun_x1
|
|
112
|
+
reactions.append(atropy_core.reaction.Reaction(propensity, nu))
|
|
113
|
+
|
|
114
|
+
reaction_system = atropy_core.reaction.ReactionSystem(reactions, species_names)
|
|
115
|
+
|
|
116
|
+
return reaction_system
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
if __name__ == "__main__":
|
|
120
|
+
import numpy as np
|
|
121
|
+
|
|
122
|
+
reaction_system = convertRulesToReactions(
|
|
123
|
+
"atropy_core/examples/models/boolean/pancreatic_cancer.hpp"
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
func_pattern = re.compile(r"return (.+)\\n")
|
|
127
|
+
for mu, reaction in enumerate(reaction_system.reactions):
|
|
128
|
+
print(f"reaction {mu}, product {int(np.nonzero(reaction.nu)[0])}")
|
|
129
|
+
for k, v in reaction.propensity.items():
|
|
130
|
+
func_string = str(inspect.getsourcelines(v)[0])
|
|
131
|
+
func = re.findall(func_pattern, func_string)
|
|
132
|
+
print(k, func)
|
|
133
|
+
print(reaction.nu, "\n")
|
|
File without changes
|
|
File without changes
|