-
Notifications
You must be signed in to change notification settings - Fork 62
Description
I have a problem with adaptive, which becomes extremely slow after a certain number of iterations for high-dimensional issues (in my case, nine input dimensions). It works fine for a certain amount of iterations but then sharply increases computation time.
I am not using the Runner
because I need to run some code around the evaluation function that is not easily passed to the learner function argument.
My original problem (which I can't reproduce easily here) occurred at around 85 iterations. However, in the reproduction case below, it occurs after 256 iterations on my machine.
Minimum reproduction:
import time
import adaptive
import numpy as np
def sphere(xx):
x1, x2, x3, x4, x5, x6, x7, x8, x9 = xx
a = 0.4
return x1 + x9**2 + np.exp(-((x1**2 + x2**2 + x3**2 + x4**2 + x5**2 + x6**2 + x7**2 + x8**2 + x9**2 - 0.75**2) ** 2) / a**4) # fmt: skip
def test_learner(num_points):
print(f"Testing {num_points} points")
learner = adaptive.LearnerND(
func=None,
bounds=[(-1, 1)] * 9,
)
times = []
for i in range(num_points):
point, loss = learner.ask(1)
point = point[0]
t0 = time.time()
learner.tell(point, sphere(point))
t1 = time.time()
times.append(t1 - t0)
print(f"Avg tell time: {np.mean(times):.7f}s")
print(f"Std tell time: {np.std(times):.7f}s")
print(f"Max tell time: {np.max(times):.7f}s")
print(f"Min tell time: {np.min(times):.7f}s")
if __name__ == "__main__":
for i in range(1, 300):
test_learner(i)
Here, the average time steadily increases as one would expect, but it suddenly jumps in computational time above the 256th iteration.
...
Testing 256 points
Avg tell time: 0.0001s
Std tell time: 0.0001s
Max tell time: 0.0003s
Min tell time: 0.0000s
Min tell time: 0.0000s
Testing 257 points
Avg tell time: 0.0226s
Std tell time: 0.3602s
Max tell time: 5.7853s
Min tell time: 0.0000s
Testing 258 points
Avg tell time: 1.5320s
Std tell time: 24.1880s
Max tell time: 389.2496s
Min tell time: 0.0000s
The entire output is plotted here:
Minimum reproduction dependencies after installing adaptive with uv
python=3.11.10
adaptive==1.3.0
cloudpickle==3.1.0
loky==3.4.1
numpy==2.1.3
packaging==24.2
scipy==1.14.1
sortedcollections==2.1.0
sortedcontainers==2.4.0
versioningit==3.1.2