A python package for rounding polytopes.
Project description
PolyRound
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:
with matrices and and vectors and .
This formulation often arises in Systems Biology as the flux space of a metabolic network.
As output, PolyRound produces a polytope on the form where and the zero vector is a stricly interior point. For transforming points back to the original space, it also provides a matrix and a vector , so that .
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:
- create a polytope object from a file path
- simplify, reduce, and round a polytope in separate steps, togehter with some printed checks
- simplify, reduce and round a polytope in one step
- save the rounded polytope in various formats
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)
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)
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 hdf5
out_hdf5 = os.path.join("PolyRound", 'output', 'rounded_e_coli_core.hdf5')
PolyRoundApi.polytope_to_hdf5(one_step_rounded_polytope, out_hdf5)
#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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file PolyRound-0.2.6.tar.gz
.
File metadata
- Download URL: PolyRound-0.2.6.tar.gz
- Upload date:
- Size: 37.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dce63964dfa2ab31ec9460eacfd3e5c710b4c1a072988262acf15139d5c1603f |
|
MD5 | 2cd9d7e12f05f9dd8d689d616d37dfc7 |
|
BLAKE2b-256 | 176613791507d47180e471ec0dbc6ef7b2f833fe39c3a9a35bfdc231f0d2e44f |
File details
Details for the file PolyRound-0.2.6-py3-none-any.whl
.
File metadata
- Download URL: PolyRound-0.2.6-py3-none-any.whl
- Upload date:
- Size: 42.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31f2561f672c19e9a34d11b0220256ed4f2c34f0b59f8416a41ff9e595990673 |
|
MD5 | 4fa228a201ef47eec1dc93ef83a6165a |
|
BLAKE2b-256 | e5df0224b025e55619260258d988ce756b4b1b0bdcbfaba819a1fe9d9a8ad5c2 |