Another question again sorry, is it possible to ge...
# questions
m
Another question again sorry, is it possible to get updated parameters with
--params
in code with
KedroSession
? I have something like that
Copy code
def get_session() -> Optional[MyKedroSession]:
    bootstrap_project(Path.cwd())
    try:
        session = MyKedroSession.create()
    except RuntimeError as exc:
        <http://_log.info|_log.info>(f"Session doesn't exist, creating a new one. Raise: {exc}")
        package_name = str(Path(__file__).resolve().parent.name)
        session = MyKedroSession.create(package_name)
    return session


def get_parameters():
    context = get_session().load_context()
    return context.params
But
get_parameters
gives the parameters set in yaml and not the updated with
--params
? thx !
d
you can get this with a hook
m
ok I will check that thanks 🙂
if anyone has an example I'm interested 🫥
f
I am not sure I understand your question, if you want the equivalent of
--params
but with
KedroSession
, you can use
extra_params
:
Copy code
with KedroSession.create(extra_params={"my_param": 1}) as session:
    parameters = session.load_context().params
And here the
my_param
value will be updated
m
No, I want to access the parameters via a
get_parameters
function (for example). The function written above retrieves the parameters displayed in
parameters.yml
. However, when using
--params
the parameters file does not change so I can't get the parameters updated with
--params
.
f
Where do you intend to run this
get_parameters
function? Because, the way I gave you above is the equivalent of passing
--params
, but programaticaly. If you want to use it inside of a pipeline, then don't write this function, and pass the parameter name in the node directly, and let Kedro handle that for you
m
I want to get a parameter to build my list of nodes (pipeline) based on a parameter. I can also indeed add a parameter to some node, and depending on the parameter, run the node or not
f
I think we tried to go this way, but then went the other way. Kedro works best when you build a static pipeline, which is then deterministic. If you want to run several pipelines, based on several parameters, then create a bash script to run those, or make it a 2 step: one pipeline that will create a file with the parameters value, and another pipeline that will be based on the file content (not sure if that is your use case though)
m
My case: I want, depending on a parameter, not to execute a node.
Copy code
def create_pipeline(**kwargs) -> Pipeline:
    pipelines = [
      node(...),
      node(...),
    ]

    if param1 == "value":
      pipelines += [node(...)]

    return pipeline(pipelines)
f
You could make 2 pipelines, one with this node and one without, this would be the most explicit. Or indeed, adding the parameter to the node and return early depending on the parameter value
m
yes I think I will do this method this parameter in node 🙂 thanks for you help