Skip to content

Commit fac6ca3

Browse files
author
Nikola Jajcay
authored
Merge pull request #17 from jajcayn/feature/igraph_optional
igraph dependency now optional
2 parents 51b8eb9 + 2d1fdf6 commit fac6ca3

8 files changed

+21
-4
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ python:
66

77
install:
88
- pip install -r requirements.txt
9+
- pip install -r requirements_optional.txt
910
- pip install codecov pytest-cov
1011
- pip install .
1112

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
include README_pypi.md
22
include requirements.txt
3+
include requirements_optional.txt

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ The package offers plotting functions for visualising the results. Again, those
7474
### Notes
7575
Gaussian Processes regression uses normalised coordinates within the bounds [0, 1]. All normalisation and de-normalisation is done automatically, however when you want to call `predict_y` on GPR model, do not forget to pass normalised coordinates. The normalisation is handled by `sklearn.MinMaxScaler` and `ParameterSpace` instance offers a convenience functions for this: `ParameterSpace.normalise_coords(orig_coords)` and `ParameterSpace.denormalise_coords(normed_coords)`.
7676

77+
Plotting of the ternary tree (`gpso.plotting.plot_ternary_tree()`) requires `igraph` package, whose layout function is exploited. If you want to see the resulting beautiful tree, please install `python-igraph`.
78+
7779
## Known bugs and future improvements
7880
* currently cannot be installed through `pip` from PyPI, since `GPFlow` 2.0 is not on PyPI yet
7981
* saving and resuming of the optimisation

gpso/plotting.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import matplotlib.pyplot as plt
77
import numpy as np
88
from anytree import PreOrderIter
9-
from igraph import Graph
109
from scipy.stats import gaussian_kde
1110
from sklearn.preprocessing import MinMaxScaler
1211

@@ -53,6 +52,8 @@ def plot_ternary_tree(
5352
:type fname: str|None
5453
:*kwargs: keyword arguments for `plt.figure()`
5554
"""
55+
from igraph import Graph
56+
5657
assert isinstance(param_space, ParameterSpace)
5758
leaves_preorder = list(PreOrderIter(param_space))
5859
# assign indexes in pre-order order to nodes

requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ pathos
55
scipy
66
scikit-learn
77
matplotlib
8-
python-igraph
98
flake8
109
pytest
1110
black

requirements_optional.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python-igraph # plotting-extras

setup.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,16 @@
1818
requirement = f"{pkg_name.lower()} @ " + requirement
1919
checked_requirements.append(requirement)
2020

21+
extra_requirements = {}
22+
with open("requirements_optional.txt") as f:
23+
extra_reqs = f.read().splitlines()
24+
for req in extra_reqs:
25+
pkg, feature = req.split("#")
26+
extra_requirements[feature.strip()] = [pkg.strip()]
27+
2128
setuptools.setup(
2229
name="pygpso",
23-
version="0.2",
30+
version="0.3",
2431
description="Bayesian optimisation method leveraging Gaussian Processes "
2532
"surrogate",
2633
long_description=long_description,
@@ -41,5 +48,6 @@
4148
],
4249
python_requires=">=3.6",
4350
install_requires=checked_requirements,
51+
extras_require=extra_requirements,
4452
include_package_data=True,
4553
)

tests/test_plotting.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
from shutil import rmtree
88

99
import numpy as np
10+
import pytest
1011
from gpso.optimisation import GPSOptimiser
1112
from gpso.param_space import ParameterSpace
1213
from gpso.plotting import (
1314
plot_conditional_surrogate_distributions,
1415
plot_parameter_marginal_distributions,
15-
plot_ternary_tree,
1616
)
1717

1818

@@ -78,6 +78,10 @@ def tearDownClass(cls):
7878
rmtree(cls.TEMP_FOLDER)
7979

8080
def test_plot_ternary_tree(self):
81+
_ = pytest.importorskip("igraph")
82+
83+
from gpso.plotting import plot_ternary_tree
84+
8185
FILENAME = os.path.join(self.TEMP_FOLDER, "tree.png")
8286
plot_ternary_tree(
8387
self.opt_done.param_space, fname=FILENAME,

0 commit comments

Comments
 (0)