<@U06RKAMK0UC> Can i create a task/workflow withou...
# ask-ai
v
@ancient-wolf-19325 Can i create a task/workflow without version or is there a way to update the particular version of task/workflow ?
j
In Flyte, tasks and workflows are versioned and immutable once registered. You cannot create a task or workflow without specifying a version, nor can you update a specific version after it has been registered. Each task or workflow is defined by a unique combination of project, domain, name, and version, and once registered, it cannot be altered (source). Would you like more details on how versioning works in Flyte or how to manage different versions? Sources: - https://docs.flyte.org/en/latest/user_guide/concepts/main_concepts/workflows.html#structure 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
v
@ancient-wolf-19325, then how do we productionise? i mean lets say i create a workflow and its launch plan and execute it, later i made changes to a task which is used by my workflow, so it means i have to pyflyte register with different version because of this i have to create new launch with new workflow version. How can i avoid do this again and again ?
j
To manage changes in a production environment without constantly creating new launch plans, you can use Flyte's versioning and registration strategies effectively. When you update a task, you indeed need to register it with a new version. However, you can manage launch plans to always point to the latest version of a workflow by using FlyteRemote's
register_launch_plan
method, which allows you to register a launch plan without specifying a workflow version, thus always using the latest version (source). Would you like more details on how to implement this or any other specific aspect? Sources: - https://discuss.flyte.org/t/2719045/let-s-say-we-have-a-workflow-that-should-be-associated-with-/ 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
v
@ancient-wolf-19325 example pls
j
To ensure that a launch plan always uses the latest version of a workflow, you can use FlyteRemote to register the launch plan without specifying a workflow version. Here's an example:
Copy code
from flytekit.remote import FlyteRemote
from flytekit.configuration import Config
from flytekit import LaunchPlan

# Initialize FlyteRemote with your Flyte backend configuration
remote = FlyteRemote(config=Config.for_sandbox())

# Define your workflow and launch plan
workflow_name = "my_project.my_domain.my_workflow"
launch_plan_name = "my_launch_plan"

# Register the launch plan without specifying a workflow version
launch_plan = LaunchPlan.get_or_create(
    workflow_name=workflow_name,
    name=launch_plan_name,
    schedule=None  # Add a schedule if needed
)

# Register the launch plan with FlyteRemote
remote.register_launch_plan(launch_plan)
This approach ensures that the launch plan will always use the latest registered version of the specified workflow. You only need to update the task or workflow version when changes are made, and the launch plan will automatically use the latest version. Would you like more details on any specific part of this process? Sources: - https://github.com/flyteorg/flyte/issues/5073 - https://docs.flyte.org/en/latest/user_guide/concepts/main_concepts/versioning.html#why-do-you-need-versioning 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
v
@ancient-wolf-19325, can we do the same thing via http endpoint ?
j
Yes, you can interact with Flyte using HTTP endpoints by leveraging the Flyte Admin API. Although the documentation does not provide explicit examples for registering launch plans via HTTP, you can use the Flyte Admin API to perform such operations. You would need to construct an HTTP POST request to the appropriate endpoint with the necessary payload to register a launch plan (source). Would you like more details on constructing such an HTTP request? Sources: - https://github.com/flyteorg/flyte/issues/5158 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
v
@ancient-wolf-19325 i know how to use the http endpoints but question is how do i mention launchplan always refer the latest workflow version via http way. is it in *LaunchPlanSpec(*https://docs.flyte.org/projects/flyteidl/en/latest/protos/docs/admin/admin.html#launchplanspec) under workflow_id i mention only project, domain and name but not version ??
@ancient-wolf-19325 i know how to use the http endpoints but question is how do i mention launchplan always refer the latest workflow version via http way. is it in *LaunchPlanSpec(*https://docs.flyte.org/projects/flyteidl/en/latest/protos/docs/admin/admin.html#launchplanspec) under workflow_id i mention only project, domain and name but not version ?? (
j
The
LaunchPlanSpec
requires a
workflow_id
that includes the project, domain, name, and version. There is no direct way to specify a launch plan to always refer to the latest workflow version using the
LaunchPlanSpec
via HTTP. You would need to programmatically determine the latest version of the workflow and then use that version when creating or updating the launch plan (source). Would you like more details on how to programmatically determine the latest version? Sources: - https://docs.flyte.org/en/latest/api/flytectl/gen/flytectl_get_launchplan.html#rtd-footer-container 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
v
@ancient-wolf-19325, so only way is to use register_launch_plan python api ?
j
Yes, using the
register_launch_plan
method in FlyteRemote is a straightforward way to ensure a launch plan always uses the latest workflow version. This method allows you to register a launch plan without specifying a workflow version, thereby defaulting to the latest version (source). Would you like more details on using FlyteRemote for this purpose? Sources: - https://discuss.flyte.org/t/2719045/let-s-say-we-have-a-workflow-that-should-be-associated-with-/ 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
v
@ancient-wolf-19325, Config.for_sandbox() this one take the config from my config.yaml ?
j
Config.for_sandbox()
does not take configuration from your
config.yaml
. It constructs a configuration object specifically for connecting to a Flyte sandbox environment, using default settings like
localhost:30080
as the endpoint (source). Would you like more details on how to customize configurations for different environments? Sources: - https://github.com/flyteorg/flytekit/blob/master/flytekit/configuration/__init__.py 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
v
@ancient-wolf-19325, in this example(which u have shared)
Copy code
from flytekit.remote import FlyteRemote
from flytekit.configuration import Config
from flytekit import LaunchPlan

# Initialize FlyteRemote with your Flyte backend configuration
remote = FlyteRemote(config=Config.for_sandbox())

# Define your workflow and launch plan
workflow_name = "my_project.my_domain.my_workflow"
launch_plan_name = "my_launch_plan"

# Register the launch plan without specifying a workflow version
launch_plan = LaunchPlan.get_or_create(
    workflow_name=workflow_name,
    name=launch_plan_name,
    schedule=None  # Add a schedule if needed
)

# Register the launch plan with FlyteRemote
remote.register_launch_plan(launch_plan)
how do i execute launchplan with latest version ??
j
To execute a launch plan with the latest version using FlyteRemote, you can fetch the launch plan without specifying a version, which will default to the latest version. Here's how you can do it:
Copy code
from flytekit.remote import FlyteRemote
from flytekit.configuration import Config

# Initialize FlyteRemote with your Flyte backend configuration
remote = FlyteRemote(config=Config.for_sandbox())

# Fetch the launch plan without specifying a version
launch_plan = remote.fetch_launch_plan(
    name="my_launch_plan",
    project="my_project",
    domain="my_domain"
)

# Execute the launch plan
execution = remote.execute(
    launch_plan,
    inputs={"input_name": "input_value"},  # Replace with actual inputs
    wait=True
)

print(f"Execution ID: {execution.id.name}")
This approach ensures that the launch plan execution uses the latest registered version of the workflow. Would you like more details on any specific part of this process? Sources: - https://github.com/flyteorg/flyte/blob/master/docs/user_guide/development_lifecycle/running_launch_plans.md 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
v
@ancient-wolf-19325 where can i see the source code of LaunchPlan.get_or_create
j
The source code for
LaunchPlan.get_or_create
can be found in the Flytekit repository on GitHub. Specifically, it is located in the
launch_plan.py
file within the Flytekit core module (source). Would you like more details on how this method works or any specific part of the code? Sources: - https://github.com/flyteorg/flytekit/blob/master/flytekit/core/launch_plan.py 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
v
@ancient-wolf-19325 launch_plan = LaunchPlan.get_or_create( workflow_name=workflow_name, name=launch_plan_name, schedule=None # Add a schedule if needed ) get_or_create doesn't have workflow_name parameter
j
You're correct. The
LaunchPlan.get_or_create
method does not have a
workflow_name
parameter. Instead, it requires a
workflow
object, which is an instance of the workflow you want to create a launch plan for. Here's the correct usage:
Copy code
from flytekit import LaunchPlan
from my_workflows import my_workflow  # Import your workflow

# Create or get a launch plan for the workflow
launch_plan = LaunchPlan.get_or_create(
    workflow=my_workflow,
    name="my_launch_plan",
    schedule=None  # Add a schedule if needed
)
Would you like more details on how to define and use workflows with launch plans? Sources: - https://docs.flyte.org/en/latest/api/flytekit/generated/flytekit.LaunchPlan.html#flytekit.LaunchPlan.get_or_create 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
v
@ancient-wolf-19325 can u update the example with workflowbase?
j
Certainly! Here's how you can use
LaunchPlan.get_or_create
with a
WorkflowBase
object:
Copy code
from flytekit import LaunchPlan
from flytekit.core.workflow import WorkflowBase

# Assume my_workflow is an instance of WorkflowBase
class MyWorkflow(WorkflowBase):
    # Define your workflow logic here
    pass

my_workflow = MyWorkflow()

# Create or get a launch plan for the workflow
launch_plan = LaunchPlan.get_or_create(
    workflow=my_workflow,
    name="my_launch_plan",
    schedule=None  # Add a schedule if needed
)
This example assumes that
MyWorkflow
is a subclass of
WorkflowBase
and contains the logic for your workflow. The
LaunchPlan.get_or_create
method is then used to create or retrieve a launch plan for this workflow. Would you like more details on any specific part of this process? Sources: - https://docs.flyte.org/en/latest/api/flytekit/design/authoring.html#launch-plans - https://github.com/flyteorg/flyte/blob/master/docs/user_guide/flyte_fundamentals/running_and_scheduling_workflows.md 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
v
@ancient-wolf-19325, no i mean construct workflowbase object with required parameters
j
To construct a
WorkflowBase
object, you typically use the
PythonFunctionWorkflow
or
ImperativeWorkflow
classes, which are derived from
WorkflowBase
. Here's an example using `PythonFunctionWorkflow`:
Copy code
from flytekit import task, LaunchPlan
from flytekit.core.workflow import PythonFunctionWorkflow

# Define a simple task
@task
def my_task(x: int) -> int:
    return x + 1

# Define a workflow using PythonFunctionWorkflow
class MyWorkflow(PythonFunctionWorkflow):
    def __init__(self):
        super().__init__(name="my_workflow")

    def execute(self, x: int) -> int:
        return my_task(x=x)

# Instantiate the workflow
my_workflow = MyWorkflow()

# Create or get a launch plan for the workflow
launch_plan = LaunchPlan.get_or_create(
    workflow=my_workflow,
    name="my_launch_plan",
    schedule=None  # Add a schedule if needed
)
In this example,
MyWorkflow
is a subclass of
PythonFunctionWorkflow
, which is a specific implementation of
WorkflowBase
. The
execute
method defines the workflow logic, and
LaunchPlan.get_or_create
is used to create or retrieve a launch plan for this workflow. Would you like more details on any specific part of this process? Sources: - https://docs.flyte.org/en/latest/api/flytekit/design/authoring.html#workflows 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
v
@ancient-wolf-19325 PythonFunctionWorkflow.__init__() got an unexpected keyword argument 'name'
j
The
PythonFunctionWorkflow
class does not accept a
name
parameter in its constructor. Instead, you should define a workflow using the
@workflow
decorator on a Python function. Here's how you can define and use a workflow with a launch plan:
Copy code
from flytekit import task, workflow, LaunchPlan

# Define a simple task
@task
def my_task(x: int) -> int:
    return x + 1

# Define a workflow using the @workflow decorator
@workflow
def my_workflow(x: int) -> int:
    return my_task(x=x)

# Create or get a launch plan for the workflow
launch_plan = LaunchPlan.get_or_create(
    workflow=my_workflow,
    name="my_launch_plan",
    schedule=None  # Add a schedule if needed
)
In this example, the
@workflow
decorator is used to define
my_workflow
, and
LaunchPlan.get_or_create
is used to create or retrieve a launch plan for this workflow. Would you like more details on any specific part of this process? Sources: - https://docs.flyte.org/en/latest/api/flytekit/design/authoring.html#workflows 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
v
@ancient-wolf-19325 FlyteRemote.register_launch_plan() missing 1 required positional argument: 'version'
j
When using
FlyteRemote.register_launch_plan
, you need to provide a
version
argument. This is required to specify the version of the launch plan you are registering. Here's how you can do it:
Copy code
from flytekit.remote import FlyteRemote
from flytekit.configuration import Config
from flytekit import LaunchPlan
from my_workflows import my_workflow  # Import your workflow

# Initialize FlyteRemote with your Flyte backend configuration
remote = FlyteRemote(config=Config.for_sandbox())

# Create or get a launch plan for the workflow
launch_plan = LaunchPlan.get_or_create(
    workflow=my_workflow,
    name="my_launch_plan",
    schedule=None  # Add a schedule if needed
)

# Register the launch plan with FlyteRemote, specifying a version
remote.register_launch_plan(
    launch_plan,
    project="my_project",
    domain="my_domain",
    version="v1"  # Specify the version
)
In this example, the
version
parameter is specified as
"v1"
, but you can use any versioning scheme that suits your needs. Would you like more details on any specific part of this process? Sources: - https://github.com/flyteorg/flyte/issues/5415 - https://discuss.flyte.org/t/2719045/let-s-say-we-have-a-workflow-that-should-be-associated-with-/ 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.