idmtools 0.0.0.dev0__py3-none-any.whl → 0.0.3__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.
Files changed (118) hide show
  1. idmtools/__init__.py +27 -8
  2. idmtools/analysis/__init__.py +5 -0
  3. idmtools/analysis/add_analyzer.py +89 -0
  4. idmtools/analysis/analyze_manager.py +490 -0
  5. idmtools/analysis/csv_analyzer.py +103 -0
  6. idmtools/analysis/download_analyzer.py +96 -0
  7. idmtools/analysis/map_worker_entry.py +100 -0
  8. idmtools/analysis/platform_analysis_bootstrap.py +94 -0
  9. idmtools/analysis/platform_anaylsis.py +291 -0
  10. idmtools/analysis/tags_analyzer.py +93 -0
  11. idmtools/assets/__init__.py +9 -0
  12. idmtools/assets/asset.py +453 -0
  13. idmtools/assets/asset_collection.py +514 -0
  14. idmtools/assets/content_handlers.py +19 -0
  15. idmtools/assets/errors.py +23 -0
  16. idmtools/assets/file_list.py +191 -0
  17. idmtools/builders/__init__.py +11 -0
  18. idmtools/builders/arm_simulation_builder.py +152 -0
  19. idmtools/builders/csv_simulation_builder.py +76 -0
  20. idmtools/builders/simulation_builder.py +348 -0
  21. idmtools/builders/sweep_arm.py +109 -0
  22. idmtools/builders/yaml_simulation_builder.py +82 -0
  23. idmtools/config/__init__.py +7 -0
  24. idmtools/config/idm_config_parser.py +486 -0
  25. idmtools/core/__init__.py +10 -0
  26. idmtools/core/cache_enabled.py +114 -0
  27. idmtools/core/context.py +68 -0
  28. idmtools/core/docker_task.py +207 -0
  29. idmtools/core/enums.py +51 -0
  30. idmtools/core/exceptions.py +91 -0
  31. idmtools/core/experiment_factory.py +71 -0
  32. idmtools/core/id_file.py +70 -0
  33. idmtools/core/interfaces/__init__.py +5 -0
  34. idmtools/core/interfaces/entity_container.py +64 -0
  35. idmtools/core/interfaces/iassets_enabled.py +58 -0
  36. idmtools/core/interfaces/ientity.py +331 -0
  37. idmtools/core/interfaces/iitem.py +206 -0
  38. idmtools/core/interfaces/imetadata_operations.py +89 -0
  39. idmtools/core/interfaces/inamed_entity.py +17 -0
  40. idmtools/core/interfaces/irunnable_entity.py +159 -0
  41. idmtools/core/logging.py +387 -0
  42. idmtools/core/platform_factory.py +316 -0
  43. idmtools/core/system_information.py +104 -0
  44. idmtools/core/task_factory.py +145 -0
  45. idmtools/entities/__init__.py +10 -0
  46. idmtools/entities/command_line.py +229 -0
  47. idmtools/entities/command_task.py +155 -0
  48. idmtools/entities/experiment.py +787 -0
  49. idmtools/entities/generic_workitem.py +43 -0
  50. idmtools/entities/ianalyzer.py +163 -0
  51. idmtools/entities/iplatform.py +1106 -0
  52. idmtools/entities/iplatform_default.py +39 -0
  53. idmtools/entities/iplatform_ops/__init__.py +5 -0
  54. idmtools/entities/iplatform_ops/iplatform_asset_collection_operations.py +148 -0
  55. idmtools/entities/iplatform_ops/iplatform_experiment_operations.py +415 -0
  56. idmtools/entities/iplatform_ops/iplatform_simulation_operations.py +315 -0
  57. idmtools/entities/iplatform_ops/iplatform_suite_operations.py +322 -0
  58. idmtools/entities/iplatform_ops/iplatform_workflowitem_operations.py +301 -0
  59. idmtools/entities/iplatform_ops/utils.py +185 -0
  60. idmtools/entities/itask.py +316 -0
  61. idmtools/entities/iworkflow_item.py +167 -0
  62. idmtools/entities/platform_requirements.py +20 -0
  63. idmtools/entities/relation_type.py +14 -0
  64. idmtools/entities/simulation.py +255 -0
  65. idmtools/entities/suite.py +188 -0
  66. idmtools/entities/task_proxy.py +37 -0
  67. idmtools/entities/templated_simulation.py +325 -0
  68. idmtools/frozen/frozen_dict.py +71 -0
  69. idmtools/frozen/frozen_list.py +66 -0
  70. idmtools/frozen/frozen_set.py +86 -0
  71. idmtools/frozen/frozen_tuple.py +18 -0
  72. idmtools/frozen/frozen_utils.py +179 -0
  73. idmtools/frozen/ifrozen.py +66 -0
  74. idmtools/plugins/__init__.py +5 -0
  75. idmtools/plugins/git_commit.py +117 -0
  76. idmtools/registry/__init__.py +4 -0
  77. idmtools/registry/experiment_specification.py +105 -0
  78. idmtools/registry/functions.py +28 -0
  79. idmtools/registry/hook_specs.py +132 -0
  80. idmtools/registry/master_plugin_registry.py +51 -0
  81. idmtools/registry/platform_specification.py +138 -0
  82. idmtools/registry/plugin_specification.py +129 -0
  83. idmtools/registry/task_specification.py +104 -0
  84. idmtools/registry/utils.py +119 -0
  85. idmtools/services/__init__.py +5 -0
  86. idmtools/services/ipersistance_service.py +135 -0
  87. idmtools/services/platforms.py +13 -0
  88. idmtools/utils/__init__.py +5 -0
  89. idmtools/utils/caller.py +24 -0
  90. idmtools/utils/collections.py +246 -0
  91. idmtools/utils/command_line.py +45 -0
  92. idmtools/utils/decorators.py +300 -0
  93. idmtools/utils/display/__init__.py +22 -0
  94. idmtools/utils/display/displays.py +181 -0
  95. idmtools/utils/display/settings.py +25 -0
  96. idmtools/utils/dropbox_location.py +30 -0
  97. idmtools/utils/entities.py +127 -0
  98. idmtools/utils/file.py +72 -0
  99. idmtools/utils/file_parser.py +151 -0
  100. idmtools/utils/filter_simulations.py +182 -0
  101. idmtools/utils/filters/__init__.py +5 -0
  102. idmtools/utils/filters/asset_filters.py +88 -0
  103. idmtools/utils/general.py +286 -0
  104. idmtools/utils/gitrepo.py +336 -0
  105. idmtools/utils/hashing.py +239 -0
  106. idmtools/utils/info.py +124 -0
  107. idmtools/utils/json.py +82 -0
  108. idmtools/utils/language.py +107 -0
  109. idmtools/utils/local_os.py +40 -0
  110. idmtools/utils/time.py +22 -0
  111. idmtools-0.0.3.dist-info/METADATA +120 -0
  112. idmtools-0.0.3.dist-info/RECORD +116 -0
  113. idmtools-0.0.3.dist-info/entry_points.txt +9 -0
  114. idmtools-0.0.3.dist-info/licenses/LICENSE.TXT +3 -0
  115. idmtools-0.0.0.dev0.dist-info/METADATA +0 -41
  116. idmtools-0.0.0.dev0.dist-info/RECORD +0 -5
  117. {idmtools-0.0.0.dev0.dist-info → idmtools-0.0.3.dist-info}/WHEEL +0 -0
  118. {idmtools-0.0.0.dev0.dist-info → idmtools-0.0.3.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,229 @@
1
+ """
2
+ Defines the CommandLine class that represents our remote command line to be executed.
3
+
4
+ Copyright 2021, Bill & Melinda Gates Foundation. All rights reserved.
5
+ """
6
+ import re
7
+ import shlex
8
+ from typing import TypeVar, Dict, Any, List
9
+ from dataclasses import dataclass, field
10
+
11
+
12
+ @dataclass(init=False)
13
+ class CommandLine:
14
+ """
15
+ A class to construct command-line strings from executable, options, and params.
16
+ """
17
+ #: The executable portion of the command
18
+ _executable: str = None
19
+ #: Options for the command
20
+ _options: Dict[str, Any] = field(default_factory=dict)
21
+ #: Arguments for the command
22
+ _args: List[Any] = field(default_factory=list)
23
+ #: Raw Arguments. These arguments are not quoted, so if you need quotes, you have to do that manually
24
+ _raw_args: List[Any] = field(default_factory=list)
25
+ #: Is this a command line for a windows system
26
+ is_windows: bool = field(default=False)
27
+
28
+ def __init__(self, executable=None, *args, is_windows: bool = False, raw_args: List[Any] = None, **kwargs):
29
+ """
30
+ Initialize CommandLine.
31
+
32
+ Args:
33
+ executable: Executable
34
+ *args: Additional Arguments
35
+ is_windows: is the command for windows
36
+ raw_args: Any raw arguments
37
+ **kwargs: Keyword arguments
38
+ """
39
+ # If there is a space in executable, we probably need to split it
40
+ self._executable = executable
41
+ self._options = kwargs or {}
42
+ self._args = list(args) if args else []
43
+ self.is_windows = is_windows
44
+ self._raw_args = list(raw_args) if raw_args else []
45
+ # check if user is providing a full command line
46
+ if executable and " " in executable:
47
+ other = self.from_string(executable)
48
+ self._executable = other._executable
49
+ if other._args:
50
+ self._args += other._args
51
+ if other.options:
52
+ self._options += other._options
53
+
54
+ @property
55
+ def executable(self) -> str:
56
+ """
57
+ Return executable as string.
58
+
59
+ Returns:
60
+ Executable
61
+ """
62
+ return self._executable.replace('/', "\\") if self.is_windows else self._executable
63
+
64
+ @executable.setter
65
+ def executable(self, executable):
66
+ """
67
+ Set the executable portion of the command line.
68
+
69
+ Args:
70
+ executable: Executable
71
+
72
+ Returns:
73
+ None
74
+ """
75
+ self._executable = executable
76
+
77
+ def add_argument(self, arg):
78
+ """
79
+ Add argument.
80
+
81
+ Args:
82
+ arg: Argument string
83
+
84
+ Returns:
85
+ None
86
+ """
87
+ self._args.append(str(arg))
88
+
89
+ def add_raw_argument(self, arg):
90
+ """
91
+ Add an argument that won't be quote on format.
92
+
93
+ Args:
94
+ arg:arg
95
+
96
+ Returns:
97
+ None
98
+ """
99
+ self._raw_args.append(str(arg))
100
+
101
+ def add_option(self, option, value):
102
+ """
103
+ Add a command-line option.
104
+
105
+ Args:
106
+ option: Option to add
107
+ value: Value of option
108
+
109
+ Returns:
110
+ None
111
+ """
112
+ self._options[option] = str(value)
113
+
114
+ @property
115
+ def options(self):
116
+ """
117
+ Options as a string.
118
+
119
+ Returns:
120
+ Options string
121
+ """
122
+ options = []
123
+ for k, v in self._options.items():
124
+ # Handles spaces
125
+ # value = '"%s"' % v if ' ' in str(v) else str(v) # Wrong: result in option value with both single and double quotes!
126
+ value = str(v)
127
+ if k[-1] == ':':
128
+ options.append(k + value) # if the option ends in ':', don't insert a space
129
+ else:
130
+ options.extend([k, value]) # otherwise let join (below) add a space
131
+
132
+ if self.is_windows:
133
+ return ' '.join([self.__quote_windows(s) for s in options if s])
134
+ else:
135
+ return ' '.join([shlex.quote(s) for s in options if s])
136
+
137
+ @staticmethod
138
+ def __quote_windows(s):
139
+ """
140
+ Quote a parameter for windows command line.
141
+
142
+ Args:
143
+ s: String to quote
144
+
145
+ Returns:
146
+ Quoted string
147
+ """
148
+ n = s.replace('"', '\\"')
149
+ if re.search(r'(["\s])', s):
150
+ return f'"{n}"'
151
+ return n
152
+
153
+ @property
154
+ def arguments(self):
155
+ """
156
+ The CommandLine arguments.
157
+
158
+ Returns:
159
+ Arguments as string
160
+ """
161
+ quote_fn = self.__quote_windows if self.is_windows else self.__quote_linux
162
+ qargs = ' '.join([quote_fn(s) for s in self._args if s])
163
+ qargs += ' ' + self.raw_arguments
164
+ return qargs
165
+
166
+ def __quote_linux(self, s):
167
+ """
168
+ Quote linux.
169
+
170
+ Args:
171
+ s: String to quote
172
+
173
+ Returns:
174
+ Quotes string
175
+ """
176
+ return shlex.quote(s)
177
+
178
+ @property
179
+ def raw_arguments(self):
180
+ """
181
+ Raw arguments(arguments not to be parsed).
182
+
183
+ Returns:
184
+ Raw arguments as a string
185
+ """
186
+ return ' '.join(self._raw_args)
187
+
188
+ @property
189
+ def cmd(self):
190
+ """
191
+ Converts command to string.
192
+
193
+ Returns:
194
+ Command as string
195
+ """
196
+ return ' '.join(filter(None, [self._executable.strip() if self._executable else None, self.options.strip(), self.arguments.strip()]))
197
+
198
+ def __str__(self):
199
+ """
200
+ String representation of command.
201
+
202
+ Returns:
203
+ String of command
204
+ """
205
+ return self.cmd
206
+
207
+ @staticmethod
208
+ def from_string(command: str, as_raw_args: bool = False) -> 'CommandLine':
209
+ """
210
+ Creates a command line object from string.
211
+
212
+ Args:
213
+ command: Command
214
+ as_raw_args: When set to true, arguments will preserve the quoting provided
215
+
216
+ Returns:
217
+ CommandLine object from string
218
+ """
219
+ parts = shlex.split(command.replace("\\", "/"))
220
+ arguments = parts[1:] if len(parts) > 1 else []
221
+ cl = CommandLine(parts[0], *arguments if not as_raw_args else [])
222
+ if as_raw_args:
223
+ # replace executable
224
+ remaining = command.replace(parts[0], "", 1)
225
+ cl.add_raw_argument(remaining)
226
+ return cl
227
+
228
+
229
+ TCommandLine = TypeVar("TCommandLine", bound=CommandLine)
@@ -0,0 +1,155 @@
1
+ """
2
+ Command Task is the simplest task. It defined a simple task object with a command line.
3
+
4
+ Copyright 2021, Bill & Melinda Gates Foundation. All rights reserved.
5
+ """
6
+ from dataclasses import dataclass, field
7
+ from typing import List, Callable, Type, Union, TYPE_CHECKING
8
+ from idmtools.assets import AssetCollection
9
+ from idmtools.entities.itask import ITask
10
+ from idmtools.registry.task_specification import TaskSpecification
11
+ from idmtools.entities.simulation import Simulation
12
+
13
+ if TYPE_CHECKING: # pragma: no cover
14
+ from idmtools.entities.iplatform import IPlatform
15
+ from idmtools.entities.iworkflow_item import IWorkflowItem
16
+
17
+
18
+ @dataclass()
19
+ class CommandTask(ITask):
20
+ """
21
+ CommandTask is the simplest task.
22
+
23
+ A CommandTask is basically a command line and assets.
24
+ """
25
+ #: Hooks to gather common assets
26
+ gather_common_asset_hooks: List[Callable[[ITask], AssetCollection]] = field(default_factory=list)
27
+ #: Hooks to gather transient assets
28
+ gather_transient_asset_hooks: List[Callable[[ITask], AssetCollection]] = field(default_factory=list)
29
+ """
30
+ Defines an extensible simple task that implements functionality through optional supplied use hooks
31
+ """
32
+
33
+ def __post_init__(self):
34
+ """
35
+ Post init.
36
+
37
+ Returns:
38
+ None
39
+ """
40
+ super().__post_init__()
41
+ if self.command is None:
42
+ raise ValueError("Command is required")
43
+
44
+ def gather_common_assets(self) -> AssetCollection:
45
+ """
46
+ Gather common(experiment-level) assets for task.
47
+
48
+ Returns:
49
+ AssetCollection containing common assets
50
+ """
51
+ # TODO validate hooks have expected return type
52
+ ac = AssetCollection()
53
+ for x in self.gather_common_asset_hooks:
54
+ ac += x(self)
55
+ ac += self.common_assets
56
+ return ac
57
+
58
+ def gather_transient_assets(self) -> AssetCollection:
59
+ """
60
+ Gather transient(experiment-level) assets for task.
61
+
62
+ Returns:
63
+ AssetCollection containing transient assets
64
+ """
65
+ ac = AssetCollection()
66
+ for x in self.gather_transient_asset_hooks:
67
+ ac += x(self)
68
+ ac += self.transient_assets
69
+ if len(ac.assets) != 0:
70
+ self.transient_assets = ac
71
+ return ac
72
+
73
+ def reload_from_simulation(self, simulation: 'Simulation'): # noqa: F821
74
+ """
75
+ Reload task from a simulation.
76
+
77
+ Args:
78
+ simulation: Simulation to load
79
+
80
+ Returns:
81
+ None
82
+ """
83
+ pass
84
+
85
+ def pre_creation(self, parent: Union['Simulation', 'IWorkflowItem'], platform: 'IPlatform'):
86
+ """
87
+ pre-creation for the command task.
88
+
89
+ The default is to set the windows on the command line based on the platform.
90
+
91
+ Args:
92
+ parent: Parent of task
93
+ platform: Platform we are going to pre-creation
94
+
95
+ Returns:
96
+ None
97
+ """
98
+ super().pre_creation(parent, platform)
99
+ if platform.is_windows_platform(parent):
100
+ self.command.is_windows = True
101
+
102
+
103
+ class CommandTaskSpecification(TaskSpecification):
104
+ """
105
+ CommandTaskSpecification is the plugin definition for CommandTask.
106
+ """
107
+
108
+ def get(self, configuration: dict) -> CommandTask:
109
+ """
110
+ Get instance of CommandTask with configuration.
111
+
112
+ Args:
113
+ configuration: configuration for CommandTask
114
+
115
+ Returns:
116
+ CommandTask with configuration
117
+ """
118
+ return CommandTask(**configuration)
119
+
120
+ def get_description(self) -> str:
121
+ """
122
+ Get description of plugin.
123
+
124
+ Returns:
125
+ Plugin description
126
+ """
127
+ return "Defines a general command that provides user hooks. Intended for use in advanced scenarios"
128
+
129
+ def get_example_urls(self) -> List[str]:
130
+ """
131
+ Get example urls related to CommandTask.
132
+
133
+ Returns:
134
+ List of urls that have examples related to CommandTask
135
+ """
136
+ return ['https://github.com/InstituteforDiseaseModeling/corvid-idmtools']
137
+
138
+ def get_type(self) -> Type[CommandTask]:
139
+ """
140
+ Get task type provided by plugin.
141
+
142
+ Returns:
143
+ CommandTask
144
+ """
145
+ return CommandTask
146
+
147
+ def get_version(self) -> str:
148
+ """
149
+ Get version of command task plugin.
150
+
151
+ Returns:
152
+ Version of plugin
153
+ """
154
+ from idmtools import __version__
155
+ return __version__