-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds setstate getstate to driver and fixes 1093 (#1100)
* Adds setstate getstate to driver and fixes 1093 This fixes #1093. Modules were not picklable. So this fixes that by serializing their fully qualified names, and then when the driver object is deserialized, they are reinstantiated as module objects.
- Loading branch information
Showing
4 changed files
with
91 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from typing import Any | ||
|
||
from hamilton.htypes import Collect, Parallelizable | ||
|
||
|
||
def mapper( | ||
drivers: list, | ||
inputs: list, | ||
final_vars: list = None, | ||
) -> Parallelizable[dict]: | ||
if final_vars is None: | ||
final_vars = [] | ||
for dr, input_ in zip(drivers, inputs): | ||
yield { | ||
"dr": dr, | ||
"final_vars": final_vars or dr.list_available_variables(), | ||
"input": input_, | ||
} | ||
|
||
|
||
def inside(mapper: dict) -> dict: | ||
_dr = mapper["dr"] | ||
_inputs = mapper["input"] | ||
_final_var = mapper["final_vars"] | ||
return _dr.execute(final_vars=_final_var, inputs=_inputs) | ||
|
||
|
||
def passthrough(inside: dict) -> dict: | ||
return inside | ||
|
||
|
||
def reducer(passthrough: Collect[dict]) -> Any: | ||
return passthrough |
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,2 @@ | ||
def double(a: int) -> int: | ||
return a * 2 |
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