Returns a dictionary from job names to their tasks. For each job, if the task index space is dense, the corresponding value will be a list of network addresses; otherwise it will be a dictionary mapping (sparse) task indices to the corresponding addresses. Returns: A dict
(self)
| 334 | return "ClusterSpec({" + ", ".join(string_items) + "})" |
| 335 | |
| 336 | def as_dict(self): |
| 337 | """Returns a dictionary from job names to their tasks. |
| 338 | |
| 339 | For each job, if the task index space is dense, the corresponding |
| 340 | value will be a list of network addresses; otherwise it will be a |
| 341 | dictionary mapping (sparse) task indices to the corresponding |
| 342 | addresses. |
| 343 | |
| 344 | Returns: |
| 345 | A dictionary mapping job names to lists or dictionaries |
| 346 | describing the tasks in those jobs. |
| 347 | """ |
| 348 | ret = {} |
| 349 | for job in self.jobs: |
| 350 | task_indices = self.task_indices(job) |
| 351 | if len(task_indices) == 0: |
| 352 | ret[job] = {} |
| 353 | continue |
| 354 | if max(task_indices) + 1 == len(task_indices): |
| 355 | # Return a list because the task indices are dense. This |
| 356 | # matches the behavior of `as_dict()` before support for |
| 357 | # sparse jobs was added. |
| 358 | ret[job] = self.job_tasks(job) |
| 359 | else: |
| 360 | ret[job] = {i: self.task_address(job, i) for i in task_indices} |
| 361 | return ret |
| 362 | |
| 363 | def as_cluster_def(self): |
| 364 | """Returns a `tf.train.ClusterDef` protocol buffer based on this cluster.""" |