Comments (1)
Would like to hear from @elijahbenizzy, but I think this dataflow works as intended since Parallelizable/Collect was introduced.
Issue 1: motor
is collected twice
Parallel/Collect work in pair. Since motor
is Parallel, it should be Collected downstream only once. In the simplest case, Parallel iterates and Collect creates a list. When I see a Parallel
when reading the code, I'm asking myself "where is it collected?". It seems to improve readability to have it collected only once.
Issue 2: a node can't be collect and parallel
I don't know why it's a limitation, but it seems to improve readability of the graph. Metaflow imposes the same constraint. Each foreach
step need an explicit join
step to merge artifacts (it's not always trivial). However, Metaflow allows for nested foreach
.
Solution
As you describe @skrawcz , the following code works and is also IMHO more readable.
def motor(motor_list: list[int]) -> Parallelizable[int]:
for _motor in motor_list:
yield _motor
def _is_motor_on(motor: int ) -> bool:
return motor % 2 == 0
def motor_status(motor: int) -> dict:
# logic to check
return {
"motor_id": motor,
"is_on": _is_motor_on(motor)
}
def motor_status_collection(motor_status: Collect[dict]) -> list[dict]:
return list(motor_status)
def on_motor(motor_status_collection: list[dict]) -> Parallelizable[int]:
for motor_dict in motor_status_collection:
if motor_dict["is_on"]:
yield motor_dict["motor_id"]
def status_check_1(on_motor: int) -> float:
# some status check.
return 2.3 * on_motor
def status_check_2(on_motor: int, status_check_1: float) -> str:
return f"some result based on {on_motor} and {status_check_1}"
def status_result(on_motor: int, status_check_1: float, status_check_2: str) -> dict:
return locals()
def on_motor_statuses(status_result: Collect[dict]) -> pd.DataFrame:
return pd.DataFrame(status_result)
Next steps
It seems that the desired user workflow is easy to support with the current features (with the few edits shared). I think we can improve the documentation around Parallel/Collect. Also, we might want to catch these errors at Driver instantiation and make the graph fail. I believe the challenge is that without the parallel / collect stuff, the initial DAG structure is valid. Otherwise, since the submitted DAG is invalid, it's unclear what the behavior of the viz should be. The issue seem to exist upstream of the viz.
from hamilton.
Related Issues (20)
- Add version field to data saver/ loader metadata HOT 2
- Add support for Polars LazyFrame and with_columns
- OSError when using jupyter magic in databricks notebook due to missing source code HOT 1
- Add SODA integration
- Umbrella Issue: Lifecycle Adapter Ideas HOT 2
- Add data source sinks for Polars Lazyframe implementation
- Add sources for missing Polars inputs
- Slack notifier. Have one that can notify a slack channel on error.
- Error cleanly when no output requested using .materialize
- Add xarray example
- `check_output_custom` could pass the information about the feature definition to the output validators HOT 4
- Pandas spss HOT 1
- Streamlining materializer definition HOT 1
- Lifecycle adapter for automatic schema evolution
- Adapter mapping types to pyarrow
- `.visualize_execution()` doesn't show config nodes
- Improve API for `.execute()` all nodes HOT 10
- pandas fwf
- TDQM hook with overrides HOT 2
- Deprecate dependency on `networkx` for `sf-hamilton[visualization]`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hamilton.