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)

MPI support for parallel tempering

If you want to use the parallel tempering implemented in hops, you need a working MPI installation, because threads would not work due to the python GIL. The next step is to compile hopsy by source and to check that the script examples/parallel_tempering.py works. Both modes of the distribution should be found, otherwise there is some issue. In this case, please contact us.

In order to use parallel tempering, python interpreter must be called with MPI:

mpirun -np 10 parallel_tempering_application.py

In this case, 10 parallel chains would be constructed.

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

Development

The development of hopsy primarily takes place on (JuGit)[https://jugit.fz-juelich.de/IBG-1/ModSim/hopsy], where we have access to powerful continuous integration and a Docker registry. The GitHub repository is only a mirror, so please report issues and make pull requests on JuGit. Please install pre-commit before commiting to our repository, see pre-commit step in .gitlab-ci.yml.

Building docs & updading docs

docs-sources$ make html  # make will tell you which python packages you might be missing
docs-sources$ rm ../docs/* -r
docs-sources$ cp _build/html/* ../docs/ -r
docs-sources$ git add ../ docs && git commit -m "updated docs" && git push  # and so on...

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 Distribution

hopsy-1.2.0.tar.gz (20.9 kB view details)

Uploaded Source

Built Distributions

hopsy-1.2.0-cp311-cp311-win_amd64.whl (823.2 kB view details)

Uploaded CPython 3.11 Windows x86-64

hopsy-1.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (804.7 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

hopsy-1.2.0-cp310-cp310-win_amd64.whl (820.4 kB view details)

Uploaded CPython 3.10 Windows x86-64

hopsy-1.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (803.4 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

hopsy-1.2.0-cp39-cp39-win_amd64.whl (820.4 kB view details)

Uploaded CPython 3.9 Windows x86-64

hopsy-1.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (803.7 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

hopsy-1.2.0-cp38-cp38-win_amd64.whl (820.3 kB view details)

Uploaded CPython 3.8 Windows x86-64

hopsy-1.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (802.5 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

hopsy-1.2.0-cp37-cp37m-win_amd64.whl (844.0 kB view details)

Uploaded CPython 3.7m Windows x86-64

hopsy-1.2.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (822.0 kB view details)

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

File details

Details for the file hopsy-1.2.0.tar.gz.

File metadata

  • Download URL: hopsy-1.2.0.tar.gz
  • Upload date:
  • Size: 20.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for hopsy-1.2.0.tar.gz
Algorithm Hash digest
SHA256 7033e9dbb510b59e33d969f83aa136f0966b496823b4482d052e371b2d1919d8
MD5 afdbca2e5d306d6e866297c29106f1da
BLAKE2b-256 647bcc743c8742abea1ac2f080129b7fa7206015933746068a546968c09246fe

See more details on using hashes here.

File details

Details for the file hopsy-1.2.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: hopsy-1.2.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 823.2 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for hopsy-1.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 de2deeae6469d459376b6abedf965dcadde0672b33998cb5747065e91cf3dde3
MD5 90062c1590d3d68ba9fd205416848378
BLAKE2b-256 bd024e9da0b3981b7757565bb91bfcd5ca543cf8f7391512f8332c6431410489

See more details on using hashes here.

File details

Details for the file hopsy-1.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hopsy-1.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1c0c679fc269e8e9fe4eae3b78d83fb1a8e528d50f47a9f5c220f7edae9c48ff
MD5 d9ab4cf51bbf4114036b89882cd9d4f1
BLAKE2b-256 4945e850955dde4aed6ca45c90ce4b150c9cb4e7ef708235e3a403732a390431

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopsy-1.2.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 820.4 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for hopsy-1.2.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 623e9fe101573f7bfb3c6106b46578216fbfb57916a02c05f2b1805b887dace3
MD5 3c543f9068c2617b99e8b2442cd5fd98
BLAKE2b-256 2a6e538a3845f287b7b3e75ed867316ce758096803d2eec03abf2a5ec783f3dc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e865d2b58491088b0b55d86612fc383ae4c54fa54006b1ddf46777dfcaa1dfc4
MD5 6d9bddc976bd7fb4d366f530299af5c1
BLAKE2b-256 f5166399403a3196e3c31d153c4148567772d3108000eba0b717403016724704

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopsy-1.2.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 820.4 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for hopsy-1.2.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 c61d85e2a787d11e0e8ced8d9413c791c33cf889433190d50f107ec61e3e6ca5
MD5 b5d8776feebc83d91a648709bae5c531
BLAKE2b-256 4777af6bc34ac1efda4eb4ddee80580f06785ff5b7cd3c24dec19186d76c4731

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c56a043a6107ba3af345c3404b1f863b4d830f069e94de25378c2522d7ecfe97
MD5 21e4c2ccf5b5cb41d48b36ff8baae217
BLAKE2b-256 ce7e98508652b5f159ae6bfd3d970cf69ccdda3b109d43828a6322291e6cc357

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopsy-1.2.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 820.3 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for hopsy-1.2.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 3fc9034248981f8d3b46dda71a6babfa77df1e515c7157084b57bdf018922d07
MD5 459f4d6ca7926bdddbc9432ca4f514ba
BLAKE2b-256 d7818af9206af4df59b3bf2ee2c6a083a2f1ef3078b0ed1e07e6094536c2d47f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 562f9cea94ccd460241786af50fdc1e9c1c431ad6435a58c10c0ad6b8ee4df61
MD5 c15d8dcc1fb761cc66c3fcf6f2813e5b
BLAKE2b-256 d073c4e59eec5e46e47295743ae17b7ada57dbb9212ecb2f0dae0aedc448194e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopsy-1.2.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 844.0 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for hopsy-1.2.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 0897c719bb22bfb85b514bb6df5bf8ef60269b658b8cdbecea3a8d2dc73ef9ef
MD5 ae01da80f8fa9f442656d9c186554185
BLAKE2b-256 53874847ae6a666d6648e04345204903695519d90f0a0ce4bd85b9abf5ddcccc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.2.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a8669efe3f926d5df4db155630ee5deb8ffc46be2b9ff02692a1ca2499a3fde8
MD5 b1db2e0b575f0a151d6147fa10827970
BLAKE2b-256 0d6067f82141c091d164f79e599471644b0f0034774cc75990e9dc465f82536c

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