Core
KoshExecutionGraph
Bases: object
Source code in kosh/exec_graphs/core.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 |
|
__getitem__(key)
Very bare bone get item function It is highly recommended to re-implement this. Calls traverse then getitem on the result of traverse
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
object (usually int, slice | str)
|
key to access |
required |
Source code in kosh/exec_graphs/core.py
describe_entries()
Return a generator of describe_feature for each entry feature.
It will crawl the graph backward when
it encounters transformers or operators.
If a loader did not implement describe_feature
an empty dictionary
will be used instead.
Returns:
Type | Description |
---|---|
generator of info dictionaries |
Source code in kosh/exec_graphs/core.py
execution_graph(seed=None, verbose=False, png_template='LOADER_GRAPH_{}')
makes a new graph with unique seed Helps networkx differentiate between identical loaders/transformers/operators
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seed |
int
|
seed to use for new graph |
None
|
verbose |
bool
|
verbose generation, also generates a png with the grap representation Mostly used for debug purposes |
False
|
png_template |
str
|
template to use to generate graph png in verbose mode "_IN"/"_OUT" will be appended and seed will be fed |
'LOADER_GRAPH_{}'
|
Source code in kosh/exec_graphs/core.py
get_input_datasets()
Return a generator of the originating datasets for the inputs. It will crawl the graph backward when it encounters transformers or operators.
Returns:
Type | Description |
---|---|
KoshDataset generator
|
generator of Kosh datasets |
Source code in kosh/exec_graphs/core.py
get_input_loaders()
Return a generator of the originating loaders for the inputs. It will crawl the graph backward when it encounters transformers or operators.
Returns:
Type | Description |
---|---|
KoshLoader generator
|
generator of Kosh datasets |
Source code in kosh/exec_graphs/core.py
load(cache_file)
Loads content from cache :rtpye: object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cache_file |
str
|
name of cache fileA will be joined with self.cache_dir |
required |
Returns:
Type | Description |
---|---|
unpickled data |
Source code in kosh/exec_graphs/core.py
save(cache_file, *content)
Pickles some data to a cache file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cache_file |
str
|
name of cache file, will be joined with self.cache_dir |
required |
content |
object
|
content to save to cache |
()
|
Source code in kosh/exec_graphs/core.py
show_cache_file(input, format)
Given a set of input and format returns the unique signature used for cache file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input |
object
|
set of input passed from loader or previous transformer |
required |
format |
str
|
desired output format |
required |
Returns:
Type | Description |
---|---|
str
|
The unique signature |
Source code in kosh/exec_graphs/core.py
traverse(format=None, *args, **kargs)
Traverse the execution graph and returns data
Parameters:
Name | Type | Description | Default |
---|---|---|---|
format |
str
|
desired output format |
None
|
Source code in kosh/exec_graphs/core.py
update_signature(*args, **kargs)
Updated the signature based to a set of args and kargs
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
list
|
as many arguments as you want |
()
|
**kargs |
dict
|
key=value style argmunets |
{}
|
Returns:
Type | Description |
---|---|
str
|
updated signature |
Source code in kosh/exec_graphs/core.py
apply_weight(G, output_format=None, weight_same=2.0, weight_output=3.0)
Given a graph, lower the weight to edges that end in required format
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_format |
str
|
Desired output format, used to lower weight if edge ends in that format |
None
|
weight_same |
float
|
Weight to use if both end of an edge are the same format |
2.0
|
weight_output |
float
|
Weight to use if end of an edge is the desired output format |
3.0
|
Returns:
Type | Description |
---|---|
None
|
Notne but the input graph is modified |
Source code in kosh/exec_graphs/core.py
find_network_ends(G, start=True, end=True)
Given an Ordered networkx.DiGraph finds start or end nodes or both.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
G |
networkx.DiGraph (OrderedDiGraph on older version of networkx)
|
Network of interest |
required |
start |
bool
|
Are we searching for start nodes? |
True
|
end |
bool
|
Are we searching for end nodes? |
True
|
Returns:
Type | Description |
---|---|
(tuple of) list
|
start and end node lists or just start/end node list |
Raises:
Type | Description |
---|---|
ValueError
|
if neither start or end is True |
Source code in kosh/exec_graphs/core.py
get_seed(G, node, end_seed=None)
Assigns a new random seed to a node unless it is an end_seed, in which case we assign the Graph's seed
Parameters:
Name | Type | Description | Default |
---|---|---|---|
G |
networkx.Graph
|
Parent graph |
required |
node |
a graph node
|
Node of interest (is it and end node?) |
required |
end_seed |
The seed to assign if the node is an end seed. If None is passed then used parent Graph's seed |
None
|
Returns:
Type | Description |
---|---|
int
|
new seed for the node |
Source code in kosh/exec_graphs/core.py
populate(G, node, output_formats, next_nodes)
Populates networkx
Parameters:
Name | Type | Description | Default |
---|---|---|---|
G |
nx.Graph
|
networkx Graph to populate |
required |
node |
object with types attributes as a dictionary
|
transformer to be chained, needs to have dict "types" attribute |
required |
output_formats |
list
|
output_format of the first node |
required |
next_nodes |
object with 'types' attribute as a dictionary
|
next set of transformers to add to graph |
required |
Returns:
Type | Description |
---|---|
Nothing but the graph passed is updated |
Source code in kosh/exec_graphs/core.py
possible_ends(graph, start_nodes, end_nodes)
Finds all network ends that can be reached by all start nodes
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph |
networkx.DiGraph (OrderedDiGraph on older version of networkx)
|
The full graph |
required |
start_nodes |
list of nodes
|
Node to start paths from |
required |
end_nodes |
list of nodes
|
Node to end paths from |
required |
Returns:
Type | Description |
---|---|
list
|
list of possible end nodes |