Skip to main content

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

Project description

hopsy - a methods marketplace for convex polytope sampling powered by the C++ library HOPS

pipeline status docstring coverage license: MIT

HOPSY Logo

hopsy is a versatile open-source domain-agnostic platform for (MCMC)-sampling convex polytopes

P = {x : Ax ≤ b},

which appear in many domains:

  • metabolic flux analysis
  • ecological modeling
  • optimization of chromatography pipelines
  • Bayesian multi criteria decision analysis in economics
  • Bell scenarios in quantum mechanics
  • ...

hopsy is a Python3 package powered by the C++ library HOPS. Using pybind11 hopsy calls and extends HOPS with a range of useful features, bringing the performance of C++ and simplicity of Python together in one package. Details and more use-cases are described here.

Installation

hopsy can be easily installed from the Python Package Index using pip install hopsy. It is also possible to install the source dist on pypi in case there is no wheel for your particular OS yet.

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

Citing

If you like hopsy and used it in your scientific work, please cite our paper

@article{10.1093/bioinformatics/btae430,
    author = {Paul, Richard D and Jadebeck, Johann F and Stratmann, Anton and Wiechert, Wolfgang and Nöh, Katharina},
    title = "{hopsy — a methods marketplace for convex polytope sampling in Python}",
    journal = {Bioinformatics},
    volume = {40},
    number = {7},
    pages = {btae430},
    year = {2024},
    month = {07},
    issn = {1367-4811},
    doi = {10.1093/bioinformatics/btae430},
    url = {https://doi.org/10.1093/bioinformatics/btae430},
}

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.5.2.tar.gz (12.0 MB view details)

Uploaded Source

Built Distributions

hopsy-1.5.2-cp312-cp312-win_amd64.whl (991.0 kB view details)

Uploaded CPython 3.12 Windows x86-64

hopsy-1.5.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

hopsy-1.5.2-cp312-cp312-macosx_14_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.12 macOS 14.0+ ARM64

hopsy-1.5.2-cp311-cp311-win_amd64.whl (976.0 kB view details)

Uploaded CPython 3.11 Windows x86-64

hopsy-1.5.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

hopsy-1.5.2-cp311-cp311-macosx_14_0_arm64.whl (732.7 kB view details)

Uploaded CPython 3.11 macOS 14.0+ ARM64

hopsy-1.5.2-cp310-cp310-win_amd64.whl (973.6 kB view details)

Uploaded CPython 3.10 Windows x86-64

hopsy-1.5.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

hopsy-1.5.2-cp310-cp310-macosx_14_0_arm64.whl (731.2 kB view details)

Uploaded CPython 3.10 macOS 14.0+ ARM64

hopsy-1.5.2-cp39-cp39-win_amd64.whl (973.5 kB view details)

Uploaded CPython 3.9 Windows x86-64

hopsy-1.5.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

hopsy-1.5.2-cp39-cp39-macosx_14_0_arm64.whl (731.2 kB view details)

Uploaded CPython 3.9 macOS 14.0+ ARM64

hopsy-1.5.2-cp38-cp38-win_amd64.whl (973.6 kB view details)

Uploaded CPython 3.8 Windows x86-64

hopsy-1.5.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

hopsy-1.5.2-cp38-cp38-macosx_14_0_arm64.whl (730.9 kB view details)

Uploaded CPython 3.8 macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hopsy-1.5.2.tar.gz
  • Upload date:
  • Size: 12.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for hopsy-1.5.2.tar.gz
Algorithm Hash digest
SHA256 c3e544bf6a6bd57e84a8c1412510b3a212e4151c53e7cd7047978f5d3513cf78
MD5 6ac004f6d25439af2186bf8e205d4f15
BLAKE2b-256 af27adb4fbf095bcd5d4acdebfbb8f44debe980171441126790d633b71310039

See more details on using hashes here.

File details

Details for the file hopsy-1.5.2-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: hopsy-1.5.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 991.0 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for hopsy-1.5.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 fa85b5d797c302556d5e88f379c17e859411b71b4d49a3492ec3aa91fc7c8c64
MD5 fe12bf9a6e2020e4cabcc80b985462c6
BLAKE2b-256 f8240cd3cb6ef85018ca544ab43fe0c8964dc3dbce787e02b9758865ac3a4cc3

See more details on using hashes here.

File details

Details for the file hopsy-1.5.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hopsy-1.5.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e0a77ce2a4a4b508d4dad7602cd9061b04202fe270f0f319fb6cd706a3fb42c0
MD5 3c62ecd8b9708aa3b0b4e9d7821fcfa4
BLAKE2b-256 0aa288a29df7b78b29b42b9a31d6d2ba3f9af07580261c8b5cec9215ec78f383

See more details on using hashes here.

File details

Details for the file hopsy-1.5.2-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for hopsy-1.5.2-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 ff95ec20f1b67543ff30190d89e0cfa8b41bcf6c69de7f86c4b6505e355469a1
MD5 e460863a1ba3095a87d4d647b96cdf53
BLAKE2b-256 290b8f4330800c39aa4e1ad9f49261b28bb407e8be2214c5c51196323bf646e7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopsy-1.5.2-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 976.0 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for hopsy-1.5.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 2e628949bb6bf894376788e842e1ee4ae67b767d5742611ba2ecd3a88900d8b8
MD5 a8349ca6e4f3eeaeb9b12e5eaac5da99
BLAKE2b-256 efbbc8801429ec31e70268b3691ea85d08ab40c3a47ff214c4381f146207ab9d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.5.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6dfc4aad366cfd040b1068c8baa6ab5e1bda3e05ceb7e67ec57aa8d675781f72
MD5 54cc3a5f70284c7bb3f88de00b93d8e1
BLAKE2b-256 fbc0a6f023a1eb058834bef766a4cd7ba703e05ee6098f2c5d7ec4f9381c9d3f

See more details on using hashes here.

File details

Details for the file hopsy-1.5.2-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for hopsy-1.5.2-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 86a89fa52bd71e19a7b89655352bc3cf2b0aa454b0e00684300dd3bc286d5494
MD5 377f314b33bf74721c5120933cc7d10b
BLAKE2b-256 e389b7a19f5a4a04d6699f57da4df51e4e26eeefae13362a18e9701888d31513

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopsy-1.5.2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 973.6 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for hopsy-1.5.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 5994c324b225d6b9e0e1bd183b79c0d2b28e0b71c137de21ee9b33cd095c0d97
MD5 57d66e09d78ab36de6e4f63bf56e9336
BLAKE2b-256 eaa3909e86f1f1f78c32376d4d5bdcd4805562d8cf1e1b3653947ddb6434e13d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.5.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cdfffaf0c3c47b87dd266e9225b4f18ca8f549e9046f1d7a364b31766d969b3b
MD5 06ba100a2577cd5de81180042f667a6b
BLAKE2b-256 a3871e60e2faba8907ab9a59b9481641d5faeeb6d3ba84ca8c343343c67d0db6

See more details on using hashes here.

File details

Details for the file hopsy-1.5.2-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for hopsy-1.5.2-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 bacdc386fb49e3dbe95de8bc814b365f60b769847c8a4cee46a544a911d46867
MD5 cdf6bb68df7177a122adecece55e8425
BLAKE2b-256 8ae9a52fa1e4407d4a0a29627238c7cf4eab811733ac9cce1396bd81df1ab61c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopsy-1.5.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 973.5 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for hopsy-1.5.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 cb8dedd94e5114f178f57f976cdc0449de1108cb5e65c65f3a85b929196f1622
MD5 139f63dd4aa59d70058b80e8c0db4abb
BLAKE2b-256 a00b37bab37c19797e737b3efdd58e13c829008ac9f23172e8699618771a91d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.5.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ea6e0444f34e4cd8aca4e88941ea4279e513296af9390d0b301b5f383a77b5c6
MD5 eef983c56846d5d7d6b648e9c2333582
BLAKE2b-256 b3e87c1c16973eb4fab1ef7cc419fae4726da757836f049fbadd331bb38ff4ef

See more details on using hashes here.

File details

Details for the file hopsy-1.5.2-cp39-cp39-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for hopsy-1.5.2-cp39-cp39-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 92ba6a91f50aac1c39d517aad06dda801dbdae9190f74e9b50b889a38732f633
MD5 de316fa9b0a4ae8b9e917c83303722bc
BLAKE2b-256 0d8f6c561ca7957808e03f3b18a099e0ff2d67ebd9434e2ccadcc4208fa50cd5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopsy-1.5.2-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 973.6 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for hopsy-1.5.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 2359e7a1c1d31234b800dfee5962022873730c33a1683acff0ffe57e93b5b57d
MD5 5868da65a717ebf8c6efdf8253565139
BLAKE2b-256 f4cb86eed12b2fb5f6bda6e8cee6236c288eb06f30f4495698febadd6c86d6ad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.5.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 353d24f2b6943bb9a3c81e001c12eaa32e3cef6ab497730b6a41a60f6b53102c
MD5 c2468faca48f81a04a2be2a3b69bb4b1
BLAKE2b-256 abe3b995f5ea9c326fe9379fc4c3e21d5e98f88ee61028f7db725ce26e21da8c

See more details on using hashes here.

File details

Details for the file hopsy-1.5.2-cp38-cp38-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for hopsy-1.5.2-cp38-cp38-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 ed4e7d26063a175bfba26a93a077ed1799df4ba957e0990508c0f8e1de0967ff
MD5 05ef60cfa7fd9fcf660502ef1050f716
BLAKE2b-256 77c330d3cfe75fdd0dfb886ae3e62cecda9a65c0fe86124f3f3a801ed8296ede

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