idmtools-models 0.0.0.dev0__tar.gz → 0.0.2__tar.gz
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-0.0.2/.bumpversion.cfg +28 -0
- idmtools_models-0.0.2/LICENSE.TXT +3 -0
- idmtools_models-0.0.2/MANIFEST.in +3 -0
- idmtools_models-0.0.2/Makefile +2 -0
- idmtools_models-0.0.2/PKG-INFO +57 -0
- idmtools_models-0.0.2/README.md +29 -0
- idmtools_models-0.0.2/idmtools_models/__init__.py +18 -0
- idmtools_models-0.0.2/idmtools_models/json_configured_task.py +337 -0
- idmtools_models-0.0.2/idmtools_models/python/__init__.py +5 -0
- idmtools_models-0.0.2/idmtools_models/python/json_python_task.py +154 -0
- idmtools_models-0.0.2/idmtools_models/python/python_task.py +163 -0
- idmtools_models-0.0.2/idmtools_models/r/__init__.py +5 -0
- idmtools_models-0.0.2/idmtools_models/r/json_r_task.py +155 -0
- idmtools_models-0.0.2/idmtools_models/r/r_task.py +146 -0
- idmtools_models-0.0.2/idmtools_models/templated_script_task.py +587 -0
- idmtools_models-0.0.2/idmtools_models.egg-info/PKG-INFO +57 -0
- idmtools_models-0.0.2/idmtools_models.egg-info/SOURCES.txt +22 -0
- idmtools_models-0.0.2/idmtools_models.egg-info/entry_points.txt +8 -0
- idmtools_models-0.0.2/idmtools_models.egg-info/requires.txt +13 -0
- idmtools_models-0.0.2/pyproject.toml +82 -0
- idmtools_models-0.0.2/requirements-idmtools_idmtools_models-test.txt +2 -0
- {idmtools_models-0.0.0.dev0 → idmtools_models-0.0.2}/setup.cfg +4 -4
- idmtools_models-0.0.0.dev0/PKG-INFO +0 -41
- idmtools_models-0.0.0.dev0/README.md +0 -21
- idmtools_models-0.0.0.dev0/idmtools_models/__init__.py +0 -8
- idmtools_models-0.0.0.dev0/idmtools_models.egg-info/PKG-INFO +0 -41
- idmtools_models-0.0.0.dev0/idmtools_models.egg-info/SOURCES.txt +0 -7
- idmtools_models-0.0.0.dev0/pyproject.toml +0 -32
- {idmtools_models-0.0.0.dev0 → idmtools_models-0.0.2}/idmtools_models.egg-info/dependency_links.txt +0 -0
- {idmtools_models-0.0.0.dev0 → idmtools_models-0.0.2}/idmtools_models.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[bumpversion]
|
|
2
|
+
current_version = 3.0.0+nightly
|
|
3
|
+
commit = False
|
|
4
|
+
tag = False
|
|
5
|
+
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(?P<release>\+\w+)?(\.(?P<build>\d+))?
|
|
6
|
+
serialize =
|
|
7
|
+
{major}.{minor}.{patch}{release}.{build}
|
|
8
|
+
{major}.{minor}.{patch}{release}
|
|
9
|
+
{major}.{minor}.{patch}
|
|
10
|
+
|
|
11
|
+
[bumpversion:part:release]
|
|
12
|
+
optional_value = prod
|
|
13
|
+
first_value = prod
|
|
14
|
+
values =
|
|
15
|
+
prod
|
|
16
|
+
+nightly
|
|
17
|
+
|
|
18
|
+
[bumpversion:file:./idmtools_models/__init__.py]
|
|
19
|
+
search = __version__ = "{current_version}"
|
|
20
|
+
replace = __version__ = "{new_version}"
|
|
21
|
+
serialize = {major}.{minor}.{patch}{release}
|
|
22
|
+
{major}.{minor}.{patch}
|
|
23
|
+
|
|
24
|
+
[bumpversion:file:./pyproject.toml]
|
|
25
|
+
search = version = "{current_version}"
|
|
26
|
+
replace = version = "{new_version}"
|
|
27
|
+
serialize = {major}.{minor}.{patch}{release}
|
|
28
|
+
{major}.{minor}.{patch}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: idmtools_models
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: Core tools for modeling
|
|
5
|
+
Author-email: Ross Carter <rcarter@idmod.org>, Sharon Chen <shchen@idmod.org>, Clinton Collins <ccollins@idmod.org>, Zhaowei Du <zdu@idmod.org>, Mary Fisher <mafisher@idmod.org>, Mandy Izzo <mizzo@idmod.org>, Clark Kirkman IV <ckirkman@idmod.org>, Benoit Raybaud <braybaud@idmod.org>, Jen Schripsema <jschripsema@idmod.org>
|
|
6
|
+
Project-URL: Homepage, https://github.com/InstituteforDiseaseModeling/idmtools
|
|
7
|
+
Keywords: modeling,IDM
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Requires-Python: >=3.8
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE.TXT
|
|
16
|
+
Requires-Dist: idmtools<1.0.0,>=0.0.0
|
|
17
|
+
Provides-Extra: test
|
|
18
|
+
Requires-Dist: idmtools[test]; extra == "test"
|
|
19
|
+
Requires-Dist: pyCOMPS~=2.11; extra == "test"
|
|
20
|
+
Requires-Dist: idmtools_test; extra == "test"
|
|
21
|
+
Requires-Dist: matplotlib~=3.10; extra == "test"
|
|
22
|
+
Provides-Extra: packaging
|
|
23
|
+
Requires-Dist: flake8; extra == "packaging"
|
|
24
|
+
Requires-Dist: coverage; extra == "packaging"
|
|
25
|
+
Requires-Dist: bump2version; extra == "packaging"
|
|
26
|
+
Requires-Dist: twine; extra == "packaging"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+

|
|
30
|
+
|
|
31
|
+
# idmtools-models
|
|
32
|
+
|
|
33
|
+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
34
|
+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
35
|
+
**Table of Contents**
|
|
36
|
+
|
|
37
|
+
- [Installing](#installing)
|
|
38
|
+
- [Development Tips](#development-tips)
|
|
39
|
+
|
|
40
|
+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
|
41
|
+
|
|
42
|
+
## Installing
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install idmtools-models --index-url=https://packages.idmod.org/api/pypi/pypi-production/simple
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
# Development Tips
|
|
49
|
+
|
|
50
|
+
There is a Makefile file available for most common development tasks. Here is a list of commands
|
|
51
|
+
```bash
|
|
52
|
+
clean - Clean up temproary files
|
|
53
|
+
lint - Lint package and tests
|
|
54
|
+
test - Run All tests
|
|
55
|
+
coverage - Run tests and generate coverage report that is shown in browser
|
|
56
|
+
```
|
|
57
|
+
On Windows, you can use `pymake` instead of `make`
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
# idmtools-models
|
|
4
|
+
|
|
5
|
+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
6
|
+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
7
|
+
**Table of Contents**
|
|
8
|
+
|
|
9
|
+
- [Installing](#installing)
|
|
10
|
+
- [Development Tips](#development-tips)
|
|
11
|
+
|
|
12
|
+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
|
13
|
+
|
|
14
|
+
## Installing
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install idmtools-models --index-url=https://packages.idmod.org/api/pypi/pypi-production/simple
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
# Development Tips
|
|
21
|
+
|
|
22
|
+
There is a Makefile file available for most common development tasks. Here is a list of commands
|
|
23
|
+
```bash
|
|
24
|
+
clean - Clean up temproary files
|
|
25
|
+
lint - Lint package and tests
|
|
26
|
+
test - Run All tests
|
|
27
|
+
coverage - Run tests and generate coverage report that is shown in browser
|
|
28
|
+
```
|
|
29
|
+
On Windows, you can use `pymake` instead of `make`
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""idmtools models package.
|
|
2
|
+
|
|
3
|
+
This package provides some common model tasks like Python, Template Scripts, or Python task.
|
|
4
|
+
|
|
5
|
+
Copyright 2021, Bill & Melinda Gates Foundation. All rights reserved.
|
|
6
|
+
"""
|
|
7
|
+
try:
|
|
8
|
+
from importlib.metadata import version, PackageNotFoundError
|
|
9
|
+
except ImportError:
|
|
10
|
+
# Python < 3.8
|
|
11
|
+
from importlib_metadata import version, PackageNotFoundError
|
|
12
|
+
|
|
13
|
+
try:
|
|
14
|
+
__version__ = version("idmtools-models") # Use your actual package name
|
|
15
|
+
except PackageNotFoundError:
|
|
16
|
+
# Package not installed, use fallback
|
|
17
|
+
__version__ = "0.0.0+unknown"
|
|
18
|
+
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
"""idmtools json configured task.
|
|
2
|
+
|
|
3
|
+
Copyright 2021, Bill & Melinda Gates Foundation. All rights reserved.
|
|
4
|
+
"""
|
|
5
|
+
import json
|
|
6
|
+
from dataclasses import dataclass, field, fields
|
|
7
|
+
from functools import partial
|
|
8
|
+
from logging import getLogger, DEBUG
|
|
9
|
+
from typing import Union, Dict, Any, List, Optional, Type, TYPE_CHECKING
|
|
10
|
+
from idmtools.assets import Asset, AssetCollection
|
|
11
|
+
from idmtools.entities.itask import ITask
|
|
12
|
+
from idmtools.entities.simulation import Simulation
|
|
13
|
+
from idmtools.registry.task_specification import TaskSpecification
|
|
14
|
+
if TYPE_CHECKING: # pragma: no cover
|
|
15
|
+
from idmtools.entities.iplatform import IPlatform
|
|
16
|
+
|
|
17
|
+
TJSONConfigKeyType = Union[str, int, float]
|
|
18
|
+
TJSONConfigValueType = Union[str, int, float, Dict[TJSONConfigKeyType, Any]]
|
|
19
|
+
|
|
20
|
+
logger = getLogger(__name__)
|
|
21
|
+
user_logger = getLogger('user')
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass
|
|
25
|
+
class JSONConfiguredTask(ITask):
|
|
26
|
+
"""
|
|
27
|
+
Defines an extensible simple task that implements functionality through optional supplied use hooks.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
# Note: large amounts of parameters will increase size of metadata
|
|
31
|
+
parameters: dict = field(default_factory=lambda: {}, metadata={"md": True})
|
|
32
|
+
envelope: str = field(default=None, metadata={"md": True})
|
|
33
|
+
# If we don't define this we assume static name the script consuming file will know
|
|
34
|
+
config_file_name: str = field(default="config.json", metadata={"md": True})
|
|
35
|
+
# is the config file a common asset or a transient. We default ot transient
|
|
36
|
+
is_config_common: bool = field(default=False)
|
|
37
|
+
configfile_argument: str = field(default=None)
|
|
38
|
+
# If command_line_argument is set, defines if we pass the filename after the argument
|
|
39
|
+
# for example, if the argument is --config and the config file name is config.json we would run the command as
|
|
40
|
+
# cmd --config config.json
|
|
41
|
+
command_line_argument_no_filename: bool = field(default=False)
|
|
42
|
+
|
|
43
|
+
def __post_init__(self):
|
|
44
|
+
"""Constructor."""
|
|
45
|
+
super().__post_init__()
|
|
46
|
+
if self.parameters is not None and self.envelope is not None and self.envelope in self.parameters:
|
|
47
|
+
logger.debug(f'Loading parameters from envelope: {self.envelope}')
|
|
48
|
+
self.parameters = self.parameters[self.envelope]
|
|
49
|
+
|
|
50
|
+
def gather_common_assets(self) -> AssetCollection:
|
|
51
|
+
"""
|
|
52
|
+
Gather assets common across an Experiment(Set of Simulations).
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
Common AssetCollection
|
|
56
|
+
"""
|
|
57
|
+
if self.is_config_common:
|
|
58
|
+
self.__dump_config(self.common_assets)
|
|
59
|
+
return self.common_assets
|
|
60
|
+
|
|
61
|
+
def gather_transient_assets(self) -> AssetCollection:
|
|
62
|
+
"""
|
|
63
|
+
Gather assets that are unique to this simulation/worktiem.
|
|
64
|
+
|
|
65
|
+
Returns:
|
|
66
|
+
Simulation/workitem level AssetCollection
|
|
67
|
+
"""
|
|
68
|
+
self.__dump_config(self.transient_assets)
|
|
69
|
+
return self.transient_assets
|
|
70
|
+
|
|
71
|
+
def __dump_config(self, assets) -> None:
|
|
72
|
+
"""
|
|
73
|
+
Writes the configuration out to asset.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
assets: Asset to add configuration too
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
None
|
|
80
|
+
"""
|
|
81
|
+
if self.config_file_name is not None:
|
|
82
|
+
params = {self.envelope: self.parameters} if self.envelope else self.parameters
|
|
83
|
+
if logger.isEnabledFor(DEBUG):
|
|
84
|
+
logger.debug('Adding JSON Configured File %s', self.config_file_name)
|
|
85
|
+
logger.debug(f'Generating {self.config_file_name} as an asset from JSONConfiguredTask')
|
|
86
|
+
logger.debug('Writing Config %s', json.dumps(params))
|
|
87
|
+
assets.add_or_replace_asset(Asset(filename=self.config_file_name, content=json.dumps(params)))
|
|
88
|
+
|
|
89
|
+
def set_parameter(self, key: TJSONConfigKeyType, value: TJSONConfigValueType):
|
|
90
|
+
"""
|
|
91
|
+
Update a parameter. The type hinting encourages JSON supported types.
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
key: Config
|
|
95
|
+
value:
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
Tags to be defined on the simulation/workitem
|
|
99
|
+
"""
|
|
100
|
+
if logger.isEnabledFor(DEBUG):
|
|
101
|
+
logger.info('Setting parameter %s to %s', key, str(value))
|
|
102
|
+
self.parameters[key] = value
|
|
103
|
+
return {key: value}
|
|
104
|
+
|
|
105
|
+
def get_parameter(self, key: TJSONConfigKeyType) -> TJSONConfigValueType:
|
|
106
|
+
"""
|
|
107
|
+
Returns a parameter value.
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
key: Key of parameter
|
|
111
|
+
|
|
112
|
+
Returns:
|
|
113
|
+
Value of parameter
|
|
114
|
+
Raises:
|
|
115
|
+
KeyError
|
|
116
|
+
"""
|
|
117
|
+
return self.parameters[key]
|
|
118
|
+
|
|
119
|
+
def update_parameters(self, values: Dict[TJSONConfigKeyType, TJSONConfigValueType]):
|
|
120
|
+
"""
|
|
121
|
+
Perform bulk update from another dictionary.
|
|
122
|
+
|
|
123
|
+
Args:
|
|
124
|
+
values: Values to update as dictionaryy
|
|
125
|
+
|
|
126
|
+
Returns:
|
|
127
|
+
Values
|
|
128
|
+
"""
|
|
129
|
+
if logger.isEnabledFor(DEBUG):
|
|
130
|
+
for k, p in values.items():
|
|
131
|
+
logger.debug('Setting parameter %s to %s', k, str(p))
|
|
132
|
+
self.parameters.update(values)
|
|
133
|
+
return values
|
|
134
|
+
|
|
135
|
+
def reload_from_simulation(self, simulation: 'Simulation', config_file_name: Optional[str] = None,
|
|
136
|
+
envelope: Optional[str] = None, **kwargs): # noqa: F821
|
|
137
|
+
"""
|
|
138
|
+
Reload from Simulation.
|
|
139
|
+
|
|
140
|
+
To do this, the process is
|
|
141
|
+
|
|
142
|
+
1. First check for a configfile name from arguments, then tags, or the default name
|
|
143
|
+
2. Load the json config file
|
|
144
|
+
3. Check if we got an envelope argument from parameters or the simulation tags, or on the task object
|
|
145
|
+
|
|
146
|
+
Args:
|
|
147
|
+
simulation: Simulation object with metadata to load info from
|
|
148
|
+
config_file_name: Optional name of config file
|
|
149
|
+
envelope: Optional name of envelope
|
|
150
|
+
|
|
151
|
+
Returns:
|
|
152
|
+
Populates the config with config from object
|
|
153
|
+
"""
|
|
154
|
+
if simulation.platform:
|
|
155
|
+
self.parameters = self.__find_config(simulation)
|
|
156
|
+
if envelope and envelope in self.parameters:
|
|
157
|
+
self.parameters = self.parameters[envelope]
|
|
158
|
+
elif 'task_envelope' in simulation.tags and simulation.tags['task_envelope'] in self.parameters:
|
|
159
|
+
self.parameters = self.parameters[simulation.tags['task_envelope']]
|
|
160
|
+
elif self.envelope and self.envelope in self.parameters:
|
|
161
|
+
self.parameters = self.parameters[self.envelope]
|
|
162
|
+
|
|
163
|
+
def __find_config(self, simulation: Simulation, config_file_name: str = None) -> Dict[str, Any]:
|
|
164
|
+
"""
|
|
165
|
+
Used to rebuild configuration using simulation data that has been ran.
|
|
166
|
+
|
|
167
|
+
Args:
|
|
168
|
+
simulation: Simulation to load from
|
|
169
|
+
config_file_name: Config file name
|
|
170
|
+
|
|
171
|
+
Returns:
|
|
172
|
+
Config reloaded
|
|
173
|
+
"""
|
|
174
|
+
# find the ocnfig
|
|
175
|
+
if config_file_name:
|
|
176
|
+
cfn = config_file_name
|
|
177
|
+
elif 'task_config_file_name' in simulation.tags:
|
|
178
|
+
cfn = simulation.tags['task_config_file_name']
|
|
179
|
+
else:
|
|
180
|
+
cfn = self.config_file_name
|
|
181
|
+
if logger.isEnabledFor(DEBUG):
|
|
182
|
+
logger.debug(f'Loading Config from {simulation.id}:{cfn}')
|
|
183
|
+
config = dict()
|
|
184
|
+
if simulation.assets and isinstance(simulation.assets, (AssetCollection, list)):
|
|
185
|
+
for file in simulation.assets:
|
|
186
|
+
if file.filename == cfn:
|
|
187
|
+
config = file.content
|
|
188
|
+
if isinstance(config, bytes):
|
|
189
|
+
config = json.loads(config.decode('utf-8'))
|
|
190
|
+
new_assets = []
|
|
191
|
+
# filter our config from the simulation
|
|
192
|
+
for _i, asset in enumerate(simulation.assets.assets):
|
|
193
|
+
if asset.filename != cfn:
|
|
194
|
+
new_assets.append(asset)
|
|
195
|
+
simulation.assets.assets = new_assets
|
|
196
|
+
else:
|
|
197
|
+
# try to load the config
|
|
198
|
+
config = simulation.platform.get_files(simulation, [cfn])
|
|
199
|
+
config = config[cfn]
|
|
200
|
+
if isinstance(config, bytes):
|
|
201
|
+
config = json.loads(config.decode('utf-8'))
|
|
202
|
+
|
|
203
|
+
# filter config from transient assets
|
|
204
|
+
if self.transient_assets:
|
|
205
|
+
nw = AssetCollection()
|
|
206
|
+
for asset in self.transient_assets:
|
|
207
|
+
if isinstance(asset, dict) and asset['filename'] != cfn:
|
|
208
|
+
self.transient_assets.add_asset(Asset(**asset))
|
|
209
|
+
elif isinstance(asset, Asset) and asset.filename != cfn:
|
|
210
|
+
self.transient_assets.add_asset(Asset(**asset))
|
|
211
|
+
self.transient_assets = nw
|
|
212
|
+
return config
|
|
213
|
+
|
|
214
|
+
def pre_creation(self, parent: Union['Simulation', 'WorkflowItem'], platform: 'IPlatform'): # noqa: F821
|
|
215
|
+
"""
|
|
216
|
+
Pre-creation. For JSONConfiguredTask, we finalize our configuration file and command line here.
|
|
217
|
+
|
|
218
|
+
Args:
|
|
219
|
+
parent: Parent of task
|
|
220
|
+
platform: Platform task is being created on
|
|
221
|
+
|
|
222
|
+
Returns:
|
|
223
|
+
None
|
|
224
|
+
"""
|
|
225
|
+
defaults = [x for x in fields(JSONConfiguredTask) if x.name == "config_file_name"][0].default
|
|
226
|
+
|
|
227
|
+
if self.config_file_name != defaults:
|
|
228
|
+
logger.info('Found non-default name for config_file_name. Adding tag task_config_file_name')
|
|
229
|
+
parent.tags['task_config_file_name'] = self.config_file_name
|
|
230
|
+
|
|
231
|
+
if self.envelope:
|
|
232
|
+
logger.info('Found envelope name. Adding tag envelope')
|
|
233
|
+
parent.tags['task_envelope'] = self.envelope
|
|
234
|
+
# Ensure our command line argument is added if configured
|
|
235
|
+
if self.configfile_argument:
|
|
236
|
+
logger.debug('Adding command_line_argument to command')
|
|
237
|
+
if self.configfile_argument not in self.command.arguments:
|
|
238
|
+
# check if we should add filename with arg?
|
|
239
|
+
if self.command_line_argument_no_filename:
|
|
240
|
+
self.command.add_argument(self.configfile_argument)
|
|
241
|
+
else:
|
|
242
|
+
self.command.add_argument(self.configfile_argument)
|
|
243
|
+
self.command.add_argument(self.config_file_name)
|
|
244
|
+
|
|
245
|
+
def __repr__(self):
|
|
246
|
+
"""String version of task Prints config filename and parameters."""
|
|
247
|
+
return f"<JSONConfiguredTask config:{self.config_file_name} parameters: {self.parameters}"
|
|
248
|
+
|
|
249
|
+
@staticmethod
|
|
250
|
+
def set_parameter_sweep_callback(simulation: Simulation, param: str, value: Any) -> Dict[str, Any]:
|
|
251
|
+
"""
|
|
252
|
+
Performs a callback with a parameter and a value. Most likely users want to use set_parameter_partial instead of this method.
|
|
253
|
+
|
|
254
|
+
Args:
|
|
255
|
+
simulation: Simulation object
|
|
256
|
+
param: Param name
|
|
257
|
+
value: Value to set
|
|
258
|
+
|
|
259
|
+
Returns:
|
|
260
|
+
Tags to add to simulation
|
|
261
|
+
"""
|
|
262
|
+
if not hasattr(simulation.task, 'set_parameter'):
|
|
263
|
+
raise ValueError("update_task_with_set_parameter can only be used on tasks with a set_parameter")
|
|
264
|
+
return simulation.task.set_parameter(param, value)
|
|
265
|
+
|
|
266
|
+
@classmethod
|
|
267
|
+
def set_parameter_partial(cls, parameter: str):
|
|
268
|
+
"""
|
|
269
|
+
Callback to be used when sweeping with a json configured model.
|
|
270
|
+
|
|
271
|
+
Args:
|
|
272
|
+
parameter: Param name
|
|
273
|
+
|
|
274
|
+
Returns:
|
|
275
|
+
Partial setting a specific parameter
|
|
276
|
+
|
|
277
|
+
Notes:
|
|
278
|
+
- TODO Reference some examples code here
|
|
279
|
+
"""
|
|
280
|
+
return partial(cls.set_parameter_sweep_callback, param=parameter)
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
class JSONConfiguredTaskSpecification(TaskSpecification):
|
|
284
|
+
"""
|
|
285
|
+
JSONConfiguredTaskSpecification defines the plugin specs for JSONConfiguredTask.
|
|
286
|
+
"""
|
|
287
|
+
|
|
288
|
+
def get(self, configuration: dict) -> JSONConfiguredTask:
|
|
289
|
+
"""
|
|
290
|
+
Get instance of JSONConfiguredTask with configuration specified.
|
|
291
|
+
|
|
292
|
+
Args:
|
|
293
|
+
configuration: Configuration for configuration
|
|
294
|
+
|
|
295
|
+
Returns:
|
|
296
|
+
JSONConfiguredTask with configuration
|
|
297
|
+
"""
|
|
298
|
+
return JSONConfiguredTask(**configuration)
|
|
299
|
+
|
|
300
|
+
def get_description(self) -> str:
|
|
301
|
+
"""
|
|
302
|
+
Get description for plugin.
|
|
303
|
+
|
|
304
|
+
Returns:
|
|
305
|
+
Description of plugin
|
|
306
|
+
"""
|
|
307
|
+
return "Defines a general command that has a simple JSON based config"
|
|
308
|
+
|
|
309
|
+
def get_example_urls(self) -> List[str]:
|
|
310
|
+
"""
|
|
311
|
+
Get list of urls with examples for JSONConfiguredTask.
|
|
312
|
+
|
|
313
|
+
Returns:
|
|
314
|
+
List of urls that point to examples relating to JSONConfiguredTask
|
|
315
|
+
"""
|
|
316
|
+
from idmtools_models import __version__
|
|
317
|
+
examples = [f'examples/{example}' for example in ['python_model', 'load_lib']]
|
|
318
|
+
return [self.get_version_url(f'v{__version__}', x) for x in examples]
|
|
319
|
+
|
|
320
|
+
def get_type(self) -> Type[JSONConfiguredTask]:
|
|
321
|
+
"""
|
|
322
|
+
Get task type provided by plugin.
|
|
323
|
+
|
|
324
|
+
Returns:
|
|
325
|
+
JSONConfiguredTask
|
|
326
|
+
"""
|
|
327
|
+
return JSONConfiguredTask
|
|
328
|
+
|
|
329
|
+
def get_version(self) -> str:
|
|
330
|
+
"""
|
|
331
|
+
Returns the version of the plugin.
|
|
332
|
+
|
|
333
|
+
Returns:
|
|
334
|
+
Plugin Version
|
|
335
|
+
"""
|
|
336
|
+
from idmtools_models import __version__
|
|
337
|
+
return __version__
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"""idmtools json configured python task.
|
|
2
|
+
|
|
3
|
+
Copyright 2021, Bill & Melinda Gates Foundation. All rights reserved.
|
|
4
|
+
"""
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from typing import Optional, 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.python.python_task import PythonTask
|
|
13
|
+
|
|
14
|
+
if TYPE_CHECKING: # pragma: no cover
|
|
15
|
+
from idmtools.entities.iplatform import IPlatform
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass
|
|
19
|
+
class JSONConfiguredPythonTask(JSONConfiguredTask, PythonTask):
|
|
20
|
+
"""
|
|
21
|
+
JSONConfiguredPythonTask combines JSONConfiguredTask and PythonTask.
|
|
22
|
+
|
|
23
|
+
Notes:
|
|
24
|
+
- TODO Add examples here
|
|
25
|
+
|
|
26
|
+
See Also:
|
|
27
|
+
:class:`idmtools_models.json_configured_task.JSONConfiguredTask`
|
|
28
|
+
:class:`idmtools_models.python.python_task.PythonTask`
|
|
29
|
+
"""
|
|
30
|
+
configfile_argument: Optional[str] = field(default="--config")
|
|
31
|
+
|
|
32
|
+
def __post_init__(self):
|
|
33
|
+
"""Constructor."""
|
|
34
|
+
JSONConfiguredTask.__post_init__(self)
|
|
35
|
+
PythonTask.__post_init__(self)
|
|
36
|
+
|
|
37
|
+
def gather_common_assets(self):
|
|
38
|
+
"""
|
|
39
|
+
Return the common assets for a JSON Configured Task a derived class.
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
Assets
|
|
43
|
+
"""
|
|
44
|
+
return PythonTask.gather_common_assets(self)
|
|
45
|
+
|
|
46
|
+
def gather_transient_assets(self) -> AssetCollection:
|
|
47
|
+
"""
|
|
48
|
+
Get Transient assets. This should general be the config.json.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
Transient assets
|
|
52
|
+
"""
|
|
53
|
+
return JSONConfiguredTask.gather_transient_assets(self)
|
|
54
|
+
|
|
55
|
+
def reload_from_simulation(self, simulation: Simulation, **kwargs):
|
|
56
|
+
"""
|
|
57
|
+
Reload the task from a simulation.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
simulation: Simulation to reload from
|
|
61
|
+
**kwargs:
|
|
62
|
+
|
|
63
|
+
Returns:
|
|
64
|
+
None
|
|
65
|
+
|
|
66
|
+
See Also
|
|
67
|
+
:meth:`idmtools_models.json_configured_task.JSONConfiguredTask.reload_from_simulation`
|
|
68
|
+
:meth:`idmtools_models.python.python_task.PythonTask.reload_from_simulation`
|
|
69
|
+
"""
|
|
70
|
+
JSONConfiguredTask.reload_from_simulation(self, simulation, **kwargs)
|
|
71
|
+
PythonTask.reload_from_simulation(self, simulation, **kwargs)
|
|
72
|
+
|
|
73
|
+
def pre_creation(self, parent: Union[Simulation, IWorkflowItem], platform: 'IPlatform'):
|
|
74
|
+
"""
|
|
75
|
+
Pre-creation.
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
parent: Parent of task
|
|
79
|
+
platform: Platform Python Script is being executed on
|
|
80
|
+
|
|
81
|
+
Returns:
|
|
82
|
+
None
|
|
83
|
+
See Also
|
|
84
|
+
:meth:`idmtools_models.json_configured_task.JSONConfiguredTask.pre_creation`
|
|
85
|
+
:meth:`idmtools_models.python.python_task.PythonTask.pre_creation`
|
|
86
|
+
"""
|
|
87
|
+
PythonTask.pre_creation(self, parent, platform)
|
|
88
|
+
JSONConfiguredTask.pre_creation(self, parent, platform)
|
|
89
|
+
|
|
90
|
+
def post_creation(self, parent: Union[Simulation, IWorkflowItem], platform: 'IPlatform'):
|
|
91
|
+
"""
|
|
92
|
+
Post-creation.
|
|
93
|
+
|
|
94
|
+
For us, we proxy the underlying JSONConfiguredTask and PythonTask/
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
parent: Parent
|
|
98
|
+
platform: Platform Python Script is being executed on
|
|
99
|
+
|
|
100
|
+
Returns:
|
|
101
|
+
None
|
|
102
|
+
|
|
103
|
+
See Also
|
|
104
|
+
:meth:`idmtools_models.json_configured_task.JSONConfiguredTask.post_creation`
|
|
105
|
+
:meth:`idmtools_models.python.python_task.PythonTask.post_creation`
|
|
106
|
+
"""
|
|
107
|
+
JSONConfiguredTask.post_creation(self, parent, platform)
|
|
108
|
+
PythonTask.post_creation(self, parent, platform)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
class JSONConfiguredPythonTaskSpecification(TaskSpecification):
|
|
112
|
+
"""
|
|
113
|
+
JSONConfiguredPythonTaskSpecification provides the plugin info for JSONConfiguredPythonTask.
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
def get(self, configuration: dict) -> JSONConfiguredPythonTask:
|
|
117
|
+
"""
|
|
118
|
+
Get instance of JSONConfiguredPythonTask with configuration.
|
|
119
|
+
|
|
120
|
+
Args:
|
|
121
|
+
configuration: Configuration for task
|
|
122
|
+
|
|
123
|
+
Returns:
|
|
124
|
+
JSONConfiguredPythonTask with configuration
|
|
125
|
+
"""
|
|
126
|
+
return JSONConfiguredPythonTask(**configuration)
|
|
127
|
+
|
|
128
|
+
def get_description(self) -> str:
|
|
129
|
+
"""
|
|
130
|
+
Get description for plugin.
|
|
131
|
+
|
|
132
|
+
Returns:
|
|
133
|
+
Plugin Description
|
|
134
|
+
"""
|
|
135
|
+
return "Defines a python script that has a single JSON config file"
|
|
136
|
+
|
|
137
|
+
def get_type(self) -> Type[JSONConfiguredPythonTask]:
|
|
138
|
+
"""
|
|
139
|
+
Get Type for Plugin.
|
|
140
|
+
|
|
141
|
+
Returns:
|
|
142
|
+
JSONConfiguredPythonTask
|
|
143
|
+
"""
|
|
144
|
+
return JSONConfiguredPythonTask
|
|
145
|
+
|
|
146
|
+
def get_version(self) -> str:
|
|
147
|
+
"""
|
|
148
|
+
Returns the version of the plugin.
|
|
149
|
+
|
|
150
|
+
Returns:
|
|
151
|
+
Plugin Version
|
|
152
|
+
"""
|
|
153
|
+
from idmtools_models import __version__
|
|
154
|
+
return __version__
|