Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tactus/argparse_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def get_args_parser(program_name=GeneralConstants.PACKAGE_NAME):
required=False,
default=False,
)
add_generate_tasklist(parser_run)
parser_run.set_defaults(run_command=run_task)

##########################################
Expand Down Expand Up @@ -221,6 +222,7 @@ def get_args_parser(program_name=GeneralConstants.PACKAGE_NAME):
add_keep_def_file(
parser_case, help_message="Keep suite definition file in case of submission"
)
add_generate_tasklist(parser_case)
add_expand_config(parser_case)
parser_case.set_defaults(run_command=create_exp)

Expand Down Expand Up @@ -252,6 +254,7 @@ def get_args_parser(program_name=GeneralConstants.PACKAGE_NAME):
help="Suite definition file",
default="",
)
add_generate_tasklist(parser_start_suite)
add_keep_def_file(parser_start_suite)
parser_start_suite.set_defaults(run_command=start_suite)

Expand Down Expand Up @@ -645,6 +648,24 @@ def add_keep_def_file(
)


def add_generate_tasklist(parser_object):
"""Add object args.

Args:
parser_object (args oject): args object to update

"""
parser_object.add_argument(
"--generate-tasklist-off",
"-g",
help="Do not force generation of tasklist",
action="store_false",
default=True,
required=False,
dest="force_generation",
)


def add_expand_config(parser_object):
"""Add object args.

Expand Down
8 changes: 3 additions & 5 deletions tactus/commands_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from .scheduler import EcflowServer
from .submission import NoSchedulerSubmission, TaskSettings
from .suites.discover_suite import get_suite
from .tasks.discover_task import create_task_index
from .tasks.discover_task import load_task_index
from .toolbox import Platform


Expand Down Expand Up @@ -98,9 +98,6 @@ def run_task(args: RunTaskNamespace, config: ParsedConfig):
submission_defs = TaskSettings(config)
sub = NoSchedulerSubmission(submission_defs)

if not args.create_only:
create_task_index(config)

sub.submit(
task=args.task,
config=config,
Expand All @@ -109,6 +106,7 @@ def run_task(args: RunTaskNamespace, config: ParsedConfig):
output=output,
troika=args.troika,
create_only=args.create_only,
force_tasklist_generation=args.force_generation,
)
logger.info("Task {} submitted.", args.task)

Expand Down Expand Up @@ -303,7 +301,7 @@ def start_suite(args, config):
raise SystemExit(f"Copying {temp_troika_config_file} FAILED.") from e
logger.info("--- File copying to Ecflow server DONE ---")

create_task_index(config)
load_task_index(config, force=args.force_generation)
server.start_suite(suite_name, def_file)
logger.info("Done with suite.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,11 @@
"description": "Path to the forecast json config file",
"default": "@CYCLE@/forecast.json"
},
"task_index_file_path": {
"type": "string",
"description": "Path for task index file",
"default": "@CASEDIR@"
},
"c903_input_definition": {
"type": "string",
"description": "Path to the c903 json config file",
Expand Down
4 changes: 3 additions & 1 deletion tactus/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ def submit(
member: Optional[int] = None,
troika: Optional[str] = "troika",
create_only: Optional[bool] = False,
force_tasklist_generation: Optional[bool] = False,
):
"""Submit task.

Expand All @@ -432,12 +433,13 @@ def submit(
Defaults to None.
troika (str, optional): troika binary. Defaults to "troika".
create_only: (bool, optional): Only create the job, do not submit it.
force_tasklist_generation: (bool, optional): Switch for tasklist generation

Raises:
RuntimeError: Submission failure.
"""
name = task.lower()
if name not in load_task_index(config):
if name not in load_task_index(config, force=force_tasklist_generation):
raise NotImplementedError(f"Task {name} not implemented")

troika_config = Platform(config).get_value("troika.config_file")
Expand Down
8 changes: 5 additions & 3 deletions tactus/tasks/discover_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,24 @@ def _task_index_file(config):
task_index_file (str): Full path to task index_file

"""
task_index_file_path = Platform(config).get_system_value("casedir")
task_index_file_path = Platform(config).get_system_value("task_index_file_path")
return Path(task_index_file_path) / "tasks_index.json"


def load_task_index(config):
def load_task_index(config, force=False):
"""Load a task index file.

Args:
config (ConfigParse): Config
force (boolean): Control of forced tasklist generation

Returns:
known_types(dict): Dict of known tasks, and their location

"""
task_index_file = _task_index_file(config)

if os.path.isfile(task_index_file):
if os.path.isfile(task_index_file) and not force:
logger.info("Read task index from {}", task_index_file)
with open(task_index_file, "r", encoding="utf-8") as infile:
known_types = json.load(infile)
Expand Down Expand Up @@ -152,6 +153,7 @@ def get_task(name, config) -> Task:
try:
cls = known_types[name.lower()]
except KeyError:
logger.info("Task {} not found in index, recreate task index file", name.lower())
known_types = create_task_index(config)
try:
cls = known_types[name.lower()]
Expand Down
Loading