idmtools-models 0.0.0.dev0__py3-none-any.whl → 0.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- idmtools_models/__init__.py +18 -8
- idmtools_models/json_configured_task.py +337 -0
- idmtools_models/python/__init__.py +5 -0
- idmtools_models/python/json_python_task.py +154 -0
- idmtools_models/python/python_task.py +163 -0
- idmtools_models/r/__init__.py +5 -0
- idmtools_models/r/json_r_task.py +155 -0
- idmtools_models/r/r_task.py +146 -0
- idmtools_models/templated_script_task.py +587 -0
- idmtools_models-0.0.2.dist-info/METADATA +57 -0
- idmtools_models-0.0.2.dist-info/RECORD +15 -0
- idmtools_models-0.0.2.dist-info/entry_points.txt +8 -0
- idmtools_models-0.0.2.dist-info/licenses/LICENSE.TXT +3 -0
- idmtools_models-0.0.0.dev0.dist-info/METADATA +0 -41
- idmtools_models-0.0.0.dev0.dist-info/RECORD +0 -5
- {idmtools_models-0.0.0.dev0.dist-info → idmtools_models-0.0.2.dist-info}/WHEEL +0 -0
- {idmtools_models-0.0.0.dev0.dist-info → idmtools_models-0.0.2.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"""idmtools jsonr task.
|
|
2
|
+
|
|
3
|
+
Copyright 2021, Bill & Melinda Gates Foundation. All rights reserved.
|
|
4
|
+
"""
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from typing import Optional, List, Type, Union, TYPE_CHECKING
|
|
7
|
+
from idmtools.assets import AssetCollection
|
|
8
|
+
from idmtools.entities.iworkflow_item import IWorkflowItem
|
|
9
|
+
from idmtools.entities.simulation import Simulation
|
|
10
|
+
from idmtools.registry.task_specification import TaskSpecification
|
|
11
|
+
from idmtools_models.json_configured_task import JSONConfiguredTask
|
|
12
|
+
from idmtools_models.r.r_task import RTask
|
|
13
|
+
if TYPE_CHECKING: # pragma: no cover
|
|
14
|
+
from idmtools.entities.iplatform import IPlatform
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass
|
|
18
|
+
class JSONConfiguredRTask(JSONConfiguredTask, RTask):
|
|
19
|
+
"""
|
|
20
|
+
JSONConfiguredRTask combines JSONConfiguredTask and RTask.
|
|
21
|
+
|
|
22
|
+
Notes:
|
|
23
|
+
- TODO Add example references here
|
|
24
|
+
|
|
25
|
+
See Also:
|
|
26
|
+
:class:`idmtools_models.json_configured_task.JSONConfiguredTask`
|
|
27
|
+
:class:`idmtools_models.r.r_task.RTask`
|
|
28
|
+
"""
|
|
29
|
+
configfile_argument: Optional[str] = field(default="--config", metadata={"md": True})
|
|
30
|
+
|
|
31
|
+
def __post_init__(self):
|
|
32
|
+
"""Constructor."""
|
|
33
|
+
JSONConfiguredTask.__post_init__(self)
|
|
34
|
+
RTask.__post_init__(self)
|
|
35
|
+
|
|
36
|
+
def gather_common_assets(self):
|
|
37
|
+
"""
|
|
38
|
+
Return the common assets for a JSON Configured Task.
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
Assets
|
|
42
|
+
"""
|
|
43
|
+
return RTask.gather_common_assets(self)
|
|
44
|
+
|
|
45
|
+
def gather_transient_assets(self) -> AssetCollection:
|
|
46
|
+
"""
|
|
47
|
+
Get Transient assets. This should general be the config.json.
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
Transient assets
|
|
51
|
+
"""
|
|
52
|
+
return JSONConfiguredTask.gather_transient_assets(self)
|
|
53
|
+
|
|
54
|
+
def reload_from_simulation(self, simulation: Simulation, **kwargs):
|
|
55
|
+
"""
|
|
56
|
+
Reload task details from a simulation. Used in some fetch operations.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
simulation: Simulation that is parent item
|
|
60
|
+
**kwargs:
|
|
61
|
+
|
|
62
|
+
Returns:
|
|
63
|
+
None
|
|
64
|
+
"""
|
|
65
|
+
JSONConfiguredTask.reload_from_simulation(self, simulation, **kwargs)
|
|
66
|
+
RTask.reload_from_simulation(self, simulation, **kwargs)
|
|
67
|
+
|
|
68
|
+
def pre_creation(self, parent: Union[Simulation, IWorkflowItem], platform: 'IPlatform'):
|
|
69
|
+
"""
|
|
70
|
+
Pre-creation event.
|
|
71
|
+
|
|
72
|
+
Proxy calls to JSONConfiguredTask and RTask
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
parent: Parent item
|
|
76
|
+
platform: Platform item is being created on
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
None
|
|
80
|
+
"""
|
|
81
|
+
RTask.pre_creation(self, parent, platform)
|
|
82
|
+
JSONConfiguredTask.pre_creation(self, parent, platform)
|
|
83
|
+
|
|
84
|
+
def post_creation(self, parent: Union[Simulation, IWorkflowItem], platform: 'IPlatform'):
|
|
85
|
+
"""
|
|
86
|
+
Post-creation of task.
|
|
87
|
+
|
|
88
|
+
Proxy calls to JSONConfiguredTask and RTask
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
parent: Parent item
|
|
92
|
+
platform: Platform we are executing on
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
None
|
|
96
|
+
"""
|
|
97
|
+
JSONConfiguredTask.post_creation(self, parent, platform)
|
|
98
|
+
RTask.post_creation(self, parent, platform)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class JSONConfiguredRTaskSpecification(TaskSpecification):
|
|
102
|
+
"""
|
|
103
|
+
JSONConfiguredRTaskSpecification provides the plugin info for JSONConfiguredRTask.
|
|
104
|
+
"""
|
|
105
|
+
|
|
106
|
+
def get(self, configuration: dict) -> JSONConfiguredRTask:
|
|
107
|
+
"""
|
|
108
|
+
Get instance of JSONConfiguredRTaskSpecification with configuration provided.
|
|
109
|
+
|
|
110
|
+
Args:
|
|
111
|
+
configuration: Configuration for object
|
|
112
|
+
|
|
113
|
+
Returns:
|
|
114
|
+
JSONConfiguredRTaskSpecification with configuration
|
|
115
|
+
"""
|
|
116
|
+
return JSONConfiguredRTask(**configuration)
|
|
117
|
+
|
|
118
|
+
def get_description(self) -> str:
|
|
119
|
+
"""
|
|
120
|
+
Get description of plugin.
|
|
121
|
+
|
|
122
|
+
Returns:
|
|
123
|
+
Description of plugin
|
|
124
|
+
"""
|
|
125
|
+
return "Defines a R script that has a single JSON config file"
|
|
126
|
+
|
|
127
|
+
def get_example_urls(self) -> List[str]:
|
|
128
|
+
"""
|
|
129
|
+
Get Examples for JSONConfiguredRTask.
|
|
130
|
+
|
|
131
|
+
Returns:
|
|
132
|
+
List of Urls that point to examples for JSONConfiguredRTask
|
|
133
|
+
"""
|
|
134
|
+
from idmtools_models import __version__
|
|
135
|
+
examples = [f'examples/{example}' for example in ['r_model']]
|
|
136
|
+
return [self.get_version_url(f'v{__version__}', x) for x in examples]
|
|
137
|
+
|
|
138
|
+
def get_type(self) -> Type[JSONConfiguredRTask]:
|
|
139
|
+
"""
|
|
140
|
+
Get Type for Plugin.
|
|
141
|
+
|
|
142
|
+
Returns:
|
|
143
|
+
JSONConfiguredRTask
|
|
144
|
+
"""
|
|
145
|
+
return JSONConfiguredRTask
|
|
146
|
+
|
|
147
|
+
def get_version(self) -> str:
|
|
148
|
+
"""
|
|
149
|
+
Returns the version of the plugin.
|
|
150
|
+
|
|
151
|
+
Returns:
|
|
152
|
+
Plugin Version
|
|
153
|
+
"""
|
|
154
|
+
from idmtools_models import __version__
|
|
155
|
+
return __version__
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"""idmtools rtask.
|
|
2
|
+
|
|
3
|
+
Copyright 2021, Bill & Melinda Gates Foundation. All rights reserved.
|
|
4
|
+
"""
|
|
5
|
+
import os
|
|
6
|
+
from dataclasses import field, dataclass
|
|
7
|
+
from logging import getLogger, DEBUG
|
|
8
|
+
from typing import Type, Union, TYPE_CHECKING
|
|
9
|
+
from idmtools.assets import Asset, AssetCollection
|
|
10
|
+
from idmtools.core.docker_task import DockerTask
|
|
11
|
+
from idmtools.entities import CommandLine
|
|
12
|
+
from idmtools.entities.iworkflow_item import IWorkflowItem
|
|
13
|
+
from idmtools.entities.simulation import Simulation
|
|
14
|
+
from idmtools.registry.task_specification import TaskSpecification
|
|
15
|
+
|
|
16
|
+
logger = getLogger(__name__)
|
|
17
|
+
|
|
18
|
+
if TYPE_CHECKING: # pragma: no cover
|
|
19
|
+
from idmtools.entities.iplatform import IPlatform
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass
|
|
23
|
+
class RTask(DockerTask):
|
|
24
|
+
"""
|
|
25
|
+
Defines an RTask for idmtools. Currently only useful for local platform.
|
|
26
|
+
|
|
27
|
+
Notes:
|
|
28
|
+
- TODO rework this to be non-docker
|
|
29
|
+
"""
|
|
30
|
+
script_path: str = field(default=None, metadata={"md": True})
|
|
31
|
+
r_path: str = field(default='Rscript', metadata={"md": True})
|
|
32
|
+
|
|
33
|
+
def __post_init__(self):
|
|
34
|
+
"""Constructor."""
|
|
35
|
+
super().__post_init__()
|
|
36
|
+
cmd_str = f'{self.r_path} ./Assets/{os.path.basename(self.script_path)}'
|
|
37
|
+
if logger.isEnabledFor(DEBUG):
|
|
38
|
+
logger.info('Setting command line to %s', cmd_str)
|
|
39
|
+
self.command = CommandLine.from_string(cmd_str)
|
|
40
|
+
|
|
41
|
+
def reload_from_simulation(self, simulation: Simulation, **kwargs):
|
|
42
|
+
"""
|
|
43
|
+
Reload RTask from a simulation. Used when fetching an simulation to do a recreation.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
simulation: Simulation object containing our metadata to rebuild task
|
|
47
|
+
**kwargs:
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
None
|
|
51
|
+
"""
|
|
52
|
+
logger.debug("Reload from simulation")
|
|
53
|
+
# check experiment level assets for items
|
|
54
|
+
if simulation.parent.assets:
|
|
55
|
+
new_assets = AssetCollection()
|
|
56
|
+
for _i, asset in enumerate(simulation.parent.assets.assets):
|
|
57
|
+
if asset.filename != self.script_path and asset.absolute_path != self.script_path:
|
|
58
|
+
new_assets.add_asset(asset)
|
|
59
|
+
simulation.parent.assets = new_assets
|
|
60
|
+
|
|
61
|
+
def gather_common_assets(self) -> AssetCollection:
|
|
62
|
+
"""
|
|
63
|
+
Gather R Assets.
|
|
64
|
+
|
|
65
|
+
Returns:
|
|
66
|
+
Common assets
|
|
67
|
+
"""
|
|
68
|
+
super().gather_common_assets()
|
|
69
|
+
if logger.isEnabledFor(DEBUG):
|
|
70
|
+
logger.info('Adding Common asset from %s', self.script_path)
|
|
71
|
+
self.common_assets.add_or_replace_asset(Asset(absolute_path=self.script_path))
|
|
72
|
+
return self.common_assets
|
|
73
|
+
|
|
74
|
+
def gather_transient_assets(self) -> AssetCollection:
|
|
75
|
+
"""
|
|
76
|
+
Gather transient assets. Generally this is the simulation level assets.
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
Transient assets(Simulation level Assets)
|
|
80
|
+
"""
|
|
81
|
+
return self.transient_assets
|
|
82
|
+
|
|
83
|
+
def pre_creation(self, parent: Union[Simulation, IWorkflowItem], platform: 'IPlatform'):
|
|
84
|
+
"""
|
|
85
|
+
Called before creation of parent.
|
|
86
|
+
|
|
87
|
+
Args:
|
|
88
|
+
parent: Parent
|
|
89
|
+
platform: Platform R Task is executing on
|
|
90
|
+
|
|
91
|
+
Returns:
|
|
92
|
+
None
|
|
93
|
+
|
|
94
|
+
Raise:
|
|
95
|
+
ValueError if script name is not provided
|
|
96
|
+
"""
|
|
97
|
+
if self.script_path is None:
|
|
98
|
+
raise ValueError("Script name is required")
|
|
99
|
+
|
|
100
|
+
self.command = CommandLine.from_string(f'{self.r_path} {platform.join_path(platform.common_asset_path, os.path.basename(self.script_path))}')
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class RTaskSpecification(TaskSpecification):
|
|
104
|
+
"""
|
|
105
|
+
RTaskSpecification defines plugin specification for RTask.
|
|
106
|
+
"""
|
|
107
|
+
|
|
108
|
+
def get(self, configuration: dict) -> RTask:
|
|
109
|
+
"""
|
|
110
|
+
Get instance of RTask.
|
|
111
|
+
|
|
112
|
+
Args:
|
|
113
|
+
configuration: configuration for task
|
|
114
|
+
|
|
115
|
+
Returns:
|
|
116
|
+
RTask with configuration
|
|
117
|
+
"""
|
|
118
|
+
return RTask(**configuration)
|
|
119
|
+
|
|
120
|
+
def get_description(self) -> str:
|
|
121
|
+
"""
|
|
122
|
+
Returns the Description of the plugin.
|
|
123
|
+
|
|
124
|
+
Returns:
|
|
125
|
+
Plugin Description
|
|
126
|
+
"""
|
|
127
|
+
return "Defines a R script command"
|
|
128
|
+
|
|
129
|
+
def get_type(self) -> Type[RTask]:
|
|
130
|
+
"""
|
|
131
|
+
Get Type for Plugin.
|
|
132
|
+
|
|
133
|
+
Returns:
|
|
134
|
+
RTask
|
|
135
|
+
"""
|
|
136
|
+
return RTask
|
|
137
|
+
|
|
138
|
+
def get_version(self) -> str:
|
|
139
|
+
"""
|
|
140
|
+
Returns the version of the plugin.
|
|
141
|
+
|
|
142
|
+
Returns:
|
|
143
|
+
Plugin Version
|
|
144
|
+
"""
|
|
145
|
+
from idmtools_models import __version__
|
|
146
|
+
return __version__
|