From 3c2b5b93b154e2e8e090b260840aa5acc6053d67 Mon Sep 17 00:00:00 2001 From: Sarath Menon Date: Thu, 7 Sep 2023 11:25:06 +0200 Subject: [PATCH] finalise minimal mode --- calphy/input.py | 20 ++++++++++ calphy/kernel.py | 101 ++++++++++++++++++++++++++++++++++++----------- 2 files changed, 98 insertions(+), 23 deletions(-) diff --git a/calphy/input.py b/calphy/input.py index 525da3c..c84af5d 100644 --- a/calphy/input.py +++ b/calphy/input.py @@ -167,6 +167,8 @@ def __init__(self): self._lattice_constant = 0 self._repeat = [1, 1, 1] self._script_mode = False + self._lammps_executable = None + self._mpi_executable = None self._npt = True self._n_equilibration_steps = 25000 self._n_switching_steps = 50000 @@ -542,6 +544,22 @@ def script_mode(self, val): self._script_mode = val else: raise TypeError("script mode should be either True/False") + + @property + def lammps_executable(self): + return self._lammps_executable + + @lammps_executable.setter + def lammps_executable(self, val): + self._lammps_executable = val + + @property + def mpi_executable(self): + return self._mpi_executable + + @mpi_executable.setter + def mpi_executable(self, val): + self._mpi_executable = val @property def n_equilibration_steps(self): @@ -718,6 +736,8 @@ def generate(cls, indata): calc.element = indata["element"] calc.mass = indata["mass"] calc.script_mode = indata["script_mode"] + calc.lammps_executable = indata["lammps_executable"] + calc.mpi_executable = indata["mpi_executable"] if "md" in indata.keys(): calc.md.add_from_dict(indata["md"]) diff --git a/calphy/kernel.py b/calphy/kernel.py index 5197ba1..dac1083 100644 --- a/calphy/kernel.py +++ b/calphy/kernel.py @@ -55,29 +55,84 @@ def run_jobs(inputfile): calculations = read_inputfile(inputfile) print("Total number of %d calculations found" % len(calculations)) - for count, calc in enumerate(calculations): - - identistring = calc.create_identifier() - scriptpath = os.path.join(os.getcwd(), ".".join([identistring, "sub"])) - errfile = os.path.join(os.getcwd(), ".".join([identistring, "err"])) - - #the below part assigns the schedulers - #now we have to write the submission scripts for the job - #parse Queue and import module - if calc.queue.scheduler == "local": - scheduler = pq.Local(calc.queue.__dict__, cores=calc.queue.cores) - elif calc.queue.scheduler == "slurm": - scheduler = pq.SLURM(calc.queue.__dict__, cores=calc.queue.cores) - elif calc.queue.scheduler == "sge": - scheduler = pq.SGE(calc.queue.__dict__, cores=calc.queue.cores) - else: - raise ValueError("Unknown scheduler") - - #for lattice just provide the number of position - scheduler.maincommand = "calphy_kernel -i %s -k %d"%(inputfile, - count) - scheduler.write_script(scriptpath) - _ = scheduler.submit() + if calculations[0].script_mode: + for count, calc in enumerate(calculations): + identistring = calc.create_identifier() + scriptpath = os.path.join(os.getcwd(), ".".join([identistring, "sub"])) + errfile = os.path.join(os.getcwd(), ".".join([identistring, "err"])) + if calc.queue.scheduler == "local": + scheduler = pq.Local(calc.queue.__dict__, cores=calc.queue.cores) + elif calc.queue.scheduler == "slurm": + scheduler = pq.SLURM(calc.queue.__dict__, cores=calc.queue.cores) + elif calc.queue.scheduler == "sge": + scheduler = pq.SGE(calc.queue.__dict__, cores=calc.queue.cores) + else: + raise ValueError("Unknown scheduler") + + #add run commands + command = f'calphy_run_averaging -i {inputfile} -k {count}' + scheduler.queueoptions['commands'].append(command) + + command = f'cp input.yaml {os.path.join(os.getcwd(), identistring)}' + scheduler.queueoptions['commands'].append(command) + + command = f'cd {os.path.join(os.getcwd(), identistring)}' + scheduler.queueoptions['commands'].append(command) + if calc.queue.cores > 1: + #here turn on mpi + command = f'{calc.mpi_executable} -np {calc.queue.cores} {calc.lammps_executable} -in averaging.lmp' + else: + command = f'{calc.lammps_executable} -in averaging.lmp' + scheduler.queueoptions['commands'].append(command) + scheduler.queueoptions['commands'].append('cd ..') + + command = f'calphy_process_averaging -i {inputfile} -k {count}' + scheduler.queueoptions['commands'].append(command) + + command = f'calphy_run_integration -i {inputfile} -k {count}' + scheduler.queueoptions['commands'].append(command) + + command = f'cd {os.path.join(os.getcwd(), identistring)}' + scheduler.queueoptions['commands'].append(command) + if calc.queue.cores > 1: + #here turn on mpi + command = f'{calc.mpi_executable} -np {calc.queue.cores} {calc.lammps_executable} -in integration.lmp' + else: + command = f'{calc.lammps_executable} -in integration.lmp' + scheduler.queueoptions['commands'].append(command) + scheduler.queueoptions['commands'].append('cd ..') + + command = f'calphy_process_integration -i {inputfile} -k {count}' + scheduler.maincommand = command + scheduler.write_script(scriptpath) + #_ = scheduler.submit() + + + + else: + for count, calc in enumerate(calculations): + + identistring = calc.create_identifier() + scriptpath = os.path.join(os.getcwd(), ".".join([identistring, "sub"])) + errfile = os.path.join(os.getcwd(), ".".join([identistring, "err"])) + + #the below part assigns the schedulers + #now we have to write the submission scripts for the job + #parse Queue and import module + if calc.queue.scheduler == "local": + scheduler = pq.Local(calc.queue.__dict__, cores=calc.queue.cores) + elif calc.queue.scheduler == "slurm": + scheduler = pq.SLURM(calc.queue.__dict__, cores=calc.queue.cores) + elif calc.queue.scheduler == "sge": + scheduler = pq.SGE(calc.queue.__dict__, cores=calc.queue.cores) + else: + raise ValueError("Unknown scheduler") + + #for lattice just provide the number of position + scheduler.maincommand = "calphy_kernel -i %s -k %d"%(inputfile, + count) + scheduler.write_script(scriptpath) + _ = scheduler.submit()