Skip to content

Commit 4e983ec

Browse files
0.15.6
tkagg handling
1 parent 7e4d982 commit 4e983ec

5 files changed

Lines changed: 23 additions & 6 deletions

File tree

notebooks/00_spotPython_tests.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4860,7 +4860,7 @@
48604860
"name": "python",
48614861
"nbconvert_exporter": "python",
48624862
"pygments_lexer": "ipython3",
4863-
"version": "3.11.9"
4863+
"version": "3.11.7"
48644864
}
48654865
},
48664866
"nbformat": 4,

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
77

88
[project]
99
name = "spotpython"
10-
version = "0.15.5"
10+
version = "0.15.6"
1111
authors = [
1212
{ name="T. Bartz-Beielstein", email="tbb@bartzundbartz.de" }
1313
]

src/spotpython/spot/spot.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
from spotpython.utils.numpy2json import NumpyEncoder
4545

4646
# Setting up the backend to use QtAgg
47-
matplotlib.use("TkAgg")
47+
# matplotlib.use("TkAgg")
48+
# matplotlib.use("Agg")
4849

4950

5051
logger = logging.getLogger(__name__)
@@ -259,6 +260,9 @@ def __init__(
259260
self.n_points = self.fun_control["n_points"]
260261
self.max_surrogate_points = self.fun_control["max_surrogate_points"]
261262
self.progress_file = self.fun_control["progress_file"]
263+
self.tkagg = self.fun_control["tkagg"]
264+
if self.tkagg:
265+
matplotlib.use("TkAgg")
262266

263267
# Tensorboard:
264268
self.init_spot_writer()
@@ -1447,7 +1451,7 @@ def infill(self, x) -> float:
14471451
return self.surrogate.predict(X)
14481452

14491453
def plot_progress(
1450-
self, show=True, log_x=False, log_y=False, filename="plot.png", style=["ko", "k", "ro-"], dpi=300
1454+
self, show=True, log_x=False, log_y=False, filename="plot.png", style=["ko", "k", "ro-"], dpi=300, tkagg=False
14511455
) -> None:
14521456
"""Plot the progress of the hyperparameter tuning (optimization).
14531457
@@ -1495,6 +1499,8 @@ def plot_progress(
14951499
S.plot_progress(log_y=True)
14961500
14971501
"""
1502+
if tkagg:
1503+
matplotlib.use("TkAgg")
14981504
fig = pylab.figure(figsize=(9, 6))
14991505
s_y = pd.Series(self.y)
15001506
s_c = s_y.cummin()
@@ -1904,6 +1910,7 @@ def plot_contour(
19041910
figsize=(12, 6),
19051911
use_min=False,
19061912
use_max=True,
1913+
tkagg=False,
19071914
) -> None:
19081915
"""Plot the contour of any dimension."""
19091916

@@ -1942,6 +1949,8 @@ def plot_contour_subplots(X, Y, Z, ax, min_z, max_z, contour_levels):
19421949
contour = ax.contourf(X, Y, Z, contour_levels, zorder=1, cmap="jet", vmin=min_z, vmax=max_z)
19431950
pylab.colorbar(contour, ax=ax)
19441951

1952+
if tkagg:
1953+
matplotlib.use("TkAgg")
19451954
fig = setup_plot()
19461955

19471956
(X, Y), x, y = generate_mesh_grid(self.lower, self.upper, n_grid)
@@ -2017,6 +2026,7 @@ def plot_important_hyperparameter_contour(
20172026
dpi=200,
20182027
use_min=False,
20192028
use_max=True,
2029+
tkagg=False,
20202030
) -> None:
20212031
"""
20222032
Plot the contour of important hyperparameters.
@@ -2123,6 +2133,7 @@ def plot_important_hyperparameter_contour(
21232133
dpi=dpi,
21242134
use_max=use_max,
21252135
use_min=use_min,
2136+
tkagg=tkagg,
21262137
)
21272138

21282139
def get_importance(self) -> list:
@@ -2181,7 +2192,7 @@ def print_importance(self, threshold=0.1, print_screen=True) -> list:
21812192
print("Importance requires more than one theta values (n_theta>1).")
21822193
return output
21832194

2184-
def plot_importance(self, threshold=0.1, filename=None, dpi=300, show=True) -> None:
2195+
def plot_importance(self, threshold=0.1, filename=None, dpi=300, show=True, tkagg=False) -> None:
21852196
"""Plot the importance of each variable.
21862197
21872198
Args:
@@ -2198,6 +2209,8 @@ def plot_importance(self, threshold=0.1, filename=None, dpi=300, show=True) -> N
21982209
None
21992210
"""
22002211
if self.surrogate.n_theta > 1:
2212+
if tkagg:
2213+
matplotlib.use("TkAgg")
22012214
theta = np.power(10, self.surrogate.theta)
22022215
imp = 100 * theta / np.max(theta)
22032216
idx = np.where(imp > threshold)[0]

src/spotpython/torch/traintest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def evaluate_cv(
129129
best_val_loss = float("inf")
130130
counter = 0
131131
for epoch in range(epochs_instance):
132-
print(f"Epoch: {epoch +1}", end=" | ")
132+
print(f"Epoch: {epoch+1}", end=" | ")
133133
# training loss from one epoch:
134134
training_loss = train_one_epoch(
135135
net=net,

src/spotpython/utils/init.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def fun_control_init(
7979
test=None,
8080
test_seed=1234,
8181
test_size=0.4,
82+
tkagg=False,
8283
train=None,
8384
tolerance_x=0,
8485
upper=None,
@@ -240,6 +241,8 @@ def fun_control_init(
240241
test_size (float):
241242
The size of the test set. Default is 0.4, i.e.,
242243
60% of the data is used for training and 40% for testing.
244+
tkagg (bool):
245+
Whether to use matplotlib TkAgg or not. Default is False.
243246
tolerance_x (float):
244247
tolerance for new x solutions. Minimum distance of new solutions,
245248
generated by `suggest_new_X`, to already existing solutions.
@@ -415,6 +418,7 @@ def fun_control_init(
415418
"test": test,
416419
"test_seed": test_seed,
417420
"test_size": test_size,
421+
"tkagg": tkagg,
418422
"tolerance_x": tolerance_x,
419423
"train": train,
420424
"upper": upper,

0 commit comments

Comments
 (0)