-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_results.py
More file actions
102 lines (75 loc) · 3.43 KB
/
process_results.py
File metadata and controls
102 lines (75 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import numpy as np
import matplotlib.pyplot as plt
from scipy import linalg
import pandas as pd
import glob
import os
def fetch_blist(filepath):
loaded_data = pd.read_csv(filepath, header=None)
blist = loaded_data.to_numpy()[:,0]
return blist
def eigensystem_from_blist(blist):
diag = np.zeros(len(blist)+1)
envals, envecs = linalg.eigh_tridiagonal(diag, blist)
return envals, envecs
def save_eigensystem(envals, envecs, filepath):
dirname, basename = os.path.split(filepath)
new_prefix = "evals"
new_basename = basename.replace('bn', new_prefix, 1)
new_filepath = os.path.join(dirname,"processed" ,new_basename)
np.savetxt(new_filepath, envals, delimiter=',')
new_prefix = "evecs"
new_basename = basename.replace('bn', new_prefix, 1)
new_filepath = os.path.join(dirname,"processed" ,new_basename)
np.savetxt(new_filepath, envecs, delimiter=',')
return
def fetch_data(nspins, system_type, operator_label):
allowed_systems = ['intg', 'nonintg']
if system_type not in allowed_systems:
raise ValueError(f"System type must be one of {allowed_systems}")
allowed_operators = ['X1', 'Z1', 'X2', 'Z2', 'X3', 'Z3', '1s']
if operator_label not in allowed_operators:
raise ValueError(f"Operator label must be one of {allowed_operators}")
allowed_nspins = [5, 6, 7]
if nspins not in allowed_nspins:
raise ValueError(f"Number of spins must be one of {allowed_nspins}")
suffix = f"{system_type}_{nspins}_{operator_label}.csv"
filepath = f"data/n={nspins}/bn_{suffix}"
if not os.path.exists(filepath):
raise FileNotFoundError(f"File not found: {filepath}")
blist = pd.read_csv(filepath, header=None).to_numpy()[:,0]
evals_filepath = f"data/n={nspins}/processed/evals_{suffix}"
evecs_filepath = f"data/n={nspins}/processed/evecs_{suffix}"
if not os.path.exists(evals_filepath):
raise FileNotFoundError(f"File not found: {evals_filepath}")
if not os.path.exists(evecs_filepath):
raise FileNotFoundError(f"File not found: {evecs_filepath}")
evals = pd.read_csv(evals_filepath, header=None).to_numpy()[:,0]
evecs = pd.read_csv(evecs_filepath, header=None).to_numpy()
return blist, evals, evecs
def fetch_all_operators(nspins, system_type):
allowed_systems = ['intg', 'nonintg']
if system_type not in allowed_systems:
raise ValueError(f"System type must be one of {allowed_systems}")
allowed_nspins = [5, 6, 7]
if nspins not in allowed_nspins:
raise ValueError(f"Number of spins must be one of {allowed_nspins}")
directory = f'data/n={nspins}'
# Get all CSV file paths in the directory
csv_files = glob.glob(os.path.join(directory, "*.csv"))
prefix = f"bn_{system_type}_{nspins}_"
csv_files = [f for f in csv_files if os.path.basename(f).startswith(prefix)]
if not csv_files:
raise FileNotFoundError(f"No files found for nspins={nspins}, system_type={system_type}")
operators = set()
for filepath in csv_files:
basename = os.path.basename(filepath)
operator = basename.split('_')[3].split('.')[0]
operators.add(operator)
results = {}
for operator in operators:
blist, evals, evecs = fetch_data(nspins, system_type, operator)
results[operator] = (blist, evals, evecs)
return results
# blist, evals, evecs = fetch_data(6, 'intg', 'X2')
# results = fetch_all_operators(6, 'intg')