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

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

hopsy-1.7.0-cp314-cp314-win_amd64.whl (881.8 kB view details)

Uploaded CPython 3.14Windows x86-64

hopsy-1.7.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

hopsy-1.7.0-cp314-cp314-macosx_14_0_arm64.whl (756.4 kB view details)

Uploaded CPython 3.14macOS 14.0+ ARM64

hopsy-1.7.0-cp313-cp313-win_amd64.whl (882.0 kB view details)

Uploaded CPython 3.13Windows x86-64

hopsy-1.7.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

hopsy-1.7.0-cp313-cp313-macosx_14_0_arm64.whl (755.2 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

hopsy-1.7.0-cp312-cp312-win_amd64.whl (882.0 kB view details)

Uploaded CPython 3.12Windows x86-64

hopsy-1.7.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

hopsy-1.7.0-cp312-cp312-macosx_14_0_arm64.whl (755.2 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hopsy-1.7.0-cp311-cp311-win_amd64.whl (878.6 kB view details)

Uploaded CPython 3.11Windows x86-64

hopsy-1.7.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

hopsy-1.7.0-cp311-cp311-macosx_14_0_arm64.whl (749.1 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hopsy-1.7.0-cp310-cp310-win_amd64.whl (877.9 kB view details)

Uploaded CPython 3.10Windows x86-64

hopsy-1.7.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

hopsy-1.7.0-cp310-cp310-macosx_14_0_arm64.whl (747.6 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hopsy-1.7.0.tar.gz
  • Upload date:
  • Size: 17.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for hopsy-1.7.0.tar.gz
Algorithm Hash digest
SHA256 24659f594c6859823d887adc576f11667abcd2548f8e22341c313841e809fc1e
MD5 470840f04821f38ed91508c5607edf35
BLAKE2b-256 3e49b4c800828736a3c8b57555f694f06a59f0acee84996f8b35948703636f5b

See more details on using hashes here.

File details

Details for the file hopsy-1.7.0-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: hopsy-1.7.0-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 881.8 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for hopsy-1.7.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 3d15f0a978bee85560571d5a1e01d47dde91adb0d37cbfc0796418593b4406a3
MD5 c2e5e0a42a7a60635d299fb1f6dc5644
BLAKE2b-256 0a40cbdf04274323f12e9c3c252ea1e6f1754b1e7c561a2a4141ceffb9d42179

See more details on using hashes here.

File details

Details for the file hopsy-1.7.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for hopsy-1.7.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 55fc00e3f8206fa65ac317b220d560f1f172f10ed040bc40ed5b9ca345463e25
MD5 1f25eaf20bfadf2ad301787c13efe2e9
BLAKE2b-256 b669faa76743c59d6c99b4014acee721216d63b47201eec4584ae30cfc078167

See more details on using hashes here.

File details

Details for the file hopsy-1.7.0-cp314-cp314-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for hopsy-1.7.0-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 ef54f8eb3090e2f9fac10da594a8d740a7bac99f00c38d350f7904aee9c5a96c
MD5 3fb7ea3d08b5e1c38387ef18c42a8c61
BLAKE2b-256 96825a94d691251cba4957fdad18c6a435ecae2ff5450dbe36def34d2d764ba8

See more details on using hashes here.

File details

Details for the file hopsy-1.7.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: hopsy-1.7.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 882.0 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for hopsy-1.7.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 88144254cb8ecd920942cc12d60e9308f696b68da43e2c42958d1561b1e9c459
MD5 78807387f1e9f95ffc29036205d57bb2
BLAKE2b-256 ceee80e7eebc1e4e481e668a77fe35dd9033947e055c1bd957a5fa4c4e74f027

See more details on using hashes here.

File details

Details for the file hopsy-1.7.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for hopsy-1.7.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 636fdfb344772d27e89c60a350e4c8044aed290f176fc2484483fb7c64d16194
MD5 3e4e56e0a5f59dbcf9af0eb8770ffdbd
BLAKE2b-256 20fecde31d6d9427e1076634af8a0da767bc4f86e52ea1ac90e66d8ec010b755

See more details on using hashes here.

File details

Details for the file hopsy-1.7.0-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for hopsy-1.7.0-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 79e5aaa30f4f6d9e9250c07c16863735b79dd65f8687caba360367f49c894401
MD5 7c29fb7dce1c93e4d36c1ea6ba6ff0c2
BLAKE2b-256 0c48c6597905564fe4c4c6285e6eb5d30df3000cbfa6b9c9b61ada0d091b49ba

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopsy-1.7.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 882.0 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for hopsy-1.7.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 1d42ac1a875190b234c69a568e3899c32a9c00877f2b9534b855ee4860530815
MD5 6c637ff76ee0374834309d7307f522f1
BLAKE2b-256 a6b0c1e3535b6afd6ceb7da66e5e1833d9d4b19f52cd34b5ca5239cd847c1ba0

See more details on using hashes here.

File details

Details for the file hopsy-1.7.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for hopsy-1.7.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e52214b8b9b896c830e1897df20530f3f15df6b95abf87895c643f53f7d49b7c
MD5 0d551b589c3510e5e5c84406ab590255
BLAKE2b-256 4457726e2a83330cb726815ae87830b846bf4e5939b06fccd30ae55d01e62c93

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.7.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 f35ee99bddc343884a18705d8136f72686139a19af558f66c03ba67c4b572761
MD5 adfcd03a030dc257ebd740dca1ddade8
BLAKE2b-256 35df8d13d83d49a52aea0d1e593476984950d322bec068127982e288212cd40c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopsy-1.7.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 878.6 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for hopsy-1.7.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 e14c21b1f6c3b9e79b755ddbb47e429f4d46a6f1334f0b19f04941629745d1aa
MD5 64cab2cfe48e3e366aa69665c253dee9
BLAKE2b-256 5b76d419d668ba4133dd70afbbc537f59caee861b187dc8f5d72d7e63cb818e7

See more details on using hashes here.

File details

Details for the file hopsy-1.7.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for hopsy-1.7.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 217ea3e506b1dcca926c46f2375e7fac6018f694dd6ca4c6d26342b746adc8d9
MD5 68d220f1af4a29b5b6f670e0fa1c4725
BLAKE2b-256 1bbacc3000ba18bc4d6f24000df40c3434b3a495eb74fe4a38192ffdb3225a52

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.7.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c83c0f15a5233030377f5a7974ccbd6cb9a18e50ead4489e22371a7803b8e3a4
MD5 642794406075a5e36c91410b4473529e
BLAKE2b-256 11e8f30136fa6171686b247d1c8a355323cc69857bc18675ba20cb26117e627b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopsy-1.7.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 877.9 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for hopsy-1.7.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 2ee067ddaa612531820fe28894e333c8ffd8c521fb15ce41e6f0b4e5c9e76e9e
MD5 7eba76cb5ceef6b2e9aa4fb9d23d610a
BLAKE2b-256 e5dc8c9263422b3aee787fa5344b51e6ec0509070df239af9a3b84b7706368d3

See more details on using hashes here.

File details

Details for the file hopsy-1.7.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for hopsy-1.7.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 397cec7f809cc79cd3ca819fe25e06d0b666ed513a5b41ca1f2a2422439e69eb
MD5 9880730c31906c5ba2bb3b77ece1900f
BLAKE2b-256 e1cbf47a606fc1c59f91b9d33b09f85d9acc2580fa689c8a581a856c491bd7fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.7.0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 059b59a52015c62dbbc89ca58522769124cc91e96d61a0289ffe2bb1b0f5cc9c
MD5 3834396d740fc6720faac194ef8e8e5e
BLAKE2b-256 700803ca238ea12bdcffbef4a0d5be44b2d1c9e5d3fe98f19afa4932d061a2b4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page