-
Notifications
You must be signed in to change notification settings - Fork 76
feat: Add App abstraction class to standardize API and add hooks #418
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
Merged
+106
−18
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8c56ab6
First iteration of App abstract class
Tw1ZZLER 70eb669
Add app to init list
Tw1ZZLER a2379bb
Refactor RequestApp to follow App and remove redudant methods
Tw1ZZLER 3dbdd07
Change node's set_app to use new abstract class
Tw1ZZLER 7e2bb9c
Update tutorial for new abstract App
Tw1ZZLER e30a85e
Apply suggestions from code review
Tw1ZZLER cbd45c5
Remove get_throughput from app, should use metrics instead
Tw1ZZLER 838327a
Potential fix for pull request finding 'Unused import'
Tw1ZZLER 54bc8d5
Remove quotes from types
Tw1ZZLER 8f1c97f
Add pass to abstract methods
Tw1ZZLER 571e148
Added teleport_app and request_app
Tw1ZZLER 0e8016b
Added warning that get_throughput is deprecated
Tw1ZZLER 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| __all__ = ['random_request'] | ||
| __all__ = ["app", "random_request", "teleport_app", "request_app"] | ||
|
|
||
|
|
||
| def __dir__(): | ||
| return sorted(__all__) |
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,81 @@ | ||
| """Abstract base class for SeQUeNCe applications. | ||
|
|
||
| This module defines the `App` interface that all node-attached applications | ||
| must implement. The three abstract callback methods, `get_memory`, `get_reservation_result`, | ||
| and `get_other_reservation` are correspond to the calls that `QuantumRouter` already | ||
| makes on whatever application is attached via `set_app`. | ||
|
|
||
| Subclasses that track throughput (e.g. `RequestApp`) should override it with a | ||
| meaningful implementation. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from abc import ABC, abstractmethod | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| if TYPE_CHECKING: | ||
| from ..network_management.reservation import Reservation | ||
| from ..resource_management.memory_manager import MemoryInfo | ||
| from ..topology.node import QuantumRouter | ||
|
|
||
|
|
||
| class App(ABC): | ||
| """Abstract base application attached to a quantum network node. | ||
|
|
||
| Every concrete application must subclass `App` and implement the three | ||
| abstract callback methods that `QuantumRouter` relies on. | ||
|
|
||
| The constructor automatically registers the application on the node via | ||
| `node.set_app(self)`, so subclasses should always call | ||
| `super().__init__(node)`! | ||
|
|
||
| Attributes: | ||
| node (QuantumRouter): The node this application is attached to. | ||
| name (str): Human-readable name for the application instance. | ||
| """ | ||
|
|
||
| def __init__(self, node: QuantumRouter): | ||
| self.node: QuantumRouter = node | ||
| self.node.set_app(self) | ||
| self.name: str = f"{self.node.name}.{self.__class__.__name__}" | ||
|
|
||
| @abstractmethod | ||
| def get_memory(self, info: MemoryInfo) -> None: | ||
| """Called when an entangled memory becomes available. | ||
|
|
||
| Args: | ||
| info (MemoryInfo): Information about the available memory. | ||
| """ | ||
|
Tw1ZZLER marked this conversation as resolved.
|
||
| pass | ||
|
|
||
| @abstractmethod | ||
| def get_reservation_result(self, reservation: Reservation, result: bool) -> None: | ||
| """Called when a reservation result is received from the network manager. | ||
|
|
||
| Args: | ||
| reservation (Reservation): The reservation that completed. | ||
| result (bool): Whether the reservation was approved. | ||
| """ | ||
|
Tw1ZZLER marked this conversation as resolved.
|
||
| pass | ||
|
|
||
| @abstractmethod | ||
| def get_other_reservation(self, reservation: Reservation) -> None: | ||
| """Called when a reservation initiated by another node is approved and | ||
| uses this node as the responder. | ||
|
|
||
| Args: | ||
| reservation (Reservation): The approved reservation. | ||
| """ | ||
| pass | ||
|
|
||
| def set_name(self, name: str) -> None: | ||
| """Override the default application name. | ||
|
|
||
| Args: | ||
| name (str): New name for the application. | ||
| """ | ||
| self.name = name | ||
|
|
||
| def __str__(self) -> str: | ||
| return self.name | ||
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
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.