ancient-wolf-19325
06/28/2024, 12:49 PMv = 3.14
square = v*v
print(square)
from flytekitplugins.papermill import record_outputs
record_outputs(square=square)
And my task:
hello_nb = NotebookTask(
name="hello_world",
notebook_path=str(pathlib.Path(__file__).parent.absolute() / "hello_world.ipynb"),
render_deck=True,
inputs=kwtypes(v=float),
outputs=kwtypes(square=float),
)
And the workflow:
@workflow
def hello_world_nb_workflow(
v: float = 3.1415926535,
) -> float:
out = hello_nb(v=v)
sq_root = square_root_task(f=out.square)
However, I am getting the error:
File "/usr/src/app/.venv/lib/python3.8/site-packages/flytekit/exceptions/scopes.py", line 183, in system_entry_point
return wrapped(*args, **kwargs)
File "/usr/src/app/.venv/lib/python3.8/site-packages/flytekit/core/base_task.py", line 707, in dispatch_execute
native_outputs = self.execute(**native_inputs)
File "/usr/src/app/.venv/lib/python3.8/site-packages/flytekitplugins/papermill/task.py", line 291, in execute
raise TypeError(f"Expected output {k} of type {type_v} not found in the notebook outputs")
Message:
TypeError: Expected output square of type <class 'float'> not found in the notebook outputs
SYSTEM ERROR! Contact platform administrators.
Even though I am able to see square in the node outputs.
Could you help me with that if the error is familiar or you can catch up why that is? Thank you!
# Answer
The error indicates that the expected output square of type float is not found in the notebook outputs. This can occur if the notebook's output cell is not correctly tagged or if the record_outputs function is not properly capturing the output.
Ensure that:
1. The cell containing record_outputs is tagged with outputs.
2. The notebook path is correctly specified and accessible.
Here is a checklist to troubleshoot the issue:
1. Tagging the Output Cell:
Ensure that the cell with record_outputs is tagged with outputs. This is crucial for Flyte to recognize the output. You can tag a cell in Jupyter by clicking on the cell, selecting "View" -> "Cell Toolbar" -> "Tags", and then adding the outputs tag.
2. Notebook Path:
Verify that the notebook path in NotebookTask is correct and accessible. The path should be absolute and correctly point to the notebook file.
3. Correct Usage of record_outputs:
Ensure that record_outputs is called correctly in the notebook.
Here is a refined version of your code:
Notebook Content (hello_world.ipynb):
# Parameters
v = 3.14
# Computation
square = v * v
print(square)
# Record Outputs
from flytekitplugins.papermill import record_outputs
record_outputs(square=square)ancient-wolf-19325
06/28/2024, 12:49 PM>>Task Definition:
import os
import pathlib
from flytekit import kwtypes, task, workflow
from flytekitplugins.papermill import NotebookTask
hello_nb = NotebookTask(
name="hello_world",
notebook_path=str(pathlib.Path(__file__).parent.absolute() / "hello_world.ipynb"),
render_deck=True,
inputs=kwtypes(v=float),
outputs=kwtypes(square=float),
)
Workflow Definition:
@task
def square_root_task(f: float) -> float:
import math
return math.sqrt(f)
@workflow
def hello_world_nb_workflow(v: float = 3.1415926535) -> float:
out = hello_nb(v=v)
return square_root_task(f=out.square)
Execution:
if __name__ == "__main__":
print(hello_world_nb_workflow(v=3.14))
Make sure to run the workflow using the correct command and ensure all dependencies are installed.
If the issue persists, please verify that the notebook is correctly packaged and uploaded when running the workflow. You might need to inspect the uploaded tarball to ensure the notebook is included.
Would you like more detailed steps or further assistance?
Sources:
- Flyte Jupyter Notebook Tasks Example
- Flyte NotebookTask API
Slack Link
https://flyte-org.slack.com/archives/CP2HDHKE1/p1719578960.380769 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.