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.6.1.tar.gz (7.3 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.6.1-cp313-cp313-win_amd64.whl (961.8 kB view details)

Uploaded CPython 3.13Windows x86-64

hopsy-1.6.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (991.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

hopsy-1.6.1-cp313-cp313-macosx_14_0_arm64.whl (736.1 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

hopsy-1.6.1-cp312-cp312-win_amd64.whl (961.9 kB view details)

Uploaded CPython 3.12Windows x86-64

hopsy-1.6.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (992.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

hopsy-1.6.1-cp312-cp312-macosx_14_0_arm64.whl (736.0 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hopsy-1.6.1-cp311-cp311-win_amd64.whl (944.9 kB view details)

Uploaded CPython 3.11Windows x86-64

hopsy-1.6.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (989.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

hopsy-1.6.1-cp311-cp311-macosx_14_0_arm64.whl (730.0 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hopsy-1.6.1-cp310-cp310-win_amd64.whl (942.1 kB view details)

Uploaded CPython 3.10Windows x86-64

hopsy-1.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (987.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

hopsy-1.6.1-cp310-cp310-macosx_14_0_arm64.whl (728.6 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

hopsy-1.6.1-cp39-cp39-win_amd64.whl (942.0 kB view details)

Uploaded CPython 3.9Windows x86-64

hopsy-1.6.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (988.3 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

hopsy-1.6.1-cp39-cp39-macosx_14_0_arm64.whl (728.7 kB view details)

Uploaded CPython 3.9macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hopsy-1.6.1.tar.gz
  • Upload date:
  • Size: 7.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for hopsy-1.6.1.tar.gz
Algorithm Hash digest
SHA256 1eb812a0ad42c34ef4c4e949ad804b4860f18795c9447954e175bcbd4b1edf64
MD5 81f9f7bff8d64981f46ab05f6ac25335
BLAKE2b-256 a051164517fc870771d17b3dd9d0afef23b128dc22352688069e238916dec309

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopsy-1.6.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 961.8 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for hopsy-1.6.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 53d49094e96edd7e6b425c62006eae9aeb878fb41ae63cedc54639f685a62f69
MD5 74e0b14ee2d3195680c475002fc6e1da
BLAKE2b-256 1e37751ab1e34c8e900737e9d964f63a4dd7e1502684c98c7ef8b1875d24703e

See more details on using hashes here.

File details

Details for the file hopsy-1.6.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hopsy-1.6.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fdfb78fc445f0f70a2d7025ac42e02de34d2eac457892fd2cdd1f91826fdcece
MD5 cedd5d61cfd618e57a84b2c57e7e1e6f
BLAKE2b-256 ca21537996d2328368323f08ac9d02fa2e158df63acc210bf19a2dd7ffa28bb5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.6.1-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 2675e0dba93591d5ff144b5d573d1867f09eac71e6c596f59d09390ab068b587
MD5 62e94e33496fdff6505971251af27dc9
BLAKE2b-256 fecdb99bee05141201d7a280b2da0902f59dfda0ba7c96bb34fd53ed7ef3f955

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopsy-1.6.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 961.9 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for hopsy-1.6.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 efed7a7ec3e58e40055eb70d4694a59ca117ee04930528a8b95824d2f02371f3
MD5 b9f22e12bfc014f8efd57963b0ce8da1
BLAKE2b-256 51f8612cfaaa6943e27257a22baeb5351c30dc96f0cc8c717457866ef377aba6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.6.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 42843d9fc38d99df1861bc0965a87ecc57c52b11cf4dd1d224b4c9bc8f095eba
MD5 6d1d72edd48bf41a753858bf770fcc0d
BLAKE2b-256 c2ae51077c9eb7aeb51e2f3d6e16fea6930931ad55e73692d19c1da83870f30e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.6.1-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 84d6efa0202dcd7aab716fe240525f32482e90f1d7b8eea07b29d25254b4fc2e
MD5 257916b28715190b4e4df8d23e458eb4
BLAKE2b-256 e586f94eb3f6a5f88e37e53ab45be32240a569ade754d7051003448bc4278e99

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopsy-1.6.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 944.9 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for hopsy-1.6.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 20dfc5020a18fde834c38661edb8ea3f1b9c4245f282d79619afe798e0620336
MD5 97ec9e9b79d59c7c79bf566ac4251398
BLAKE2b-256 042b8f2cf2cc1cb4891c8ddaa5dbb7420809bf0674b82b3bc63fcf1f662880af

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.6.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5b8fc6257a71ebd06d1a967cae41151d2b31fe490bd3e8c246db14ae7549820a
MD5 2154ad5c7078c3e66d99c48e716252ff
BLAKE2b-256 be4b1ff628b101104c61d600e8701a20a593721f810a517ac5b95de6a79b95c8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.6.1-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 0ab345af6d585111a45905357f06ada13dc30a70599a23925b896cec9ed9048a
MD5 c7eb5c092de102c0b408d7fe58addeae
BLAKE2b-256 7f9e5a8ff4b789477fe38d745a737505a181015366e1bed39d4fae037cd4daf3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopsy-1.6.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 942.1 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for hopsy-1.6.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 6f621fba6e13b839c2206796b5688a9d4bf0597b7db130ef7af39a8acc417954
MD5 d8c25ea241d9411be27ee12bd8e75794
BLAKE2b-256 a7e49066c89d7ff73928451c0f87fb40d13f2f27bea8849091e4081ec364f735

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 da0420f6efd6cc920eec2650af586882181781edc1d3232144afee470b1554ec
MD5 f0f72297332b5e29ed4bf1a51693e21d
BLAKE2b-256 e2c10335645a3a5f13f4a48e3d4de80a721fea28e0e9347f3eaeb1b97879544c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.6.1-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 2e8db935b05ef724c510752a7c5317ca552ba5664783fe76d7658026a157ee2c
MD5 afd40092f3a6d4f37199b50ecf62a7ba
BLAKE2b-256 9c3c508fd0ea92eb0a44a9ebfc15fe16241e81f94543ccee3a74bd60abd39afe

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopsy-1.6.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 942.0 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for hopsy-1.6.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 9e02d51cee80d9da607a194eb2ba8a9d8d1372e02418999f40b62ebba681937a
MD5 efaa1e128fd4948b7353e5b74972b9a9
BLAKE2b-256 1831231d029a73470b4acd25ddb098768155b7934cf3d919f526d50bbf9b1851

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.6.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8a6602cd333fbf1cac47c63a0030c546f8d909a381b049d2a2dbcbb3a6996c6a
MD5 3faadbc7e9eead84a3148b31abe34b94
BLAKE2b-256 afe76e09a790482b972a93cf1fd676b7e63254082b6d9544199e4bde726c447d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopsy-1.6.1-cp39-cp39-macosx_14_0_arm64.whl
  • Upload date:
  • Size: 728.7 kB
  • Tags: CPython 3.9, macOS 14.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for hopsy-1.6.1-cp39-cp39-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 8bad93270257e0ca7caf6c7074bf4aedf08a8e82985d08c0a5cd94b464f2f1e8
MD5 17b4bc14d1dc53587cf650b56d311dd3
BLAKE2b-256 e6374e5e3b1c495a851cebe2b3ab6d1b2597cf82b2427ec7522227b4e831223f

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