Skip to content

Commit

Permalink
Remove python (SimVascular#34)
Browse files Browse the repository at this point in the history
* Remove python folder

* Delete python test

* Make simulate function return a pandas dataframe

* Cleanup tests and dependencies

* Remove coverage settings for pytest

* Remove python doc

* Move cpp docs one level up

* Update doxyfile

* Update Readme

* Update github actions

* Remove unnecessary entries from gitignore

* Fix bug

* Add stub file

* Fix tests

* Test cases for shared library interface (SimVascular#33)

* added test case and included in github/workflows/test.yml

* modified test

* included dylib extension for macos

* clean up

* added test2

* updated library path

* add cmake build to github workflows

* updated docs

* more docs updates

* added svzerdcalibrator to features in doc

* cmake build for interface tests

* tests use common LPNSolverInterface

* added to github workflows

---------

Co-authored-by: Karthik Menon <[email protected]>
Co-authored-by: Karthik Menon <[email protected]>
Co-authored-by: Karthik Menon <[email protected]>

* Remove python folder

* Delete python test

* Make simulate function return a pandas dataframe

* Cleanup tests and dependencies

* Remove coverage settings for pytest

* Remove python doc

* Move cpp docs one level up

* Update doxyfile

* Update Readme

* Update github actions

* Remove unnecessary entries from gitignore

* Fix bug

* Add stub file

* Fix tests

* Fix bug

* Update documentation

* Fix bug

---------

Co-authored-by: Jakob Richter <[email protected]>
Co-authored-by: Karthik Menon <[email protected]>
Co-authored-by: Karthik Menon <[email protected]>
Co-authored-by: Karthik Menon <[email protected]>
Co-authored-by: Karthik Menon <[email protected]>
Co-authored-by: Martin R. Pfaller <[email protected]>
  • Loading branch information
7 people authored Sep 20, 2023
1 parent 18c04c6 commit 7d8afbf
Show file tree
Hide file tree
Showing 41 changed files with 529 additions and 2,900 deletions.
21 changes: 6 additions & 15 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This workflow builds and deploys the html documentation for svZeroDSolver.
# This workflow builds and deploys the html documentation for svZeroDPlus.
name: Documentation
on: [push, pull_request]
permissions:
Expand All @@ -8,32 +8,23 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Make html directory
run: mkdir docs/html
- name: Make build directory
run: mkdir docs/build
- name: Build doxygen documentation
continue-on-error: true
uses: mattnotmitt/[email protected]
with:
working-directory: '.'
doxyfile-path: 'docs/cpp/Doxyfile'
doxyfile-path: 'docs/Doxyfile'
enable-latex: true
- name: Install sphinx dependencies
run: |
conda create -n zerod python=3.9
conda run -n zerod pip install -e .[dev]
- name: Build sphinx documentation
continue-on-error: true
run: |
conda run -n zerod sphinx-apidoc -o docs/python/source svzerodsolver
conda run -n zerod sphinx-build -b html -d docs/python/build/doctrees docs/python/source docs/html/python
- name: Save documentation
uses: actions/upload-artifact@v3
with:
name: documentation
path: ./docs/html
path: ./docs/build/html
- name: Deploy documentation
if: github.ref == 'refs/heads/master'
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/html
publish_dir: ./docs/build/html
37 changes: 7 additions & 30 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# This workflow builds and tests svZeroDSolver. The Python version is tested on
# ubuntu and the C++ version is built and tested on different versions of
# ubuntu and macOS.
# This workflow builds and tests svZeroDPlus. It is built and tested on
# different versions of ubuntu and macOS.
name: Build and test
on: [push, pull_request]
jobs:
cpp:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -18,11 +17,11 @@ jobs:
- name: Install svZeroDPlus
run: |
conda create -n zerod python=3.9
conda run -n zerod pip install pytest pytest-cov pytest-mock
conda run -n zerod pip install -e .
conda run -n zerod pip install -e ".[dev]"
- name: Test the build
run: |
conda run -n zerod pytest tests/test_integration_cpp.py
cd tests
conda run -n zerod pytest
- name: Build using CMake
run: |
mkdir Release
Expand All @@ -39,26 +38,4 @@ jobs:
cd test_01
./svZeroD_interface_test01 ../../../../Release ../../test_01/svzerod_3Dcoupling.json
cd ../test_02
./svZeroD_interface_test02 ../../../../Release ../../test_02/svzerod_tuned.json
python:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up environment
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
conda create -n zerod python=3.9
conda run -n zerod pip install pytest pytest-cov pytest-mock
conda run -n zerod pip install -e .
- name: Run pytest
run: |
conda run -n zerod pytest tests/test_integration.py
- name: Save coverage report
uses: actions/upload-artifact@v3
with:
name: coverage_report
path: htmlcov

./svZeroD_interface_test02 ../../../../Release ../../test_02/svzerod_tuned.json
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ __pycache__
public

# Documentation
docs/html
docs/python/source/*.rst
!docs/python/source/index.rst
!docs/python/source/modules.rst
docs/python/build
docs/build

# C++ build and externals directories
Release*/
Expand Down
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@
</div>

svZeroDPlus is a fast simulation tool for modeling the hemodynamics of
vascular networks using zero-dimensional (0D) lumped parameter models. There
are two different implementations of the solver, a high performance C++
version and an easy to use Python version. You can find more information about
both under the following links:
vascular networks using zero-dimensional (0D) lumped parameter models.
You can find more information about svZeroDPlus under the following links:

* [**C++ Documentation**](https://StanfordCBCL.github.io/svZeroDPlus/cpp)
* [**C++ Developer Guide**](https://StanfordCBCL.github.io/svZeroDPlus/cpp/md_developer_guide.html)
* [**Python Documentation**](https://StanfordCBCL.github.io/svZeroDPlus/python)
* [**Documentation**](https://StanfordCBCL.github.io/svZeroDPlus)
* [**Developer Guide**](https://StanfordCBCL.github.io/svZeroDPlus/md_developer_guide.html)
* [**Wiki**](https://github.com/StanfordCBCL/svZeroDPlus/wiki)
* [**Bug Reports**](https://github.com/StanfordCBCL/svZeroDPlus/issues)
* [**Forum**](https://github.com/StanfordCBCL/svZeroDPlus/discussions)
Expand Down
22 changes: 18 additions & 4 deletions applications/svzerodplus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ namespace py = pybind11;

PYBIND11_MODULE(svzerodplus, m) {
using Solver = SOLVE::Solver<double>;
m.doc() = "svZeroDSolver";
py::class_<Solver>(m, "Solver")
.def(py::init([](py::dict& config) {
const nlohmann::json& config_json = config;
Expand All @@ -55,17 +54,32 @@ PYBIND11_MODULE(svzerodplus, m) {
const auto& config_json = nlohmann::json::parse(ifs);
return Solver(config_json);
}))
.def("copy", [](Solver& solver) { return Solver(solver); })
.def("run", &Solver::run)
.def("get_single_result", &Solver::get_single_result)
.def("get_single_result_avg", &Solver::get_single_result_avg)
.def("update_block_params", &Solver::update_block_params);
.def("get_full_result", [](Solver& solver) {
py::module_ pd = py::module_::import("pandas");
py::module_ io = py::module_::import("io");
auto result = solver.get_full_result();
return pd.attr("read_csv")(io.attr("StringIO")(result));
});

m.def("simulate", [](py::dict& config) {
py::module_ pd = py::module_::import("pandas");
py::module_ io = py::module_::import("io");
const nlohmann::json& config_json = config;
auto solver = Solver(config_json);
solver.run();
return solver.get_full_result();
return pd.attr("read_csv")(io.attr("StringIO")(solver.get_full_result()));
});
m.def("simulate", [](std::string config_file) {
py::module_ pd = py::module_::import("pandas");
py::module_ io = py::module_::import("io");
std::ifstream ifs(config_file);
const auto& config_json = nlohmann::json::parse(ifs);
auto solver = Solver(config_json);
solver.run();
return pd.attr("read_csv")(io.attr("StringIO")(solver.get_full_result()));
});
m.def("calibrate", [](py::dict& config) {
const nlohmann::json& config_json = config;
Expand Down
16 changes: 8 additions & 8 deletions docs/cpp/Doxyfile → docs/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ PROJECT_NAME = svZeroDPlus
PROJECT_NUMBER =
PROJECT_BRIEF =
PROJECT_LOGO =
OUTPUT_DIRECTORY = docs/html
OUTPUT_DIRECTORY = docs/build
CREATE_SUBDIRS = NO
OUTPUT_LANGUAGE = English
BRIEF_MEMBER_DESC = YES
Expand All @@ -27,7 +27,7 @@ ABBREVIATE_BRIEF = "The $name class" \
ALWAYS_DETAILED_SEC = YES
INLINE_INHERITED_MEMB = NO
FULL_PATH_NAMES = YES
STRIP_FROM_PATH = "src" "docs/cpp/pages"
STRIP_FROM_PATH = "src" "docs/pages"
STRIP_FROM_INC_PATH =
SHORT_NAMES = NO
JAVADOC_AUTOBRIEF = NO
Expand Down Expand Up @@ -90,8 +90,8 @@ SHOW_USED_FILES = YES
SHOW_FILES = YES
SHOW_NAMESPACES = YES
FILE_VERSION_FILTER =
LAYOUT_FILE = ./docs/cpp/DoxygenLayout.xml
CITE_BIB_FILES = ./docs/cpp/references.bib
LAYOUT_FILE = ./docs/DoxygenLayout.xml
CITE_BIB_FILES = ./docs/references.bib
#---------------------------------------------------------------------------
# Configuration options related to warning and progress messages
#---------------------------------------------------------------------------
Expand All @@ -106,7 +106,7 @@ WARN_LOGFILE =
# Configuration options related to the input files
#---------------------------------------------------------------------------
INPUT = "src" \
"docs/cpp/pages"
"docs/pages"
INPUT_ENCODING = UTF-8
FILE_PATTERNS = *.cpp \
*.hpp \
Expand All @@ -122,7 +122,7 @@ EXCLUDE_SYMBOLS =
EXAMPLE_PATH =
EXAMPLE_PATTERNS = *
EXAMPLE_RECURSIVE = NO
IMAGE_PATH = docs/cpp
IMAGE_PATH = images
INPUT_FILTER =
FILTER_PATTERNS =
FILTER_SOURCE_FILES = NO
Expand All @@ -149,12 +149,12 @@ IGNORE_PREFIX =
# Configuration options related to the HTML output
#---------------------------------------------------------------------------
GENERATE_HTML = YES
HTML_OUTPUT = cpp
HTML_OUTPUT = html
HTML_FILE_EXTENSION = .html
HTML_HEADER =
HTML_FOOTER =
HTML_STYLESHEET =
HTML_EXTRA_STYLESHEET = ./docs/cpp/doxygen-awesome.css
HTML_EXTRA_STYLESHEET = ./docs/doxygen-awesome.css
HTML_EXTRA_FILES =
HTML_COLORSTYLE_HUE = 220
HTML_COLORSTYLE_SAT = 100
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ The documentation is automatically build in the GitHub CI/CD and published
on GitHub pages. If you want to build the documentation locally, you can use:

```
doxygen docs/cpp/Doxyfile
doxygen docs/Doxyfile
```

If you do not have Doxygen install you can do that with `brew install doxygen`
Expand Down
64 changes: 55 additions & 9 deletions docs/cpp/pages/main.md → docs/pages/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,35 +125,35 @@ you installed svZerodPlus via pip to enable this feature. We start by
importing svzerodplus:

```python
import svzerodplus
>>> import svzerodplus
```

Next, we create a solver from our configuration. The configuration can
be specified by either a path to a JSON file:

```python
solver = svzerodplus.Solver("tests/cases/steadyFlow_RLC_R.json")
>>> solver = svzerodplus.Solver("tests/cases/steadyFlow_RLC_R.json")
```

or as a Python dictionary:

```python
my_config = {...}
solver = svzerodplus.Solver(my_config)
>>> my_config = {...}
>>> solver = svzerodplus.Solver(my_config)
```

To run the simulation we add:

```python
solver.run()
>>> solver.run()
```

The simulation result is now saved in the solver instance. We can obtain
results for individual degrees-of-freedom (DOFs) as
```python
solver.get_single_result("flow:INFLOW:branch0_seg0")
>>> solver.get_single_result("flow:INFLOW:branch0_seg0")

>>> array([5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5.,
array([5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5.,
5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5.,
5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5.,
5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5.,
Expand All @@ -164,11 +164,57 @@ The naming of the DOFs is similar to how results are written if the simulation
option `output_variable_based` is activated (see below). We can also obtain
the mean result for a DOF over time with:
```python
solver.get_single_result_avg("flow:INFLOW:branch0_seg0")
>>> solver.get_single_result_avg("flow:INFLOW:branch0_seg0")

5.0
```

Or the result of the full simulation as a pandas data frame:

```python
>>> solver.get_full_result()

name time flow_in flow_out pressure_in pressure_out
0 branch0_seg0 0.00 5.0 5.0 1100.0 600.0
1 branch0_seg0 0.01 5.0 5.0 1100.0 600.0
2 branch0_seg0 0.02 5.0 5.0 1100.0 600.0
3 branch0_seg0 0.03 5.0 5.0 1100.0 600.0
4 branch0_seg0 0.04 5.0 5.0 1100.0 600.0
.. ... ... ... ... ... ...
96 branch0_seg0 0.96 5.0 5.0 1100.0 600.0
97 branch0_seg0 0.97 5.0 5.0 1100.0 600.0
98 branch0_seg0 0.98 5.0 5.0 1100.0 600.0
99 branch0_seg0 0.99 5.0 5.0 1100.0 600.0
100 branch0_seg0 1.00 5.0 5.0 1100.0 600.0

[101 rows x 6 columns]
```

There is also a function to retrieve the full result directly based on a given configuration:

```python

>>> my_config = {...}
>>> svzerodplus.simulate(my_config)

name time flow_in flow_out pressure_in pressure_out
0 branch0_seg0 0.00 5.0 5.0 1100.0 600.0
1 branch0_seg0 0.01 5.0 5.0 1100.0 600.0
2 branch0_seg0 0.02 5.0 5.0 1100.0 600.0
3 branch0_seg0 0.03 5.0 5.0 1100.0 600.0
4 branch0_seg0 0.04 5.0 5.0 1100.0 600.0
.. ... ... ... ... ... ...
96 branch0_seg0 0.96 5.0 5.0 1100.0 600.0
97 branch0_seg0 0.97 5.0 5.0 1100.0 600.0
98 branch0_seg0 0.98 5.0 5.0 1100.0 600.0
99 branch0_seg0 0.99 5.0 5.0 1100.0 600.0
100 branch0_seg0 1.00 5.0 5.0 1100.0 600.0

[101 rows x 6 columns]

>>> 5.0
```


## Configuration

svZeroDSolver is configured using either a JSON file or a Python
Expand Down
41 changes: 0 additions & 41 deletions docs/python/source/conf.py

This file was deleted.

Loading

0 comments on commit 7d8afbf

Please sign in to comment.