Skip to main content

A python interface for hops, the highly optimized polytope sampling toolbox.

Project description

hopsy - Python bindings for HOPS

pipeline status docstring coverage

A python interface for HOPS - the Highly Optimized toolbox for Polytope Sampling. Built using pybind11

HOPSY Logo

hopsy is a Python package 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 binary wheels for distribution (e.g. 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

hopsy is licensed under the MIT license.

Examples

A basic usage example is presented below. More examples can be found in tests/ directory.

import hopsy
import matplotlib.pyplot as plt

# the polytope is defined as 
#          P := {x : Ax <= b}
# thus we need to define A and b. these constraints form the simple box [0,5]^2.
A = [[1, 0], [0, 1], [-1, 0], [0, -1]]
b = [5, 5, 0, 0]

# next we construct a 2-dim standard Gaussian
model = hopsy.Gaussian(dim=2)

# 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.
mc = hopsy.MarkovChain(problem, proposal=hopsy.GaussianHitAndRunProposal, starting_point=[.5, .5])
rng = hopsy.RandomNumberGenerator(seed=42)

# we finally sample
acceptance_rate, states = hopsy.sample(mc, rng, n_samples=10_000, thinning=2)

# the states have 3 dimensions: number of chains, number of samples, number of dimensions.
plt.scatter(states[:,:,0].flatten(), states[:,:,1].flatten())
plt.show()

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

hopsy-1.0.0b0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (653.9 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

hopsy-1.0.0b0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (654.5 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

hopsy-1.0.0b0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (654.0 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

hopsy-1.0.0b0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (676.6 kB view details)

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

File details

Details for the file hopsy-1.0.0b0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hopsy-1.0.0b0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2fdd99171acc4481354f9b235ce36daf42d23994475476c643bc7656266bc638
MD5 b52ac6d0c7cc5d4af3d618a3a77d30ad
BLAKE2b-256 18750dbac639f70c7e1515f9d43f7657f55317305e2edb18ce2b14269675cd97

See more details on using hashes here.

File details

Details for the file hopsy-1.0.0b0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hopsy-1.0.0b0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ea00a6d319098e21325131a58d2357e97bebc2a536063cbf8b643a0af973cba0
MD5 8ea264c31a82d1491132788a03a7e6d2
BLAKE2b-256 fc0a3649747a119a1b4ed1a11191a5478743d134924471058f37f8505493f2f7

See more details on using hashes here.

File details

Details for the file hopsy-1.0.0b0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hopsy-1.0.0b0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c27bf7acd586066f28751feb7125913d1a592f17892a212c7162b3337e9cabc2
MD5 2064feba6287f7fe0d77d91f24367b35
BLAKE2b-256 b4e8ab46bcd8803bfd4535f69692a5b98693aca04206a18d9914d1d10685ea75

See more details on using hashes here.

File details

Details for the file hopsy-1.0.0b0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hopsy-1.0.0b0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 689de64ab3d42079e9663ace4a730add3faa78b17d540bf0cc6d29850caa3a3d
MD5 f70841fe6598ff2d775e052a43412c8e
BLAKE2b-256 7970ecae3f583b2b87ff7ef54ef887e46ab4f4d0b784d566aa7000a78f9a6f07

See more details on using hashes here.

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