MCPcopy Create free account
hub / github.com/dask/dask / annotate

Function annotate

dask/base.py:90–204  ·  view source on GitHub ↗

Context Manager for setting HighLevelGraph Layer annotations. Annotations are metadata or soft constraints associated with tasks that dask schedulers may choose to respect: They signal intent without enforcing hard constraints. As such, they are primarily designed for use with the d

(**annotations: Any)

Source from the content-addressed store, hash-verified

88
89@contextmanager
90def annotate(**annotations: Any) -> Iterator[None]:
91 """Context Manager for setting HighLevelGraph Layer annotations.
92
93 Annotations are metadata or soft constraints associated with
94 tasks that dask schedulers may choose to respect: They signal intent
95 without enforcing hard constraints. As such, they are
96 primarily designed for use with the distributed scheduler.
97
98 Almost any object can serve as an annotation, but small Python objects
99 are preferred, while large objects such as NumPy arrays are discouraged.
100
101 Callables supplied as an annotation should take a single *key* argument and
102 produce the appropriate annotation. Individual task keys in the annotated collection
103 are supplied to the callable.
104
105 Parameters
106 ----------
107 **annotations : key-value pairs
108
109 Examples
110 --------
111
112 All tasks within array A should have priority 100 and be retried 3 times
113 on failure.
114
115 >>> import dask
116 >>> import dask.array as da
117 >>> with dask.annotate(priority=100, retries=3):
118 ... A = da.ones((10000, 10000))
119
120 Prioritise tasks within Array A on flattened block ID.
121
122 >>> nblocks = (10, 10)
123 >>> with dask.annotate(priority=lambda k: k[1]*nblocks[1] + k[2]):
124 ... A = da.ones((1000, 1000), chunks=(100, 100))
125
126 Annotations may be nested.
127
128 >>> with dask.annotate(priority=1):
129 ... with dask.annotate(retries=3):
130 ... A = da.ones((1000, 1000))
131 ... B = A + 1
132
133 See Also
134 --------
135 get_annotations
136 """
137
138 # Sanity check annotations used in place of
139 # legacy distributed Client.{submit, persist, compute} keywords
140 if "workers" in annotations:
141 if isinstance(annotations["workers"], (list, set, tuple)):
142 annotations["workers"] = list(annotations["workers"])
143 elif isinstance(annotations["workers"], str):
144 annotations["workers"] = [annotations["workers"]]
145 elif callable(annotations["workers"]):
146 pass
147 else:

Callers

nothing calls this directly

Calls 3

setMethod · 0.80
mergeFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected