-
Notifications
You must be signed in to change notification settings - Fork 1
Import backends from RHAPSODY #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mturilli
wants to merge
26
commits into
main
Choose a base branch
from
feat/rhapsody
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
c765fa9
Use rhapsody for backends, maintain compatibility layer
mturilli 5911079
Install rhapsody from GH@dev
mturilli 3dbfc6d
Fix and extend linting
mturilli 44e1c3e
Fix overeager ruff type fixing
mturilli 5efc4aa
Fix pytest-asyncio scope mismatch error
mturilli 229e9f3
RP init is very slow. Share async scope on for RP int tests
mturilli f490381
Crate a backends-specific scope
mturilli f104023
Add an explicit loop_scope. Got to love RP...
mturilli a18065b
Make it DRY!
mturilli b79a3d2
Implement a registry and factory for backends
mturilli d49ace2
Make rhapsody facultative and autoload backends
mturilli 90441ff
Fix CI testing issues.
mturilli 5775577
Fixing unit tests, still issues with the integration ones
mturilli 8bb6ab9
Use patch targets for 3.9/10, worked with 3.11+
mturilli a1655da
Knowing more than I wanted to about 3.9
mturilli eff3819
Address Gemini review
mturilli 5f98a11
Address Gemini review: remove obsolete register_optional_backends()
mturilli 84c640d
Update documentation with new backend factory
mturilli 2f60d8d
Update and test examples
mturilli 1c22351
Export to JSON...
mturilli 785814e
Well, maybe better we use the work we did...
mturilli d43814c
From inheritance to duck-typing validation. We may review this in the…
mturilli d36b073
Using a protocol-based type system to use rhapsody different type system
mturilli a5d2af9
Unit tests now use the type protocol
mturilli 36622b0
Use protocol for tests
mturilli d5c1314
Use an available backend for unit tests
mturilli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| """Backend subsystem for AsyncFlow using Rhapsody backends. | ||
|
|
||
| This module provides execution backends from the Rhapsody package for running | ||
| scientific workflows on various computing infrastructures. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| # Import execution backends from rhapsody | ||
| from rhapsody.backends.execution import ConcurrentExecutionBackend, NoopExecutionBackend | ||
|
|
||
| # Import base class and session from our compatibility layer | ||
| from .base import BaseExecutionBackend, Session | ||
|
|
||
| __all__ = [ | ||
| "BaseExecutionBackend", | ||
| "Session", | ||
| "NoopExecutionBackend", | ||
| "ConcurrentExecutionBackend", | ||
| ] | ||
|
|
||
| # Add optional backends that may be available | ||
| try: | ||
| from rhapsody.backends.execution import DaskExecutionBackend | ||
|
|
||
| __all__.append("DaskExecutionBackend") | ||
| except ImportError: | ||
| pass | ||
|
|
||
| try: | ||
| from rhapsody.backends.execution import RadicalExecutionBackend | ||
|
|
||
| __all__.append("RadicalExecutionBackend") | ||
| except ImportError: | ||
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| """Base execution backend compatibility layer. | ||
| This module provides a compatibility layer for rhapsody backends to work | ||
| with AsyncFlow's type system. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| from abc import ABC, abstractmethod | ||
|
|
||
| # Import the original rhapsody base class | ||
| try: | ||
| from rhapsody.backends import \ | ||
| BaseExecutionBackend as RhapsodyBaseExecutionBackend | ||
| from rhapsody.backends import Session as RhapsodySession | ||
|
|
||
| # Create compatibility aliases | ||
| BaseExecutionBackend = RhapsodyBaseExecutionBackend | ||
| Session = RhapsodySession | ||
|
|
||
| except ImportError: | ||
| # Fallback to local definitions if rhapsody is not available | ||
| class BaseExecutionBackend(ABC): | ||
| """Abstract base class for execution backends that manage task execution and state. | ||
| This class defines the interface for execution backends that handle task submission, | ||
| state management, and dependency linking in a distributed or parallel execution | ||
| environment. | ||
| """ | ||
|
|
||
| @abstractmethod | ||
| async def submit_tasks(self, tasks: list[dict]) -> None: | ||
| """Submit a list of tasks for execution. | ||
| Args: | ||
| tasks: A list of dictionaries containing task definitions and metadata. | ||
| Each task dictionary should contain the necessary information for | ||
| task execution. | ||
| """ | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| async def shutdown(self) -> None: | ||
| """Gracefully shutdown the execution backend. | ||
| This method should clean up resources, terminate running tasks if necessary, | ||
| and prepare the backend for termination. | ||
| """ | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| def state(self) -> str: | ||
| """Get the current state of the execution backend. | ||
| Returns: | ||
| A string representing the current state of the backend (e.g., 'running', | ||
| 'idle', 'shutting_down', 'error'). | ||
| """ | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| def task_state_cb(self, task: dict, state: str) -> None: | ||
| """Callback function invoked when a task's state changes. | ||
| Args: | ||
| task: Dictionary containing task information and metadata. | ||
| state: The new state of the task (e.g., 'pending', 'running', 'completed', | ||
| 'failed'). | ||
| """ | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| def register_callback(self, func) -> None: | ||
| """Register a callback function for task state changes. | ||
| Args: | ||
| func: A callable that will be invoked when task states change. | ||
| The function should accept task and state parameters. | ||
| """ | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| def get_task_states_map(self) -> None: | ||
| """Retrieve a mapping of task IDs to their current states. | ||
| Returns: | ||
| A dictionary mapping task identifiers to their current execution states. | ||
| """ | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| def build_task(self, task: dict) -> None: | ||
| """Build or prepare a task for execution. | ||
| Args: | ||
| task: Dictionary containing task definition, parameters, and metadata | ||
| required for task construction. | ||
| """ | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| def link_implicit_data_deps(self, src_task, dst_task): | ||
| """Link implicit data dependencies between two tasks. | ||
| Creates a dependency relationship where the destination task depends on | ||
| data produced by the source task, with the dependency being inferred | ||
| automatically. | ||
| Args: | ||
| src_task: The source task that produces data. | ||
| dst_task: The destination task that depends on the source task's output. | ||
| """ | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| def link_explicit_data_deps( | ||
| self, src_task=None, dst_task=None, file_name=None, file_path=None | ||
| ): | ||
| """Link explicit data dependencies between tasks or files. | ||
| Creates explicit dependency relationships based on specified file names | ||
| or paths, allowing for more precise control over task execution order. | ||
| Args: | ||
| src_task: The source task that produces the dependency. | ||
| dst_task: The destination task that depends on the source. | ||
| file_name: Name of the file that represents the dependency. | ||
| file_path: Full path to the file that represents the dependency. | ||
| """ | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| async def cancel_task(self, uid: str) -> bool: | ||
| """ | ||
| Cancel a task in the execution backend. | ||
| Args: | ||
| uid: Task identifier | ||
| Raises: | ||
| NotImplementedError: If the backend doesn't support cancellation | ||
| """ | ||
| raise NotImplementedError("Not implemented in the base backend") | ||
|
|
||
|
|
||
| class Session: | ||
| """Manages execution session state and working directory. | ||
| This class maintains session-specific information including the current | ||
| working directory path for task execution. | ||
| """ | ||
|
|
||
| def __init__(self): | ||
| """Initialize a new session with the current working directory. | ||
| Sets the session path to the current working directory at the time | ||
| of initialization. | ||
| """ | ||
| self.path = os.getcwd() | ||
|
|
||
mturilli marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| __all__ = ["BaseExecutionBackend", "Session"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| """Execution backends for AsyncFlow using Rhapsody backends. | ||
|
|
||
| This module re-exports all execution backends from rhapsody.backends.execution. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| # Import execution backends from rhapsody | ||
| from rhapsody.backends.execution import ConcurrentExecutionBackend, NoopExecutionBackend | ||
|
|
||
| # Import base class for compatibility | ||
| from ..base import BaseExecutionBackend | ||
|
|
||
| __all__ = ["BaseExecutionBackend", "NoopExecutionBackend", "ConcurrentExecutionBackend"] | ||
|
|
||
| # Add optional backends | ||
| try: | ||
| from rhapsody.backends.execution import DaskExecutionBackend | ||
|
|
||
| __all__.append("DaskExecutionBackend") | ||
| except ImportError: | ||
| pass | ||
|
|
||
| try: | ||
| from rhapsody.backends.execution import RadicalExecutionBackend | ||
|
|
||
| __all__.append("RadicalExecutionBackend") | ||
| except ImportError: | ||
| pass |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.