Skip to content

Commit 4080ef4

Browse files
committed
Add support for the installation via pip.
1 parent 663a521 commit 4080ef4

File tree

6 files changed

+172
-6
lines changed

6 files changed

+172
-6
lines changed

README.md

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,8 @@ The documentation of the current state of the main branch can be found [here](ht
485485

486486
### Installing
487487

488+
#### Install via CMake
489+
488490
The library supports the `install` target:
489491

490492
```bash
@@ -502,6 +504,48 @@ export LD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_PREFIX}/lib64
502504
export CPLUS_INCLUDE_PATH=${CMAKE_INSTALL_PREFIX}/include:${CPLUS_INCLUDE_PATH}
503505
```
504506

507+
If our library was built with the Python bindings enabled, the `PYTHONPATH` must additionally be set:
508+
509+
```bash
510+
export PYTHONPATH=${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_PREFIX}/lib64:${PYTHONPATH}
511+
```
512+
513+
#### Install via pip
514+
515+
We also support a pip packages that can be used to install our library:
516+
517+
```bash
518+
pip install plssvm
519+
```
520+
521+
This pip install behaves **as if** the CMake `all_python` preset is used.
522+
This means that the `PLSSVM_TARGET_PLATFORMS` are automatically determined and PLSSVM is build with all supported
523+
backends that available on the target machine at the point of the `pip install plssvm` invocation.
524+
To check the installation, including, e.g., the installed backends, we provide the `plssvm-install-check` command after
525+
PLSSVM has been installed via pip.
526+
An example output of this command can look like:
527+
528+
```text
529+
PLSSVM - Parallel Least Squares Support Vector Machine (3.0.0)
530+
531+
Copyright(C) 2018-today The PLSSVM project - All Rights Reserved
532+
This is free software distributed under the MIT license.
533+
534+
Available target platforms: TargetPlatform.AUTOMATIC, TargetPlatform.GPU_NVIDIA, TargetPlatform.CPU
535+
Default target platform: TargetPlatform.GPU_NVIDIA
536+
537+
Available backends: BackendType.AUTOMATIC, BackendType.OPENMP, BackendType.CUDA, BackendType.OPENCL, BackendType.SYCL
538+
Default backend for target platform TargetPlatform.GPU_NVIDIA: BackendType.CUDA
539+
Default backend for target platform TargetPlatform.CPU: BackendType.SYCL
540+
541+
Available SYCL implementations: ImplementationType.AUTOMATIC, ImplementationType.ADAPTIVECPP
542+
543+
544+
Repository: https://github.com/SC-SGS/PLSSVM.git
545+
Documentation: https://sc-sgs.github.io/PLSSVM
546+
Issues: https://github.com/SC-SGS/PLSSVM/issues
547+
```
548+
505549
## Usage
506550

507551
PLSSVM provides three executables: `plssvm-train`, `plssvm-predict`, and `plssvm-scale`.
@@ -1020,12 +1064,6 @@ with an example output:
10201064
<img alt="Example regression output using a sine curve." src="https://github.com/SC-SGS/PLSSVM/raw/regression/.figures/regression_example.png" width="80%">
10211065
</p>
10221066

1023-
**Note:** it may be necessary to set the environment variable `PYTHONPATH` to the `lib` folder in the PLSSVM install path.
1024-
1025-
```bash
1026-
export PYTHONPATH=${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_PREFIX}/lib64:${PYTHONPATH}
1027-
```
1028-
10291067
Note that currently not all sklearn `SVC` and `SVR` functionality has been implemented in PLSSVM.
10301068
The respective functions will throw a Python `AttributeError` if called.
10311069
For a detailed overview of the functions that are currently implemented, see [our API documentation](bindings/Python/README.md).

bindings/Python/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,13 @@ target_compile_options(${PLSSVM_BASE_LIBRARY_NAME} PUBLIC -fPIC)
124124

125125
# append pybind11 bindings library to installed targets
126126
append_local_and_parent(PLSSVM_TARGETS_TO_INSTALL ${PLSSVM_PYTHON_BINDINGS_LIBRARY_NAME})
127+
128+
# install the __init__.py file so Python recognizes the package when installed via pip
129+
# install the __cli__.py file so the PLSSVM executables can be used when installed via pip
130+
# install the __install_check__.py file creating a new executable plssvm-install-check outputting some information when installed via pip
131+
include(GNUInstallDirs)
132+
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/__init__.py"
133+
"${CMAKE_CURRENT_SOURCE_DIR}/__cli__.py"
134+
"${CMAKE_CURRENT_SOURCE_DIR}/__install_check__.py"
135+
DESTINATION "${CMAKE_INSTALL_LIBDIR}"
136+
)

bindings/Python/__cli__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import sys
2+
import subprocess
3+
from pathlib import Path
4+
5+
6+
# support for plssvm-train including command line arguments
7+
def train():
8+
exe_path = Path(__file__).parent / "plssvm-train"
9+
subprocess.run([str(exe_path)] + sys.argv[1:])
10+
11+
12+
# support for plssvm-predict including command line arguments
13+
def predict():
14+
exe_path = Path(__file__).parent / "plssvm-predict"
15+
subprocess.run([str(exe_path)] + sys.argv[1:])
16+
17+
18+
# support for plssvm-scale including command line arguments
19+
def scale():
20+
exe_path = Path(__file__).parent / "plssvm-scale"
21+
subprocess.run([str(exe_path)] + sys.argv[1:])

bindings/Python/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# import all bindings from the compiled PLSSVM module
2+
from .plssvm import *
3+
4+
# explicitly set the module level attributes
5+
__doc__ = plssvm.__doc__
6+
__version__ = plssvm.__version__
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import plssvm
2+
3+
# print information regarding the current installation after an installation via pip
4+
def check():
5+
print("{} ({})".format(plssvm.__doc__, plssvm.__version__))
6+
print()
7+
8+
print("Copyright(C) 2018-today The PLSSVM project - All Rights Reserved")
9+
print("This is free software distributed under the MIT license.")
10+
print()
11+
12+
print("Available target platforms: {}".format(', '.join(str(target) for target in plssvm.list_available_target_platforms())))
13+
print("Default target platform: {}\n".format(str(plssvm.determine_default_target_platform())))
14+
15+
print("Available backends: {}".format(', '.join(str(backend) for backend in plssvm.list_available_backends())))
16+
for target in plssvm.list_available_target_platforms():
17+
if target == plssvm.TargetPlatform.AUTOMATIC:
18+
continue
19+
try:
20+
backend = plssvm.determine_default_backend(available_target_platforms=[target])
21+
print("Default backend for target platform {}: {}".format(str(target), str(backend)))
22+
except:
23+
pass
24+
print()
25+
26+
if plssvm.BackendType.SYCL in plssvm.list_available_backends():
27+
print("Available SYCL implementations: {}".format(', '.join(str(impl) for impl in plssvm.sycl.list_available_sycl_implementations())))
28+
print()
29+
30+
print()
31+
print("Repository: https://github.com/SC-SGS/PLSSVM.git")
32+
print("Documentation: https://sc-sgs.github.io/PLSSVM/")
33+
print("Issues: https://github.com/SC-SGS/PLSSVM/issues")

pyproject.toml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
[build-system]
2+
requires = ["scikit-build-core"]
3+
build-backend = "scikit_build_core.build"
4+
5+
# set the necessary CMake build options
6+
[tool.scikit-build]
7+
cmake.args = [
8+
"--preset all_python",
9+
"-DCMAKE_INSTALL_LIBDIR=plssvm",
10+
"-DCMAKE_INSTALL_BINDIR=plssvm",
11+
"-DCMAKE_INSTALL_INCLUDEDIR=plssvm",
12+
"-DCMAKE_INSTALL_MANDIR=plssvm",
13+
"-DCMAKE_INSTALL_DATAROOTDIR=plssvm/cmake",
14+
"-DCMAKE_INSTALL_RPATH=$ORIGIN"
15+
]
16+
sdist.exclude = ["build*/", "dist/", "docs/html/", ".github", ".jenkins", "examples", "install", "tests", ".clang*", ".clion*", ".gitignore"]
17+
18+
# expose the PLSSVM executables after a pip install
19+
[project.scripts]
20+
plssvm-train = "plssvm.__cli__:train"
21+
plssvm-predict = "plssvm.__cli__:predict"
22+
plssvm-scale = "plssvm.__cli__:scale"
23+
plssvm-install-check = "plssvm.__install_check__:check"
24+
25+
# project specific metadata
26+
[project]
27+
name = "plssvm"
28+
version = "3.0.3" # TODO: fix
29+
description = "PLSSVM - A high-performance Least Squares Support Vector Machine implementation for GPUs and CPUs"
30+
readme = "README.md"
31+
license = { file = "LICENSE.md" }
32+
authors = [
33+
{ name = "Alexander Van Craen, Marcel Breyer" }
34+
]
35+
maintainers = [
36+
{ name = "University of Stuttgart IPVS - SC", email = "[email protected]" }
37+
]
38+
dependencies = ["numpy"]
39+
requires-python = ">=3.8"
40+
classifiers = [
41+
"Development Status :: 5 - Production/Stable",
42+
"Environment :: GPU",
43+
"Intended Audience :: Science/Research",
44+
"License :: OSI Approved :: MIT License",
45+
"Natural Language :: English",
46+
"Operating System :: POSIX :: Linux",
47+
"Operating System :: Microsoft :: Windows",
48+
"Programming Language :: C++",
49+
"Programming Language :: Python :: 3",
50+
"Topic :: Scientific/Engineering :: Artificial Intelligence"
51+
]
52+
53+
# project specific URLs
54+
[project.urls]
55+
homepage = "https://www.ipvs.uni-stuttgart.de/departments/sc/research/projects/recent/plssvm/"
56+
documentation = "https://sc-sgs.github.io/PLSSVM/"
57+
repository = "https://github.com/SC-SGS/PLSSVM.git"
58+
issues = "https://github.com/SC-SGS/PLSSVM/issues"

0 commit comments

Comments
 (0)