Skip to content
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

Exhaust generator operators when executing directly #3803

Merged
merged 2 commits into from Nov 14, 2023

Conversation

brimoor
Copy link
Contributor

@brimoor brimoor commented Nov 11, 2023

Fixes a bug where foo.execute_operator() would not exhaust generator operators. While fixing this, took the opportunity to remove code duplication, since the same logic was already in-place when executing delegated operations.

import fiftyone as fo
import fiftyone.zoo as foz
import fiftyone.operators as foo

dataset = foz.load_zoo_dataset("quickstart")

ctx = {
    "dataset": dataset,
    "params": {
        "num_workers": 1,
        "delegate": False,
    }
}

# Previously did no computation, now works as expected
foo.execute_operator("@voxel51/utils/compute_metadata", ctx)

@brimoor brimoor added the bug Bug fixes label Nov 11, 2023
@brimoor brimoor requested review from nebulae and a team November 11, 2023 07:35
@brimoor brimoor self-assigned this Nov 11, 2023
@@ -362,30 +367,8 @@ async def _execute_operator(self, doc, log=False, run_link=None):
set_progress=self.set_progress,
)

# if a validation error happened during preparation,
# only an ExecutionResult with an error is returned.
# Raise it so the delegated operation is marked as a failure.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the previous implementation, validation errors would result in set_failed() being called without set_running() ever being called, which seemed weird to me? Now all operations will have a running time logged before possibly failing.


if log:
logger.info("Running operator %s", operator_uri)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a duplicate log

Copy link

codecov bot commented Nov 11, 2023

Codecov Report

Attention: 65 lines in your changes are missing coverage. Please review.

Comparison is base (20153cc) 15.57% compared to head (e0e6505) 15.57%.
Report is 37 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3803   +/-   ##
========================================
  Coverage    15.57%   15.57%           
========================================
  Files          645      645           
  Lines        74120    74120           
  Branches       990      990           
========================================
  Hits         11542    11542           
  Misses       62578    62578           
Flag Coverage Δ
app 15.57% <2.98%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
.../components/src/components/ThemeProvider/index.tsx 90.03% <100.00%> (ø)
app/packages/app/src/Sync.tsx 0.00% <0.00%> (ø)
app/packages/app/src/routing/RouterContext.ts 0.00% <0.00%> (ø)
app/packages/app/src/useEvents/index.ts 0.00% <0.00%> (ø)
app/packages/app/src/useWriters/useWriters.ts 0.00% <0.00%> (ø)
app/packages/state/src/session.ts 74.85% <0.00%> (ø)
app/packages/app/src/useEvents/useSetGroupSlice.ts 0.00% <0.00%> (ø)
app/packages/app/src/useEvents/registerEvent.ts 0.00% <0.00%> (ø)
.../components/src/components/Selection/SearchBox.tsx 29.80% <0.00%> (ø)
.../components/src/components/Selection/Selection.tsx 23.00% <0.00%> (ø)
... and 4 more

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

if not exhaust:
return result

if inspect.isgenerator(result):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of swallowing the messages the operator is sending via the generator. We should probably allow for the callee to pass in a function that processes these. Otherwise there is no path to handling messages when calling execute_operator() directly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although in this could be the behavior of exhaust which would be the default. I'm thinking mostlyu about adding execute_operator(message_reader=MyMessageReader()) or similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds potentially useful to me 👍

This PR just unifies how execute_operator() work with generators with how delegated operator execution works (which already "swallows" generators)

@brimoor brimoor merged commit a655dd9 into develop Nov 14, 2023
9 checks passed
@brimoor brimoor deleted the bugfix/execute-generator branch November 14, 2023 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants