diff --git a/python/contracted_tensor_check.py b/python/contracted_tensor_check.py new file mode 100644 index 0000000..3ce628b --- /dev/null +++ b/python/contracted_tensor_check.py @@ -0,0 +1,36 @@ + +from os import listdir, linesep +from os.path import isfile, join + +CTcsv = '/home/sernst/tensor_contractor/bin/contracted_tensors.csv' +CTcsv_ref = '/home/sernst/tensor_contractor/bin/tests/contracted_tensors_mathematica.csv' + +refs = {}; + +with open(CTcsv_ref,'r') as file: + for line in file.readlines(): + splited = line.split(',') + p = splited[0] + u = splited[1] + pp = splited[2] + val = float(splited[3]) + refs[(p,u,pp)] = val; + + +max_error = 0; +count = 0; +with open(CTcsv,'r') as file: + for line in file.readlines(): + splited = line.split(',') + p = splited[0] + u = splited[1] + pp = splited[2] + val = float(splited[3]) + error = abs(val - refs[(p,u,pp)]); + count += 1 + max_error = max(max_error, error) + #print('Error: %e' % error) + +print('Max error:', max_error); +print(len(refs), 'in CTcsv_ref') +print(count, 'in CTcsv') diff --git a/python/contracted_tensor_merge.py b/python/contracted_tensor_merge.py new file mode 100644 index 0000000..5570758 --- /dev/null +++ b/python/contracted_tensor_merge.py @@ -0,0 +1,51 @@ + +from os import listdir, linesep +from os.path import isfile, join + +CTcsv = '/home/sernst/tensor_contractor/bin/contracted_tensors.csv' +errorcsv = '/home/sernst/tensor_contractor/bin/contracted_tensors_errors.csv' +CTdir = '/home/sernst/tensor_contractor/bin/output' +CTfiles = [f for f in listdir(CTdir) if isfile(join(CTdir, f))] + +coeffs = [] +error_cases = [] + +for f in CTfiles: + filepath = join(CTdir, f) + if 'last_computed' in filepath: continue + + try: + with open(filepath,'r') as file: + p = int(file.readline().split('=')[1]) + u = int(file.readline().split('=')[1]) + pp = int(file.readline().split('=')[1]) + val = file.readline().split('=')[1] + if val[0] == ' ': + # Mathematica write small number with scientific notation on two line + # we have to catch those + exp = val.strip() + val = file.readline().split(' ')[0] + 'e'+exp + val = val.strip() + timing = float(file.readline().split('=')[1]) + val = val.strip() + coeffs.append((p,u,pp,val, timing)) + + except Exception as err: + print("Error within: %s" % filepath) + tmp = filepath.split('.') + error_cases.append((int(tmp[1]),int(tmp[3]),int(tmp[5]))) + +# We sort first by i, then p, then pp +coeffs.sort(key=lambda x: (x[0],x[2],x[1])) + +with open(CTcsv, 'w') as file: + for p,u,pp,val,timing in coeffs: + line = '%i,%i,%i,%s,%f' % (p,u,pp,val,timing) + file.write(line+linesep) + +print('Merged %i files from \'%s\' into \'%s\'.' % (len(coeffs), CTdir, CTcsv)) + +with open(errorcsv,'w') as file: + for p,u,pp in error_cases: + file.write("%i,%i,%i\n" % (p,u,pp)) +print('Generated error csv for %i files intointo \'%s\'.' % (len(error_cases), CTcsv))