Skip to content

Commit c5d229a

Browse files
committed
style + cleanup
1 parent ade3472 commit c5d229a

10 files changed

+39
-201
lines changed

pyobs/core/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@
2525
from .gradient import gradient
2626
from .transform import transform
2727
from . import mftools
28-
from .complex import complex_observable
2928

3029
__all__ = ["observable"]
3130
__all__.extend(["derobs", "num_grad", "error_bias4"])
3231
__all__.extend(["errinfo"])
3332
__all__.extend(["mftools"])
3433
__all__.extend(["gradient"])
3534
__all__.extend(["transform"])
36-
__all__.extend(["complex_observable"])

pyobs/core/complex.py

-157
This file was deleted.

pyobs/core/data.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def axpy(self, grad, d):
197197

198198
# takes into accounts holes present in d.delta but absent in self.delta
199199
rescale_delta = self.n / d.n
200-
200+
201201
if (np.iscomplexobj(grad.grad)) or (np.iscomplexobj(d.delta)):
202202
self.delta = self.delta.astype(pyobs.complex)
203203
grad.apply(self.delta, self.mask, jlist, d.delta * rescale_delta, d.mask)
@@ -223,14 +223,12 @@ def gamma(self, xmax, a, b=None):
223223
self.delta, self.idx, self.ncnfg() if isMC else self.lat, xmax, a, b
224224
)
225225
return [m, g]
226-
226+
227227
def bias4(self, hess):
228228
oid = np.array(self.mask)
229229
idx = np.ix_(oid, oid)
230230
# no rescaling factor; prone to roundoff errors
231-
d2 = np.einsum(
232-
"abc,bj,cj->aj", hess[:, idx[0], idx[1]], self.delta, self.delta
233-
)
231+
d2 = np.einsum("abc,bj,cj->aj", hess[:, idx[0], idx[1]], self.delta, self.delta)
234232
return np.sum(d2, axis=1)
235233

236234
def blocked(self, bs):

pyobs/core/error.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ def __init__(self, n, g, Stau, D, k, fold=False):
4949
idx = numpy.arange(len(mask))[mask]
5050
self.x = [i for i in (idx if fold else numpy.sqrt(idx))]
5151

52-
###gg = pyobs.double_array((self.size, len(self.x)), zeros=True)
5352
gg = g[:, idx] / n[:, idx]
5453

5554
if fold:
@@ -83,13 +82,12 @@ def find_opt(self):
8382
for i in range(1, len(self.x)):
8483
if self.g(i, a) > 0:
8584
break
86-
while (self.cvar[a, i] < self.cvar[a, 0]):
85+
while self.cvar[a, i] < self.cvar[a, 0]:
8786
i -= 1
8887
if self.cvar[a, i] < 0:
8988
i = 0
9089
print(f"Warning: automatic window failed for obs {a}, using {i}")
91-
92-
90+
9391
self.xopt[a] = self.x[i]
9492
self.var[a, 0] = self.cvar[a, i]
9593
self.var[a, 1] = self.cvar[a, i] * self.stat_relerr(self.x[i], a)
@@ -98,7 +96,6 @@ def find_opt(self):
9896
print(
9997
f"Warning: automatic window failed for obs {a}, using {self.xopt[a]}"
10098
)
101-
10299

103100
def set_opt(self, xopt):
104101
for a in range(self.size):
@@ -252,10 +249,10 @@ def __init__(self, x, name, Stau, k):
252249
mask += x.delta[ik].mask
253250
self.mask = list(set(mask))
254251
self.size = len(self.mask)
255-
252+
256253
n = pyobs.double_array((self.size, xmax), zeros=True)
257254
g = pyobs.double_array((self.size, xmax), zeros=True)
258-
255+
259256
# with this code we cover the situation where 1 obs happens to be known on 1 replica
260257
# and another obs in another replica, which may have different dtrj
261258
for i in range(len(keys)):
@@ -338,6 +335,7 @@ def __init__(self, Stau=1.5, k=0, W=None, gamma_bias=True):
338335
self.W = W
339336
self.gamma_bias = gamma_bias
340337

338+
341339
def gamma_error(x, name, plot=False, pfile=None, einfo=None):
342340
if einfo is None:
343341
einfo = errinfo()

pyobs/core/gradient.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __init__(self, g, x0=None, gtype="full"):
3838
self.gtype = gtype
3939

4040
_grad = g(numpy.ones(x0.shape)).flatten()
41-
41+
4242
if gtype == "full":
4343
self.grad = pyobs.array((self.Na, self.Ni), _grad.dtype, zeros=True)
4444
dx = pyobs.double_array(self.Ni, zeros=True)
@@ -51,9 +51,9 @@ def __init__(self, g, x0=None, gtype="full"):
5151
pyobs.assertion(self.Na == self.Ni, "diagonal gradient error")
5252
else: # pragma: no cover
5353
raise pyobs.PyobsError("gradient error")
54-
54+
5555
del _grad
56-
56+
5757
def get_mask(self, mask):
5858
idx = pyobs.int_array(mask)
5959
if self.gtype == "full":

pyobs/core/ndobs.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def create(self, ename, data, icnfg=None, rname=None, shape=(1,), lat=None):
142142
data = [np.array(data).astype(pyobs.complex)]
143143
else:
144144
pyobs.assertion(True, "Data type not supported")
145-
145+
146146
R = len(data)
147147
nc = [len(data[ir]) // self.size for ir in range(R)]
148148
if rname is None:
@@ -175,7 +175,9 @@ def create(self, ename, data, icnfg=None, rname=None, shape=(1,), lat=None):
175175
key not in self.delta.keys(), f"Replica name {key} already used"
176176
)
177177
N0 = sum([self.delta[key].n for key in self.delta])
178-
mean_old = np.copy(self.mean.flatten()) #np.reshape(self.mean, (self.size,))
178+
mean_old = np.copy(
179+
self.mean.flatten()
180+
) # np.reshape(self.mean, (self.size,))
179181
print(N0, mean_old, sum(nc), mean_data)
180182
self.mean = (N0 * mean_old + sum(nc) * mean_data) / (N0 + sum(nc))
181183
shift = sum(nc) * (mean_old - mean_data) / (N0 + sum(nc))
@@ -336,7 +338,7 @@ def peek(self, verbose=False):
336338
outstr = f' - {"Replica" if self.delta[key].lat is None else "Master-field"} {rn[1]}'
337339
outstr = f'{outstr} with {f"ncnfg {self.delta[key].n}" if self.delta[key].lat is None else f"lattice {self.delta[key].lat}"}'
338340
print(outstr)
339-
outstr = f' index field {self.delta[key].idx}'
341+
outstr = f" index field {self.delta[key].idx}"
340342
print(outstr)
341343
mm = (
342344
self.delta[key].ncnfg() * 8.0 * 2.0
@@ -568,18 +570,18 @@ def __itruediv__(self, y):
568570
self = pyobs.observable(tmp)
569571
del tmp
570572
return self
571-
573+
572574
def real(self):
573-
return pyobs.observable(self, projector = lambda x: x.real)
574-
575+
return pyobs.observable(self, projector=lambda x: x.real)
576+
575577
def imag(self):
576-
return pyobs.observable(self, projector = lambda x: x.imag)
577-
578+
return pyobs.observable(self, projector=lambda x: x.imag)
579+
578580
def conj(self):
579581
if np.iscomplexobj(self.mean):
580582
return self.real() - 1j * self.imag()
581583
return self
582-
584+
583585
##################################
584586
# Error functions
585587

@@ -658,7 +660,7 @@ class provides additional details for the automatic or manual
658660
h = [len(self.ename), len(self.cdata)]
659661
if sum(h) > 1:
660662
plot_piechart(self.description, sigma, sigma_tot.real)
661-
663+
662664
return [self.mean, np.sqrt(sigma_tot)]
663665

664666
def error_breakdown(self, errinfo={}):

pyobs/core/transform.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,26 @@
3434
# idx_b += [b.index(_a)]
3535
# return idx_a, idx_b
3636

37-
def indices_isin(a,b):
37+
38+
def indices_isin(a, b):
3839
# idx_a = indices of elements of a that are present in b preserving the order a
39-
idx_a = numpy.arange(len(a))[numpy.in1d(a,b)]
40-
if idx_a.size==0:
40+
idx_a = numpy.arange(len(a))[numpy.in1d(a, b)]
41+
if idx_a.size == 0:
4142
return [], []
4243
# idx_b = indices of elements of b that are present in a preserving the order a
43-
idx_b = numpy.arange(len(b))[numpy.in1d(b,a)]
44-
mask = numpy.array(a)[idx_a,None] == numpy.array(b)[idx_b]
45-
idx_b_2 = numpy.stack([idx_b]*len(idx_a))[mask]
44+
idx_b = numpy.arange(len(b))[numpy.in1d(b, a)]
45+
mask = numpy.array(a)[idx_a, None] == numpy.array(b)[idx_b]
46+
idx_b_2 = numpy.stack([idx_b] * len(idx_a))[mask]
4647
return list(idx_a), list(idx_b_2)
47-
48+
4849

4950
def transform(obs, f):
5051
new_mean = f(obs.mean)
5152
res = pyobs.observable(description=obs.description)
5253
res.set_mean(new_mean)
5354

5455
subset_mask = f(numpy.reshape(numpy.arange(obs.size), obs.shape)).flatten()
55-
56+
5657
for key in obs.delta:
5758
d = obs.delta[key]
5859
idx_subset_mask, idx_mask = indices_isin(subset_mask, d.mask)

0 commit comments

Comments
 (0)