Skip to main content

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

Project description

hopsy - Python bindings for HOPS

pipeline status docstring coverage

A python interface for HOPS - the Highly Optimized toolbox for Polytope Sampling. Built using pybind11

HOPSY Logo

hopsy is a Python package for Markov chain Monte Carlo sampling on convex polytopes

P = {x : Ax ≤ b},

which often arises in metabolic flux analysis.

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

Uploaded Source

Built Distributions

hopsy-1.3.0-cp311-cp311-win_amd64.whl (4.6 kB view details)

Uploaded CPython 3.11 Windows x86-64

hopsy-1.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (804.9 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

hopsy-1.3.0-cp311-cp311-macosx_10_15_x86_64.whl (748.3 kB view details)

Uploaded CPython 3.11 macOS 10.15+ x86-64

hopsy-1.3.0-cp310-cp310-win_amd64.whl (823.6 kB view details)

Uploaded CPython 3.10 Windows x86-64

hopsy-1.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (804.0 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

hopsy-1.3.0-cp310-cp310-macosx_10_15_x86_64.whl (727.3 kB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

hopsy-1.3.0-cp39-cp39-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.9 Windows x86-64

hopsy-1.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (804.2 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

hopsy-1.3.0-cp39-cp39-macosx_10_15_x86_64.whl (727.3 kB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

hopsy-1.3.0-cp38-cp38-win_amd64.whl (820.7 kB view details)

Uploaded CPython 3.8 Windows x86-64

hopsy-1.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (803.2 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

hopsy-1.3.0-cp38-cp38-macosx_10_15_x86_64.whl (727.2 kB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

hopsy-1.3.0-cp37-cp37m-win_amd64.whl (844.5 kB view details)

Uploaded CPython 3.7m Windows x86-64

hopsy-1.3.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (821.9 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

hopsy-1.3.0-cp37-cp37m-macosx_10_15_x86_64.whl (733.9 kB view details)

Uploaded CPython 3.7m macOS 10.15+ x86-64

File details

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

File metadata

  • Download URL: hopsy-1.3.0.tar.gz
  • Upload date:
  • Size: 6.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for hopsy-1.3.0.tar.gz
Algorithm Hash digest
SHA256 7f4d4bde2a1cf89af334ca7f970b9c3defb4c79d89d1cb1495fb1ce0db0580c8
MD5 9fd804e92949174257e47507dd313c7c
BLAKE2b-256 d140f91d7e46b541db54f7a878a74c1d92cdb2e9ab542aad96f87a18240e71ad

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopsy-1.3.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for hopsy-1.3.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3a5ecb99046451089635829bf326dea0c4b7be4c54f0300a12c1ae083e1fb21f
MD5 ff6c0fde564b539ead0b7c8fc59df21a
BLAKE2b-256 1906c186bbd5da2bb05fa9c00edf70379898465cbc87cd2a80c137502d1a7577

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4ce13e026139d507cf90baff314caead657f0637bfdf5a4535f5c088ba918e0d
MD5 9cec9367e26202d22e6c6a71576ba35c
BLAKE2b-256 0372f7dfeb1fcd6846dc59016b2ad6aeaced455df216f76dc0ab499f07b48b98

See more details on using hashes here.

File details

Details for the file hopsy-1.3.0-cp311-cp311-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for hopsy-1.3.0-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 82a097985dd7cac0eed8acb40fd2756f170b6b88b186c4ccdf54119411fb5a10
MD5 0852811cbce15af1e81a1d57651bbd5d
BLAKE2b-256 d004b79dfef615e0e3f7cfdd26d6f8532af8927f66e1883171410e13b2d3f790

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopsy-1.3.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 823.6 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for hopsy-1.3.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d7a8e7080908ffee5ff8666b081f2977c51679f6352bd9ad17fd21902014bf42
MD5 63449cd834426bbcd5acb973c20ecdd5
BLAKE2b-256 f9069ca3ef7d2c0872a7eda73bc15537d0c52a691b6dc887f0d882104efba881

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a89d7ec7646bb2a56c39ba0eab746d3c4e7edca4649e9bd0a3f3ab9e298415f8
MD5 3d8a18fa971017e919a72400f7da175e
BLAKE2b-256 d0694373923976ab16babd1e3c2f43fffa2c1fa6356f24c78bc24a19bae8c903

See more details on using hashes here.

File details

Details for the file hopsy-1.3.0-cp310-cp310-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for hopsy-1.3.0-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 08388b14b1f523562eca5dda90957621ad8caaad34b85c472e844bf8ab8fd703
MD5 60a4458222631e4c1c6e2cca42f0f7d4
BLAKE2b-256 9ddf21d7974277bb5f86549ac28e0a0ddbe32241bf7b9638fc42b5cfeeca0dac

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopsy-1.3.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for hopsy-1.3.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 269c74f08d0fe86675f653dacaf999c85c97529a4237c2ab5b3863c3076c8b8b
MD5 c0c1b20b9edccbf36cca2dcd1bc2f3a0
BLAKE2b-256 a707e65f3b870b883b8cbeacdaac1578739948ae354c958c4a42a4a8752d133b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9b7abff211dc5539e6ee501702e8cb38162426085fc52810b5baec3bf8815cd1
MD5 5a7692ead5d07a9fa13e80a1a1fea286
BLAKE2b-256 9e900ddf4d7d84fa7b8608fb870f4794d6a931a3bfde84788c701429cf4c433d

See more details on using hashes here.

File details

Details for the file hopsy-1.3.0-cp39-cp39-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for hopsy-1.3.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 bedf6c955649c8accd5d53451ff94e8fe5f0974a783affbf00ce85abd7c0bc4c
MD5 ff20125f4540ddac47dbd85e696d841f
BLAKE2b-256 c9b60ac3ff8abe9201707068a2e56a585608ee3c0bc94add4ef70889e58b71f1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hopsy-1.3.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 820.7 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for hopsy-1.3.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 9b113a58a8f2557d8504fcdc19c4dfa6c5f9731e0151aef55e5588ed3c41ca75
MD5 8693448f885197a1e15a6c0c6dca6526
BLAKE2b-256 588eb4afad75cb2c5d273e19b98746f2850b3634f3699cc73ba637351c77f423

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hopsy-1.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 68b0fdc1d9a94791de723cb1dd72bb6b591379c6ac73cd10ade864daa01dcc47
MD5 de9ec6e5acece8045dc3d3a5ee6a3642
BLAKE2b-256 1aa0727f8b5d51f3fa450cfa59bd41e50b6c39a8435df2c49a74f9558aac1841

See more details on using hashes here.

File details

Details for the file hopsy-1.3.0-cp38-cp38-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for hopsy-1.3.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 55ca87e27fd15ca8ea15edc7e2510ed10a37645775ac7b5e173e9edc31982661
MD5 9cf136da762533d4e1be268f205b24b0
BLAKE2b-256 4f10f3a0c990f284a42f5e80081dd680cf4314d16b11ec6b4e0f107f2a8c455a

See more details on using hashes here.

File details

Details for the file hopsy-1.3.0-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: hopsy-1.3.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 844.5 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for hopsy-1.3.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 323922ede3805506575545ea868941a3371a1e547484498d2e081b224207ccbf
MD5 d85394552e6b9715b8ed2d76748267ab
BLAKE2b-256 6ca506c6e4be9035f6740476d475657db62ba17ffa7c71bc0d10a24836f3d037

See more details on using hashes here.

File details

Details for the file hopsy-1.3.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hopsy-1.3.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9f33bb14056b6e42f53b8c8ede8fb0002e00fa30ec3c90d0712df62e26cee887
MD5 e76127f164ad089478d3c2a841184a0e
BLAKE2b-256 2a433e2f86e941475fd957cf40732fe9e77e05e85697b134c078d7c7f3fa5b0a

See more details on using hashes here.

File details

Details for the file hopsy-1.3.0-cp37-cp37m-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for hopsy-1.3.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 d16be59f07c5ad7547966dc3f10d028c3054d87428dd1bd9c83913c8d9efbd35
MD5 b9b7190b393212ecbdf1f73c2db11cea
BLAKE2b-256 88282a9d7f601dd634669688b5edaddb099b52a0883ba2e7712130a8606f3da0

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