Hi, I am testing launch plan by following the docu...
# ask-the-community
y
Hi, I am testing launch plan by following the documents. However, I got some errors and questions. • It seems that
version
is a mandatory parameter for executing launch plan. However, from the document, I did not see where to enter the version parameter. • Does the
register_launch_plan
have to be called before
remote.execute
? Thanks.
Copy code
(flyte) ➜  workflows git:(main) ✗ cat launch_plan.py
from flytekit import LaunchPlan, current_context, task, workflow
from flytekit.remote import FlyteRemote
from flytekit.configuration import Config


@task
def square(val: int) -> int:
    return val * val


@workflow
def my_wf(val: int) -> int:
    result = square(val=val)
    return result


default_lp = LaunchPlan.get_default_launch_plan(current_context(), my_wf)
square_3 = default_lp(val=3)
print(f"square_3 = {square_3}")

my_lp = LaunchPlan.create("default_4_lp", my_wf, default_inputs={"val": 4})
square_4 = my_lp()
square_5 = my_lp(val=5)
print(f"square_4 = {square_4}")
print(f"square_5 = {square_5}")

my_fixed_lp = LaunchPlan.get_or_create(name="always_2_lp", workflow=my_wf, fixed_inputs={"val": 2})
square_2 = my_fixed_lp()
print(f"square_2= {square_2}")


remote = FlyteRemote(
    config=Config.for_sandbox(),
    default_project="flytesnacks",
    default_domain="development"
)
execution = remote.execute(my_fixed_lp, inputs={})
Copy code
(flyte) ➜  workflows git:(main) ✗ python launch_plan.py
square_3 = 9
square_4 = 16
square_5 = 25
square_2= 4
╭───────────────────────────────────────────── Traceback (most recent call last) ─────────────────────────────────────────────╮
│ /Users/yuanwang/venvs/flyte/lib/python3.11/site-packages/flytekit/remote/remote.py:1440 in execute_local_launch_plan        │
│                                                                                                                             │
│ ❱ 1440 │   │   │   flyte_launchplan: FlyteLaunchPlan = self.fetch_launch_plan(                                              │
│                                                                                                                             │
│ /Users/yuanwang/venvs/flyte/lib/python3.11/site-packages/flytekit/remote/remote.py:388 in fetch_launch_plan                 │
│                                                                                                                             │
│ ❱  388 │   │   launch_plan_id = _get_entity_identifier(                                                                     │
│                                                                                                                             │
│ /Users/yuanwang/venvs/flyte/lib/python3.11/site-packages/flytekit/remote/remote.py:134 in _get_entity_identifier            │
│                                                                                                                             │
│ ❱  134 │   │   version if version is not None else _get_latest_version(list_entities_method, pr                             │
│                                                                                                                             │
│ /Users/yuanwang/venvs/flyte/lib/python3.11/site-packages/flytekit/remote/remote.py:117 in _get_latest_version               │
│                                                                                                                             │
│ ❱  117 │   │   raise user_exceptions.FlyteEntityNotExistException("Named entity {} not found".f                             │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
FlyteEntityNotExistException: Named entity <FlyteLiteral project: "flytesnacks" domain: "development" name: "always_2_lp"> not
found

During handling of the above exception, another exception occurred:

╭───────────────────────────────────────────── Traceback (most recent call last) ─────────────────────────────────────────────╮
│ /Users/yuanwang/projects/flyte/test_case/workflows/launch_plan.py:37 in <module>                                            │
│                                                                                                                             │
│ ❱ 37 execution = remote.execute(my_fixed_lp, inputs={})                                                                     │
│                                                                                                                             │
│ /Users/yuanwang/venvs/flyte/lib/python3.11/site-packages/flytekit/remote/remote.py:1196 in execute                          │
│                                                                                                                             │
│ ❱ 1196 │   │   │   return self.execute_local_launch_plan(                                                                   │
│                                                                                                                             │
│ /Users/yuanwang/venvs/flyte/lib/python3.11/site-packages/flytekit/remote/remote.py:1447 in execute_local_launch_plan        │
│                                                                                                                             │
│ ❱ 1447 │   │   │   flyte_launchplan: FlyteLaunchPlan = self.register_launch_plan(                                           │
│                                                                                                                             │
│ /Users/yuanwang/venvs/flyte/lib/python3.11/site-packages/flytekit/remote/remote.py:931 in register_launch_plan              │
│                                                                                                                             │
│ ❱  931 │   │   ident = self._resolve_identifier(ResourceType.LAUNCH_PLAN, entity.name, version,                             │
│                                                                                                                             │
│ /Users/yuanwang/venvs/flyte/lib/python3.11/site-packages/flytekit/remote/remote.py:546 in _resolve_identifier               │
│                                                                                                                             │
│ ❱  546 │   │   │   raise ValueError(                                                                                        │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
ValueError: To register a new 3, (project, domain, name, version) required, received (flytesnacks, development, always_2_lp,
None).
s
If you haven't registered the launch plan, then yes, you need to register it before you execute. You can send
version
to
register_launch_plan
.
y
Copy code
(flyte) ➜  workflows git:(main) ✗ cat launch_plan.py
from flytekit import LaunchPlan, current_context, task, workflow
from flytekit.remote import FlyteRemote
from flytekit.configuration import Config, SerializationSettings, ImageConfig


@task
def square(val: int) -> int:
    return val * val


@workflow
def my_wf(val: int) -> int:
    result = square(val=val)
    return result


default_lp = LaunchPlan.get_default_launch_plan(current_context(), my_wf)
square_3 = default_lp(val=3)
print(f"square_3 = {square_3}")

my_lp = LaunchPlan.create("default_4_lp", my_wf, default_inputs={"val": 4})
square_4 = my_lp()
square_5 = my_lp(val=5)
print(f"square_4 = {square_4}")
print(f"square_5 = {square_5}")

my_fixed_lp = LaunchPlan.get_or_create(name="always_2_lp", workflow=my_wf, fixed_inputs={"val": 2})
square_2 = my_fixed_lp()
print(f"square_2= {square_2}")


remote = FlyteRemote(
    config=Config.for_sandbox(),
    default_project="flytesnacks",
    default_domain="development"
)

ss = SerializationSettings(
    image_config=ImageConfig.auto_default_image(),
    project="flytesnacks",
    domain="development",
    version="v1")

registered_wf = remote.register_workflow(
    entity=my_wf,
    serialization_settings=ss
)

registered_lp = remote.register_launch_plan(
    entity=my_fixed_lp,
    project="flytesnacks",
    domain="development",
    version="v1")

execution = remote.execute(
    entity=registered_lp,
    inputs={}
)

print(execution)
By using the coding above, I am able to register and execute the launch plan. However, I got this error in the flyte console.
s
Did
register_workflow
work for you, before you registered your launch plan? As per my understanding,
register_workflow
needs a little bit of tweaking to get it to work.
register_script
, on the other hand, has to work.