Hi Everyone, we have a MLOps use-case where differ...
# ask-community
h
Hi Everyone, we have a MLOps use-case where different jobs needs to be scheduled with different hardware resources so we have opted for flow of flow option as parent represent a single experiment we want to store/register artifacts using the parent id, is there any way to get parent flow id if you use create_flow_run
k
Hi @Hammad Ahmed, I don’t think this is available immediately because the
create_flow_run
just creates a flow with schedule = now. I think in order to do this, you would need to pass it in as a parameter to the child flow. This experience will be improved in Orion though
h
Thanks Kevin
a
Not sure if I understood correctly, but if you schedule some child flows using create_flow_run, then the parent flow ID can be accessed using:
Copy code
prefect.context.flow_id
If you meant flow run id, then:
Copy code
prefect.context.flow_run_id
and the child flow run ID is the result of the create_flow_run task
k
I think he wants the parent flow id to save the artifacts file names in the sub flow run.
a
oh, in that case perhaps passing it to the child flow using Parameter?
Copy code
import prefect
from prefect import Flow, task
from prefect.tasks.prefect import create_flow_run, wait_for_flow_run

@task
def get_parent_flow_run_id():
    return prefect.context.flow_run_id

with Flow("parametrized_child_flow_run_from_parent_flow") as flow:
    parent_flow_run_id = get_parent_flow_run_id()
    child_flow_run_id = create_flow_run(
        flow_name="parametrized_flow", project_name="community", parameters=dict(parent_flow_run_id=parent_flow_run_id)
    )
    wait_for_flow_run(child_flow_run_id, stream_logs=True, raise_final_state=True)