A python interface for hops, the highly optimized polytope sampling toolbox.
Project description
HOPSY - Python bindings for HOPS
A python interface for HOPS - the Highly Optimized toolbox for Polytope Sampling.
Built using pybind11
hopsy is the attempt to offer some of the key functionatlity of hops through a Python interface. hops is a highly template-based C++-library for Markov chain Monte Carlo sampling on convex polytopes
P = {x : Ax ≤ b},
which often arises in metabolic flux analysis.
Installation
hopsy can be easily installed from the Python Package Index using pip install hopsy
.
Alternatively, you can download the source code from our GitHub repository with
git clone https://github.com/modsim/hopsy --recursive
Note the --recursive
option which is
needed for hops, eigen and pybind11 submodules.
Next, compile either a binary wheel using pip
pip wheel --no-deps hopsy/
or use the standard CMake routine
mkdir hopsy/cmake-build-release && cd hopsy/cmake-build-release
cmake ..
make
Note however that the binary wheel produced from pip
can be actually installed using pip
, using
pip install hopsy-x.y.z-tag.whl
where the version x.y.z
and tag tag
will depend on the verison you downloaded and your build environment.
If you use the CMake routine, the compiled shared library will be located in build/
and can
be used within the directory.
To compile wheels for distribution via the Python Package Index (pypi.org), use the makewheels.sh
script.
Prerequisites for compiling from source
On Unix (Linux, OS X)
- A compiler with C++11 support
- CMake >= 3.4 or Pip 10+
- Ninja or Pip 10+
- Docker (optional, for building wheels)
License
Examples
A basic usage example is presented below. More examples can be found in tests/
directory.
import hopsy
import numpy as np
# the polytope is defined as
# P := {x : Ax <= b}
# thus we need to define A and b. these constraints form the simple box [0,1]^2.
A = np.array([[1, 0], [0, 1], [-1, 0], [0, -1]])
b = np.array([[1], [1], [0], [0]]);
# next we define our target distribution as an isotropic Gaussian with mean 0 and
# identity covariance.
mu = np.zeros((2,1))
cov = np.identity(2)
model = hopsy.MultivariateGaussianModel(mu, cov)
# the complete problem is defined by the target distribution and the constrained domain,
# defined by the above mentioned inequality
problem = hopsy.Problem(A, b, model)
# the run object contains and constructs the markov chains. in the default case, the
# Run object will have a single chain using the Hit-and-Run proposal algorithm and is
# set to produce 10,000 samples.
run = hopsy.Run(problem)
# we finally sample
run.sample()
# from the run, we can now extract the produced data
data = run.data
# the states is a list of lists of numpy.ndarrays, which can be casted to a numpy.ndarray
# which then has the shape (m,n,d), where m is the number of chains, n the number of samples
# and d the dimenion
states = data.states
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
File details
Details for the file hopsy-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: hopsy-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 942.0 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.1 requests/2.22.0 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59a67fecd9c2cc0c4a647196ba1ae52183755bf6febc675c622f9abc6f61a43a |
|
MD5 | 40c281de411f5112d78d6cd33c649947 |
|
BLAKE2b-256 | 389a189cef139f918c2a13ae50e09a1f5c93eb46515a90eba86d3919d26426c2 |
File details
Details for the file hopsy-0.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: hopsy-0.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 942.4 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.1 requests/2.22.0 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a48949116da0c02b371b10426b076588837ce38589a84c205ecf73e35fe7f406 |
|
MD5 | 8c5869dd727be50e5e9d177f999691a6 |
|
BLAKE2b-256 | da511d23010d2d06ad690baec02bf6dbaed6125d663cd9a3fec84716964abe72 |
File details
Details for the file hopsy-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: hopsy-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 942.6 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.1 requests/2.22.0 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 202fab9ea63e26c430fac31a56a5ff773947b678948b537897f9e638165febc2 |
|
MD5 | 7938d7685cf45ce7efbe4a0d9f828389 |
|
BLAKE2b-256 | 7d972bc242507f325ac3d14ac951ae0c914bf61cbf34b1f6f6bee8d7dbf7d86a |
File details
Details for the file hopsy-0.2.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: hopsy-0.2.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 936.6 kB
- Tags: CPython 3.7m, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.1 requests/2.22.0 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d611cb0c15e1bbacede9df1654539e438f7ce3d8cd8338c1cb034f993615a73 |
|
MD5 | f386c18df0e85f2d3e46c16a1a68ce7e |
|
BLAKE2b-256 | f933537636e618674b844de6574b4d41508d565261a87f8819bf0f83e6a9d2d4 |
File details
Details for the file hopsy-0.2.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: hopsy-0.2.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 937.0 kB
- Tags: CPython 3.6m, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.1 requests/2.22.0 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fae396c2670bc293b8933dd42e9c7e5fdd857e8c7813ba27f483c80da10c8a3d |
|
MD5 | b92c3822ae6d403492ba7b52bdd6d2fe |
|
BLAKE2b-256 | f8dc9c1e522ad632c96de695450277ac45003a7c45f61565b58c63b93055f729 |