Loading pygriffin/__init__.py +1 −0 Original line number Diff line number Diff line __version__ = '0.0.1' from pygriffin.config import * from pygriffin.pygriffin import * pygriffin/pygriffin.py +80 −0 Original line number Diff line number Diff line from numbers import Integral from pathlib import Path import subprocess import pygriffin.checkvalue as cv from pygriffin.config import PyGriffinConfig class PyGriffin: """ Class for connecting PyGriffin inputs and running the problems Parameters ---------- input : str or Path object Location of Griffin input file n_procs : int Number of processes in Griffin run n_threads : int """ def __init__(self, input, n_procs=1, n_threads=1): self.config = PyGriffinConfig() self.input = input self.n_procs = n_procs def run(self): """ Execute Griffin Returns ------- int Errorcode of the Griffin run (0 is success) """ cmd = [] if self.n_procs > 1: cmd += ['mpirun', '-n', str(self.n_procs)] # add griffin executable to command line cmd.append(str(self.config.griffin_exec)) cmd += ['-i', str(self.input)] if self.n_threads > 1: cmd.append('--n-threads={}'.format(self.n_threads)) p = subprocess.Popen(cmd, universal_newlines=True) return p.wait() @property def input(self): return self._input @input.setter def input(self, input): cv.check_type('Griffin input', input, (str, Path)) self._input = Path(input).absolute() @property def n_procs(self): return self._n_procs @n_procs.setter def n_procs(self, procs): cv.check_type('Griffin processes', procs, Integral) cv.check_greater_than('Griffin processes', procs, 0) self._n_procs = procs @property def n_threads(self): return self._n_threads @n_threads.setter def n_threads(self, threads): cv.check_type('Griffin threads', threads, Integral) cv.check_greater_than('Griffin threads', threads, 0) self._n_threads = threads Loading
pygriffin/__init__.py +1 −0 Original line number Diff line number Diff line __version__ = '0.0.1' from pygriffin.config import * from pygriffin.pygriffin import *
pygriffin/pygriffin.py +80 −0 Original line number Diff line number Diff line from numbers import Integral from pathlib import Path import subprocess import pygriffin.checkvalue as cv from pygriffin.config import PyGriffinConfig class PyGriffin: """ Class for connecting PyGriffin inputs and running the problems Parameters ---------- input : str or Path object Location of Griffin input file n_procs : int Number of processes in Griffin run n_threads : int """ def __init__(self, input, n_procs=1, n_threads=1): self.config = PyGriffinConfig() self.input = input self.n_procs = n_procs def run(self): """ Execute Griffin Returns ------- int Errorcode of the Griffin run (0 is success) """ cmd = [] if self.n_procs > 1: cmd += ['mpirun', '-n', str(self.n_procs)] # add griffin executable to command line cmd.append(str(self.config.griffin_exec)) cmd += ['-i', str(self.input)] if self.n_threads > 1: cmd.append('--n-threads={}'.format(self.n_threads)) p = subprocess.Popen(cmd, universal_newlines=True) return p.wait() @property def input(self): return self._input @input.setter def input(self, input): cv.check_type('Griffin input', input, (str, Path)) self._input = Path(input).absolute() @property def n_procs(self): return self._n_procs @n_procs.setter def n_procs(self, procs): cv.check_type('Griffin processes', procs, Integral) cv.check_greater_than('Griffin processes', procs, 0) self._n_procs = procs @property def n_threads(self): return self._n_threads @n_threads.setter def n_threads(self, threads): cv.check_type('Griffin threads', threads, Integral) cv.check_greater_than('Griffin threads', threads, 0) self._n_threads = threads