-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Small bugfix for async prefect functions (#2462)
## Summary of Changes This provides a small bug fix for the recent patch to how prefect flows are handled. The prior methods only worked for sync flows. ### Requirements - [x] My PR is focused on a [single feature addition or bugfix](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/getting-started/best-practices-for-pull-requests#write-small-prs). - [x] My PR has relevant, comprehensive [unit tests](https://quantum-accelerators.github.io/quacc/dev/contributing.html#unit-tests). - [x] My PR is on a [custom branch](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-and-deleting-branches-within-your-repository) (i.e. is _not_ named `main`). Note: If you are an external contributor, you will see a comment from [@buildbot-princeton](https://github.com/buildbot-princeton). This is solely for the maintainers. --------- Co-authored-by: Andrew S. Rosen <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
85615ef
commit c39345b
Showing
6 changed files
with
201 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,55 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
from prefect import flow, task | ||
|
||
from quacc.wflow_tools.prefect_utils import ( | ||
resolve_futures_to_results, | ||
resolve_futures_to_results_async, | ||
) | ||
|
||
|
||
def test_resolve_futures_to_results(): | ||
@task | ||
def test_task(): | ||
return {"test": 5} | ||
|
||
@flow | ||
def test_flow(): | ||
future = test_task.submit() | ||
nested_future = {"nest": future} | ||
return resolve_futures_to_results(nested_future) | ||
|
||
result = test_flow() | ||
assert result["nest"]["test"] == 5 | ||
|
||
|
||
def test_resolve_futures_to_results_taskfail(): | ||
@task | ||
def test_task(): | ||
raise Exception | ||
return {"test": 5} | ||
|
||
@flow | ||
def test_flow(): | ||
future = test_task.submit() | ||
nested_future = {"nest": future} | ||
return resolve_futures_to_results(nested_future) | ||
|
||
with pytest.raises(BaseException): # noqa: B017, PT011 | ||
test_flow() | ||
|
||
|
||
async def test_resolve_futures_to_results_async(): | ||
@task | ||
async def test_task(): | ||
return {"test": 5} | ||
|
||
@flow | ||
async def test_flow(): | ||
future = test_task.submit() | ||
nested_future = {"nest": future} | ||
return await resolve_futures_to_results_async(nested_future) | ||
|
||
result = await test_flow() | ||
assert result["nest"]["test"] == 5 |
This file contains 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