Skip to content

Commit 4089238

Browse files
committed
[Fix] Fix further mutable default arguments and smaller issues.
1 parent 668fa62 commit 4089238

File tree

9 files changed

+44
-28
lines changed

9 files changed

+44
-28
lines changed

pyerrors/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
r'''
1+
r"""
22
# What is pyerrors?
33
`pyerrors` is a python package for error computation and propagation of Markov chain Monte Carlo data.
44
It is based on the gamma method [arXiv:hep-lat/0306017](https://arxiv.org/abs/hep-lat/0306017). Some of its features are:
@@ -476,7 +476,7 @@ def func(a, x):
476476
A JSON schema that may be used to verify the correctness of a file with respect to the format definition is stored in ./examples/json_schema.json. The schema is a self-descriptive format definition and contains an exemplary file.
477477
478478
Julia I/O routines for the json.gz format, compatible with [ADerrors.jl](https://gitlab.ift.uam-csic.es/alberto/aderrors.jl), can be found [here](https://github.com/fjosw/ADjson.jl).
479-
'''
479+
"""
480480
from .obs import *
481481
from .correlators import *
482482
from .fits import *

pyerrors/fits.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def __repr__(self):
7171

7272

7373
def least_squares(x, y, func, priors=None, silent=False, **kwargs):
74-
r'''Performs a non-linear fit to y = func(x).
74+
r"""Performs a non-linear fit to y = func(x).
7575
```
7676
7777
Parameters
@@ -224,7 +224,7 @@ def func_b(a, x):
224224
chisquare/d.o.f.: 0.5388013574561786 # random
225225
fit parameters [1.11897846 0.96361162 0.92325319] # random
226226
227-
'''
227+
"""
228228
output = Fit_result()
229229

230230
if (isinstance(x, dict) and isinstance(y, dict) and isinstance(func, dict)):
@@ -504,7 +504,7 @@ def chisqfunc_compact(d):
504504

505505

506506
def total_least_squares(x, y, func, silent=False, **kwargs):
507-
r'''Performs a non-linear fit to y = func(x) and returns a list of Obs corresponding to the fit parameters.
507+
r"""Performs a non-linear fit to y = func(x) and returns a list of Obs corresponding to the fit parameters.
508508
509509
Parameters
510510
----------
@@ -553,7 +553,7 @@ def func(a, x):
553553
-------
554554
output : Fit_result
555555
Parameters and information on the fitted result.
556-
'''
556+
"""
557557

558558
output = Fit_result()
559559

pyerrors/input/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
r'''
1+
r"""
22
`pyerrors` includes an `input` submodule in which input routines and parsers for the output of various numerical programs are contained.
33
44
# Jackknife samples
55
For comparison with other analysis workflows `pyerrors` can also generate jackknife samples from an `Obs` object or import jackknife samples into an `Obs` object.
66
See `pyerrors.obs.Obs.export_jackknife` and `pyerrors.obs.import_jackknife` for details.
7-
'''
7+
"""
88
from . import bdio as bdio
99
from . import dobs as dobs
1010
from . import hadrons as hadrons

pyerrors/input/dobs.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def _dict_to_xmlstring_spaces(d, space=' '):
8585
return o
8686

8787

88-
def create_pobs_string(obsl, name, spec='', origin='', symbol=[], enstag=None):
88+
def create_pobs_string(obsl, name, spec='', origin='', symbol=None, enstag=None):
8989
"""Export a list of Obs or structures containing Obs to an xml string
9090
according to the Zeuthen pobs format.
9191
@@ -113,6 +113,8 @@ def create_pobs_string(obsl, name, spec='', origin='', symbol=[], enstag=None):
113113
XML formatted string of the input data
114114
"""
115115

116+
if symbol is None:
117+
symbol = []
116118
od = {}
117119
ename = obsl[0].e_names[0]
118120
names = list(obsl[0].deltas.keys())
@@ -176,7 +178,7 @@ def create_pobs_string(obsl, name, spec='', origin='', symbol=[], enstag=None):
176178
return rs
177179

178180

179-
def write_pobs(obsl, fname, name, spec='', origin='', symbol=[], enstag=None, gz=True):
181+
def write_pobs(obsl, fname, name, spec='', origin='', symbol=None, enstag=None, gz=True):
180182
"""Export a list of Obs or structures containing Obs to a .xml.gz file
181183
according to the Zeuthen pobs format.
182184
@@ -206,6 +208,8 @@ def write_pobs(obsl, fname, name, spec='', origin='', symbol=[], enstag=None, gz
206208
-------
207209
None
208210
"""
211+
if symbol is None:
212+
symbol = []
209213
pobsstring = create_pobs_string(obsl, name, spec, origin, symbol, enstag)
210214

211215
if not fname.endswith('.xml') and not fname.endswith('.gz'):
@@ -309,7 +313,7 @@ def read_pobs(fname, full_output=False, gz=True, separator_insertion=None):
309313
full_output : bool
310314
If True, a dict containing auxiliary information and the data is returned.
311315
If False, only the data is returned as list.
312-
separatior_insertion: str or int
316+
separator_insertion: str or int
313317
str: replace all occurences of "separator_insertion" within the replica names
314318
by "|%s" % (separator_insertion) when constructing the names of the replica.
315319
int: Insert the separator "|" at the position given by separator_insertion.
@@ -409,7 +413,7 @@ def import_dobs_string(content, full_output=False, separator_insertion=True):
409413
full_output : bool
410414
If True, a dict containing auxiliary information and the data is returned.
411415
If False, only the data is returned as list.
412-
separatior_insertion: str, int or bool
416+
separator_insertion: str, int or bool
413417
str: replace all occurences of "separator_insertion" within the replica names
414418
by "|%s" % (separator_insertion) when constructing the names of the replica.
415419
int: Insert the separator "|" at the position given by separator_insertion.
@@ -677,7 +681,7 @@ def _dobsdict_to_xmlstring_spaces(d, space=' '):
677681
return o
678682

679683

680-
def create_dobs_string(obsl, name, spec='dobs v1.0', origin='', symbol=[], who=None, enstags=None):
684+
def create_dobs_string(obsl, name, spec='dobs v1.0', origin='', symbol=None, who=None, enstags=None):
681685
"""Generate the string for the export of a list of Obs or structures containing Obs
682686
to a .xml.gz file according to the Zeuthen dobs format.
683687
@@ -708,6 +712,8 @@ def create_dobs_string(obsl, name, spec='dobs v1.0', origin='', symbol=[], who=N
708712
xml_str : str
709713
XML string generated from the data
710714
"""
715+
if symbol is None:
716+
symbol = []
711717
if enstags is None:
712718
enstags = {}
713719
od = {}
@@ -866,7 +872,7 @@ def create_dobs_string(obsl, name, spec='dobs v1.0', origin='', symbol=[], who=N
866872
return rs
867873

868874

869-
def write_dobs(obsl, fname, name, spec='dobs v1.0', origin='', symbol=[], who=None, enstags=None, gz=True):
875+
def write_dobs(obsl, fname, name, spec='dobs v1.0', origin='', symbol=None, who=None, enstags=None, gz=True):
870876
"""Export a list of Obs or structures containing Obs to a .xml.gz file
871877
according to the Zeuthen dobs format.
872878
@@ -900,6 +906,8 @@ def write_dobs(obsl, fname, name, spec='dobs v1.0', origin='', symbol=[], who=No
900906
-------
901907
None
902908
"""
909+
if symbol is None:
910+
symbol = []
903911
if enstags is None:
904912
enstags = {}
905913

pyerrors/input/hadrons.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def extract_t0_hd5(path, filestem, ens_id, obs='Clover energy density', fit_rang
245245
return fit_t0(t2E_dict, fit_range, plot_fit=kwargs.get('plot_fit'))
246246

247247

248-
def read_DistillationContraction_hd5(path, ens_id, diagrams=["direct"], idl=None):
248+
def read_DistillationContraction_hd5(path, ens_id, diagrams=None, idl=None):
249249
"""Read hadrons DistillationContraction hdf5 files in given directory structure
250250
251251
Parameters
@@ -265,6 +265,8 @@ def read_DistillationContraction_hd5(path, ens_id, diagrams=["direct"], idl=None
265265
extracted DistillationContration data
266266
"""
267267

268+
if diagrams is None:
269+
diagrams = ["direct"]
268270
res_dict = {}
269271

270272
directories, idx = _get_files(path, "data", idl)
@@ -486,7 +488,7 @@ def read_Bilinear_hd5(path, filestem, ens_id, idl=None):
486488
return result_dict
487489

488490

489-
def read_Fourquark_hd5(path, filestem, ens_id, idl=None, vertices=["VA", "AV"]):
491+
def read_Fourquark_hd5(path, filestem, ens_id, idl=None, vertices=None):
490492
"""Read hadrons FourquarkFullyConnected hdf5 file and output an array of CObs
491493
492494
Parameters
@@ -508,6 +510,8 @@ def read_Fourquark_hd5(path, filestem, ens_id, idl=None, vertices=["VA", "AV"]):
508510
extracted fourquark matrizes
509511
"""
510512

513+
if vertices is None:
514+
vertices = ["VA", "AV"]
511515
files, idx = _get_files(path, filestem, idl)
512516

513517
mom_in = None
@@ -596,7 +600,7 @@ def _get_lorentz_names(name):
596600
assert len(name) == 2
597601

598602
if 'S' in name or 'P' in name:
599-
if not set(name) <= set(['S', 'P']):
603+
if not set(name) <= {'S', 'P'}:
600604
raise Exception("'" + name + "' is not a Lorentz scalar")
601605

602606
g_names = {'S': 'Identity',
@@ -605,7 +609,7 @@ def _get_lorentz_names(name):
605609
res.append((g_names[name[0]], g_names[name[1]]))
606610

607611
else:
608-
if not set(name) <= set(['V', 'A']):
612+
if not set(name) <= {'V', 'A'}:
609613
raise Exception("'" + name + "' is not a Lorentz scalar")
610614

611615
for ind in lorentz_index:

pyerrors/input/openQCD.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,9 @@ def _parse_array_openQCD2(d, n, size, wa, quadrupel=False):
596596
return arr
597597

598598

599-
def _find_files(path, prefix, postfix, ext, known_files=[]):
599+
def _find_files(path, prefix, postfix, ext, known_files=None):
600+
if known_files is None:
601+
known_files = []
600602
found = []
601603
files = []
602604

@@ -1268,7 +1270,7 @@ def read_ms5_xsf(path, prefix, qc, corr, sep="r", **kwargs):
12681270
idl_wanted = True
12691271
if 'idl' in kwargs:
12701272
idl_wanted = (cnfg in expected_idl[repnum])
1271-
left_idl = left_idl - set([cnfg])
1273+
left_idl = left_idl - {cnfg}
12721274
if idl_wanted:
12731275
cnfgs[repnum].append(cnfg)
12741276

pyerrors/input/sfcf.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def read_sfcf_multi(path, prefix, name_list, quarks_list=['.*'], corr_type_list=
176176
# Exclude folders with different names
177177
for exc in ls:
178178
if not fnmatch.fnmatch(exc, prefix + '*'):
179-
ls = list(set(ls) - set([exc]))
179+
ls = list(set(ls) - {exc})
180180

181181
if not appended:
182182
ls = sort_names(ls)
@@ -343,7 +343,7 @@ def read_sfcf_multi(path, prefix, name_list, quarks_list=['.*'], corr_type_list=
343343
name_ls = ls
344344
for exc in name_ls:
345345
if not fnmatch.fnmatch(exc, prefix + '*.' + name):
346-
name_ls = list(set(name_ls) - set([exc]))
346+
name_ls = list(set(name_ls) - {exc})
347347
name_ls = sort_names(name_ls)
348348
pattern = intern[name]['spec'][quarks][off][w][w2]['pattern']
349349
deltas = []
@@ -460,7 +460,9 @@ def _extract_corr_type(corr_type):
460460
return b2b, single
461461

462462

463-
def _find_files(rep_path, prefix, compact, files=[]):
463+
def _find_files(rep_path, prefix, compact, files=None):
464+
if files is None:
465+
files = []
464466
sub_ls = []
465467
if not files == []:
466468
files.sort(key=lambda x: int(re.findall(r'\d+', x)[-1]))
@@ -474,12 +476,12 @@ def _find_files(rep_path, prefix, compact, files=[]):
474476
if compact:
475477
for exc in sub_ls:
476478
if not fnmatch.fnmatch(exc, prefix + '*'):
477-
sub_ls = list(set(sub_ls) - set([exc]))
479+
sub_ls = list(set(sub_ls) - {exc})
478480
sub_ls.sort(key=lambda x: int(re.findall(r'\d+', x)[-1]))
479481
else:
480482
for exc in sub_ls:
481483
if not fnmatch.fnmatch(exc, 'cfg*'):
482-
sub_ls = list(set(sub_ls) - set([exc]))
484+
sub_ls = list(set(sub_ls) - {exc})
483485
sub_ls.sort(key=lambda x: int(x[3:]))
484486
files = sub_ls
485487
if len(files) == 0:
@@ -665,7 +667,7 @@ def _get_appended_rep_names(ls, prefix, name, ens_name=None):
665667
new_names = []
666668
for exc in ls:
667669
if not fnmatch.fnmatch(exc, prefix + '*.' + name):
668-
ls = list(set(ls) - set([exc]))
670+
ls = list(set(ls) - {exc})
669671
ls.sort(key=lambda x: int(re.findall(r'\d+', x)[-1]))
670672
for entry in ls:
671673
myentry = entry[:-len(name) - 1]

pyerrors/input/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def check_params(path, param_hash, prefix, param_prefix="parameters_"):
112112
# Exclude folders with different names
113113
for exc in ls:
114114
if not fnmatch.fnmatch(exc, prefix + '*'):
115-
ls = list(set(ls) - set([exc]))
115+
ls = list(set(ls) - {exc})
116116

117117
ls = sort_names(ls)
118118
nums = {}

pyerrors/misc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def gen_correlated_data(means, cov, name, tau=0.5, samples=1000):
174174
return [Obs([dat], [name]) for dat in corr_data.T]
175175

176176

177-
def _assert_equal_properties(ol, otype=Obs):
177+
def _assert_equal_properties(ol):
178178
otype = type(ol[0])
179179
for o in ol[1:]:
180180
if not isinstance(o, otype):

0 commit comments

Comments
 (0)