Skip to content

Commit 569884a

Browse files
committed
remove dependencies and move some to optional
1 parent 5b482c4 commit 569884a

File tree

6 files changed

+138
-51
lines changed

6 files changed

+138
-51
lines changed

docs/source/installation.rst

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ This page covers various ways to install Surfaces and its dependencies.
99
Requirements
1010
============
1111

12-
Surfaces requires:
12+
Surfaces has minimal core requirements:
1313

1414
- Python |min_python| or higher
1515
- NumPy >= 1.18.1
16-
- pandas
17-
- matplotlib
18-
- plotly
19-
- scikit-learn
20-
- search-data-collector >= 0.6.0
16+
17+
Optional dependencies for additional features:
18+
19+
- **Visualization**: matplotlib, plotly
20+
- **Machine Learning functions**: scikit-learn
2121

2222
Installing from PyPI
2323
====================
@@ -26,26 +26,44 @@ The recommended way to install Surfaces is via pip:
2626

2727
.. code-block:: bash
2828
29+
# Minimal install (algebraic + engineering functions only)
2930
pip install surfaces
3031
31-
This will install Surfaces and all required dependencies.
32+
# With visualization support
33+
pip install surfaces[viz]
34+
35+
# With machine learning functions
36+
pip install surfaces[ml]
37+
38+
# Full installation (all features)
39+
pip install surfaces[full]
40+
41+
The minimal installation includes all algebraic (mathematical) and engineering
42+
test functions. These require only NumPy and are ideal for CI/CD pipelines
43+
where minimal dependencies are preferred.
3244

3345
Installing with Extras
3446
======================
3547

36-
For development or testing, you can install additional dependencies:
48+
Available optional dependency groups:
3749

3850
.. code-block:: bash
3951
52+
# Visualization (matplotlib + plotly)
53+
pip install surfaces[viz]
54+
55+
# Machine learning functions (scikit-learn)
56+
pip install surfaces[ml]
57+
58+
# All optional features
59+
pip install surfaces[full]
60+
4061
# Development dependencies
4162
pip install surfaces[dev]
4263
4364
# Test dependencies
4465
pip install surfaces[test]
4566
46-
# All extras
47-
pip install surfaces[dev,test]
48-
4967
Installing from Source
5068
======================
5169

@@ -116,11 +134,18 @@ Troubleshooting
116134
Import Errors
117135
-------------
118136

119-
If you get import errors, make sure all dependencies are installed:
137+
If you get import errors for visualization or ML functions:
120138

121139
.. code-block:: bash
122140
123-
pip install numpy pandas matplotlib plotly scikit-learn
141+
# For visualization functions
142+
pip install surfaces[viz]
143+
144+
# For machine learning functions
145+
pip install surfaces[ml]
146+
147+
# For all features
148+
pip install surfaces[full]
124149
125150
Version Conflicts
126151
-----------------

pyproject.toml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,42 @@ classifiers=[
3333
]
3434
dependencies = [
3535
"numpy>=1.18.1",
36-
"pandas",
36+
]
37+
38+
[project.optional-dependencies]
39+
# Visualization (matplotlib + plotly)
40+
viz = [
3741
"matplotlib",
3842
"plotly",
43+
]
44+
# Machine learning test functions
45+
ml = [
3946
"scikit-learn",
40-
"search-data-collector>=0.6.0",
4147
]
42-
43-
[project.optional-dependencies]
48+
# All optional features
49+
full = [
50+
"surfaces[viz,ml]",
51+
]
52+
# Development
4453
dev = [
54+
"surfaces[full]",
4555
"flake8",
4656
"check-manifest",
4757
]
58+
# Testing
4859
test = [
60+
"surfaces[full]",
4961
"pytest>=7.0.0",
5062
"pytest-cov",
5163
"flake8",
5264
"tox",
5365
"gradient-free-optimizers",
5466
]
67+
# Build
5568
build = [
5669
"build",
5770
]
71+
# Surrogate models
5872
surrogate = [
5973
"onnxruntime>=1.16.0",
6074
]

src/surfaces/_visualize.py

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,52 @@
55
# Internal module - not part of public API
66
# Visualization utilities for test functions (experimental)
77

8-
import numpy as np
9-
import plotly.graph_objects as go
10-
import plotly.express as px
11-
import matplotlib as mpl
12-
import matplotlib.pyplot as plt
13-
from typing import Dict, List, Optional, Union, Any
8+
from __future__ import annotations
149

15-
color_scale = px.colors.sequential.Jet
10+
import numpy as np
11+
from typing import Dict, List, Optional, Union, Any, TYPE_CHECKING
12+
13+
if TYPE_CHECKING:
14+
import plotly.graph_objects as go
15+
import matplotlib.pyplot as plt
16+
17+
try:
18+
import plotly.graph_objects as go
19+
import plotly.express as px
20+
import matplotlib as mpl
21+
import matplotlib.pyplot as plt
22+
_HAS_VIZ_DEPS = True
23+
color_scale = px.colors.sequential.Jet
24+
except ImportError:
25+
_HAS_VIZ_DEPS = False
26+
go = None # type: ignore[assignment]
27+
px = None
28+
mpl = None
29+
plt = None # type: ignore[assignment]
30+
color_scale = None
31+
32+
33+
def _check_viz_deps():
34+
"""Check if visualization dependencies are available."""
35+
if not _HAS_VIZ_DEPS:
36+
raise ImportError(
37+
"Visualization features require matplotlib and plotly. "
38+
"Install with: pip install surfaces[viz]"
39+
)
1640

1741

1842
def _create_grid(objective_function, search_space: Dict[str, np.ndarray]):
1943
"""Create a 2D grid for visualization from a search space and objective function.
20-
44+
2145
Args:
2246
objective_function: Function that takes a dict of parameters and returns a scalar
2347
search_space: Dictionary with exactly 2 keys, each mapping to numpy arrays
24-
48+
2549
Returns:
2650
tuple: (xi, yi, zi) meshgrid arrays for plotting
2751
"""
52+
_check_viz_deps()
53+
2854
def objective_function_np(*args):
2955
para = {}
3056
for arg, key in zip(args, search_space.keys()):

src/surfaces/test_functions/__init__.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,18 @@
22
# Email: simon.blanke@yahoo.com
33
# License: MIT License
44

5+
# Algebraic functions (always available - numpy only)
56
from .algebraic import algebraic_functions
67
from .algebraic import * # noqa: F401,F403
78

9+
# Machine learning functions (require sklearn)
810
from .machine_learning import machine_learning_functions
9-
from .machine_learning import * # noqa: F401,F403
11+
if machine_learning_functions: # Only import if sklearn available
12+
from .machine_learning import * # noqa: F401,F403
1013

14+
# Engineering functions (always available - numpy only)
1115
from .engineering import * # noqa: F401,F403
12-
13-
# Engineering function list
14-
engineering_functions = [
15-
"ThreeBarTrussFunction",
16-
"WeldedBeamFunction",
17-
"PressureVesselFunction",
18-
"TensionCompressionSpringFunction",
19-
"CantileverBeamFunction",
20-
]
16+
from .engineering import engineering_functions
2117

2218
# Backwards compatibility alias
2319
mathematical_functions = algebraic_functions

src/surfaces/test_functions/engineering/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,13 @@
7171
"PressureVesselFunction",
7272
"TensionCompressionSpringFunction",
7373
"CantileverBeamFunction",
74+
"engineering_functions",
75+
]
76+
77+
engineering_functions = [
78+
ThreeBarTrussFunction,
79+
WeldedBeamFunction,
80+
PressureVesselFunction,
81+
TensionCompressionSpringFunction,
82+
CantileverBeamFunction,
7483
]

src/surfaces/test_functions/machine_learning/__init__.py

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,40 @@
22
# Email: simon.blanke@yahoo.com
33
# License: MIT License
44

5+
try:
6+
from sklearn.neighbors import KNeighborsClassifier # noqa: F401
7+
_HAS_SKLEARN = True
8+
except ImportError:
9+
_HAS_SKLEARN = False
510

6-
from .tabular import (
7-
KNeighborsClassifierFunction,
8-
KNeighborsRegressorFunction,
9-
GradientBoostingRegressorFunction,
10-
)
1111

12+
def _check_sklearn():
13+
"""Check if scikit-learn is available."""
14+
if not _HAS_SKLEARN:
15+
raise ImportError(
16+
"Machine learning functions require scikit-learn. "
17+
"Install with: pip install surfaces[ml]"
18+
)
1219

13-
__all__ = [
14-
"KNeighborsClassifierFunction",
15-
"KNeighborsRegressorFunction",
16-
"GradientBoostingRegressorFunction",
17-
]
1820

21+
if _HAS_SKLEARN:
22+
from .tabular import (
23+
KNeighborsClassifierFunction,
24+
KNeighborsRegressorFunction,
25+
GradientBoostingRegressorFunction,
26+
)
1927

20-
machine_learning_functions = [
21-
KNeighborsClassifierFunction,
22-
GradientBoostingRegressorFunction,
23-
KNeighborsRegressorFunction,
24-
]
28+
__all__ = [
29+
"KNeighborsClassifierFunction",
30+
"KNeighborsRegressorFunction",
31+
"GradientBoostingRegressorFunction",
32+
]
33+
34+
machine_learning_functions = [
35+
KNeighborsClassifierFunction,
36+
GradientBoostingRegressorFunction,
37+
KNeighborsRegressorFunction,
38+
]
39+
else:
40+
__all__ = []
41+
machine_learning_functions = []

0 commit comments

Comments
 (0)