Skip to main content

A python package for rounding polytopes.

Project description

PolyRound

PyPI version

Efficient random sampling in convex polytopes relies on a 'rounding' preprocessing step, in which the polytope is rescaled so that the width is as uniform as possible across different dimensions. PolyRound rounds polytopes on the general form:

$P:=\{x \in \mathcal{R}^n: A_{eq} x = b_{eq}, A_{ineq} x \leq b_{ineq}\}$ with matrices $A_{eq} \in \mathcal{R}^{m,n}$ and $A_{ineq} \in \mathcal{R}^{k,n}$ and vectors $b_{eq} \in \mathcal{R}^{m}$ and $b_{ineq} \in \mathcal{R}^{k}$.

This formulation often arises in Systems Biology as the flux space of a metabolic network.

As output, PolyRound produces a polytope on the form $P^{r}:=\{v \in \mathcal{R}^l: A^{r}_{ineq}v \leq b^{r}_{ineq}\}$ where $l \leq n$ and the zero vector is a stricly interior point. For transforming points back to the original space, it also provides a matrix $S \in \mathcal{R}^{n,l}$ and a vector $t \in \mathcal{R}^{n}$, so that $x=Sv + t$.

Currently, PolyRound is supported for python 3.7 to 3.9.

PolyRound no longer depends on a Gurobi installation and uses optlang (https://github.com/opencobra/optlang) to delegate linear programs to GLPK in case Gurobi is not installed. However, PolyRound is more reliable with Gurobi. Free Gurobi licenses for academic use can be obtained at https://www.gurobi.com/. Once the license is installed, gurobipy can be installed directly through pip, or by getting the optional requirements by 'pip install -r optional_requirements.txt'.

An easy example of how to get started is presented in the jupyter notebook cells below.

They show how to:

  1. create a polytope object from a file path
  2. simplify, reduce, and round a polytope in separate steps, togehter with some printed checks
  3. simplify, reduce and round a polytope in one step
  4. save the rounded polytope
import os
from PolyRound.api import PolyRoundApi
from PolyRound.static_classes.lp_utils import ChebyshevFinder
from PolyRound.settings import PolyRoundSettings
from pathlib import Path

model_path = os.path.join("PolyRound", "models", "e_coli_core.xml")
# Create a settings object with the default settings.
settings = PolyRoundSettings()
# Import model and create Polytope object
polytope = PolyRoundApi.sbml_to_polytope(model_path)
# Remove redundant constraints and refunction inequality constraints that are de-facto equalities.
# Due to these inequalities, the polytope is empty (distance from chebyshev center to boundary is zero)
x, dist = ChebyshevFinder.chebyshev_center(polytope, settings)
print(dist)
simplified_polytope = PolyRoundApi.simplify_polytope(polytope)
# The simplified polytope has non-zero border distance
x, dist = ChebyshevFinder.chebyshev_center(simplified_polytope, settings)
print(dist)
# Embed the polytope in a space where it has non-zero volume
transformed_polytope = PolyRoundApi.transform_polytope(simplified_polytope)
# The distance from the chebyshev center to the boundary changes in the new coordinate system
x, dist = ChebyshevFinder.chebyshev_center(transformed_polytope, settings)
print(dist)
# Round the polytope
rounded_polytope = PolyRoundApi.round_polytope(transformed_polytope)
# After rounding, the distance from the chebyshev center to the boundary is set to be close to 1
x, dist = ChebyshevFinder.chebyshev_center(rounded_polytope, settings)
print(dist)

# The chebyshev center can be back transformed into an interior point in the simplified space.
print(simplified_polytope.border_distance(rounded_polytope.back_transform(x)))
# simplify, transform and round in one call
one_step_rounded_polytope = PolyRoundApi.simplify_transform_and_round(polytope)
# save to csv
out_csv_dir = os.path.join("PolyRound", "output", "e_coli_core")
Path(out_csv_dir).mkdir(parents=True, exist_ok=True)
PolyRoundApi.polytope_to_csvs(one_step_rounded_polytope, out_csv_dir)
# Special use case: remove redundant constraints without removing zero facettes. This will leave th polytope with its original border distance.
x, dist = ChebyshevFinder.chebyshev_center(polytope, settings)
print(dist)
settings.simplify_only = True
simplified_polytope = PolyRoundApi.simplify_polytope(polytope, settings=settings)
# The simplified polytope still has zero border distance
x, dist = ChebyshevFinder.chebyshev_center(simplified_polytope, settings)
print(dist)

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

PolyRound-0.2.10.tar.gz (37.2 kB view details)

Uploaded Source

Built Distribution

PolyRound-0.2.10-py3-none-any.whl (42.4 kB view details)

Uploaded Python 3

File details

Details for the file PolyRound-0.2.10.tar.gz.

File metadata

  • Download URL: PolyRound-0.2.10.tar.gz
  • Upload date:
  • Size: 37.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for PolyRound-0.2.10.tar.gz
Algorithm Hash digest
SHA256 c3f1d4000574564663e96165b80aeb4f9d82bb33335d8bdcf0679ff42a27e7a7
MD5 76c4b5d7fec0c82cc3d09450159ef830
BLAKE2b-256 591dfb7980ae1960924ea8479733686f9ff206291c33fa83683199685a17e5ac

See more details on using hashes here.

File details

Details for the file PolyRound-0.2.10-py3-none-any.whl.

File metadata

  • Download URL: PolyRound-0.2.10-py3-none-any.whl
  • Upload date:
  • Size: 42.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for PolyRound-0.2.10-py3-none-any.whl
Algorithm Hash digest
SHA256 7c6b9cb4a158c2673439c17596182dc6ef4fd4bc792d8a17800aa52cd525da3b
MD5 32971868c3875028b5a8b1c81608b9df
BLAKE2b-256 1f35909433bcc9d409307bd1c4b67bd679fd87aab4c269201cfd94f8c780f691

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