自动化实验并探索数据。
autodora的Python项目详细描述
autodora
Autodora是一个帮助您的框架:
- 设置实验
- 为多个参数运行它们
- 存储结果
- 探索结果
这个包的目的是使这些步骤尽可能简单和集成。
安装
pip install autodora
实验可以通过观察者跟踪。专门的观察者可能需要可选的包来运行 默认情况下不包括(因为您可能不需要它们)。
电报观察员
pip install autodora[telegram]
为了使用观察者,必须设置环境变量TELEGRAM_BOT_TOKEN
和TELEGRAM_CHAT_ID
。
示例用法
export TELEGRAM_BOT_TOKEN="<your-bot-token>"
export TELEGRAM_CHAT_ID="<your-chat-id>"
pytest
使用Autodora
考虑这样一个字符串中两个数的乘积的计算问题:"0.1 x 0.3"
。
这个计算的繁重工作是由函数multiply
:
def multiply(x, y):
return x * y
设置
我们首先在一个名为product_experiment.py
:
class ProductExperiment(Experiment):
input = Parameter(str, "0.0x0.0", "The input values to be multiplied (e.g. 0.2x10)")
product = Result(float, description="Computed product")
@derived(cache=True)
def derived_x(self):
return float(self.get(self.input).split("x")[0])
@derived(cache=True)
def derived_y(self):
return float(self.get(self.input).split("x")[1])
def run_internal(self):
x, y = self.get("x"), self.get("y")
result = multiply(x, y)
self["product"] = result
ProductExperiment.enable_cli()
描述参数
...
input = Parameter(str, "0.0x0.0", "The input values to be multiplied (e.g. 0.2x10)")
...
...
input = Parameter(str, "0.0x0.0", "The input values to be multiplied (e.g. 0.2x10)")
...
第一步是描述实验的参数,名字取自你给它们赋值的变量, 除此之外,还必须指定参数的类型、可选的默认值和说明。
虽然这是一种设置参数的强大而简单的方法,但您也可以将它们添加到构造函数中:
class ProductExperiment(Experiment):
def __init__(self, group, storage=None, identifier=None):
super().__init__(group, storage=None, identifier=None)
self.parameters.add_parameter("complicated.name", datetime, None, "Description")
描述结果
...
product = Result(float, description="Computed product")
...
...
product = Result(float, description="Computed product")
...
与参数类似,我们指定预期结果。结果类与参数类完全相同,但 name,它只用于指示您正在尝试分配结果。
计算衍生功能
...
@derived(cache=True)
def derived_x(self):
return float(self.get(self.input).split("x")[0])
@derived(cache=True)
def derived_y(self):
return float(self.get(self.input).split("x")[1])
...
...
@derived(cache=True)
def derived_x(self):
return float(self.get(self.input).split("x")[0])
@derived(cache=True)
def derived_y(self):
return float(self.get(self.input).split("x")[1])
...
派生特征是从其他值(或复杂的计算链)计算出来的,可以标记为缓存以避免 一次又一次地计算它们:当实验保存到存储器中时,这些特性将与 实验。
您可以使用派生的decorator构建派生特性,它在内部构建一个Derived object
,并将其保存在
词典。同样,您也可以在构造函数中执行此操作。
如果修饰后的函数名为derived_<name>
,它将被缩短为<name>
。
通过调用experiment["name"]
或experiment[""derived.name"]
来消除歧义,可以访问派生功能。
如果有其他同名的参数或结果。
运行实验
...
def run_internal(self):
x, y = self.get("x"), self.get("y")
result = multiply(x, y)
self["product"] = result
...
...
def run_internal(self):
x, y = self.get("x"), self.get("y")
result = multiply(x, y)
self["product"] = result
...
当调用experiment.run()
时,它在内部调用run_internal
方法,该方法负责运行
实际实验。在这种情况下,它获取(派生的)参数,计算结果并存储结果。
启用命令行界面
...
ProductExperiment.enable_cli()
...
ProductExperiment.enable_cli()
毫不奇怪,enable_cli
类方法允许从命令行运行当前文件。
这将启用几个关键功能:
- 通过命令行使实验可执行(供内部和外部使用)
- 允许您从命令行管理(绘图、列表,…)此类实验
指定轨迹
待办事项