differentiated papermill and python jobs more clearly
This commit is contained in:
@ -72,6 +72,12 @@ def check_type(variable:Any, expected_type:type, alt_types:list[type]=[],
|
||||
% (get_args(expected_type), type(variable))
|
||||
)
|
||||
|
||||
def check_callable(call:Any)->None:
|
||||
"""Checks if a given variable is a callable function. Raises TypeError if
|
||||
not."""
|
||||
if not callable(call):
|
||||
raise TypeError(f"Given object '{call}' is not a callable function")
|
||||
|
||||
def check_implementation(child_func, parent_class):
|
||||
"""Checks if the given function has been overridden from the one inherited
|
||||
from the parent class. Raises a NotImplementedError if this is the case."""
|
||||
@ -94,6 +100,14 @@ def check_implementation(child_func, parent_class):
|
||||
msg = get_not_imp_msg(parent_class, parent_func)
|
||||
raise NotImplementedError(msg)
|
||||
|
||||
def check_script(script:Any):
|
||||
"""Checks if a given variable is a valid script. Raises TypeError if
|
||||
not."""
|
||||
# TODO investigate more robust check here
|
||||
check_type(script, list)
|
||||
for line in script:
|
||||
check_type(line, str)
|
||||
|
||||
def valid_string(variable:str, valid_chars:str, min_length:int=1)->None:
|
||||
"""Checks that all characters in a given string are present in a provided
|
||||
list of characters. Will raise an ValueError if unexpected character is
|
||||
|
@ -80,10 +80,24 @@ DIR_EVENTS = [
|
||||
# meow jobs
|
||||
JOB_TYPE = "job_type"
|
||||
JOB_TYPE_PYTHON = "python"
|
||||
JOB_TYPE_PAPERMILL = "papermill"
|
||||
PYTHON_FUNC = "func"
|
||||
PYTHON_EXECUTION_BASE = "exection_base"
|
||||
PYTHON_OUTPUT_DIR = "output_dir"
|
||||
|
||||
JOB_TYPES = {
|
||||
JOB_TYPE_PAPERMILL: [
|
||||
"base.ipynb",
|
||||
"job.ipynb",
|
||||
"result.ipynb",
|
||||
],
|
||||
JOB_TYPE_PYTHON: [
|
||||
"base.py",
|
||||
"job.py",
|
||||
"result.py",
|
||||
]
|
||||
}
|
||||
|
||||
# job definitions
|
||||
JOB_ID = "id"
|
||||
JOB_EVENT = "event"
|
||||
@ -108,10 +122,7 @@ STATUS_DONE = "done"
|
||||
|
||||
# job definition files
|
||||
META_FILE = "job.yml"
|
||||
BASE_FILE = "base.ipynb"
|
||||
PARAMS_FILE = "params.yml"
|
||||
JOB_FILE = "job.ipynb"
|
||||
RESULT_FILE = "result.ipynb"
|
||||
|
||||
# Parameter sweep keys
|
||||
SWEEP_START = "start"
|
||||
@ -132,3 +143,12 @@ def get_not_imp_msg(parent_class, class_function):
|
||||
return f"Children of the '{parent_class.__name__}' class must implement " \
|
||||
f"the '{class_function.__name__}({signature(class_function)})' " \
|
||||
"function"
|
||||
|
||||
def get_base_file(job_type:str):
|
||||
return JOB_TYPES[job_type][0]
|
||||
|
||||
def get_job_file(job_type:str):
|
||||
return JOB_TYPES[job_type][1]
|
||||
|
||||
def get_result_file(job_type:str):
|
||||
return JOB_TYPES[job_type][2]
|
||||
|
Reference in New Issue
Block a user