神圣的,python - ex.config 在一个文件中和 ex
sacred, python - ex.config in one file and ex
所以我一直在探索神圣的一点点,它看起来很棒。不幸的是,我没有找到像我正在尝试实现的任何多文件用例示例。
所以我有一个名为 configuration.py 的文件,它旨在包含不同的变量,这些变量将(使用神圣的)插入到代码的其余部分(放置在不同的文件中):
from sacred import Experiment
ex = Experiment('Analysis')
@ex.config
def configure_analysis_default():
"""Initializes default """
generic_name = "C:\basic_config.cfg" # configuration filename
message = "This is my generic name: %s!" % generic_name
print(message)
@ex.automain #automain function needs to be at the end of the file. Otherwise everything below it is not defined yet
# when the experiment is run.
def my_main(message):
print(message)
这本身就很管用。 sacred 正在按预期工作。但是,当我尝试引入第二个名为 Analysis.py:
的文件时
import configuration
from sacred import Experiment
ex = Experiment('Analysis')
@ex.capture
def what_is_love(generic_name):
message = " I don't know"
print(message)
print(generic_name)
@ex.automain
def my_main1():
what_is_love()
运行 Analysis.py 产量:
错误:
TypeError: what_is_love is missing value(s) for ['generic_name']
我希望 'import configuration' 语句包含 configuration.py 文件,从而导入其中配置的所有内容,包括 configure_analysis_default() 及其装饰器 @ex.config然后将其注入 what_is_love(generic_name)。
我究竟做错了什么?我该如何解决这个问题?
欣赏!
所以,非常愚蠢,但我会 post 在这里支持有类似问题的人...
我的问题是我创建了一个不同的实验实例。我只需要从配置文件中导入我的实验。
替换这个:
import configuration
from sacred import Experiment
ex = Experiment('Analysis')
有了这个:
import configuration
ex = configuration.ex
看来我们应该为这种事情使用配料。
http://sacred.readthedocs.io/en/latest/ingredients.html
但我还没有完全弄明白。
我 运行 在我的设置中遇到了一个循环导入问题,所以我使用了一个单独的文件 exp.py,它只说明
from sacred import Experiment
ex = Experiment("default")
在我做的包中的每个文件中
from exp import ex
装饰器和配置变量传递似乎有效。我可以使用 --name:
在命令行上更改实验的名称
$> python main.py --name newname
所以我一直在探索神圣的一点点,它看起来很棒。不幸的是,我没有找到像我正在尝试实现的任何多文件用例示例。
所以我有一个名为 configuration.py 的文件,它旨在包含不同的变量,这些变量将(使用神圣的)插入到代码的其余部分(放置在不同的文件中):
from sacred import Experiment
ex = Experiment('Analysis')
@ex.config
def configure_analysis_default():
"""Initializes default """
generic_name = "C:\basic_config.cfg" # configuration filename
message = "This is my generic name: %s!" % generic_name
print(message)
@ex.automain #automain function needs to be at the end of the file. Otherwise everything below it is not defined yet
# when the experiment is run.
def my_main(message):
print(message)
这本身就很管用。 sacred 正在按预期工作。但是,当我尝试引入第二个名为 Analysis.py:
的文件时import configuration
from sacred import Experiment
ex = Experiment('Analysis')
@ex.capture
def what_is_love(generic_name):
message = " I don't know"
print(message)
print(generic_name)
@ex.automain
def my_main1():
what_is_love()
运行 Analysis.py 产量:
错误:
TypeError: what_is_love is missing value(s) for ['generic_name']
我希望 'import configuration' 语句包含 configuration.py 文件,从而导入其中配置的所有内容,包括 configure_analysis_default() 及其装饰器 @ex.config然后将其注入 what_is_love(generic_name)。 我究竟做错了什么?我该如何解决这个问题?
欣赏!
所以,非常愚蠢,但我会 post 在这里支持有类似问题的人...
我的问题是我创建了一个不同的实验实例。我只需要从配置文件中导入我的实验。
替换这个:
import configuration
from sacred import Experiment
ex = Experiment('Analysis')
有了这个:
import configuration
ex = configuration.ex
看来我们应该为这种事情使用配料。
http://sacred.readthedocs.io/en/latest/ingredients.html
但我还没有完全弄明白。
我 运行 在我的设置中遇到了一个循环导入问题,所以我使用了一个单独的文件 exp.py,它只说明
from sacred import Experiment
ex = Experiment("default")
在我做的包中的每个文件中
from exp import ex
装饰器和配置变量传递似乎有效。我可以使用 --name:
在命令行上更改实验的名称$> python main.py --name newname