Code Monkey home page Code Monkey logo

Comments (1)

zilto avatar zilto commented on May 28, 2024

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)

image

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.