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)

Examples

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

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)

# call sample on the mc and rng objects 
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()
2-dimensional truncated Gaussian scatter plot

Links

License

hopsy is licensed under the MIT license.

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.1.0-cp310-cp310-win_amd64.whl (767.2 kB view details)

Uploaded CPython 3.10 Windows x86-64

hopsy-1.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (663.2 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

hopsy-1.1.0-cp39-cp39-win_amd64.whl (767.2 kB view details)

Uploaded CPython 3.9 Windows x86-64

hopsy-1.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (663.6 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

hopsy-1.1.0-cp38-cp38-win_amd64.whl (767.2 kB view details)

Uploaded CPython 3.8 Windows x86-64

hopsy-1.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (663.3 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

hopsy-1.1.0-cp37-cp37m-win_amd64.whl (793.0 kB view details)

Uploaded CPython 3.7m Windows x86-64

hopsy-1.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (694.3 kB view details)

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

hopsy-1.1.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (696.2 kB view details)

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

File details

Details for the file hopsy-1.1.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: hopsy-1.1.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 767.2 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.1 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for hopsy-1.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 9dd95f8a979088e91deba99fd629e5c1fe0cdc40fb48dbdcd65af43d707fe73a
MD5 ece21691dd6638c892d4d84c68e46b62
BLAKE2b-256 b8f58a58675908c1176f8941eae62d02bcb779ed9c15423630ee2377bd882c16

See more details on using hashes here.

File details

Details for the file hopsy-1.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hopsy-1.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bf0a4a82cd503a90eb6aa5eefa1722a478123a1a2fce3b5c46fc8f769f59908b
MD5 360a3630d9464658e7a7841946dc61e6
BLAKE2b-256 b0dfb92d673dc0672ae74f91fca26db253353d50586a2749c86b35669dc69d28

See more details on using hashes here.

File details

Details for the file hopsy-1.1.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: hopsy-1.1.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 767.2 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.1 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for hopsy-1.1.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 621121f99e23729f5622a0fbb225fd719bad2b86a64e01a3a810255023c1a89e
MD5 b2d8069dc807992dc973fc450e17f3d3
BLAKE2b-256 26bd049ae2b8708a3506c0b6c78ef92c4c33afe712b7f8f29ba3b0034e8efb04

See more details on using hashes here.

File details

Details for the file hopsy-1.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hopsy-1.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ea702b5ec7e67ef900e4c5e85d5bb45d9babdba532eefb6f90964175d4eb47af
MD5 6e4918c2cc39e32cdd00e7a77522ca80
BLAKE2b-256 acb91d5d8edb0e6643b2587328d4f42359188ec9c555e7e52afb86a25e84ec72

See more details on using hashes here.

File details

Details for the file hopsy-1.1.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: hopsy-1.1.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 767.2 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.1 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for hopsy-1.1.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 273211fd4f8c8c7d47b584007e0929a90b75aeb18b3bbb876777870e90747ae4
MD5 2d7e00ae2fdc3f44249c59035bc7925e
BLAKE2b-256 c6f78f27146c065222b5f531ca9bf886da1e991c1d7fa6a72a71ba830ea295dd

See more details on using hashes here.

File details

Details for the file hopsy-1.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hopsy-1.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f36d49a1bedf07e55c91f276905dab684768cfcc2d1d5fba0f5246a8f6b36a28
MD5 6fcdf8c1cf7ebb4663e7b375f564cb63
BLAKE2b-256 a10f6cdb9fc46c093d94627a236246a752aed7f45f5c365b1630769a208c3d3f

See more details on using hashes here.

File details

Details for the file hopsy-1.1.0-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: hopsy-1.1.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 793.0 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.1 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for hopsy-1.1.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 fa73345919d26e6101ddc2d5dd2b7a5a1a2650175e8513d9fcd2aa00a398fe16
MD5 80601bec10d2afc42d80610fe2ee6bc8
BLAKE2b-256 cd00279a58ef31425aef529a86d51af1e08bc1f522476c253524d0429c6fdc93

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 76b6341f8eb0058d1813cf8af9196e334c593bbc18c5b31af56aa57d7818a3a7
MD5 eebba5fbfae8df67bb1cf76186d249b1
BLAKE2b-256 e919d76bfeb1f3715a43cabb1b22cf1d274983b50c3942cb048b386ed7578d95

See more details on using hashes here.

File details

Details for the file hopsy-1.1.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hopsy-1.1.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2404da26226722527de0f0ce54e2aa7d61802f3aac75697de4cc999bae1cb159
MD5 45285d27ac223c843afedba62032a129
BLAKE2b-256 1af563a37a20e1c9b7e9d0b1c07f959f33b67d9c06ec91c12ab924bc73bd3688

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