Coverage for python/lsst/ctrl/bps/parsl/service.py: 36%
20 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-25 17:55 +0000
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-25 17:55 +0000
1# This file is part of ctrl_bps_parsl.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org) and the LSST DESC (https://www.lsstdesc.org/).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This software is dual licensed under the GNU General Public License and also
10# under a 3-clause BSD license. Recipients may choose which of these licenses
11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt,
12# respectively. If you choose the GPL option then the following text applies
13# (but note that there is still no warranty even if you opt for BSD instead):
14#
15# This program is free software: you can redistribute it and/or modify
16# it under the terms of the GNU General Public License as published by
17# the Free Software Foundation, either version 3 of the License, or
18# (at your option) any later version.
19#
20# This program is distributed in the hope that it will be useful,
21# but WITHOUT ANY WARRANTY; without even the implied warranty of
22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23# GNU General Public License for more details.
24#
25# You should have received a copy of the GNU General Public License
26# along with this program. If not, see <https://www.gnu.org/licenses/>.
28from typing import Any
30from lsst.ctrl.bps import BaseWmsService, BaseWmsWorkflow, BpsConfig, GenericWorkflow
32from .workflow import ParslWorkflow
34__all__ = ("ParslService",)
37class ParslService(BaseWmsService):
38 """Parsl-based implementation for the WMS interface."""
40 def prepare(
41 self, config: BpsConfig, generic_workflow: GenericWorkflow, out_prefix: str | None = None
42 ) -> BaseWmsWorkflow:
43 """Convert a generic workflow to a Parsl pipeline.
45 Parameters
46 ----------
47 config : `lsst.ctrl.bps.BpsConfig`
48 Configuration of the workflow.
49 generic_workflow : `lsst.ctrl.bps.generic_workflow.GenericWorkflow`
50 Generic representation of a single workflow.
51 out_prefix : `str` or `None`
52 Prefix for WMS output files.
54 Returns
55 -------
56 workflow : `ParslWorkflow`
57 Workflow that will execute the jobs.
58 """
59 service_class = self.__class__.__module__ + "." + self.__class__.__name__
60 if out_prefix is None:
61 out_prefix = config["submitPath"]
62 workflow = ParslWorkflow.from_generic_workflow(config, generic_workflow, out_prefix, service_class)
63 workflow.write(out_prefix)
64 return workflow
66 def submit(self, workflow: BaseWmsWorkflow, **kwargs: Any):
67 """Submit a single WMS workflow.
69 Parameters
70 ----------
71 workflow : `lsst.ctrl.bps.BaseWmsWorkflow`
72 Prepared WMS Workflow to submit for execution.
73 **kwargs : `~typing.Any`
74 Additional modifiers to the configuration.
75 """
76 workflow.start()
77 workflow.run()
79 def restart(self, out_prefix: str) -> tuple[str, str, str]:
80 """Restart a workflow from the point of failure.
82 Parameters
83 ----------
84 out_prefix : `str`
85 Id for workflow to be restarted. For this service, it is the prefix
86 for WMS files, also known as the ``submitPath``.
88 Returns
89 -------
90 wms_id : `str`
91 Id of the restarted workflow. If restart failed, it will be set
92 to None.
93 run_name : `str`
94 Name of the restarted workflow. If restart failed, it will be set
95 to None.
96 message : `str`
97 A message describing any issues encountered during the restart.
98 If there were no issue, an empty string is returned.
99 """
100 workflow = ParslWorkflow.read(out_prefix)
101 workflow.restart()
102 workflow.run()
103 return workflow.name, workflow.name, ""