Skip to main content

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...

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.

Metadata

Release files for hopsy 1.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hopsy 1.7.0
File Size Uploaded Provenance
hopsy-1.7.0.tar.gz 17.5 MB Without provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for hopsy 1.7.0
File
hopsy-1.7.0-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
hopsy-1.7.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
hopsy-1.7.0-cp314-cp314-macosx_14_0_arm64.whl CPython 3.14 CPython 3.14 macOS 14.0+ ARM64 Details
hopsy-1.7.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
hopsy-1.7.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
hopsy-1.7.0-cp313-cp313-macosx_14_0_arm64.whl CPython 3.13 CPython 3.13 macOS 14.0+ ARM64 Details
hopsy-1.7.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
hopsy-1.7.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
hopsy-1.7.0-cp312-cp312-macosx_14_0_arm64.whl CPython 3.12 CPython 3.12 macOS 14.0+ ARM64 Details
hopsy-1.7.0-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
hopsy-1.7.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
hopsy-1.7.0-cp311-cp311-macosx_14_0_arm64.whl CPython 3.11 CPython 3.11 macOS 14.0+ ARM64 Details
hopsy-1.7.0-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
hopsy-1.7.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
hopsy-1.7.0-cp310-cp310-macosx_14_0_arm64.whl CPython 3.10 CPython 3.10 macOS 14.0+ ARM64 Details

Total release size: 30.9 MB

Release files / hopsy-1.7.0.tar.gz

Download URL hopsy-1.7.0.tar.gz
Size 17.5 MB
Tags Source
SHA-256 checksum
How to use checksums
24659f594c6859823d887adc576f11667abcd2548f8e22341c313841e809fc1e
BLAKE2b-256 checksum
How to use checksums
3e49b4c800828736a3c8b57555f694f06a59f0acee84996f8b35948703636f5b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / hopsy-1.7.0-cp314-cp314-win_amd64.whl

Download URL hopsy-1.7.0-cp314-cp314-win_amd64.whl
Size 881.8 kB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
3d15f0a978bee85560571d5a1e01d47dde91adb0d37cbfc0796418593b4406a3
BLAKE2b-256 checksum
How to use checksums
0a40cbdf04274323f12e9c3c252ea1e6f1754b1e7c561a2a4141ceffb9d42179
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / hopsy-1.7.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL hopsy-1.7.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 1.0 MB
Tags CPython 3.14 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
55fc00e3f8206fa65ac317b220d560f1f172f10ed040bc40ed5b9ca345463e25
BLAKE2b-256 checksum
How to use checksums
b669faa76743c59d6c99b4014acee721216d63b47201eec4584ae30cfc078167
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / hopsy-1.7.0-cp314-cp314-macosx_14_0_arm64.whl

Download URL hopsy-1.7.0-cp314-cp314-macosx_14_0_arm64.whl
Size 756.4 kB
Tags CPython 3.14 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
ef54f8eb3090e2f9fac10da594a8d740a7bac99f00c38d350f7904aee9c5a96c
BLAKE2b-256 checksum
How to use checksums
96825a94d691251cba4957fdad18c6a435ecae2ff5450dbe36def34d2d764ba8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / hopsy-1.7.0-cp313-cp313-win_amd64.whl

Download URL hopsy-1.7.0-cp313-cp313-win_amd64.whl
Size 882.0 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
88144254cb8ecd920942cc12d60e9308f696b68da43e2c42958d1561b1e9c459
BLAKE2b-256 checksum
How to use checksums
ceee80e7eebc1e4e481e668a77fe35dd9033947e055c1bd957a5fa4c4e74f027
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / hopsy-1.7.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL hopsy-1.7.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 1.0 MB
Tags CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
636fdfb344772d27e89c60a350e4c8044aed290f176fc2484483fb7c64d16194
BLAKE2b-256 checksum
How to use checksums
20fecde31d6d9427e1076634af8a0da767bc4f86e52ea1ac90e66d8ec010b755
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / hopsy-1.7.0-cp313-cp313-macosx_14_0_arm64.whl

Download URL hopsy-1.7.0-cp313-cp313-macosx_14_0_arm64.whl
Size 755.2 kB
Tags CPython 3.13 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
79e5aaa30f4f6d9e9250c07c16863735b79dd65f8687caba360367f49c894401
BLAKE2b-256 checksum
How to use checksums
0c48c6597905564fe4c4c6285e6eb5d30df3000cbfa6b9c9b61ada0d091b49ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / hopsy-1.7.0-cp312-cp312-win_amd64.whl

Download URL hopsy-1.7.0-cp312-cp312-win_amd64.whl
Size 882.0 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
1d42ac1a875190b234c69a568e3899c32a9c00877f2b9534b855ee4860530815
BLAKE2b-256 checksum
How to use checksums
a6b0c1e3535b6afd6ceb7da66e5e1833d9d4b19f52cd34b5ca5239cd847c1ba0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / hopsy-1.7.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL hopsy-1.7.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 1.0 MB
Tags CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
e52214b8b9b896c830e1897df20530f3f15df6b95abf87895c643f53f7d49b7c
BLAKE2b-256 checksum
How to use checksums
4457726e2a83330cb726815ae87830b846bf4e5939b06fccd30ae55d01e62c93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / hopsy-1.7.0-cp312-cp312-macosx_14_0_arm64.whl

Download URL hopsy-1.7.0-cp312-cp312-macosx_14_0_arm64.whl
Size 755.2 kB
Tags CPython 3.12 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
f35ee99bddc343884a18705d8136f72686139a19af558f66c03ba67c4b572761
BLAKE2b-256 checksum
How to use checksums
35df8d13d83d49a52aea0d1e593476984950d322bec068127982e288212cd40c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / hopsy-1.7.0-cp311-cp311-win_amd64.whl

Download URL hopsy-1.7.0-cp311-cp311-win_amd64.whl
Size 878.6 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
e14c21b1f6c3b9e79b755ddbb47e429f4d46a6f1334f0b19f04941629745d1aa
BLAKE2b-256 checksum
How to use checksums
5b76d419d668ba4133dd70afbbc537f59caee861b187dc8f5d72d7e63cb818e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / hopsy-1.7.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL hopsy-1.7.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 1.0 MB
Tags CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
217ea3e506b1dcca926c46f2375e7fac6018f694dd6ca4c6d26342b746adc8d9
BLAKE2b-256 checksum
How to use checksums
1bbacc3000ba18bc4d6f24000df40c3434b3a495eb74fe4a38192ffdb3225a52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / hopsy-1.7.0-cp311-cp311-macosx_14_0_arm64.whl

Download URL hopsy-1.7.0-cp311-cp311-macosx_14_0_arm64.whl
Size 749.1 kB
Tags CPython 3.11 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
c83c0f15a5233030377f5a7974ccbd6cb9a18e50ead4489e22371a7803b8e3a4
BLAKE2b-256 checksum
How to use checksums
11e8f30136fa6171686b247d1c8a355323cc69857bc18675ba20cb26117e627b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / hopsy-1.7.0-cp310-cp310-win_amd64.whl

Download URL hopsy-1.7.0-cp310-cp310-win_amd64.whl
Size 877.9 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
2ee067ddaa612531820fe28894e333c8ffd8c521fb15ce41e6f0b4e5c9e76e9e
BLAKE2b-256 checksum
How to use checksums
e5dc8c9263422b3aee787fa5344b51e6ec0509070df239af9a3b84b7706368d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / hopsy-1.7.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL hopsy-1.7.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 1.0 MB
Tags CPython 3.10 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
397cec7f809cc79cd3ca819fe25e06d0b666ed513a5b41ca1f2a2422439e69eb
BLAKE2b-256 checksum
How to use checksums
e1cbf47a606fc1c59f91b9d33b09f85d9acc2580fa689c8a581a856c491bd7fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / hopsy-1.7.0-cp310-cp310-macosx_14_0_arm64.whl

Download URL hopsy-1.7.0-cp310-cp310-macosx_14_0_arm64.whl
Size 747.6 kB
Tags CPython 3.10 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
059b59a52015c62dbbc89ca58522769124cc91e96d61a0289ffe2bb1b0f5cc9c
BLAKE2b-256 checksum
How to use checksums
700803ca238ea12bdcffbef4a0d5be44b2d1c9e5d3fe98f19afa4932d061a2b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Security for hopsy 1.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page