Younes El Hjouji
03/06/2023, 11:06 AMimport logging
import time
import typing
import uuid
from typing import Tuple
from flytekit import task, workflow, conditional
logger = logging.getLogger()
@task
def create_dataset() -> uuid.uuid4:
print("Creating dataset")
time.sleep(1)
dataset_id = uuid.uuid4()
print(f"Dataset created with id {dataset_id}")
return dataset_id
@task
def sort_dataset(dataset_id: uuid.uuid4) -> None:
print(f"Sorting dataset with id {dataset_id}")
time.sleep(1)
print(f"Dataset is sorted")
@task
def train_model(dataset_id: str) -> uuid.uuid4:
print(f"Training model using dataset with id {dataset_id}")
model_id = uuid.uuid4()
time.sleep(1)
print(f"Trained model with id {model_id}")
return model_id
@workflow
def train_workflow(sort_dataset_flag: bool) -> None:
dataset_id = create_dataset()
conditional("Sorting").if_(sort_dataset_flag.is_true()).then(sort_dataset(dataset_id=dataset_id))
train_model(dataset_id=dataset_id)
def test_workflow():
train_workflow(sort_dataset_flag=True)
Output:
Creating dataset
Dataset created with id bba83be5-8b15-417d-bd48-5cce55d1856f
Sorting dataset with id bba83be5-8b15-417d-bd48-5cce55d1856f
Dataset is sorted
Notice how last task is not executed.
How can I make this work?Samhita Alla
Younes El Hjouji
03/06/2023, 1:24 PMSamhita Alla
else
in conditional. Not sure why you aren't seeing an error, though. cc @Kevin SuYounes El Hjouji
03/06/2023, 1:29 PMSamhita Alla
Younes El Hjouji
03/06/2023, 1:34 PMNiels Bantilan
03/06/2023, 6:15 PMSamhita Alla
Yubo Wang
03/07/2023, 6:21 PMSamhita Alla
Yubo Wang
03/24/2023, 8:17 PM