Skip to main content

Python interface to goss - General ODE System Solver

Project description

CI-cpp CI-fenics github pages PyPI version coverage

goss - General ODE System Solver

goss is python wrapper around a C++ library for solving ordinary differential equations with a variety of different schemes.

Documentation is hosted at https://computationalphysiology.github.io/goss Source code is found at https://github.com/ComputationalPhysiology/goss

Motivation

The general idea is that you define your ODE in a gotran ode file and hand the ode over to goss.

First define the ode in a gotran ODE file

# lorentz.ode
parameters(
sigma=10.0,
rho=28.0,
beta=8/3
)

# The values of the states represent the initial conditions
states(
x=0.0,
y=1.0,
z=1.05
)

dx_dt = sigma * (y - x)
dy_dt = x * (rho - z) - y
dz_dt = x * y - beta * z

You can now solve the ode as follows

import numpy as np
import matplotlib.pyplot as plt
from gotran import load_ode
import goss

# Import the ode in gotran
lorentz = load_ode("lorentz.ode")
# Jit compile the code for the right hand side
ode = goss.ParameterizedODE(lorentz)
# Select a solver and instantiate the solver
solver = goss.solvers.RKF32(ode)
# Select the time steps you want to solve for
t = np.linspace(0, 100, 10001)
# Solve the system
u = solver.solve(t)

# Plot the solution
fig = plt.figure()
ax = fig.add_subplot(projection="3d")

ax.plot(u[:, 0], u[:, 1], u[:, 2], lw=0.5)
ax.set_xlabel("X Axis")
ax.set_ylabel("Y Axis")
ax.set_zlabel("Z Axis")
ax.set_title("Lorenz Attractor")
plt.show()

_

For more examples, check out the demo folder

There is also a command line interface that can be used to list the available solvers, run the solver and generate the goss code

_

Install

You can install goss with pip

python -m pip install pygoss

See installation instructions for more options

Known issues

  • There is currently an issue on Apple Silicon with exceptions raised from by the jit compiled code which means the one test is not passing. An issue has been filed for this here

Contributing

Contributions are very welcomed. To contribute please fork the repo, create a branch a submit a pull request. Before the pull request can be accepted it has to pass the test suit for the python and C++ code. Also note that we try to enforce an consistent coding style. To ensure that you follow the coding style you can install the pre-commit hook in the repo

python -m pip install pre-commit
pre-commit install

For every future commit, you will now run a set of tests that will make sure that you follow the coding style.

See the contributing section for more info.

License

goss is licensed under the GNU LGPL, version 3 or (at your option) any later version.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pygoss-0.4.1.tar.gz (14.2 MB view hashes)

Uploaded Source

Built Distributions

pygoss-0.4.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (378.4 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pygoss-0.4.1-cp311-cp311-macosx_11_0_arm64.whl (242.3 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

pygoss-0.4.1-cp311-cp311-macosx_10_9_x86_64.whl (535.4 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

pygoss-0.4.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (378.4 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pygoss-0.4.1-cp310-cp310-macosx_11_0_arm64.whl (242.4 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

pygoss-0.4.1-cp310-cp310-macosx_10_9_x86_64.whl (535.4 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pygoss-0.4.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (379.4 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pygoss-0.4.1-cp39-cp39-macosx_11_0_arm64.whl (242.5 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

pygoss-0.4.1-cp39-cp39-macosx_10_9_x86_64.whl (535.5 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pygoss-0.4.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (378.9 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pygoss-0.4.1-cp38-cp38-macosx_11_0_arm64.whl (242.3 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

pygoss-0.4.1-cp38-cp38-macosx_10_9_x86_64.whl (535.2 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pygoss-0.4.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (383.9 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

pygoss-0.4.1-cp37-cp37m-macosx_10_9_x86_64.whl (530.6 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page