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

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

Uploaded Source

Built Distributions

hopsy-1.5.1-cp312-cp312-win_amd64.whl (990.0 kB view details)

Uploaded CPython 3.12 Windows x86-64

hopsy-1.5.1-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.1-cp312-cp312-macosx_14_0_arm64.whl (2.7 MB view details)

Uploaded CPython 3.12 macOS 14.0+ ARM64

hopsy-1.5.1-cp311-cp311-win_amd64.whl (975.0 kB view details)

Uploaded CPython 3.11 Windows x86-64

hopsy-1.5.1-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.1-cp311-cp311-macosx_14_0_arm64.whl (2.7 MB view details)

Uploaded CPython 3.11 macOS 14.0+ ARM64

hopsy-1.5.1-cp310-cp310-win_amd64.whl (972.4 kB view details)

Uploaded CPython 3.10 Windows x86-64

hopsy-1.5.1-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.1-cp310-cp310-macosx_14_0_arm64.whl (2.7 MB view details)

Uploaded CPython 3.10 macOS 14.0+ ARM64

hopsy-1.5.1-cp39-cp39-win_amd64.whl (972.7 kB view details)

Uploaded CPython 3.9 Windows x86-64

hopsy-1.5.1-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.1-cp39-cp39-macosx_14_0_arm64.whl (2.7 MB view details)

Uploaded CPython 3.9 macOS 14.0+ ARM64

hopsy-1.5.1-cp38-cp38-win_amd64.whl (972.4 kB view details)

Uploaded CPython 3.8 Windows x86-64

hopsy-1.5.1-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.1-cp38-cp38-macosx_14_0_arm64.whl (2.7 MB view details)

Uploaded CPython 3.8 macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hopsy-1.5.1.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.1.tar.gz
Algorithm Hash digest
SHA256 9cee816d394fd7648d7b3c2ca11c731bf66dc156004bd9e5fe4012313f412098
MD5 332aef3de9257f264515a12533741850
BLAKE2b-256 ab15772184e8fd85a4e82f7309b5800cccbd2eb7111d9a7417a4667c4db45fb6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopsy-1.5.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 990.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.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 cc37d3c0e45bcc14cdd1039a86f4c200faf4e50296aee88de8575ae95c1612a2
MD5 36eb9a2a45a07e95e1609abe8cbe5301
BLAKE2b-256 2b5d0e3e13b7e30b6584da21d98a105e7976ecabd0a2fdfd3e11bf236480b67b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.5.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cb5feed3f45a2c5affeedc4660f4189dc8fe6757bdc4f99485d29f5c0d794287
MD5 3a4ad83f4556faa244b91cd688381983
BLAKE2b-256 576e9c691a5ce67a080fc6e78e7de265c5945741f88dbf67e054bac5667f3183

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.5.1-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 982b01da1a218f7a9b16ad5b2460518396730ae92715bbdc886a3353d50bde43
MD5 3f6989bd969e58a6c415a1dd2fadbbb0
BLAKE2b-256 9cf802f4971349c2d4804333b78630ea7da96fa67b478c3867412cb76d55d3ea

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopsy-1.5.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 975.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.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 1654fa61c490b5363c8bc1c1a68a79913c10107f9fba6d75aaf75efb8a3e0a7d
MD5 d261bdd22dbab3e230ca3fc72af135a7
BLAKE2b-256 459b9a26f9f7fa79019a532a2516b23b1f8fe624f8a767425f29d002ea2c88ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.5.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 957791780ccc061c8a3e21dc1c427bffde578306e1e5d548c5efb9ba61d09759
MD5 9b8b12aa6d1eaf6e07e8404d11bf872a
BLAKE2b-256 8349126cfb41fc9795d17e252d00f8d25f2e4189a0365c144aa5d6f96d0ca7d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.5.1-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 61999bc7108eb459d17311a9eea08cfae91b3015309027eaab6f256a4ad5460a
MD5 b424e9ea32a71499f5da43e1f97714db
BLAKE2b-256 555bf4c55d929694a8866d68275a01c4d36cdf15c120c90bcdf46eac47effe18

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopsy-1.5.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 972.4 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.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 873e008ca38ccfec7dcce741b6cc75d0df2de3d4e8da031e0c5a890bf9ed46e6
MD5 eaa08542ad884db9c88d4233a01ea371
BLAKE2b-256 2ae47935a622425ceda9f4a26ece86bbe97899737bf1ee0896ddc66a4159b275

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.5.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cc76e499bb2dfbfbd5b2c792883039a86415b922e76c2cc23dfb2ae0e9b26c2c
MD5 77676784458d9ef43cd3242c21d6a1e9
BLAKE2b-256 1f76169b95f8aff55126a65141cbad852fcad01c805c0cef99beb3ebc020e5c9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.5.1-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e046084649b662a8724ca524e6efea21682b39ca2f7aa4ab9cad109a00ba1c37
MD5 ca75022af6e0acecc2450f51b0e82498
BLAKE2b-256 57c7610008d6144d15e91b48fce403b9c80ed797dc2f787d907727d452dd15c2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopsy-1.5.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 972.7 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.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 72521adc7bdfda70daf429c505cda861a4bba68db53e18c33497e937cb408318
MD5 ff7c507e262bbdc7dbf30baeda0912bc
BLAKE2b-256 365adb45b0d59f94401cb9d2d8fd9c24825b652a7c78816c3f490b24cd6a0a3f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.5.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5614fc0ec36aef3ec9ed5fe446978ba07f1b4580ab122b1a49c6c8e97fcd0340
MD5 3a87d9090f01b223cee439f936cd4078
BLAKE2b-256 b568c00dc2e3f37c13ccf9b4859bd580db57b7baab286d9b503463065f3ce957

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.5.1-cp39-cp39-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 4da21619d711a99ded1305ee45092a3ba3f63bc381d5c82a5ee298e8735c5fe6
MD5 e6cabab9bbb091edc853bdcf77436869
BLAKE2b-256 9b46bf0c6cff742c92b00ade2322194cd108e86820daf760a9bc7ccf3c670af0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopsy-1.5.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 972.4 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.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 cb419f6fceb4921fa86d89f857bd677096a9e54383f484729d54b72ad6537e44
MD5 a866dfc8153de2f4b6a7d4f3d1527640
BLAKE2b-256 c29a15c7b29ed5e350166269fad55e0ee95442f6294e830140e4638d0c2d31b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.5.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1269f79a1ade935be10c1cd53978af18521181b1c16735fc48639b86b3c0d7e5
MD5 5f0c412906551141a7eb20abcb6f7e9e
BLAKE2b-256 9593c6e9a7b2a5ee83f73976cfab87b04aa18064aea0cc4e6ba4df36249e6319

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.5.1-cp38-cp38-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e1339b33d25de5b49349c6d966fc77fb2ff78e3b8808e982fa05c75637a75f3c
MD5 22f0d94a9ca5c59db78379f20f612454
BLAKE2b-256 0667ab9ddb853de0366aaaa8bc7cbfdc0dc40bb7507981f771f5ab61c5401977

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