Skip to content

Commit d113d11

Browse files
0.10.5
plot test
1 parent daa26bb commit d113d11

4 files changed

Lines changed: 96 additions & 24 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,5 @@ lightning_logs/*
304304
runs/*
305305
src/spotPython/data/pkldataset_intern.py
306306
runs_OLD/*
307+
test_plot.png
308+
plot.png

notebooks/00_spotPython_tests.ipynb

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,17 +1867,9 @@
18671867
},
18681868
{
18691869
"cell_type": "code",
1870-
"execution_count": 3,
1870+
"execution_count": null,
18711871
"metadata": {},
1872-
"outputs": [
1873-
{
1874-
"name": "stderr",
1875-
"output_type": "stream",
1876-
"text": [
1877-
"Seed set to 1234\n"
1878-
]
1879-
}
1880-
],
1872+
"outputs": [],
18811873
"source": [
18821874
"from spotPython.utils.device import getDevice\n",
18831875
"from spotPython.utils.init import fun_control_init\n",
@@ -1921,20 +1913,9 @@
19211913
},
19221914
{
19231915
"cell_type": "code",
1924-
"execution_count": 3,
1916+
"execution_count": null,
19251917
"metadata": {},
1926-
"outputs": [
1927-
{
1928-
"data": {
1929-
"text/plain": [
1930-
"'20240106142611888678'"
1931-
]
1932-
},
1933-
"execution_count": 3,
1934-
"metadata": {},
1935-
"output_type": "execute_result"
1936-
}
1937-
],
1918+
"outputs": [],
19381919
"source": [
19391920
"import datetime\n",
19401921
"\n",
@@ -1949,6 +1930,59 @@
19491930
" return dt\n"
19501931
]
19511932
},
1933+
{
1934+
"cell_type": "code",
1935+
"execution_count": 1,
1936+
"metadata": {},
1937+
"outputs": [
1938+
{
1939+
"name": "stderr",
1940+
"output_type": "stream",
1941+
"text": [
1942+
"Seed set to 123\n"
1943+
]
1944+
}
1945+
],
1946+
"source": [
1947+
"import pytest\n",
1948+
"import numpy as np\n",
1949+
"from spotPython.fun.objectivefunctions import analytical\n",
1950+
"from spotPython.spot import spot\n",
1951+
"from spotPython.utils.init import (\n",
1952+
" fun_control_init, surrogate_control_init, design_control_init\n",
1953+
")\n",
1954+
"\n",
1955+
"def test_plot_progress():\n",
1956+
" # number of initial points:\n",
1957+
" ni = 7\n",
1958+
" # number of points\n",
1959+
" fun_evals = 10\n",
1960+
" fun = analytical().fun_sphere\n",
1961+
" fun_control = fun_control_init(\n",
1962+
" lower = np.array([-1, -1]),\n",
1963+
" upper = np.array([1, 1]),\n",
1964+
" fun_evals=fun_evals,\n",
1965+
" tolerance_x = np.sqrt(np.spacing(1))\n",
1966+
" )\n",
1967+
" design_control=design_control_init(init_size=ni)\n",
1968+
" surrogate_control=surrogate_control_init(n_theta=3)\n",
1969+
" S = spot.Spot(fun=fun,\n",
1970+
" fun_control=fun_control,\n",
1971+
" design_control=design_control,\n",
1972+
" surrogate_control=surrogate_control,)\n",
1973+
" S.run()\n",
1974+
"\n",
1975+
" # Test plot_progress with different parameters\n",
1976+
" S.plot_progress(show=False) # Test with show=False\n",
1977+
" S.plot_progress(log_x=True, show=False) # Test with log_x=True\n",
1978+
" S.plot_progress(log_y=True, show=False) # Test with log_y=True\n",
1979+
" S.plot_progress(filename=\"test_plot.png\", show=False) # Test with a different filename\n",
1980+
" # add NaN to S.y at position 2\n",
1981+
" S.y[2] = np.nan\n",
1982+
" S.plot_progress(show=False) # Test with show=False\n",
1983+
"\n"
1984+
]
1985+
},
19521986
{
19531987
"cell_type": "code",
19541988
"execution_count": null,

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.10.4"
10+
version = "0.10.5"
1111
authors = [
1212
{ name="T. Bartz-Beielstein", email="tbb@bartzundbartz.de" }
1313
]

test/test_plot_progress.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import pytest
2+
import numpy as np
3+
from spotPython.fun.objectivefunctions import analytical
4+
from spotPython.spot import spot
5+
from spotPython.utils.init import (
6+
fun_control_init, surrogate_control_init, design_control_init
7+
)
8+
9+
def test_plot_progress():
10+
# number of initial points:
11+
ni = 7
12+
# number of points
13+
fun_evals = 10
14+
fun = analytical().fun_sphere
15+
fun_control = fun_control_init(
16+
lower = np.array([-1, -1]),
17+
upper = np.array([1, 1]),
18+
fun_evals=fun_evals,
19+
tolerance_x = np.sqrt(np.spacing(1))
20+
)
21+
design_control=design_control_init(init_size=ni)
22+
surrogate_control=surrogate_control_init(n_theta=3)
23+
S = spot.Spot(fun=fun,
24+
fun_control=fun_control,
25+
design_control=design_control,
26+
surrogate_control=surrogate_control,)
27+
S.run()
28+
29+
# Test plot_progress with different parameters
30+
S.plot_progress(show=False) # Test with show=False
31+
S.plot_progress(log_x=True, show=False) # Test with log_x=True
32+
S.plot_progress(log_y=True, show=False) # Test with log_y=True
33+
S.plot_progress(filename="test_plot.png", show=False) # Test with a different filename
34+
# add NaN to S.y at position 2
35+
S.y[2] = np.nan
36+
S.plot_progress(show=False) # Test with NaN in S.y

0 commit comments

Comments
 (0)