-
Notifications
You must be signed in to change notification settings - Fork 0
Atomic parser #73
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
base: main
Are you sure you want to change the base?
Atomic parser #73
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## data_models #73 +/- ##
===============================================
+ Coverage 96.52% 97.05% +0.53%
===============================================
Files 4 5 +1
Lines 805 950 +145
===============================================
+ Hits 777 922 +145
Misses 28 28 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
From python functions Signed-off-by: liamhuber <[email protected]>
Which must be consistent with the function analysis and output unpacking instructions Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
But still keep the linter happy Signed-off-by: liamhuber <[email protected]>
`return` and `return None` are handled differently, but actually I'm OK with that right now. Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
f7195ad to
cfa6461
Compare
samwaseda
left a comment
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.
I still would like to have the possibility of setting the output labels by annotations, i.e.:
def f(x) -> typing.Annotation[float, {"label": "output_label"}]:
...Co-authored-by: Sam Dareska <[email protected]>
Co-authored-by: Sam Dareska <[email protected]>
Per @samwaseda's request Signed-off-by: liamhuber <[email protected]>
No magic dictionary keys! Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
When trying to decorate things that aren't function definitions. Signed-off-by: liamhuber <[email protected]>
Yes, good call. This is now supported, and plays nicely with the unpacking modes such that we can leverage annotations on either the tuple itself or its components. E.g., for from typing import Annotated
from flowrep import parser
def compass2cart(direction: str) -> Annotated[
tuple[
Annotated[int, {"label": "x"}],
Annotated[int, {"label": "y"}],
],
{"label": "cartesian"}
]:
match direction.lower():
case "e":
return (1, 0)
case "ne":
return (1, 1)
case "n":
return (0, 1)
case "nw":
return (-1, 1)
case "w":
return (-1, 0)
case "sw":
return (-1, -1)
case "s":
return (0, -1)
case "se":
return (1, -1)
case _:
raise ValueError(f"Needed a compass direction, got {direction}")We can unpack the sub-labels: >>> parser.parse_atomic(compass2cart).model_dump()
{'type': <RecipeElementType.ATOMIC: 'atomic'>,
'inputs': ['direction'],
'outputs': ['x', 'y'],
'fully_qualified_name': '__main__.compass2cart',
'unpack_mode': <UnpackMode.TUPLE: 'tuple'>}Or ask for the tuple as a whole >>> parser.parse_atomic(compass2cart, unpack_mode="none").model_dump()
{'type': <RecipeElementType.ATOMIC: 'atomic'>,
'inputs': ['direction'],
'outputs': ['cartesian'],
'fully_qualified_name': '__main__.compass2cart',
'unpack_mode': <UnpackMode.NONE: 'none'>}The order of priority for output labels is:
(1) is all-or-nothing; give a label for each output port on the node or go home. (2-4) are merged together to get the prettiest output labels available from the code without user intervention. Under the hood, I also added a new data model for the output label metadata -- I really get lost quickly when we have magic dictionaries floating around with special keywords I need to memorize. Critically, the model still parses dictionary and it flexibly ignores extra fields. This means that users don't ever need to import (or even know about) the data model and can keep writing their annotations as dictionaries, and that it will play nicely with |
|
Aha, I suppose actually that I want this to populate @samwaseda, my rough idea is then that |
Signed-off-by: liamhuber <[email protected]>
So we only define a single decorating function Signed-off-by: liamhuber <[email protected]>
|
In the current version of |
Honestly, this had slipped off my radar. Yes, I agree that we will need to log the version in the |
From python functions to recipe data models
With:
E.g.
I.e. a universal atomic node decorator.
I also spent some time today re-reading @samwaseda's
workflowmodule for parsing the python as a workflow. This is obviously the harder part compared to the simple atomic nodes, but I think what's already there can be massaged to return amodel.WorkflowNode. I also think I see a way to allow non-simple function calls even when creating the workflow from pythondef!