Hi, can someone paste a minimal, self-contained ex...
# flytekit
m
Hi, can someone paste a minimal, self-contained example of using FlyteRemote.register_task with a locally defined function? The docs are missing this.
t
can you talk about the structure of your code?
the reason this is challenging (for tasks specifically) is that in the fast register case, the body of the task has to be copied into the container.
(the reason this is not relevant for workflows is because workflow structure is compiled and then submitted to admin, and thereafter, the body of the workflow function is irrelevant)
m
Yes. sure. In the simplest case, I would like the following code to run:
Copy code
import pandas as pd
from sklearn.datasets import load_wine

from flytekit import task, workflow
from flytekit.configuration import ImageConfig, Config, SerializationSettings
from flytekit.types.pickle import FlytePickle
from flytekit.remote import FlyteRemote


# 🧱 @task decorators define the building blocks of your pipeline
@task
def get_data_new(x:int) -> pd.DataFrame:
    """Get the wine dataset."""
    return load_wine(as_frame=True).frame



if __name__ == "__main__":
    # FlyteRemote object is the main entrypoint to API
    remote = FlyteRemote(
        config=Config.auto(),
        default_project="flytesnacks",
        default_domain="development",
    )

    remote.register_task(
        get_data_new, 
        serialization_settings=SerializationSettings(image_config=ImageConfig.auto(img_name="<http://ghcr.io/flyteorg/flytekit:py3.9-1.2.3|ghcr.io/flyteorg/flytekit:py3.9-1.2.3>")),
        version="v2")

    task = remote.fetch_task(name="get_data_new", version="v2")

    remote.execute(
        task,
        inputs={'x':0}
        )