我正在尝试加载带有一些额外参数的Kedro上下文。我的意图是只使用在extra_params
中传递的配置更新parameters.yml
中的配置(,因此其余配置应保持不变)。然后,我将使用此上下文实例来运行一些节点/管道(注意:我不想修改parameters.yml
文件,只需为此运行更新它即可)。我可以为parameters.yml
中在顶部/根级别定义的每个配置执行此操作,但在嵌套参数的情况下,仅保留传递的配置
复制这个问题,
参数。yml
config_root1: "name"
config_root2: "surname"
config_root3:
config_leaf1: 10
config_leaf2: 20
config_leaf3: 30
额外参数定义为
extra_params = {'config_root1': 'new_name', 'config_root3': {'config_leaf1': 11}}
通过extra_params
加载上下文
from kedro.framework.context import load_context
context = load_context(proj_path, extra_params=extra_params)
上下文中的参数更新为
config_root1: "new_name"
config_root2: "surname"
config_root3:
config_leaf1: 11
注意事项:
config_root1
在根级别,值在{config_root2
在根级别,没有传递任何值,因此它保持不变李>config_leaf1
处于叶级,传递的值因此更新李>config_leaf{2, 3}
处于叶级,因此没有传递值李>这个问题似乎与dictionary和nested dictionary如何合并有关
除了总是在extra_params
中传递所有参数(即使只需要更改很少的参数)之外,还有其他解决方法吗
多谢各位
将
config_root3
键替换为新值的问题,不能轻易忽略我想最好的方法是创建两个单独的配置,它们用Additional configuration environment相互覆盖,但这需要改变您处理load_上下文的方式
此外,您可以手动使用配置加载程序和合并参数,然后以
extra_params
的形式提供合并结果相关问题 更多 >
编程相关推荐