-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathGiltTNR3D_setup.py
173 lines (152 loc) · 5.17 KB
/
GiltTNR3D_setup.py
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import GiltTNR3D
import GiltTNR3D_impurity
import logging
version = GiltTNR3D.version
parinfo = {
"iter_count": {
"default": 0,
"idfunc": lambda dataname, pars: True
},
# Parameters for disentangling.
"gilt_eps_cubes": {
"default": 1e-4,
"idfunc": (lambda dataname, pars:
pars["gilt_eps_cubes"] >= 0
and not bool(pars["gilt_eps_cubes_list"]))
},
"gilt_eps_cubes_list": {
"default": None,
"idfunc": lambda dataname, pars: bool(pars["gilt_eps_cubes_list"])
},
"gilt_eps_squares": {
"default": 1e-4,
"idfunc": (lambda dataname, pars:
pars["gilt_eps_squares"] >= 0
and not bool(pars["gilt_eps_squares_list"]))
},
"gilt_eps_squares_list": {
"default": None,
"idfunc": lambda dataname, pars: bool(pars["gilt_eps_squares_list"])
},
"gilt_split": {
"default": True,
"idfunc": lambda dataname, pars: True
},
"gilt_split_factor": {
"default": 1.,
"idfunc": lambda dataname, pars: (pars["gilt_split"] and
not pars["gilt_split_dynamic"])
},
"gilt_split_dynamic": {
"default": True,
"idfunc": lambda dataname, pars: pars["gilt_split"]
},
"gilt_split_dynamic_eps": {
"default": 1e-8,
"idfunc": lambda dataname, pars: (pars["gilt_split"]
and pars["gilt_split_dynamic"])
},
"gilt_split_dynamic_max_factor": {
"default": 2.,
"idfunc": lambda dataname, pars: (pars["gilt_split"]
and pars["gilt_split_dynamic"])
},
"gilt_hastyquit": {
"default": False,
"idfunc": lambda dataname, pars: True
},
"gilt_print_envspec": {
"default": False,
"idfunc": lambda dataname, pars: False
},
"gilt_print_envspec_recursive": {
"default": False,
"idfunc": lambda dataname, pars: False
},
# Parameters for the coarse-graining.
"cg_chis": {
"default": [1,2,3,4,5,6],
"idfunc": lambda dataname, pars: True
},
"cg_eps": {
"default": 1e-3,
"idfunc": lambda dataname, pars: True
},
# Other parameters
"verbosity": {
"default": 10,
"idfunc": lambda dataname, pars: False
},
}
def generate(dataname, *args, pars=dict(), filelogger=None):
infostr = ("{}"
"\nGenerating {} with GiltTNR3D (version {})."
"\niter_count = {}"
.format("="*70, dataname, version, pars["iter_count"]))
logging.info(infostr)
if filelogger is not None:
# Only print the dictionary into the log file, not in stdout.
dictstr = ""
for k,v in sorted(pars.items()):
dictstr += "\n%s = %s"%(k, v)
filelogger.info(dictstr)
iter_count = pars["iter_count"]
if pars["gilt_eps_cubes_list"]:
pars = pars.copy()
try:
pars["gilt_eps_cubes"] = pars["gilt_eps_cubes_list"][iter_count-1]
except IndexError:
pars["gilt_eps_cubes"] = pars["gilt_eps_cubes_list"][-1]
if pars["gilt_eps_squares_list"]:
pars = pars.copy()
try:
pars["gilt_eps_squares"] = pars["gilt_eps_squares_list"][iter_count-1]
except IndexError:
pars["gilt_eps_squares"] = pars["gilt_eps_squares_list"][-1]
if dataname == "As":
res = generate_As(*args, pars=pars)
elif dataname == "As_impure":
res = generate_As_impure(*args, pars=pars)
else:
raise ValueError("Unknown dataname: {}".format(dataname))
return res
def generate_As(*args, pars=dict()):
As, log_facts = args[0][0], args[0][1]
# TODO The array should be the default form of returning log_facts for
# initialtensors, but that would break backwards compatibility.
if log_facts == 0:
log_facts = [0]*8
res = GiltTNR3D.gilttnr_step(As, log_facts, pars)
return res
def generate_As_impure(*args, pars=dict()):
A_impure, log_fact_impure = args[0]
ws_pure, Ms_pure, As_deed_pure, log_facts_pure = (
args[1][2], args[1][3], args[1][4], args[1][6]
)
odd_iter = (pars["iter_count"] % 2) == 1
A_impure, log_fact_impure = GiltTNR3D.gilttnr_step_impurity(
A_impure, log_fact_impure,
Ms_pure, ws_pure, As_deed_pure, log_facts_pure, pars,
start_at_7=odd_iter
)
return A_impure, log_fact_impure
def prereq_pairs(dataname, pars):
if dataname == "As":
res = prereq_pairs_As(pars)
elif dataname == "As_impure":
res = prereq_pairs_As_impure(pars)
else:
raise ValueError("Unknown dataname: {}".format(dataname))
return res
def prereq_pairs_As(pars):
prereq_pars = pars.copy()
prereq_pars["iter_count"] -= 1
res = [("As", prereq_pars)]
return res
def prereq_pairs_As_impure(pars):
prereq_pars1 = pars.copy()
prereq_pars2 = prereq_pars1.copy()
prereq_pars1["iter_count"] -= 1
res = [("As_impure", prereq_pars1)] # The previous impurity
res += [("As", prereq_pars2)] # The Ms, ws, etc. from the pure step.
return res