Skip to content

Commit

Permalink
Update to SCS 3.2.3 (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
bodono authored Apr 5, 2023
1 parent 31fab7d commit a26706a
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[bumpversion]
current_version = 3.2.2
current_version = 3.2.3

[bumpversion:file:setup.py]
59 changes: 45 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
name: black formatter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: rickstaa/action-black@v1
with:
black_args: ". --line-length=80 --check"
Expand All @@ -34,15 +34,14 @@ jobs:
strategy:
fail-fast: false
matrix:
# Windows not reporting MKL location correctly
os: [ ubuntu-18.04, macos-10.15 ] # windows-2022
python-version: [3.6, 3.7, 3.8, 3.9, "3.10", "3.11" ]
os: [ ubuntu-latest, macos-10.15 ] # windows-latest not finding MKL
python-version: [ 3.7, 3.8, 3.9, "3.10", "3.11" ]

env:
PYTHON_VERSION: ${{ matrix.python-version }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: conda-incubator/setup-miniconda@v2
Expand All @@ -59,6 +58,38 @@ jobs:
pytest
rm -rf build/
build_openmp:
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash -l {0}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
python-version: [ 3.7, 3.8, 3.9, "3.10", "3.11" ]

env:
PYTHON_VERSION: ${{ matrix.python-version }}

steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}
channels: conda-forge,anaconda
- name: Install dependencies
run: |
conda install scipy numpy pytest
- name: Test
run: |
python setup.py install --scs --openmp
pytest
rm -rf build/
build:
runs-on: ${{ matrix.os }}
defaults:
Expand All @@ -67,14 +98,14 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-18.04, macos-10.15, windows-2022 ]
python-version: [3.6, 3.7, 3.8, 3.9, "3.10", "3.11" ]
os: [ ubuntu-latest, macos-10.15, windows-latest ]
python-version: [ 3.7, 3.8, 3.9, "3.10", "3.11" ]

env:
PYTHON_VERSION: ${{ matrix.python-version }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Set Additional Envs
Expand All @@ -88,7 +119,7 @@ jobs:
channels: conda-forge,anaconda
- name: Install dependencies
run: |
if [[ "$PYTHON_VERSION" == "3.6" ]] || [[ "$PYTHON_VERSION" == "3.7" ]] || [[ "$PYTHON_VERSION" == "3.8" ]] || [[ "$PYTHON_VERSION" == "3.9" ]]; then
if [[ "$PYTHON_VERSION" == "3.7" ]] || [[ "$PYTHON_VERSION" == "3.8" ]] || [[ "$PYTHON_VERSION" == "3.9" ]]; then
conda install scipy=1.5 numpy=1.19 pytest mkl openblas lapack
elif [[ "$PYTHON_VERSION" == "3.10" ]]; then
conda install scipy=1.7 numpy=1.21 pytest mkl openblas lapack
Expand Down Expand Up @@ -123,16 +154,16 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-20.04, macos-10.15]
python-version: [ 3.6, 3.7, 3.8, 3.9, "3.10", "3.11" ]
os: [ ubuntu-latest, macos-10.15 ]
python-version: [ 3.7, 3.8, 3.9, "3.10", "3.11" ]

env:
RUNNER_OS: ${{ matrix.os }}
PYTHON_VERSION: ${{ matrix.python-version }}

steps:

- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/setup-python@v2
Expand Down Expand Up @@ -176,15 +207,15 @@ jobs:

upload_wheels:
needs: build_wheels
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

env:
PYPI_SERVER: ${{ secrets.PYPI_SERVER }}
PYPI_USER: ${{ secrets.PYPI_USER }}
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions/setup-python@v2
with:
python-version: 3.8
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ scs-python

[![Build Status](https://github.com/bodono/scs-python/actions/workflows/build.yml/badge.svg)](https://github.com/bodono/scs-python/actions/workflows/build.yml)
[![Documentation](https://img.shields.io/badge/docs-online-brightgreen?logo=read-the-docs&style=flat)](https://www.cvxgrp.org/scs/)
[![PyPI package](https://img.shields.io/pypi/dd/scs?label=PyPI%20downloads)](https://pypi.org/project/scs/)
[![PyPI package](https://img.shields.io/pypi/dm/scs?label=PyPI%20downloads)](https://pypi.org/project/scs/)


Python interface for [SCS](https://github.com/cvxgrp/scs) 3.0.0 and higher.
Expand Down
60 changes: 37 additions & 23 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
from __future__ import print_function
from distutils.msvccompiler import MSVCCompiler
from glob import glob

from platform import system
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
import shutil
import tempfile
import argparse
import os
import subprocess
import sys

SCS_ARG_MARK = "--scs"
SCS_ARG_MARK = "--scs" # used to pass custom arguments to setup

parser = argparse.ArgumentParser(description="Compilation args for SCS.")
parser.add_argument(
Expand All @@ -38,6 +33,15 @@
"to succeed. This option will be removed soon after which we shall "
"install the MKL version by default if MKL is available.",
)
parser.add_argument(
"--openmp",
dest="openmp",
action="store_true",
default=False,
help="Compile with OpenMP parallelization enabled. This can make SCS"
"faster, but requires a compiler with openMP support, the user "
"must control how many threads OpenMP uses.",
)
parser.add_argument(
"--float",
dest="float32",
Expand Down Expand Up @@ -170,10 +174,15 @@ def build_extension(self, ext):

def install_scs(**kwargs):
extra_compile_args = ["-O3"]
extra_link_args = []
libraries = []
sources = ["src/scspy.c"] + glob("scs/src/*.c") + glob("scs/linsys/*.c")
include_dirs = ["scs/include", "scs/linsys"]
define_macros = [("PYTHON", None), ("CTRLC", 1)]
if args.openmp:
extra_compile_args += ["-fopenmp"]
extra_link_args += ["-fopenmp"]
# define_macros += [("_OPENMP", None)] # TODO: do we need this?

if system() == "Linux":
libraries += ["rt"]
Expand Down Expand Up @@ -202,6 +211,7 @@ def install_scs(**kwargs):
],
libraries=list(libraries),
extra_compile_args=list(extra_compile_args),
extra_link_args=list(extra_link_args),
)

_scs_indirect = Extension(
Expand All @@ -213,6 +223,7 @@ def install_scs(**kwargs):
include_dirs=include_dirs + ["scs/linsys/cpu/indirect/"],
libraries=list(libraries),
extra_compile_args=list(extra_compile_args),
extra_link_args=list(extra_link_args),
)

ext_modules = [_scs_direct, _scs_indirect]
Expand Down Expand Up @@ -240,37 +251,40 @@ def install_scs(**kwargs):
library_dirs=library_dirs,
libraries=libraries + ["cudart", "cublas", "cusparse"],
extra_compile_args=list(extra_compile_args),
extra_link_args=list(extra_link_args),
)
ext_modules += [_scs_gpu]

if args.mkl:
# TODO: This heuristic attempts to determine if MKL is installed.
# Replace with something better.
blibs = None
blas_info, lapack_info = get_infos()
if "libraries" in blas_info and "libraries" in lapack_info:
blibs = blas_info["libraries"] + lapack_info["libraries"]
if not any("mkl" in s for s in (blibs or [])):
print(
"MKL not found in blas / lapack info dicts, skipping SCS-MKL "
"install. Please install MKL and retry. If you think this is "
"an error please let us know by opening GitHub issue."
raise ValueError(
"MKL not found in blas / lapack info dicts so cannot install "
"MKL-linked version of SCS. Please install MKL and retry. "
"If you think this is an error please let us know by opening "
"a GitHub issue."
)
else:
# MKL should be included in the libraries already:
_scs_mkl = Extension(
name="_scs_mkl",
sources=sources + glob("scs/linsys/mkl/direct/*.c"),
depends=glob("src/*.h"),
define_macros=list(define_macros) + [("PY_MKL", None)],
include_dirs=include_dirs + ["scs/linsys/mkl/direct/"],
libraries=list(libraries),
extra_compile_args=list(extra_compile_args),
)
ext_modules += [_scs_mkl]
# MKL should be included in the libraries already:
_scs_mkl = Extension(
name="_scs_mkl",
sources=sources + glob("scs/linsys/mkl/direct/*.c"),
depends=glob("src/*.h"),
define_macros=list(define_macros) + [("PY_MKL", None)],
include_dirs=include_dirs + ["scs/linsys/mkl/direct/"],
libraries=list(libraries),
extra_compile_args=list(extra_compile_args),
extra_link_args=list(extra_link_args),
)
ext_modules += [_scs_mkl]

setup(
name="scs",
version="3.2.2",
version="3.2.3",
author="Brendan O'Donoghue",
author_email="bodonoghue85@gmail.com",
url="http://github.com/cvxgrp/scs",
Expand Down
1 change: 1 addition & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
SOLVED = 1 # problem solved to desired accuracy
SOLVED_INACCURATE = 2 # SCS best guess solved


# Choose which SCS to import based on settings.
def _select_scs_module(stgs):
if stgs.pop("gpu", False): # False by default
Expand Down
2 changes: 1 addition & 1 deletion test/solve_random_cone_prob.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def main():
except ImportError:
pass

for (use_indirect, gpu) in flags:
for use_indirect, gpu in flags:
np.random.seed(1)
solve_feasible(use_indirect, gpu)
solve_infeasible(use_indirect, gpu)
Expand Down

0 comments on commit a26706a

Please sign in to comment.