Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pycddlib dependency version to 3.0.0 #15

Merged
merged 22 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
45aebf2
WIP: Update pycddlib dependency version to 3.0.0
stephane-caron Dec 20, 2024
040d84c
Update pycddlib API
stephane-caron Dec 20, 2024
f2e561e
Bump minimum supported Python version to 3.9
stephane-caron Dec 20, 2024
f6f6a7c
Update to new pycddlib API
stephane-caron Dec 20, 2024
e7b59b9
CICD: Run unit tests in conda environment
stephane-caron Dec 20, 2024
ade0219
CICD: Fix workflow syntax
stephane-caron Dec 20, 2024
ac5ef7c
CICD: Install cddlib in conda environment
stephane-caron Dec 20, 2024
ed9e517
CICD: Don't install pycddlib on windows
stephane-caron Dec 20, 2024
0289093
No need to install cddlib when wheels exist
stephane-caron Dec 20, 2024
36134ee
Update pycddlib polyhedron API
stephane-caron Dec 20, 2024
c5acb3f
Fix NumPy 2.0 deprecation warning
stephane-caron Dec 20, 2024
2d936a7
CICD: Install cddlib in conda environment
stephane-caron Jan 6, 2025
be635e2
CICD: Install libcdd-dev in Ubuntu runners
stephane-caron Jan 6, 2025
e3360a2
CICD: Update windows-latest workflow
stephane-caron Jan 6, 2025
dd60474
CICD: Drop Windows support
stephane-caron Jan 6, 2025
6d0831d
Remove cdd reference from polyhedron submodule
stephane-caron Jan 6, 2025
0ef2bcf
Ignore types when calling cdd.matrix_from_array
stephane-caron Jan 6, 2025
5fc9127
CICD: Re-enable macOS testing
stephane-caron Jan 6, 2025
9146335
CICD: Use macos-13 rather than macos-latest for now
stephane-caron Jan 6, 2025
05fab86
Update docs to re-trigger CI
stephane-caron Jan 6, 2025
f8fe69b
CICD: Fix CI YAML
stephane-caron Jan 6, 2025
8f22dda
CICD: Remove extra conda steps
stephane-caron Jan 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 36 additions & 32 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ jobs:
- name: "Checkout sources"
uses: actions/checkout@v3

- name: "Set up Python 3.8"
- name: "Set up Python 3.9"
uses: actions/setup-python@v4
with:
python-version: "3.8"
python-version: "3.9"

- name: "Install Debian dependencies"
run: |
sudo apt install libgmp3-dev
sudo apt-get install -y libcdd-dev libgmp3-dev

- name: "Install PyPI dependencies"
run: |
Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:

- name: "Install Debian dependencies"
run: |
sudo apt install libgmp3-dev
sudo apt-get install -y libcdd-dev libgmp3-dev

- name: "Install PyPI dependencies"
run: |
Expand All @@ -74,48 +74,52 @@ jobs:

strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10"]
os: [ubuntu-latest, macos-13]
python-version: ["3.9", "3.10", "3.11", "3.12"]

defaults:
run:
# See https://github.com/mamba-org/setup-micromamba?tab=readme-ov-file#about-login-shells
shell: bash -leo pipefail {0}

steps:
- name: "Checkout sources"
uses: actions/checkout@v3

- name: "Set up Python ${{ matrix.python-version }}"
uses: actions/setup-python@v4
with:
python-version: "${{ matrix.python-version }}"

- name: "Install Debian dependencies"
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt install libgmp-dev

- name: "Install macOS dependencies"
if: matrix.os == 'macos-latest'
run: |
brew install gmp

- name: "Install PyPI dependencies"
run: |
python -m pip install --upgrade pip
python -m pip install tox tox-gh-actions

- name: "Install GMP (Ubuntu)"
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get install -y libgmp-dev
sudo apt-get install -y libgmp3-dev

- name: "Install GMP (macOS)"
if: ${{ matrix.os == 'macos-latest' }}
if: ${{ matrix.os == 'macos-13' }}
run: |
brew install gmp

- name: "Test with tox for ${{ matrix.os }}"
env:
PLATFORM: ${{ matrix.os }}
- name: "Install Conda environment with Micromamba"
uses: mamba-org/setup-micromamba@v1
with:
micromamba-version: '1.5.8-0'
environment-name: pypoman_test_env
create-args: >-
python=${{ matrix.python-version }}
cddlib
cvxopt>=1.2.6
matplotlib>=3.3.4
numpy>=1.15.4
pyclipper>=1.3.0
qpsolvers>=3.3.1
scipy>=1.7.0
cache-environment: true
post-cleanup: 'all'

- name: "Install cdd and pycddlib"
run: |
pip install pycddlib

- name: "Run unit tests"
run: |
tox
python -m unittest discover

ci_success:
name: "CI success"
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Changed

- Bump minimum supported Python version to 3.9
- Update pycddlib to version 3.0.0

### Fixed

- CICD: Re-enable macOS testing

### Removed

- CICD: Dropped Windows support
- Remove cdd reference from polyhedron submodule

## [1.1.1] - 2024-12-20

### Changed
Expand Down
5 changes: 5 additions & 0 deletions doc/src/chebyshev-center.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
****************
Chebyshev center
****************

.. autofunction:: pypoman.polyhedron.compute_chebyshev_center
7 changes: 7 additions & 0 deletions doc/src/duality.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*******
Duality
*******

.. automodule:: pypoman.duality
:members:

53 changes: 9 additions & 44 deletions doc/src/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,12 @@
Welcome to the documentation of **pypoman**, a PYthon module for POlyhedral
MANipulations.

Chebyshev center
================

.. autofunction:: pypoman.polyhedron.compute_chebyshev_center

Duality
=======

.. automodule:: pypoman.duality
:members:

Intersection
============

.. automodule:: pypoman.intersection
:members:

Linear programming
==================

.. autofunction:: pypoman.lp.solve_lp

Polygon manipulation
====================

.. automodule:: pypoman.polygon
:members:

Projection
==========

.. automodule:: pypoman.projection
:members:

References
==========

.. [Boyd04] `Convex Optimization
<https://web.stanford.edu/~boyd/cvxbook/bv_cvxbook.pdf>`_, Stephen Boyd and
Lieven Vandenberghe, Cambridge University Press, 2004.

.. [Bretl08] *Testing Static Equilibrium for Legged Robots*, T. Bretl and S.
Lall, IEEE Transactions on Robotics, vol. 24, no. 4, pp. 794-807, August
2008.
.. toctree::
:maxdepth: 1

chebyshev-center.rst
duality.rst
intersection.rst
polygon.rst
projection.rst
references.rst
6 changes: 6 additions & 0 deletions doc/src/intersection.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
************
Intersection
************

.. automodule:: pypoman.intersection
:members:
5 changes: 5 additions & 0 deletions doc/src/linear-programming.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
******************
Linear programming
******************

.. autofunction:: pypoman.lp.solve_lp
7 changes: 7 additions & 0 deletions doc/src/polygon.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
********************
Polygon manipulation
********************

.. automodule:: pypoman.polygon
:members:

6 changes: 6 additions & 0 deletions doc/src/projection.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
**********
Projection
**********

.. automodule:: pypoman.projection
:members:
11 changes: 11 additions & 0 deletions doc/src/references.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
**********
References
**********

.. [Boyd04] `Convex Optimization
<https://web.stanford.edu/~boyd/cvxbook/bv_cvxbook.pdf>`_, Stephen Boyd and
Lieven Vandenberghe, Cambridge University Press, 2004.

.. [Bretl08] *Testing Static Equilibrium for Legged Robots*, T. Bretl and S.
Lall, IEEE Transactions on Robotics, vol. 24, no. 4, pp. 794-807, August
2008.
5 changes: 3 additions & 2 deletions pypoman/bretl.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ def expand(
if (
abs(
np.cross(
[xopt - v1.x, yopt - v1.y], [v1.x - v2.x, v1.y - v2.y]
)
[xopt - v1.x, yopt - v1.y, 0],
[v1.x - v2.x, v1.y - v2.y, 0],
)[2]
)
< 1e-4
):
Expand Down
22 changes: 11 additions & 11 deletions pypoman/duality.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ def compute_cone_face_matrix(S: np.ndarray) -> np.ndarray:
]
)
# V-representation: first column is 0 for rays
mat = cdd.Matrix(V, number_type="float")
mat = cdd.matrix_from_array(V) # type: ignore
mat.rep_type = cdd.RepType.GENERATOR
P = cdd.Polyhedron(mat)
ineq = P.get_inequalities()
H = np.array(ineq)
P = cdd.polyhedron_from_matrix(mat)
ineq = cdd.copy_inequalities(P)
H = np.array(ineq.array)
if H.shape == (0,): # H == []
return H
A = []
Expand Down Expand Up @@ -82,10 +82,10 @@ def compute_polytope_halfspaces(
V = np.vstack(vertices)
t = np.ones((V.shape[0], 1)) # first column is 1 for vertices
tV = np.hstack([t, V])
mat = cdd.Matrix(tV, number_type="float")
mat = cdd.matrix_from_array(tV) # type: ignore
mat.rep_type = cdd.RepType.GENERATOR
P = cdd.Polyhedron(mat)
bA = np.array(P.get_inequalities())
P = cdd.polyhedron_from_matrix(mat)
bA = np.array(cdd.copy_inequalities(P).array)
if bA.shape == (0,): # bA == []
return bA
# the polyhedron is given by b + A x >= 0 where bA = [b|A]
Expand Down Expand Up @@ -121,11 +121,11 @@ def compute_polytope_vertices(
<https://pycddlib.readthedocs.io/en/latest/matrix.html>`_.
"""
b = b.reshape((b.shape[0], 1))
mat = cdd.Matrix(np.hstack([b, -A]), number_type="float")
mat = cdd.matrix_from_array(np.hstack([b, -A])) # type: ignore
mat.rep_type = cdd.RepType.INEQUALITY
P = cdd.Polyhedron(mat)
g = P.get_generators()
V = np.array(g)
P = cdd.polyhedron_from_matrix(mat)
g = cdd.copy_generators(P)
V = np.array(g.array)
vertices = []
for i in range(V.shape[0]):
if V[i, 0] != 1: # 1 = vertex, 0 = ray
Expand Down
8 changes: 0 additions & 8 deletions pypoman/polyhedron.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@
from .lp import solve_lp
from .misc import norm

try:
import cdd
except ImportError:
warn("Could not import cdd, some functions will not be available")
cdd = None


try:
import cvxopt
except ImportError:
Expand Down Expand Up @@ -61,7 +54,6 @@ def compute_chebyshev_center(A: np.ndarray, b: np.ndarray) -> np.ndarray:


__all__ = [
"cdd",
"compute_chebyshev_center",
"cvxopt",
]
16 changes: 9 additions & 7 deletions pypoman/projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,26 @@ def project_polyhedron(
# see ftp://ftp.ifor.math.ethz.ch/pub/fukuda/cdd/cddlibman/node3.html
(A, b) = ineq
b = b.reshape((b.shape[0], 1))
linsys = cdd.Matrix(np.hstack([b, -A]), number_type="float")
linsys = cdd.matrix_from_array(np.hstack([b, -A])) # type: ignore
linsys.rep_type = cdd.RepType.INEQUALITY

# the input [d, -C] to cdd.Matrix.extend represents (d - C * x == 0)
# the input [d, -C] to the cdd function represents (d - C * x == 0)
# see ftp://ftp.ifor.math.ethz.ch/pub/fukuda/cdd/cddlibman/node3.html
if eq is not None:
(C, d) = eq
d = d.reshape((d.shape[0], 1))
linsys.extend(np.hstack([d, -C]), linear=True)
new_matrix = cdd.matrix_from_array(np.hstack([d, -C])) # type: ignore
cdd.matrix_append_to(linsys, new_matrix)
linsys.rep_type = cdd.RepType.INEQUALITY
if canonicalize:
linsys.canonicalize()
cdd.matrix_canonicalize(linsys)

# Convert from H- to V-representation
P = cdd.Polyhedron(linsys)
generators = P.get_generators()
P = cdd.polyhedron_from_matrix(linsys)
generators = cdd.copy_generators(P)
if generators.lin_set:
print("Generators have linear set: {}".format(generators.lin_set))
V = np.array(generators)
V = np.array(generators.array)

# Project output wrenches to 2D set
(E, f) = proj
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ maintainers = [
{name = "Stéphane Caron", email = "stephane.caron@normalesup.org"},
]
dynamic = ['version', 'description']
requires-python = ">=3.7"
requires-python = ">=3.9"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering :: Mathematics",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
Expand All @@ -31,7 +31,7 @@ dependencies = [
"cvxopt >=1.2.6",
"matplotlib >=3.3.4",
"numpy >=1.15.4",
"pycddlib >=2.1.4,<3",
"pycddlib >=3.0.0",
"scipy >=1.7.0",
]
keywords = ["convex, polyhedron, polyhedra, polytope, projection, duality"]
Expand Down
7 changes: 0 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ PLATFORM =
ubuntu-latest: linux
windows-latest: windows

[testenv]
deps =
pyclipper >=1.3.0
qpsolvers >=3.3.1
commands =
python -m unittest discover

[testenv:coverage]
deps =
coverage >=5.5
Expand Down
Loading