Skip to content

Commit

Permalink
Clean up Dask documentation (#1485)
Browse files Browse the repository at this point in the history
## Summary of Changes

Dask documentation cleanup as a result of the new `@subflow` method.

## Requirements

### Checklist

- [x] I have read the [Contributing
Guide](https://quantum-accelerators.github.io/quacc/dev/contributing.html).
Don't lie! 😉
- [x] My PR is on a custom branch and is _not_ named `main`.
- [x] I have used `black`, `isort`, and `ruff` as described in the
[style
guide](https://quantum-accelerators.github.io/quacc/dev/contributing.html#style).
- [x] I have added relevant, comprehensive [unit
tests](https://quantum-accelerators.github.io/quacc/dev/contributing.html#unit-tests).

### Notes

- Your PR will likely not be merged without proper and thorough tests.
- 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.
- When your code is ready for review, ping one of the [active
maintainers](https://quantum-accelerators.github.io/quacc/about/contributors.html#active-maintainers).
  • Loading branch information
Andrew-S-Rosen authored Jan 6, 2024
1 parent 9530aa8 commit 9543f1d
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 19 deletions.
8 changes: 2 additions & 6 deletions docs/user/wflow_engine/wflow_engines1.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,13 @@ graph LR
atoms = bulk("Cu")

# Define the workflow
delayed = bulk_to_slabs_flow(atoms) # (1)!
delayed = bulk_to_slabs_flow(atoms)

# Print the results
result = client.gather(client.compute(delayed)) # (2)!
result = client.compute(delayed).result()
print(result)
```

1. This has type `List[Delayed]`.

2. Running `#!Python client.compute(List[Delayed])` yields a `#!Python List[Future]` object. Calling `#!Python client.gather(List[Future])` will resolve the outputs from multiple `Future` objects. As an alternative, you could also do `#!Python result = dask.compute(delayed)[0]`, where the `[0]` indexing is needed because `#!Python dask.compute` always returns a tuple even when there is only one result.

=== "Redun"

```python
Expand Down
2 changes: 1 addition & 1 deletion docs/user/wflow_engine/wflow_engines2.md
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ graph LR
delayed = workflow(atoms)

# Fetch the results
result = client.gather(client.compute(delayed))
result = client.compute(delayed).result()
print(result)
```

Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ exclude_also = [
"if TYPE_CHECKING:",
"if __name__ == .__main__.:",
"except ImportError:",
"with worker_client() as client:",
]

[tool.ruff]
Expand Down
2 changes: 1 addition & 1 deletion tests/dask/test_dask_recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_dask_functools(tmp_path, monkeypatch):
delayed = bulk_to_slabs_flow(
atoms, job_params={"relax_job": {"opt_params": {"fmax": 0.1}}}, run_static=False
)
result = client.gather(client.compute(delayed))
result = client.compute(delayed).result()
assert len(result) == 4
assert "atoms" in result[-1]
assert result[-1]["fmax"] == 0.1
Expand Down
12 changes: 6 additions & 6 deletions tests/dask/test_dask_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def dynamic_workflow2(a, b, c):
assert client.compute(add(1, 2)).result() == 3
assert client.compute(mult(1, 2)).result() == 2
assert client.compute(workflow(1, 2, 3)).result() == 9
assert client.gather(client.compute(dynamic_workflow(1, 2, 3))) == [6, 6, 6]
assert client.gather(client.compute(dynamic_workflow2(1, 2, 3))) == [6, 6, 6]
assert client.compute(dynamic_workflow(1, 2, 3)).result() == [6, 6, 6]
assert client.compute(dynamic_workflow2(1, 2, 3)).result() == [6, 6, 6]


def test_dask_decorators_args(tmp_path, monkeypatch):
Expand Down Expand Up @@ -101,8 +101,8 @@ def dynamic_workflow2(a, b, c):
assert client.compute(add(1, 2)).result() == 3
assert client.compute(mult(1, 2)).result() == 2
assert client.compute(workflow(1, 2, 3)).result() == 9
assert client.gather(client.compute(dynamic_workflow(1, 2, 3))) == [6, 6, 6]
assert client.gather(client.compute(dynamic_workflow2(1, 2, 3))) == [6, 6, 6]
assert client.compute(dynamic_workflow(1, 2, 3)).result() == [6, 6, 6]
assert client.compute(dynamic_workflow2(1, 2, 3)).result() == [6, 6, 6]


def test_strip_decorators():
Expand Down Expand Up @@ -160,5 +160,5 @@ def test_dynamic_workflow(a, b, c=3):
add_ = update_parameters(add, {"b": 3}, decorator="job")
dynamic_workflow_ = update_parameters(dynamic_workflow, {"c": 4}, decorator="flow")
assert client.compute(add_(1)).result() == 4
assert client.gather(client.compute(dynamic_workflow_(1, 2))) == [7, 7, 7]
assert client.gather(client.compute(test_dynamic_workflow(1, 2))) == [7, 7, 7]
assert client.compute(dynamic_workflow_(1, 2)).result() == [7, 7, 7]
assert client.compute(test_dynamic_workflow(1, 2)).result() == [7, 7, 7]
6 changes: 2 additions & 4 deletions tests/dask/test_dask_tutorials.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def test_tutorial1a(tmp_path, monkeypatch):

# Print result
assert "atoms" in client.compute(delayed).result() # (2)!
assert "atoms" in delayed.compute()
assert "atoms" in dask.compute(delayed)[0]


Expand All @@ -50,8 +49,7 @@ def test_tutorial1b(tmp_path, monkeypatch):
delayed = bulk_to_slabs_flow(atoms) # (1)!

# Print the results
assert "atoms" in client.gather(client.compute(delayed))[0]
assert "atoms" in dask.compute(delayed)[0][0]
assert "atoms" in client.compute(delayed).result()[0]


def test_tutorial2a(tmp_path, monkeypatch):
Expand Down Expand Up @@ -118,7 +116,7 @@ def workflow(atoms):
delayed = workflow(atoms)

# Fetch the results
result = client.gather(client.compute(delayed))
result = client.compute(delayed).result()

# Print the results
assert len(result) == 4
Expand Down

0 comments on commit 9543f1d

Please sign in to comment.