Skip to content

Commit

Permalink
bugfix run tasks spawned by Cluster.run() now log to separate log fil…
Browse files Browse the repository at this point in the history
…es, whereas before their logs were sent to the ether

removed check function from singularity because the checks were not working from inside the container
workstation now always checks mpiexec, even if nproc == 1
  • Loading branch information
bch0w committed Sep 11, 2022
1 parent 315271c commit bda5657
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 23 deletions.
4 changes: 2 additions & 2 deletions seisflows/system/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def run(self, funcs, single=False, **kwargs):
path=self.path.scratch,
**kwargs)
logger.info(f"running functions {[_.__name__ for _ in funcs]} on "
f"system {self.ntask} times")
f"system {ntasks} times")

# Create the run call which will simply call an external Python script
# e.g., run --funcs func.p --kwargs kwargs.p --environment ...
Expand Down Expand Up @@ -194,7 +194,7 @@ def _run_task(self, run_call, task_id):
:param task_id: given task id, used for log messages and to format
the run call
"""
logger.debug(f"running task id {task_id} ({task_id + 1}/{self.ntask})")
logger.debug(f"running task id {task_id}")
try:
f = open(self._get_log_file(task_id), "w")
subprocess.run(run_call.format(task_id=task_id), shell=True,
Expand Down
14 changes: 14 additions & 0 deletions seisflows/system/runscripts/run_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import dill
import os

from seisflows import logger
from seisflows.tools.config import config_logger


def parse_args():
"""
Expand Down Expand Up @@ -94,8 +97,19 @@ def export(myenv):
else:
kwargs = {}

# Hold onto the main handler for after the task is finished
handlers = logger.handlers

# Redirect the logger to point at stdout, which the Cluster system (or sub
# class of it) will redirect to a task specific log file. Currently no
# way of accessing user defiend 'verbose' or 'log_level' parameters
config_logger(filename=None, stream_handler=True)

# Evaluate the function with given keyword arguments
for func in funcs:
func(**kwargs)

# Replace original log handler now that the tasks have finished
logger.handlers = handlers


42 changes: 21 additions & 21 deletions seisflows/system/singularity.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,27 @@ def __init__(self, title=None, mpiexec="", ntask_max=None,
self.path["container"] = path_container
self.path["run"] = os.path.join(self.path.scratch, "run")

def check(self):
"""
Checks path and parameter validity
"""
super().check()

assert(self.path.container and os.path.exists(self.path.container)), (
f"`Singularity` System class requires a Docker Image specified in "
f" path `path_container`"
)

# # Check that 'singularity' exists on system
try:
subprocess.run(f"which {self.singularity_exec}", check=True,
shell=True, stdout=subprocess.DEVNULL)
except subprocess.CalledProcessError:
logger.critical(f"Singularity exectuable {self.singularity_exec} "
f"not found on sytem (using `which`), but is "
f"required to run a `Singularity` System. Please "
f"check your parameter: `singularity_exec`.")
sys.exit(-1)
# def check(self):
# """
# Checks path and parameter validity
# """
# super().check()
#
# assert(self.path.container and os.path.exists(self.path.container)), (
# f"`Singularity` System class requires a Docker Image specified in "
# f" path `path_container`"
# )
#
# # # Check that 'singularity' exists on system
# try:
# subprocess.run(f"which {self.singularity_exec}", check=True,
# shell=True, stdout=subprocess.DEVNULL)
# except subprocess.CalledProcessError:
# logger.critical(f"Singularity exectuable {self.singularity_exec} "
# f"not found on sytem (using `which`), but is "
# f"required to run a `Singularity` System. Please "
# f"check your parameter: `singularity_exec`.")
# sys.exit(-1)

def setup(self):
"""
Expand Down
1 change: 1 addition & 0 deletions seisflows/system/workstation.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def check(self):
f"Multi-core workflows (`nproc`>1) require an MPI executable "
f"`mpiexec`"
)
if self.mpiexec is not None:
# Make user that `mpiexec` exists on system
try:
stdout = subprocess.run(f"which {self.mpiexec}", shell=True,
Expand Down

0 comments on commit bda5657

Please sign in to comment.