Commit 040ee871 authored by Jonas Schwab's avatar Jonas Schwab
Browse files

Introduce new parameter 'ham_name', to declare which hamiltonian to use. This...

Introduce new parameter 'ham_name', to declare which hamiltonian to use. This also replaces 'Executable'.
parent 85c48c18
......@@ -12,7 +12,7 @@ types:
- apt-get update && apt-get install -y pylint3 python3-numpy python3-colorama git
- pylint3 -E
- git clone https://gitlab-ci-token:${CI_JOB_TOKEN}
- ./ -RT --alfdir ./ALF --config "GNU noMPI" --branch_R master --executable_T Examples --executable_R Examples
- ./ -RT --alfdir ./ALF --config "GNU noMPI" --branch_R master --ham_name_R Examples
......@@ -24,6 +24,9 @@ if __name__ == "__main__":
'--alfdir', required=True,
help="Path to ALF directory")
'--ham_name_R', required=True,
help='Name of hamiltonian')
'-R', action='store_true',
help='Do a run')
......@@ -40,11 +43,8 @@ if __name__ == "__main__":
'--config', default='GNU noMPI',
help='Will run ./ CONFIG (default: GNU noMPI)')
help='Name of ref executable. (default: <Model>.out)')
help='Name of test executable. (default: <Model>.out)')
help='Name of test hamiltonian (default: ham_name_R)')
'--mpi', default=False,
help='mpi run (default: False)')
......@@ -52,7 +52,6 @@ if __name__ == "__main__":
'--n_mpi', default=4,
help='number of mpi processes (default: 4)')
args = parser.parse_args()
do_R = args.R
......@@ -61,8 +60,11 @@ if __name__ == "__main__":
branch_R = args.branch_R
branch_T = args.branch_T
config = args.config
executable_R = args.executable_R
executable_T = args.executable_T
ham_name_R = args.ham_name_R
if args.ham_name_T is not None:
ham_name_T = args.ham_name_T
ham_name_T = args.ham_name_R
mpi = args.mpi
n_mpi = args.n_mpi
......@@ -76,8 +78,7 @@ if __name__ == "__main__":
sim_dict = json.loads(sim, object_pairs_hook=OrderedDict)
if do_R:
print('do R')
sim_R = Simulation(sim_dict, alf_dir,
sim_R = Simulation(ham_name_R, sim_dict, alf_dir,
branch=branch_R, mpi=mpi, n_mpi=n_mpi)
......@@ -86,7 +87,7 @@ if __name__ == "__main__":
obs_R = sim_R.get_obs()
if do_T:
print('do T')
sim_T = Simulation(sim_dict, alf_dir,
sim_T = Simulation(ham_name_T, sim_dict, alf_dir,
branch=branch_T, mpi=mpi, n_mpi=n_mpi)
......@@ -34,10 +34,11 @@ class Simulation:
Provides functions for preparing, running, and postprocessing a simulation.
def __init__(self, sim_dict, alf_dir='./ALF', **kwargs):
def __init__(self, ham_name, sim_dict, alf_dir='./ALF', **kwargs):
"""Initialize the Simulation object.
Required argument:
ham_name -- Name of the hamiltonian
sim_dict -- Dictionary specfying parameters owerwriting defaults.
Can be a list of dictionaries to enable parallel tempering.
......@@ -47,8 +48,6 @@ class Simulation:
fetched from a server.
sim_dir -- Directory in which the Monte Carlo will be run.
If not specified, sim_dir will be generated from sim_dict.
executable -- Name of ALF executable to run.
If not specified, executable will be the model name.
config -- Arguments to hand over to configure script prior to compiling
or running ALF (default: 'GNU noMPI')
branch -- If specified, this will be checked out, prior to compilation.
......@@ -56,11 +55,12 @@ class Simulation:
n_mpi -- Number of MPI processes
n_omp -- Number of OpenMP threads per process
self.ham_name = ham_name
self.sim_dict = sim_dict
self.alf_dir = os.path.abspath(os.path.expanduser(alf_dir))
self.sim_dir = os.path.abspath(os.path.expanduser(
kwargs.pop("sim_dir", directory_name(sim_dict))))
self.executable = kwargs.pop("executable", sim_dict['Model'])
kwargs.pop("sim_dir", directory_name(ham_name, sim_dict))))
# self.executable = kwargs.pop("executable", sim_dict['Model'])
self.config = kwargs.pop('config', 'GNU NOMPI').upper()
self.branch = kwargs.pop('branch', None)
self.mpi = kwargs.pop("mpi", False)
......@@ -86,9 +86,9 @@ class Simulation:
if self.tempering and 'TEMPERING' not in self.config:
self.config += ' TEMPERING'
def compile(self, model='all'):
def compile(self, target='all'):
"""Compiles ALF. Clones a new repository if alf_dir does not exist."""
compile_alf(self.alf_dir, self.branch, self.config, model)
compile_alf(self.alf_dir, self.branch, self.config, target)
def run(self):
"""Prepares simulation directory and runs ALF."""
......@@ -103,7 +103,7 @@ 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', self.executable+'.out')
executable = os.path.join(self.alf_dir, 'Prog', self.ham_name+'.out')
with cd(self.sim_dir):
print('Run {}'.format(executable))
......@@ -182,13 +182,13 @@ def write_parameters(params):
def directory_name(sim_dict):
def directory_name(ham_name, sim_dict):
"""Returns name of directory for simulations, given a set of simulation
TODO: Automatically generate a list of all parameters to use.
dirname = ''
dirname = '{}_'.format(ham_name)
if isinstance(sim_dict, list):
sim_dict = sim_dict[0]
dirname = 'temper_'
......@@ -249,7 +249,7 @@ def getenv(config, alf_dir='.'):
return env
def compile_alf(alf_dir='ALF', branch=None, config='GNU noMPI', model='all',
def compile_alf(alf_dir='ALF', branch=None, config='GNU noMPI', target='all',
"""Compile ALF. Clone a new repository if alf_dir does not exist."""
......@@ -273,7 +273,7 @@ def compile_alf(alf_dir='ALF', branch=None, config='GNU noMPI', model='all',
print('Compiling ALF...')['make', 'clean'], check=True, env=env)['make', 'ana'], check=True, env=env)['make', model], check=True, env=env)['make', target], check=True, env=env)
def out_to_in(verbose=False):
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