Commit a792d3ac authored by Jonas Schwab's avatar Jonas Schwab
Browse files

Adapt py_alf to only work with submodule hamiltonians, but in a more robust way.

parent 017b7233
......@@ -28,13 +28,16 @@ def default_params(ham_name):
return params
def params_list(ham_name):
def params_list(ham_name, include_generic=False):
"""Return list of parameter names for hamiltonian,
transformed in all upper case.
p_list = []
for name in IN_HAM[ham_name]:
p_list += list(PARAMS_MODEL[name])
if include_generic:
for nlist_name, nlist in PARAMS_GENERIC.items():
p_list += list(nlist)
return [i.upper() for i in p_list]
......@@ -44,16 +47,11 @@ PARAMS_MODEL = OrderedDict()
IN_HAM = {
'Hubbard': ["VAR_Lattice", "VAR_Model_Generic", "VAR_Hubbard"],
'Hubbard_Plain_Vanilla': ["VAR_Lattice","VAR_Hubbard_Plain_Vanilla"],
'Hubbard_Plain_Vanilla': ["VAR_Lattice", "VAR_Hubbard_Plain_Vanilla"],
'Kondo': ["VAR_Lattice", "VAR_Model_Generic", "VAR_Kondo"],
'tV': ["VAR_Lattice", "VAR_Model_Generic", "VAR_tV"],
'LRC': ["VAR_Lattice", "VAR_Model_Generic", "VAR_LRC"],
'Z2_Matter': ["VAR_Lattice", "VAR_Z2_Matter"],
'Examples': ["VAR_Lattice", "VAR_Model_Generic", "VAR_Hubbard", "VAR_LRC"],
PARAMS_GENERIC["VAR_ham_name"] = {
"ham_name": ["Hubbard", "Name of Hamiltonian"]
......@@ -66,7 +66,6 @@ class Simulation:
self.ham_name = ham_name
self.sim_dict = sim_dict
self.sim_dict["ham_name"] = str(ham_name)
self.alf_dir = os.path.abspath(os.path.expanduser(alf_dir))
self.sim_dir = os.path.abspath(os.path.expanduser(os.path.join(
kwargs.pop("sim_root", "ALF_data"),
......@@ -85,6 +84,22 @@ class Simulation:
if self.tempering:
self.mpi = True
# Check if all parameters in sim_dict are defined in default_variables
p_list = params_list(self.ham_name, include_generic=True)
if self.tempering:
for sim_dict0 in self.sim_dict:
for par_name in sim_dict0:
if par_name.upper() not in p_list:
raise Exception(
'Parameter {} not listet in default_variables'
for par_name in self.sim_dict:
if par_name.upper() not in p_list:
raise Exception(
'Parameter {} not listet in default_variables'
if self.mpi and self.n_mpi is None:
raise Exception('You have to specify n_mpi if you use MPI.')
......@@ -105,9 +120,9 @@ class Simulation:
if self.tempering:
self.config += ' TEMPERING'
def compile(self, target='all'):
def compile(self):
"""Compiles ALF. Clones a new repository if alf_dir does not exist."""
compile_alf(self.alf_dir, self.branch, self.config, target)
compile_alf(self.alf_dir, self.branch, self.config)
def run(self):
"""Prepares simulation directory and runs ALF."""
......@@ -125,8 +140,6 @@ class Simulation:
env = getenv(self.config, self.alf_dir)
env['OMP_NUM_THREADS'] = str(self.n_omp)
executable = os.path.join(self.alf_dir, 'Prog', 'ALF.out')
if not os.path.isfile(executable):
executable = os.path.join(self.alf_dir, 'Prog', self.ham_name+'.out')
with cd(self.sim_dir):
print('Run {}'.format(executable))
......@@ -242,14 +255,8 @@ def _update_var(params, var, value):
for name in params:
for var2 in params[name]:
if var2.lower() == var.lower():
params[name][var2][0] = value
return params
except TypeError:
print("TypeError in _update_var")
print(var, value)
raise Exception("TypeError in _update_var")
params[name][var2][0] = value
return params
raise Exception('"{}" does not correspond to a parameter'.format(var))
......@@ -261,6 +268,10 @@ def set_param(ham_name, sim_dict):
params = default_params(ham_name)
params["VAR_ham_name"] = {
"ham_name": [ham_name, "Name of Hamiltonian"]
for name, value in sim_dict.items():
params = _update_var(params, name, value)
return params
......@@ -287,7 +298,7 @@ def getenv(config, alf_dir='.'):
return env
def compile_alf(alf_dir='ALF', branch=None, config='GNU noMPI', target='all',
def compile_alf(alf_dir='ALF', branch=None, config='GNU noMPI',
"""Compile ALF. Clone a new repository if alf_dir does not exist."""
......@@ -310,14 +321,8 @@ def compile_alf(alf_dir='ALF', branch=None, config='GNU noMPI', target='all',
env = getenv(config)
print('Compiling ALF... ', end='')['make', 'clean'], check=True, env=env)
for file in os.listdir('Prog'):
if file.endswith('.out'):
os.remove(os.path.join('Prog', file))['make', 'ana'], check=True, env=env)
try:['make', target], check=True, env=env)
except subprocess.CalledProcessError:['make', 'program'], check=True, env=env)['make', 'program'], check=True, env=env)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment