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

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

hopsy-1.0.0-cp39-cp39-win_amd64.whl (763.0 kB view details)

Uploaded CPython 3.9 Windows x86-64

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

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

hopsy-1.0.0-cp38-cp38-win_amd64.whl (762.8 kB view details)

Uploaded CPython 3.8 Windows x86-64

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

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

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

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

File details

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

File metadata

  • Download URL: hopsy-1.0.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 763.0 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.0.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d07f34e41b20eecc24a7563cfb7b8ea11685092861a70545db365ed9c815209c
MD5 2741bed886fcc0129e79615af408ae16
BLAKE2b-256 8010b57fbb325d7892f05276b04380c307d1979b940eb9c4599a9967b708c80f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 494071626d6d82619235cbe062c527a202474a7d7ad82940f72830cbc650da61
MD5 8730be53f5f25306eb41a13985399b17
BLAKE2b-256 59cfae878a15a9edded0d86d6127dbd7358297fe7f4462de71db83f9ba6028a8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopsy-1.0.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 763.0 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.0.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 41747fd17c3e0597ab9f48a6b76c4411ac5ac2b5d09f929f4941b13116b3a8e7
MD5 ad90c24e507a102c325d7a3a4a92e1fd
BLAKE2b-256 8a3c8a8dbcd6f45be21705dd08494dcd5d6b669c1b518db9d33d920423ff6bde

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 deb15ce41a03725e11dfb58342756c2aff66a1a0c04056c6f1966b9c30f5e658
MD5 9f53d462cacf00f9143b1061d1a32b47
BLAKE2b-256 b0f695c60a04de943d33949f699a746335567d010fbcd7e7beba7ea8aae78562

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopsy-1.0.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 762.8 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.0.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 0f55fb2b5ce7990f1919e52aa627dc7ebdd2fa4b206f9d8c549a716fdd218978
MD5 d6a7a2374945263be9d140b14a25d35a
BLAKE2b-256 523e3d152a7ce088f1606fcc42b20da5929794de50b4aa5ff3b36482d7654905

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 068f8738634297bd4b056d265cd5879c109c2d6c2076087804f991c547471814
MD5 77625ad5575f58216d0aebee3467a1a6
BLAKE2b-256 890c67a75ac1ec596d532047f20aa3e8a2c26fa64730cedce68168ee95bff8e6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.0.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d4a685d8f63463fa36c1046428ebdb7881d270cac008cd4e2aa8aeb5a12b3f42
MD5 cd0c27f75dbf06756472f73d9bad2d61
BLAKE2b-256 298c63de232d5fa55a328e94709773e29e51490ffe92521d4234a6765a62b245

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