-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Graceful errors #926
Graceful errors #926
Conversation
POC, this works! from hamilton import driver
from hamilton.lifecycle import default
class DoNotProceed(Exception):
pass
def working_res_1() -> int:
return 1
def working_res_2() -> int:
return 2
def do_not_proceed_1(working_res_1: int, working_res_2: int) -> int:
raise DoNotProceed()
def proceed_1(working_res_1: int, working_res_2: int) -> int:
return working_res_1 + working_res_2
def proceed_2(working_res_1: int, working_res_2: int) -> int:
return working_res_1 * working_res_2
def short_circuited_1(working_res_1: int, working_res_2: int, do_not_proceed_1: int) -> int:
return 1 # this should not be reached
def proceed_3(working_res_1: int, working_res_2: int) -> int:
return working_res_1 - working_res_2
def do_not_proceed_2(proceed_1: int, proceed_2: int, proceed_3: int) -> int:
raise DoNotProceed()
def short_circuited_2(proceed_1: int, proceed_2: int, proceed_3: int, do_not_proceed_2: int) -> int:
return 1 # this should not be reached
def short_circuited_3(short_circuited_1: int) -> int:
return 1 # this should not be reached
def proceed_4(proceed_1: int, proceed_2: int, proceed_3: int) -> int:
return proceed_1 + proceed_2 + proceed_3
if __name__ == "__main__":
import __main__
dr = (
driver.Builder()
.with_modules(__main__)
.with_adapters(
default.GracefulErrorAdapter(error_to_catch=DoNotProceed, sentinel_value=None)
)
.build()
)
dr.display_all_functions()
vars = dr.list_available_variables()
res = dr.execute(vars)
print(res) # has nones instead of values we don't want to compute or we want to short-circuit
|
This is a vote to allow multiple adapters to implement |
07c025c
to
e7bda85
Compare
e7bda85
to
316381d
Compare
|
||
Be careful using ``None`` as the default -- feel free to replace it with a sentinel value | ||
of your choice (this could negatively impact your graph's execution if you actually *do* intend | ||
to use ``None`` return values). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you provide python example of usage, e.g. passing in the Exception type to catch, and what it would do.
GracefulErrorAdapter(ValueError) vs GracefulErrorAdapter(Exception) etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just add more to the doc so a user can cut and paste an example.
This is still a bit of a WIP, but the API will stay backwards compatible so I'm OK putting it in the stdlib. This efectively cascades through null (customizable sentinel value) results, not running a node if any of its dependencies are null.
316381d
to
50b62a7
Compare
Response to slack question: https://hamilton-opensource.slack.com/archives/C03M33QB4M8/p1716954444075279