Load an app from gar. Args: algo: str Algo name inside resource. None will extract name from gar resource if there is only one app in it. gar: bytes or BytesIO or str str represent the path of resource, bytes or the resource of the specifi
(gar=None, algo=None, context=None, **kwargs)
| 490 | |
| 491 | |
| 492 | def load_app(gar=None, algo=None, context=None, **kwargs): |
| 493 | """Load an app from gar. |
| 494 | |
| 495 | Args: |
| 496 | algo: str |
| 497 | Algo name inside resource. None will extract name from gar resource |
| 498 | if there is only one app in it. |
| 499 | gar: bytes or BytesIO or str |
| 500 | str represent the path of resource, bytes or the resource of the |
| 501 | specified path or bytes. |
| 502 | |
| 503 | For java apps, gar can be none to indicate we should find the app in |
| 504 | previous added libs. |
| 505 | |
| 506 | Returns: |
| 507 | Instance of <graphscope.framework.app.AppAssets> |
| 508 | |
| 509 | Raises: |
| 510 | FileNotFoundError: File not exist. |
| 511 | PermissionError: Permission denied of path. |
| 512 | TypeError: File is not a zip file. |
| 513 | |
| 514 | Examples: |
| 515 | >>> sssp = load_app(gar='./resource.gar', algo='sssp') |
| 516 | >>> sssp(src=4) |
| 517 | |
| 518 | which will have following `.gs_conf.yaml` in resource.gar: |
| 519 | app: |
| 520 | - algo: sssp |
| 521 | type: cpp_pie |
| 522 | class_name: grape:SSSP |
| 523 | context_type: vertex_data |
| 524 | src: sssp/sssp.h |
| 525 | compatible_graph: |
| 526 | - gs::ArrowProjectedFragment |
| 527 | """ |
| 528 | if isinstance(gar, (BytesIO, bytes)): |
| 529 | return AppAssets(algo, context, gar, **kwargs) |
| 530 | elif isinstance(gar, str): |
| 531 | with open(gar, "rb") as f: |
| 532 | content = f.read() |
| 533 | if not zipfile.is_zipfile(gar): |
| 534 | raise InvalidArgumentError("{} is not a zip file.".format(gar)) |
| 535 | return AppAssets(algo, context, content, **kwargs) |
| 536 | elif isinstance(algo, str) and ( |
| 537 | algo.startswith("giraph:") or algo.startswith("java_pie:") |
| 538 | ): |
| 539 | if gar is not None: |
| 540 | raise InvalidArgumentError("Running java app expect no gar resource") |
| 541 | return AppAssets(algo, "vertex_data", None, **kwargs) |
| 542 | else: |
| 543 | raise InvalidArgumentError("Wrong type with {}".format(gar)) |