-
Notifications
You must be signed in to change notification settings - Fork 53
Epic: execution improvements #2113
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
Draft
atravitz
wants to merge
9
commits into
main
Choose a base branch
from
epic/execution_improvements
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.
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
371137e
epic: add warehouse (#1864)
atravitz ebec905
feat: filesystem exorcist worker (#1833)
ethanholz f93afcc
updates to filesystem warehouse worker-based execution (#2153)
atravitz 7627172
filesystem warehouse usability improvements (#2155)
atravitz c11378c
add exorcist status check cli command (#2156)
atravitz 15029e7
Merge branch 'main' of github.com:OpenFreeEnergy/openfe into epic/exe…
atravitz 50e3fb1
update cli sections (#2171)
atravitz 5d76747
move Worker to its own module (#2172)
atravitz c4137e6
add results handling for new worker-based execution (#2114)
atravitz 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| **Added:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Changed:** | ||
|
|
||
| * Changed CLI sections from "Network Planning", "Quickrun Exectutor" and "Miscellaneous" to "Planning & Setup", "Execution", "Results Gathering", and "Miscellaneous". | ||
|
|
||
| **Deprecated:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Removed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Fixed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Security:** | ||
|
|
||
| * <news item> | ||
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,23 @@ | ||
| **Added:** | ||
|
|
||
| * Added ``openfe status`` command (`PR #2156 <https://github.com/OpenFreeEnergy/openfe/pull/2156>`_) that shows the status of all tasks in a worker task database. | ||
|
|
||
| **Changed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Deprecated:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Removed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Fixed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Security:** | ||
|
|
||
| * <news item> |
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,23 @@ | ||
| **Added:** | ||
|
|
||
| * Added ``openfe.storage.warehouse``, which includes ``WarehouseBaseClass`` and the example implementation ``FileSystemWarehouse``. | ||
|
|
||
| **Changed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Deprecated:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Removed:** | ||
|
|
||
| * Removed the unused methods ``metadatastore``, ``resultclient``, and ``resultserver`` from ``openfe.storage``. | ||
|
|
||
| **Fixed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Security:** | ||
|
|
||
| * <news item> |
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,8 @@ | ||
| from exorcist.taskdb import TaskStatusDB | ||
|
|
||
| from .exorcist_utils import ( | ||
| build_task_db_from_alchemical_network, | ||
| get_dependency_df, | ||
| get_task_df, | ||
| ) | ||
| from .worker import Worker |
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,144 @@ | ||
| """Utilities for building Exorcist task graphs and task databases. | ||
|
|
||
| This module translates an :class:`gufe.AlchemicalNetwork` into Exorcist task | ||
| structures and can initialize an Exorcist task database from that graph. | ||
| """ | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import exorcist | ||
| import networkx as nx | ||
| import pandas as pd | ||
| from gufe import AlchemicalNetwork, ProtocolDAG | ||
|
|
||
| from ..storage.warehouse import FileSystemWarehouse, WarehouseBaseClass | ||
|
|
||
|
|
||
| def _alchemical_network_to_task_graph( | ||
| alchemical_network: AlchemicalNetwork, | ||
| warehouse: WarehouseBaseClass, | ||
| ) -> nx.DiGraph: | ||
| """Build a global task DAG from `alchemical_network` and store its relevant data | ||
| in `warehouse` the following warehouse stores: | ||
| - 'setup': The AlchemicalNetwork, deduplicated on disk | ||
| - 'tasks': The ProtocolUnits to be executed as tasks | ||
| - 'protocol_dags': The ProtocolDAGs that the ProtocolUnits belong to. | ||
| Used to gather results after execution. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| alchemical_network : AlchemicalNetwork | ||
| Network containing alchemical Transformations to be executed. | ||
| warehouse : WarehouseBaseClass | ||
| Warehouse used to store data used by the execution and simulation engines. | ||
|
|
||
| Returns | ||
| ------- | ||
| nx.DiGraph | ||
| A directed acyclic graph where each node is a task ID with the ProtocolUnit key as a name | ||
| and edges encode protocol-unit dependencies. | ||
|
|
||
| Raises | ||
| ------ | ||
| ValueError | ||
| If the assembled task graph is not acyclic. | ||
| If the input `alchemical_network` is not a valid openfe.AlchemicalNetwork | ||
| """ | ||
|
|
||
| if not isinstance(alchemical_network, AlchemicalNetwork): | ||
| raise ValueError( | ||
| f"alchemical_network must be an AlchemicalNetwork, not {type(alchemical_network)}." | ||
| ) | ||
|
|
||
| warehouse.store_setup_tokenizable(alchemical_network) | ||
|
|
||
| global_task_dag = nx.DiGraph() | ||
| for transformation in alchemical_network.edges: | ||
| dag: ProtocolDAG = transformation.create() # TODO: skip edges that already have units? | ||
| for unit in dag.protocol_units: | ||
| global_task_dag.add_node(str(unit.key)) | ||
| warehouse.store_task(unit) | ||
| for dependent_unit, dependency_unit in dag.graph.edges: | ||
| upstream_id = str(dependency_unit.key) | ||
| downstream_id = str(dependent_unit.key) | ||
| global_task_dag.add_edge(upstream_id, downstream_id) | ||
|
|
||
| # at this point, stored as a shallow dict since all its units are already stored | ||
| warehouse.store_protocol_dag(dag) | ||
|
|
||
| if not nx.is_directed_acyclic_graph(global_task_dag): | ||
| raise ValueError("AlchemicalNetwork produced a task graph that is not a DAG.") | ||
|
|
||
| return global_task_dag | ||
|
|
||
|
|
||
| def build_task_db_from_alchemical_network( | ||
| alchemical_network: AlchemicalNetwork, | ||
| warehouse_dir: Path, # TODO: make optional? | ||
| db_path: Path, # TODO: make optional? | ||
| max_tries: int = 1, | ||
| ) -> tuple[exorcist.TaskStatusDB, FileSystemWarehouse]: | ||
| """Create a task database and FileSystemWarehouse from an alchemical network. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| alchemical_network : AlchemicalNetwork | ||
| ``AlchemicalNetwork`` containing transformations to convert into task records. | ||
| warehouse_dir : pathlib.Path | ||
| Root directory at which to create a FileSystemWarehouse (e.g. ``campaign_name/``). | ||
| db_path : pathlib.Path | ||
| Location to store the SQLite-backed Exorcist database (e.g. ``campaign_name.db``). | ||
| max_tries : int, default=1 | ||
| Maximum number of times a task will attempt to be submitted before it | ||
| is labelled ``TOO_MANY_RETRIES``. | ||
|
|
||
| Returns | ||
| ------- | ||
| exorcist.TaskStatusDB | ||
| Initialized task database populated with graph nodes and dependency | ||
| edges derived from ``alchemical_network``. | ||
| """ | ||
| # require starting clean each time for now - guardrails around modifying existing state can come later | ||
| if Path(db_path).exists(): | ||
| raise FileExistsError(f"Error: {db_path} cannot already exist.") | ||
| warehouse = FileSystemWarehouse(warehouse_dir, exist_ok=False) | ||
| global_task_dag: nx.DiGraph = _alchemical_network_to_task_graph(alchemical_network, warehouse) | ||
| db = exorcist.TaskStatusDB.from_filename(db_path) | ||
| db.add_task_network(global_task_dag, max_tries) | ||
| return db, warehouse | ||
|
|
||
|
|
||
| def get_task_df(task_db: exorcist.TaskStatusDB) -> pd.DataFrame: | ||
| """Create a pandas Dataframe from task_db. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| task_db : exorcist.TaskStatusDB | ||
| A task database. | ||
|
|
||
| Returns | ||
| ------- | ||
| pd.DataFrame | ||
| A dataframe of the tasks and their statuses | ||
| """ | ||
| status_name_encoding = {e.value: e.name for e in exorcist.TaskStatus} | ||
| task_table = pd.read_sql_table("tasks", task_db.engine) | ||
| task_table.replace({"status": status_name_encoding}, inplace=True) | ||
| return task_table | ||
|
|
||
|
|
||
| def get_dependency_df(task_db: exorcist.TaskStatusDB) -> pd.DataFrame: | ||
| """Create a pandas Dataframe from task_db. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| task_db : exorcist.TaskStatusDB | ||
| A task database. | ||
|
|
||
| Returns | ||
| ------- | ||
| pd.DataFrame | ||
| A dataframe of the tasks and their dependencies. | ||
|
|
||
| """ | ||
| return pd.read_sql_table("dependencies", task_db.engine) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBD if this should stay. see #2171 (comment)