Commit 0c8ce134 authored by bellotti_r's avatar bellotti_r
Browse files

Made repo installable; added documentation; Simulation.run() returns the...

Made repo installable; added documentation; Simulation.run() returns the correct SLURM ID of the job
parent d3db9780
from .simulation import Simulation
from .opaldict import OpalDict
from PathNameGenerator import PathNameGenerator from .PathNameGenerator import PathNameGenerator
from decimal import Decimal from decimal import Decimal
from ast import literal_eval from ast import literal_eval
import sys import sys
...@@ -21,6 +21,7 @@ class OpalDict: ...@@ -21,6 +21,7 @@ class OpalDict:
Parameters Parameters
========== ==========
template: str template: str
Path the .data file.
''' '''
self.dict = {} self.dict = {}
self.rangevars = {} self.rangevars = {}
......
...@@ -95,6 +95,9 @@ class Simulation: ...@@ -95,6 +95,9 @@ class Simulation:
Run an OPAL simulation. Run an OPAL simulation.
Support for batch systems is available. Support for batch systems is available.
The directory containing the fieldmaps is given in the environment
variable FIELDMAPS.
Parameters Parameters
========== ==========
...@@ -247,7 +250,8 @@ class Simulation: ...@@ -247,7 +250,8 @@ class Simulation:
queue = os.getenv("SGE_QUEUE", "prime_bd.q") queue = os.getenv("SGE_QUEUE", "prime_bd.q")
# Merlin6 # Merlin6
if (hostname.startswith("merlin-l")): if (hostname.startswith('merlin-l')
or hostname.startswith('merlin-c')):
batchsys = 'SLURM' batchsys = 'SLURM'
runfile = 'run.merlin6' runfile = 'run.merlin6'
time = os.getenv("SLURM_TIME", "23:59:59") time = os.getenv("SLURM_TIME", "23:59:59")
...@@ -345,7 +349,12 @@ class Simulation: ...@@ -345,7 +349,12 @@ class Simulation:
elif batchsys == 'COBALT': elif batchsys == 'COBALT':
command = 'qsub' command = 'qsub'
qid = subprocess.call([command, runfile, '|', 'awk', "\'{print $3}\'"]) completed_process = subprocess.run([command, runfile],
stdout=subprocess.PIPE,
encoding='utf-8')
output = completed_process.stdout
# output format for SLURM: "Submitted batch job <ID>"
ID = output.split(' ')[-1].strip()
if not quiet: if not quiet:
print(f'Done with setup of the OPAL simulation and submitting the job with {CORES} cores \n\n\n') print(f'Done with setup of the OPAL simulation and submitting the job with {CORES} cores \n\n\n')
...@@ -357,7 +366,7 @@ class Simulation: ...@@ -357,7 +366,7 @@ class Simulation:
print("Batch system", batchsys, "not known!") print("Batch system", batchsys, "not known!")
os.chdir('..') os.chdir('..')
return qid return ID
# Write for host # Write for host
def WriteCori(self, opalexe, oinpFile, cores, time, ram, info, name): def WriteCori(self, opalexe, oinpFile, cores, time, ram, info, name):
......
from setuptools import setup
# file content adapted from:
# https://stackoverflow.com/a/39811884
setup(
name='runOPAL',
version='1.0',
description='Run OPAL simulations from within Python',
author='Andreas Adelmann et al.',
packages=['runOPAL'], # same as name
)
Markdown is supported
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