Skip to content

Commit 8812f7e

Browse files
committed
auto yapf (to avoid future diffs)
1 parent ffbf8a4 commit 8812f7e

10 files changed

Lines changed: 108 additions & 97 deletions

py/dynesty/bounding.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ def _slogdet_checked(matrix):
6969
raise ValueError(
7070
f"Invalid ellipsoid: covariance matrix has non-positive determinant "
7171
f"(sign={detsign}). This may indicate degenerate live points or "
72-
f"numerical instability. Matrix shape: {matrix.shape}"
73-
)
72+
f"numerical instability. Matrix shape: {matrix.shape}")
7473
return detln
7574

7675

tests/test_dyn.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ def test_dyn():
3737
nlive=nlive,
3838
rstate=rstate)
3939
sampler.run_nested(dlogz_init=1, print_progress=printing)
40-
assert (abs(LOGZ_TRUTH - sampler.results.logz[-1]) <
41-
THRESHOLD * sampler.results.logzerr[-1])
40+
assert (abs(LOGZ_TRUTH - sampler.results.logz[-1])
41+
< THRESHOLD * sampler.results.logzerr[-1])
4242
print(sampler.citations)

tests/test_egg.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def test_bounds(bound, sample):
4242
sample=sample,
4343
rstate=rstate)
4444
sampler.run_nested(dlogz=0.01, print_progress=printing)
45-
assert (abs(LOGZ_TRUTH - sampler.results.logz[-1]) <
46-
5. * sampler.results.logzerr[-1])
45+
assert (abs(LOGZ_TRUTH - sampler.results.logz[-1])
46+
< 5. * sampler.results.logzerr[-1])
4747

4848

4949
def test_ellipsoids_bootstrap():
@@ -59,5 +59,5 @@ def test_ellipsoids_bootstrap():
5959
bootstrap=5,
6060
rstate=rstate)
6161
sampler.run_nested(dlogz=0.01, print_progress=printing)
62-
assert (abs(LOGZ_TRUTH - sampler.results.logz[-1]) <
63-
5. * sampler.results.logzerr[-1])
62+
assert (abs(LOGZ_TRUTH - sampler.results.logz[-1])
63+
< 5. * sampler.results.logzerr[-1])

tests/test_highdim.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,9 @@ def do_gaussians(sample='rslice',
127127

128128

129129
@pytest.mark.slow
130-
@pytest.mark.parametrize("ndim,sample",
131-
list(
132-
itertools.product([10, 30],
133-
['rslice', 'rwalk', 'unif'])))
130+
@pytest.mark.parametrize(
131+
"ndim,sample",
132+
list(itertools.product([10, 30], ['rslice', 'rwalk', 'unif'])))
134133
def test_run(ndim, sample):
135134
"""
136135
Run the Gaussian likelihood test

tests/test_pathology.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ def prior_transform(x):
2626
return x * 2 - 1
2727

2828

29-
@pytest.mark.parametrize("dynamic,bound,sample",
30-
itertools.product([False, True], ['multi'],
31-
['unif', 'rslice', 'rwalk']))
29+
@pytest.mark.parametrize(
30+
"dynamic,bound,sample",
31+
itertools.product([False, True], ['multi'], ['unif', 'rslice', 'rwalk']))
3232
def test_pathology(dynamic, bound, sample):
3333
ndim = 2
3434
rstate = get_rstate()

tests/test_periodic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def test_periodic(sampler, dynamic):
4848
rstate=rstate,
4949
sample=sampler)
5050
dns.run_nested(dlogz=1, print_progress=printing)
51-
assert (np.abs(dns.results['logz'][-1] - logz_true) <
52-
thresh * dns.results['logzerr'][-1])
51+
assert (np.abs(dns.results['logz'][-1] - logz_true)
52+
< thresh * dns.results['logzerr'][-1])
5353

5454

5555
def test_error():

tests/test_proposal_stats.py

Lines changed: 87 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ def __init__(self, corr=.95, prior_win=10):
1717
self.ndim = 3
1818
self.mean = np.linspace(-1, 1, self.ndim)
1919
self.cov = np.identity(self.ndim)
20-
self.cov[self.cov ==
21-
0] = corr
20+
self.cov[self.cov == 0] = corr
2221
self.cov_inv = linalg.inv(self.cov)
2322
self.lnorm = -0.5 * (np.log(2 * np.pi) * self.ndim +
2423
np.log(linalg.det(self.cov)))
@@ -39,13 +38,14 @@ def prior_transform(self, u):
3938
def test_static_proposal_stats():
4039
rstate = get_rstate()
4140
g = Gaussian()
42-
sampler = dynesty.NestedSampler(g.loglikelihood,
43-
g.prior_transform,
44-
g.ndim,
45-
nlive=nlive,
46-
rstate=rstate,
47-
sample='rwalk',
48-
blob=False) # blob=False to isolate proposal_stats
41+
sampler = dynesty.NestedSampler(
42+
g.loglikelihood,
43+
g.prior_transform,
44+
g.ndim,
45+
nlive=nlive,
46+
rstate=rstate,
47+
sample='rwalk',
48+
blob=False) # blob=False to isolate proposal_stats
4949
sampler.run_nested(print_progress=printing, maxiter=100)
5050
res = sampler.results
5151
assert 'proposal_stats' in res
@@ -61,13 +61,14 @@ def test_static_proposal_stats():
6161
def test_dynamic_proposal_stats():
6262
rstate = get_rstate()
6363
g = Gaussian()
64-
sampler = dynesty.DynamicNestedSampler(g.loglikelihood,
65-
g.prior_transform,
66-
g.ndim,
67-
nlive=nlive,
68-
rstate=rstate,
69-
sample='unif',
70-
blob=False) # blob=False to isolate proposal_stats
64+
sampler = dynesty.DynamicNestedSampler(
65+
g.loglikelihood,
66+
g.prior_transform,
67+
g.ndim,
68+
nlive=nlive,
69+
rstate=rstate,
70+
sample='unif',
71+
blob=False) # blob=False to isolate proposal_stats
7172
sampler.run_nested(print_progress=printing, dlogz_init=1, maxiter_init=100)
7273
res = sampler.results
7374
assert 'proposal_stats' in res
@@ -84,16 +85,17 @@ def test_proposal_stats_length_consistency():
8485
"""Test that proposal_stats array has same length as samples array"""
8586
rstate = get_rstate()
8687
g = Gaussian()
87-
sampler = dynesty.NestedSampler(g.loglikelihood,
88-
g.prior_transform,
89-
g.ndim,
90-
nlive=nlive//10, # smaller for faster test
91-
rstate=rstate,
92-
sample='rwalk',
93-
blob=False)
88+
sampler = dynesty.NestedSampler(
89+
g.loglikelihood,
90+
g.prior_transform,
91+
g.ndim,
92+
nlive=nlive // 10, # smaller for faster test
93+
rstate=rstate,
94+
sample='rwalk',
95+
blob=False)
9496
sampler.run_nested(print_progress=printing, maxiter=50)
9597
res = sampler.results
96-
98+
9799
# Check length consistency
98100
assert len(res['proposal_stats']) == len(res.samples)
99101

@@ -102,30 +104,32 @@ def test_proposal_stats_different_samplers():
102104
"""Test proposal_stats with different sampling methods"""
103105
rstate = get_rstate()
104106
g = Gaussian()
105-
107+
106108
# Test different sampling methods
107109
sampling_methods = ['unif', 'rwalk', 'slice', 'rslice']
108-
110+
109111
for sample_method in sampling_methods:
110-
sampler = dynesty.NestedSampler(g.loglikelihood,
111-
g.prior_transform,
112-
g.ndim,
113-
nlive=nlive//10, # smaller for faster test
114-
rstate=rstate,
115-
sample=sample_method,
116-
blob=False)
112+
sampler = dynesty.NestedSampler(
113+
g.loglikelihood,
114+
g.prior_transform,
115+
g.ndim,
116+
nlive=nlive // 10, # smaller for faster test
117+
rstate=rstate,
118+
sample=sample_method,
119+
blob=False)
117120
sampler.run_nested(print_progress=printing, maxiter=30)
118121
res = sampler.results
119-
122+
120123
# Basic checks
121124
assert 'proposal_stats' in res
122125
assert res['proposal_stats'] is not None
123126
assert len(res['proposal_stats']) == len(res['logl'])
124-
127+
125128
# Check that we have some non-None proposal_stats
126-
non_none_count = sum(1 for ps in res['proposal_stats'] if ps is not None)
129+
non_none_count = sum(1 for ps in res['proposal_stats']
130+
if ps is not None)
127131
assert non_none_count > 0, f"No proposal_stats found for {sample_method}"
128-
132+
129133
# Check structure of non-None entries
130134
for ps in res['proposal_stats']:
131135
if ps is not None:
@@ -139,42 +143,42 @@ def test_proposal_stats_nested_vs_dynamic():
139143
"""Test proposal_stats consistency between nested and dynamic nested samplers"""
140144
rstate = get_rstate()
141145
g = Gaussian()
142-
146+
143147
# Test with nested sampler
144148
sampler_nested = dynesty.NestedSampler(g.loglikelihood,
145-
g.prior_transform,
146-
g.ndim,
147-
nlive=nlive//10,
148-
rstate=rstate,
149-
sample='rwalk',
150-
blob=False)
149+
g.prior_transform,
150+
g.ndim,
151+
nlive=nlive // 10,
152+
rstate=rstate,
153+
sample='rwalk',
154+
blob=False)
151155
sampler_nested.run_nested(print_progress=printing, maxiter=30)
152156
res_nested = sampler_nested.results
153-
157+
154158
# Test with dynamic nested sampler
155159
rstate = get_rstate() # Reset to same state
156160
sampler_dynamic = dynesty.DynamicNestedSampler(g.loglikelihood,
157-
g.prior_transform,
158-
g.ndim,
159-
nlive=nlive//10,
160-
rstate=rstate,
161-
sample='rwalk',
162-
blob=False)
163-
sampler_dynamic.run_nested(print_progress=printing,
164-
dlogz_init=1,
165-
maxiter_init=30)
161+
g.prior_transform,
162+
g.ndim,
163+
nlive=nlive // 10,
164+
rstate=rstate,
165+
sample='rwalk',
166+
blob=False)
167+
sampler_dynamic.run_nested(print_progress=printing,
168+
dlogz_init=1,
169+
maxiter_init=30)
166170
res_dynamic = sampler_dynamic.results
167-
171+
168172
# Both should have proposal_stats
169173
assert 'proposal_stats' in res_nested
170174
assert 'proposal_stats' in res_dynamic
171175
assert res_nested['proposal_stats'] is not None
172176
assert res_dynamic['proposal_stats'] is not None
173-
177+
174178
# Both should have consistent lengths
175179
assert len(res_nested['proposal_stats']) == len(res_nested['logl'])
176180
assert len(res_dynamic['proposal_stats']) == len(res_dynamic['logl'])
177-
181+
178182
# Both should have some non-None proposal_stats
179183
assert any(ps is not None for ps in res_nested['proposal_stats'])
180184
assert any(ps is not None for ps in res_dynamic['proposal_stats'])
@@ -187,67 +191,74 @@ def test_proposal_stats_content_validity():
187191
sampler = dynesty.NestedSampler(g.loglikelihood,
188192
g.prior_transform,
189193
g.ndim,
190-
nlive=nlive//10,
194+
nlive=nlive // 10,
191195
rstate=rstate,
192196
sample='rwalk',
193197
blob=False)
194198
sampler.run_nested(print_progress=printing, maxiter=30)
195199
res = sampler.results
196-
200+
197201
# Check content of proposal_stats
198202
for i, ps in enumerate(res['proposal_stats']):
199203
if ps is not None:
200204
# Should be a dictionary
201205
assert isinstance(ps, dict), f"proposal_stats[{i}] is not a dict"
202-
206+
203207
# Should contain n_proposals
204208
assert 'n_proposals' in ps, f"proposal_stats[{i}] missing 'n_proposals'"
205-
209+
206210
# n_proposals should be a positive integer
207211
n_prop = ps['n_proposals']
208-
assert isinstance(n_prop, (int, np.integer)), f"n_proposals is not an integer at index {i}"
212+
assert isinstance(
213+
n_prop,
214+
(int,
215+
np.integer)), f"n_proposals is not an integer at index {i}"
209216
assert n_prop > 0, f"n_proposals should be positive at index {i}, got {n_prop}"
210-
217+
211218
# If there are other keys, they should have reasonable values
212219
for key, value in ps.items():
213220
if key != 'n_proposals':
214221
# Any additional stats should be numeric and finite
215222
if isinstance(value, (int, float, np.number)):
216-
assert np.isfinite(value), f"Non-finite value in proposal_stats[{i}]['{key}']"
223+
assert np.isfinite(
224+
value
225+
), f"Non-finite value in proposal_stats[{i}]['{key}']"
217226

218227

219228
def test_proposal_stats_with_blob():
220229
"""Test that proposal_stats work correctly when blob is also enabled"""
230+
221231
def loglikelihood_with_blob(x):
222232
logl = -0.5 * np.sum(x**2)
223233
blob = {'param_sum': np.sum(x), 'param_max': np.max(x)}
224234
return logl, blob
225-
235+
226236
def prior_transform(u):
227237
return 4 * (u - 0.5) # uniform from -2 to 2
228-
238+
229239
rstate = get_rstate()
230-
sampler = dynesty.NestedSampler(loglikelihood_with_blob,
231-
prior_transform,
232-
3, # ndim
233-
nlive=nlive//10,
234-
rstate=rstate,
235-
sample='rwalk',
236-
blob=True)
240+
sampler = dynesty.NestedSampler(
241+
loglikelihood_with_blob,
242+
prior_transform,
243+
3, # ndim
244+
nlive=nlive // 10,
245+
rstate=rstate,
246+
sample='rwalk',
247+
blob=True)
237248
sampler.run_nested(print_progress=printing, maxiter=30)
238249
res = sampler.results
239-
250+
240251
# Should have both blob and proposal_stats
241252
assert 'blob' in res
242253
assert 'proposal_stats' in res
243254
assert res['blob'] is not None
244255
assert res['proposal_stats'] is not None
245-
256+
246257
# Both arrays should have same length as samples
247258
assert len(res['blob']) == len(res.samples)
248259
assert len(res['proposal_stats']) == len(res.samples)
249260
assert len(res['proposal_stats']) == len(res['logl'])
250-
261+
251262
# Check that both contain valid data
252263
assert any(b is not None for b in res['blob'])
253264
assert any(ps is not None for ps in res['proposal_stats'])

tests/test_reflect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def test_periodic(sampler, dynamic):
4343
reflective=[0],
4444
rstate=rstate)
4545
dns.run_nested(print_progress=printing)
46-
assert (np.abs(dns.results['logz'][-1] - logz_true) <
47-
thresh * dns.results['logzerr'][-1])
46+
assert (np.abs(dns.results['logz'][-1] - logz_true)
47+
< thresh * dns.results['logzerr'][-1])
4848

4949

5050
def test_error():

tests/test_rosenbrock.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ def domany(sample='rslice', nlive=500, niter=100, nthreads=1):
7979
start = True
8080
rstate = get_rstate()
8181
seed = rstate.integers(int(1e9))
82-
with (mp.get_context('spawn').Pool(nthreads) if nthreads > 1 else NullContextManager()) as pool:
82+
with (mp.get_context('spawn').Pool(nthreads)
83+
if nthreads > 1 else NullContextManager()) as pool:
8384
Cs = []
8485
for i in range(niter):
8586
if nthreads > 1:

tests/test_saver.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def test_saving(dopool, maxiter):
3434
rstate = get_rstate()
3535
kw = {}
3636

37-
with (NullContextManager() if not dopool else mp.get_context('spawn').Pool(2)) as pool:
37+
with (NullContextManager()
38+
if not dopool else mp.get_context('spawn').Pool(2)) as pool:
3839
if dopool:
3940
pool = pool
4041
kw['pool'] = pool

0 commit comments

Comments
 (0)