Skip to content

Commit 7a147ff

Browse files
committed
BENCH: update the cruft
1 parent 84ef248 commit 7a147ff

3 files changed

Lines changed: 36 additions & 21 deletions

File tree

benchmarks/asv.conf.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
// If missing or the empty string, the tool will be automatically
2929
// determined by looking for tools on the PATH environment
3030
// variable.
31-
"environment_type": "conda",
31+
"environment_type": "virtualenv",
3232

3333
// timeout in seconds for installing any dependencies in environment
3434
// defaults to 10 min
@@ -57,8 +57,14 @@
5757
"attrs": [],
5858
"scipy": [],
5959
"tqdm": [],
60+
"build": [],
61+
"meson-python": [],
62+
"pip": [],
63+
"meson": [],
64+
"ninja": [],
6065
},
6166

67+
"build_command": "python -mpip wheel --no-deps --no-build-isolation --no-index -w {build_cache_dir} {build_dir}",
6268

6369
// Combinations of libraries/python versions can be excluded/included
6470
// from the set to test. Each entry is a dictionary containing additional

benchmarks/benchmarks/analysis.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os.path
2+
import multiprocessing as mp
23
import numpy as np
34

45
from .common import Benchmark
@@ -35,16 +36,20 @@ def setup(self):
3536

3637
data = Data1D(data=(x, y, y_err))
3738

38-
p = Parameter(b_ls, 'b', vary=True, bounds=(-100, 100))
39-
p |= Parameter(m_ls, 'm', vary=True, bounds=(-100, 100))
39+
p = Parameter(b_ls, "b", vary=True, bounds=(-100, 100))
40+
p |= Parameter(m_ls, "m", vary=True, bounds=(-100, 100))
4041

4142
model = Model(p, fitfunc=line)
4243
self.objective = Objective(model, data)
4344
self.mcfitter = CurveFitter(self.objective)
4445
self.mcfitter_t = CurveFitter(self.objective, ntemps=20)
4546

46-
self.mcfitter.initialise('prior')
47-
self.mcfitter_t.initialise('prior')
47+
self.mcfitter.initialise("prior")
48+
self.mcfitter_t.initialise("prior")
49+
self.pool = mp.get_context("spawn").Pool()
50+
51+
def teardown(self):
52+
self.pool.close()
4853

4954
def time_sampler(self):
5055
# to get an idea of how fast the actual sampling is.
@@ -54,4 +59,5 @@ def time_sampler(self):
5459
def time_sampler_pool(self):
5560
# see how the multiprocessing in curvefitter performs
5661
# automatically use all the cores available
57-
self.mcfitter_t.sample(20, pool=-1)
62+
if __name__ == "__main__":
63+
self.mcfitter_t.sample(20, pool=self.pool.map)

benchmarks/benchmarks/reflect.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@
1515
class Abeles(Benchmark):
1616
def setup(self):
1717
self.q = np.linspace(0.005, 0.5, 50000)
18-
self.layers = np.array([[0, 2.07, 0, 3],
19-
[50, 3.47, 0.0001, 4],
20-
[200, -0.5, 1e-5, 5],
21-
[50, 1, 0, 3],
22-
[0, 6.36, 0, 3]])
18+
self.layers = np.array(
19+
[
20+
[0, 2.07, 0, 3],
21+
[50, 3.47, 0.0001, 4],
22+
[200, -0.5, 1e-5, 5],
23+
[50, 1, 0, 3],
24+
[0, 6.36, 0, 3],
25+
]
26+
)
2327
self.repeat = 20
2428
self.number = 10
2529

@@ -37,17 +41,17 @@ def time_reflectivity_pointwise_dq(self):
3741

3842

3943
class Reflect(Benchmark):
40-
timeout = 120.
44+
timeout = 120.0
4145
# repeat = 2
4246

4347
def setup(self):
4448
pth = os.path.dirname(os.path.abspath(refnx.reflect.__file__))
45-
e361 = RD(os.path.join(pth, 'test', 'e361r.txt'))
49+
e361 = RD(os.path.join(pth, "tests", "e361r.txt"))
4650

47-
sio2 = SLD(3.47, name='SiO2')
48-
si = SLD(2.07, name='Si')
49-
d2o = SLD(6.36, name='D2O')
50-
polymer = SLD(1, name='polymer')
51+
sio2 = SLD(3.47, name="SiO2")
52+
si = SLD(2.07, name="Si")
53+
d2o = SLD(6.36, name="D2O")
54+
polymer = SLD(1, name="polymer")
5155

5256
# e361 is an older dataset, but well characterised
5357
structure361 = si | sio2(10, 4) | polymer(200, 3) | d2o(0, 3)
@@ -57,7 +61,7 @@ def setup(self):
5761
model361.bkg.vary = True
5862
model361.scale.range(0.1, 2)
5963
model361.bkg.range(0, 5e-5)
60-
model361.dq = 5.
64+
model361.dq = 5.0
6165

6266
# d2o
6367
structure361[-1].sld.real.vary = True
@@ -76,10 +80,9 @@ def setup(self):
7680
self.model361 = model361
7781

7882
# e361.x_err = None
79-
self.objective = Objective(self.model361,
80-
e361)
83+
self.objective = Objective(self.model361, e361)
8184
self.fitter = CurveFitter(self.objective, nwalkers=200)
82-
self.fitter.initialise('jitter')
85+
self.fitter.initialise("jitter")
8386

8487
def time_reflect_emcee(self):
8588
# test how fast the emcee sampler runs in serial mode

0 commit comments

Comments
 (0)