idmtools-platform-general 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 (39) hide show
  1. idmtools_platform_file/__init__.py +18 -0
  2. idmtools_platform_file/assets/__init__.py +77 -0
  3. idmtools_platform_file/assets/_run.sh.jinja2 +47 -0
  4. idmtools_platform_file/assets/batch.sh.jinja2 +24 -0
  5. idmtools_platform_file/assets/run_simulation.sh +8 -0
  6. idmtools_platform_file/cli/__init__.py +5 -0
  7. idmtools_platform_file/cli/file.py +185 -0
  8. idmtools_platform_file/file_operations/__init__.py +4 -0
  9. idmtools_platform_file/file_operations/file_operations.py +298 -0
  10. idmtools_platform_file/file_operations/operations_interface.py +74 -0
  11. idmtools_platform_file/file_platform.py +288 -0
  12. idmtools_platform_file/platform_operations/__init__.py +5 -0
  13. idmtools_platform_file/platform_operations/asset_collection_operations.py +172 -0
  14. idmtools_platform_file/platform_operations/experiment_operations.py +314 -0
  15. idmtools_platform_file/platform_operations/json_metadata_operations.py +320 -0
  16. idmtools_platform_file/platform_operations/simulation_operations.py +212 -0
  17. idmtools_platform_file/platform_operations/suite_operations.py +243 -0
  18. idmtools_platform_file/platform_operations/utils.py +461 -0
  19. idmtools_platform_file/plugin_info.py +82 -0
  20. idmtools_platform_file/tools/__init__.py +4 -0
  21. idmtools_platform_file/tools/job_history.py +334 -0
  22. idmtools_platform_file/tools/status_report/__init__.py +4 -0
  23. idmtools_platform_file/tools/status_report/status_report.py +222 -0
  24. idmtools_platform_file/tools/status_report/utils.py +159 -0
  25. idmtools_platform_general-0.0.3.dist-info/METADATA +81 -0
  26. idmtools_platform_general-0.0.3.dist-info/RECORD +35 -0
  27. idmtools_platform_general-0.0.3.dist-info/entry_points.txt +6 -0
  28. idmtools_platform_general-0.0.3.dist-info/licenses/LICENSE.TXT +3 -0
  29. idmtools_platform_general-0.0.3.dist-info/top_level.txt +2 -0
  30. idmtools_platform_process/__init__.py +17 -0
  31. idmtools_platform_process/platform_operations/__init__.py +5 -0
  32. idmtools_platform_process/platform_operations/experiment_operations.py +53 -0
  33. idmtools_platform_process/plugin_info.py +80 -0
  34. idmtools_platform_process/process_platform.py +52 -0
  35. idmtools_platform_general/__init__.py +0 -8
  36. idmtools_platform_general-0.0.0.dev0.dist-info/METADATA +0 -41
  37. idmtools_platform_general-0.0.0.dev0.dist-info/RECORD +0 -5
  38. idmtools_platform_general-0.0.0.dev0.dist-info/top_level.txt +0 -1
  39. {idmtools_platform_general-0.0.0.dev0.dist-info → idmtools_platform_general-0.0.3.dist-info}/WHEEL +0 -0
@@ -0,0 +1,212 @@
1
+ """
2
+ Here we implement the FilePlatform simulation operations.
3
+
4
+ Copyright 2021, Bill & Melinda Gates Foundation. All rights reserved.
5
+ """
6
+ import shutil
7
+ from dataclasses import dataclass, field
8
+ from typing import TYPE_CHECKING, List, Dict, Type, Optional, Any
9
+ from idmtools.assets import Asset
10
+ from idmtools.core import ItemType
11
+ from idmtools.entities.experiment import Experiment
12
+ from idmtools.entities.simulation import Simulation
13
+ from idmtools.entities.iplatform_ops.iplatform_simulation_operations import IPlatformSimulationOperations
14
+ from idmtools_platform_file.platform_operations.utils import FileSimulation, FileExperiment, clean_item_name
15
+ from logging import getLogger
16
+
17
+ logger = getLogger(__name__)
18
+ user_logger = getLogger('user')
19
+
20
+ if TYPE_CHECKING:
21
+ from idmtools_platform_file.file_platform import FilePlatform
22
+
23
+ logger = getLogger(__name__)
24
+
25
+
26
+ @dataclass
27
+ class FilePlatformSimulationOperations(IPlatformSimulationOperations):
28
+ """
29
+ Simulation Operation for File Platform.
30
+ """
31
+ platform: 'FilePlatform' # noqa: F821
32
+ platform_type: Type = field(default=FileSimulation)
33
+
34
+ def get(self, simulation_id: str, **kwargs) -> FileSimulation:
35
+ """
36
+ Gets a simulation from the File platform.
37
+ Args:
38
+ simulation_id: Simulation id
39
+ kwargs: keyword arguments used to expand functionality
40
+ Returns:
41
+ File Simulation object
42
+ """
43
+ metas = self.platform._metas.filter(item_type=ItemType.SIMULATION, property_filter={'id': str(simulation_id)})
44
+ if len(metas) > 0:
45
+ # update status - data analysis may need this
46
+ file_sim = FileSimulation(metas[0])
47
+ file_sim.status = self.platform.get_simulation_status(file_sim.id)
48
+ return file_sim
49
+ else:
50
+ raise RuntimeError(f"Not found Simulation with id '{simulation_id}'")
51
+
52
+ def platform_create(self, simulation: Simulation, **kwargs) -> FileSimulation:
53
+ """
54
+ Create the simulation on File Platform.
55
+ Args:
56
+ simulation: Simulation
57
+ kwargs: keyword arguments used to expand functionality
58
+ Returns:
59
+ File Simulation object created.
60
+ """
61
+ simulation.name = clean_item_name(simulation.experiment.name if not simulation.name else simulation.name, maxlen=self.platform.maxlen)
62
+
63
+ # Generate Simulation folder structure
64
+ self.platform.mk_directory(simulation)
65
+ meta = self.platform._metas.dump(simulation)
66
+ self.platform._assets.link_common_assets(simulation)
67
+ self.platform._assets.dump_assets(simulation)
68
+ self.platform.create_batch_file(simulation, **kwargs)
69
+
70
+ # Make command executable
71
+ self.platform.make_command_executable(simulation)
72
+
73
+ # Return File Simulation
74
+ file_sim = FileSimulation(meta)
75
+ return file_sim
76
+
77
+ def get_parent(self, simulation: FileSimulation, **kwargs) -> FileExperiment:
78
+ """
79
+ Fetches the parent of a simulation.
80
+ Args:
81
+ simulation: File Simulation
82
+ kwargs: keyword arguments used to expand functionality
83
+ Returns:
84
+ The Experiment being the parent of this simulation.
85
+ """
86
+ if simulation.parent_id is None:
87
+ return None
88
+ else:
89
+ return self.platform._experiments.get(simulation.parent_id, raw=True, **kwargs)
90
+
91
+ def platform_run_item(self, simulation: Simulation, **kwargs):
92
+ """
93
+ For simulations on file, we let the experiment execute with batch.
94
+ Args:
95
+ simulation: idmtools Simulation
96
+ kwargs: keyword arguments used to expand functionality
97
+ Returns:
98
+ None
99
+ """
100
+ pass
101
+
102
+ def send_assets(self, simulation: Simulation, **kwargs):
103
+ """
104
+ Send assets.
105
+ Replaced by self.platform._metas.dump(simulation)
106
+ Args:
107
+ simulation: idmtools Simulation
108
+ kwargs: keyword arguments used to expand functionality
109
+ Returns:
110
+ None
111
+ """
112
+ pass
113
+
114
+ def get_assets(self, simulation: Simulation, files: List[str], **kwargs) -> Dict[str, bytearray]:
115
+ """
116
+ Get assets for simulation.
117
+ Args:
118
+ simulation: idmtools Simulation
119
+ files: files to be retrieved
120
+ kwargs: keyword arguments used to expand functionality
121
+ Returns:
122
+ Dict[str, bytearray]
123
+ """
124
+ ret = self.platform._assets.get_assets(simulation, files, **kwargs)
125
+ return ret
126
+
127
+ def list_assets(self, simulation: Simulation, **kwargs) -> List[Asset]:
128
+ """
129
+ List assets for simulation.
130
+ Args:
131
+ simulation: idmtools Simulation
132
+ kwargs: keyword arguments used to expand functionality
133
+ Returns:
134
+ List[Asset]
135
+ """
136
+ ret = self.platform._assets.list_assets(simulation, **kwargs)
137
+ return ret
138
+
139
+ def to_entity(self, file_sim: FileSimulation, parent: Optional[Experiment] = None, **kwargs) -> Simulation:
140
+ """
141
+ Convert a FileSimulation object to idmtools Simulation.
142
+
143
+ Args:
144
+ file_sim: simulation to convert
145
+ parent: optional experiment object
146
+ kwargs: keyword arguments used to expand functionality
147
+ Returns:
148
+ Simulation object
149
+ """
150
+ if parent is None:
151
+ parent = self.platform.get_item(file_sim.parent_id, ItemType.EXPERIMENT, force=True)
152
+ sim = Simulation(task=None)
153
+ sim.platform = self.platform
154
+ sim.uid = file_sim.uid
155
+ sim.name = file_sim.name
156
+ sim.parent_id = sim.experiment_id = parent.id
157
+ sim.parent = parent
158
+ sim.tags = file_sim.tags
159
+ sim._platform_object = file_sim
160
+ # Convert status
161
+ sim.status = file_sim.status
162
+
163
+ return sim
164
+
165
+ def refresh_status(self, simulation: Simulation, **kwargs):
166
+ """
167
+ Refresh simulation status: we actually don't really refresh simulation' status directly.
168
+ Args:
169
+ simulation: idmtools Simulation
170
+ kwargs: keyword arguments used to expand functionality
171
+ Returns:
172
+ None
173
+ """
174
+ raise NotImplementedError("Refresh simulation status is not called directly on the File Platform")
175
+
176
+ def create_sim_directory_map(self, simulation_id: str) -> Dict:
177
+ """
178
+ Build simulation working directory mapping.
179
+ Args:
180
+ simulation_id: simulation id
181
+
182
+ Returns:
183
+ Dict of simulation id as key and working dir as value
184
+ """
185
+ sim = self.platform.get_item(simulation_id, ItemType.SIMULATION, raw=False)
186
+ return {sim.id: str(self.platform.get_directory_by_id(simulation_id, ItemType.SIMULATION))}
187
+
188
+ def platform_delete(self, sim_id: str) -> None:
189
+ """
190
+ Delete platform simulation.
191
+ Args:
192
+ sim_id: platform simulation id
193
+ Returns:
194
+ None
195
+ """
196
+ sim = self.platform.get_item(sim_id, ItemType.SIMULATION, raw=False)
197
+ try:
198
+ shutil.rmtree(self.platform.get_directory(sim))
199
+ except Exception:
200
+ logger.info(f"Could not delete the simulation: {sim_id}..")
201
+ return
202
+
203
+ def platform_cancel(self, sim_id: str, force: bool = False) -> Any:
204
+ """
205
+ Cancel platform simulation's file job.
206
+ Args:
207
+ sim_id: simulation id
208
+ force: bool, True/False
209
+ Returns:
210
+ Any
211
+ """
212
+ pass
@@ -0,0 +1,243 @@
1
+ """
2
+ Here we implement the FilePlatform suite operations.
3
+
4
+ Copyright 2021, Bill & Melinda Gates Foundation. All rights reserved.
5
+ """
6
+ import shutil
7
+ from dataclasses import dataclass, field
8
+ from typing import TYPE_CHECKING, Any, List, Type, Dict, Tuple
9
+ from logging import getLogger
10
+ from idmtools.core import ItemType
11
+ from idmtools.entities import Suite
12
+ from idmtools.entities.iplatform_ops.iplatform_suite_operations import IPlatformSuiteOperations
13
+ from idmtools_platform_file.platform_operations.utils import FileSuite, FileExperiment
14
+
15
+ if TYPE_CHECKING:
16
+ from idmtools_platform_file.file_platform import FilePlatform
17
+
18
+ logger = getLogger(__name__)
19
+ user_logger = getLogger('user')
20
+
21
+
22
+ @dataclass
23
+ class FilePlatformSuiteOperations(IPlatformSuiteOperations):
24
+ """
25
+ Provides Suite operation to the FilePlatform.
26
+ """
27
+ platform: 'FilePlatform' # noqa F821
28
+ platform_type: Type = field(default=FileSuite)
29
+
30
+ def get(self, suite_id: str, **kwargs) -> FileSuite:
31
+ """
32
+ Get a suite from the File platform.
33
+ Args:
34
+ suite_id: Suite id
35
+ kwargs: keyword arguments used to expand functionality
36
+ Returns:
37
+ File Suite object
38
+ """
39
+ metas = self.platform._metas.filter(item_type=ItemType.SUITE, property_filter={'id': str(suite_id)})
40
+ if len(metas) > 0:
41
+ return FileSuite(metas[0])
42
+ else:
43
+ raise RuntimeError(f"Not found Suite with id '{suite_id}'")
44
+
45
+ def platform_create(self, suite: Suite, **kwargs) -> Tuple[FileSuite, str]:
46
+ """
47
+ Create suite on File Platform.
48
+ Args:
49
+ suite: idmtools suite
50
+ kwargs: keyword arguments used to expand functionality
51
+ Returns:
52
+ File Suite object created
53
+ """
54
+ # Generate Suite folder structure
55
+ self.platform.mk_directory(suite)
56
+ meta = self.platform._metas.dump(suite)
57
+
58
+ # Return File Suite
59
+ file_suite = FileSuite(meta)
60
+ return file_suite, file_suite.id
61
+
62
+ def platform_run_item(self, suite: Suite, **kwargs):
63
+ """
64
+ Called during commissioning of an item. This should perform what is needed to commission job on platform.
65
+ Args:
66
+ suite: Suite
67
+ kwargs: keyword arguments used to expand functionality
68
+ Returns:
69
+ None
70
+ """
71
+ # Refresh with entity ids
72
+ self.platform._metas.dump(suite)
73
+
74
+ def post_run_item(self, suite: Suite, **kwargs) -> None:
75
+ """
76
+ Perform post-processing steps after a suite run.
77
+ Args:
78
+ suite: The suite object that has just finished running
79
+ **kwargs: Additional keyword arguments
80
+
81
+ Returns:
82
+ None
83
+ """
84
+ super().post_run_item(suite, **kwargs)
85
+ # Refresh platform object
86
+ suite._platform_object = self.get(suite.id, **kwargs)
87
+
88
+ def get_parent(self, suite: FileSuite, **kwargs) -> Any:
89
+ """
90
+ Fetches the parent of a suite.
91
+ Args:
92
+ suite: File suite
93
+ kwargs: keyword arguments used to expand functionality
94
+ Returns:
95
+ None
96
+ """
97
+ return None
98
+
99
+ def get_children(self, suite: FileSuite, parent: Suite = None, raw=True, **kwargs) -> List[Any]:
100
+ """
101
+ Fetch File suite's children.
102
+ Args:
103
+ suite: File suite
104
+ raw: True/False
105
+ parent: the parent of the experiments
106
+ kwargs: keyword arguments used to expand functionality
107
+ Returns:
108
+ List of File experiments
109
+ """
110
+ exp_list = []
111
+ exp_meta_list = self.platform._metas.get_children(suite)
112
+ for meta in exp_meta_list:
113
+ file_exp = FileExperiment(meta)
114
+ if raw:
115
+ exp_list.append(file_exp)
116
+ else:
117
+ exp = self.platform._experiments.to_entity(file_exp, parent=parent)
118
+ exp_list.append(exp)
119
+ return exp_list
120
+
121
+ def to_entity(self, file_suite: FileSuite, children: bool = True, **kwargs) -> Suite:
122
+ """
123
+ Convert a FileSuite object to idmtools Suite.
124
+ Args:
125
+ file_suite: simulation to convert
126
+ children: bool True/False
127
+ kwargs: keyword arguments used to expand functionality
128
+ Returns:
129
+ Suite object
130
+ """
131
+ suite = Suite()
132
+ suite.platform = self.platform
133
+ suite.uid = file_suite.uid
134
+ suite.name = file_suite.name
135
+ suite.parent = None
136
+ suite.tags = file_suite.tags
137
+ suite._platform_object = file_suite
138
+ suite.experiments = []
139
+
140
+ if children:
141
+ suite.experiments = self.get_children(file_suite, parent=suite, raw=False)
142
+ return suite
143
+
144
+ def refresh_status(self, suite: Suite, **kwargs):
145
+ """
146
+ Refresh the status of a suite. On comps, this is done by refreshing all experiments.
147
+ Args:
148
+ suite: idmtools suite
149
+ kwargs: keyword arguments used to expand functionality
150
+ Returns:
151
+ None
152
+ """
153
+ for experiment in suite.experiments:
154
+ self.platform.refresh_status(experiment, **kwargs)
155
+
156
+ def create_sim_directory_map(self, suite_id: str) -> Dict:
157
+ """
158
+ Build simulation working directory mapping.
159
+ Args:
160
+ suite_id: suite id
161
+
162
+ Returns:
163
+ Dict of simulation id as key and working dir as value
164
+ """
165
+ # s = Suite.get(suite_id)
166
+ suite = self.platform.get_item(suite_id, ItemType.SUITE, raw=False, force=True)
167
+ exps = suite.experiments
168
+ sims_map = {}
169
+ for exp in exps:
170
+ d = self.platform._experiments.create_sim_directory_map(exp.id)
171
+ sims_map = {**sims_map, **d}
172
+ return sims_map
173
+
174
+ def platform_delete(self, suite_id: str) -> None:
175
+ """
176
+ Delete platform suite.
177
+ Args:
178
+ suite_id: platform suite id
179
+ Returns:
180
+ None
181
+ """
182
+ try:
183
+ suite = self.platform.get_item(suite_id, ItemType.SUITE, force=True, raw=False)
184
+ except RuntimeError:
185
+ return
186
+
187
+ exps = suite.experiments
188
+ for exp in exps:
189
+ try:
190
+ shutil.rmtree(self.platform.get_directory(exp))
191
+ except RuntimeError:
192
+ logger.info("Could not delete the associated experiment...")
193
+ return
194
+ try:
195
+ shutil.rmtree(self.platform.get_directory(suite))
196
+ except RuntimeError:
197
+ logger.info(f"Could not delete suite ({suite_id})...")
198
+ return
199
+
200
+ def platform_cancel(self, suite_id: str, force: bool = False) -> None:
201
+ """
202
+ Cancel platform suite's file job.
203
+ Args:
204
+ suite_id: suite id
205
+ force: bool, True/False
206
+ Returns:
207
+ None
208
+ """
209
+ pass
210
+
211
+ def get_assets(self, suite: Suite, files: List[str], **kwargs) -> Dict[str, bytearray]:
212
+ """
213
+ Fetch the files associated with a suite.
214
+
215
+ Args:
216
+ suite: Suite (idmtools Suite or FileSuite)
217
+ files: List of files to download
218
+ **kwargs:
219
+
220
+ Returns:
221
+ Dict[str, Dict[Dict[str, Dict[str, str]]]]:
222
+ A nested dictionary structured as:
223
+ {
224
+ suite.id{
225
+ experiment.id: {
226
+ simulation.id {
227
+ filename: file content as string,
228
+ ...
229
+ },
230
+ ...
231
+ },
232
+ }
233
+ }
234
+ """
235
+ ret = dict()
236
+ if isinstance(suite, FileSuite):
237
+ file_suite = suite
238
+ else:
239
+ file_suite = suite.get_platform_object()
240
+ children = self.platform._get_children_for_platform_item(file_suite)
241
+ for child in children:
242
+ ret[child.id] = self.platform._experiments.get_assets(child, files, **kwargs)
243
+ return ret