可复制库
reproducible的Python项目详细描述
可复制的python库
跟踪结果。
曾经为一篇论文出过一个结果,但几个月后才意识到 不能复制吗?你不知道代码的哪个版本 当时使用了哪些参数值?
由Cognitive Neuro-Robotics Unit在Okinawa Institute of Science and Technology (OIST)开发的可复制库旨在提供一种简单的收集和保存方法 有关计算结果的上下文的重要信息。这个 包括有关操作系统、python版本、时间、git提交、 命令行参数、输入和输出文件的散列,以及任何用户提供的 数据。
其他Python库也存在,比如 Recipy和 Sumatra。他们很好。一定要试试。 他们每个人都有自己的设计理念,这被证明是很难做到的 与认知神经机器人的一些工作流程的接口 oist的单元实验室。与reproducible一起的目标是 拥有一个小型的非侵入式库,允许对数据进行精确控制 收集并如何输出。特别是,目标是跟踪 信息放在旁边或更好,直接嵌入到结果文件中。那个 将结果发送给合作者或打包以供发布 直截了当的
可复制库在LGPL version 3下获得许可,允许您在 使用其他许可证的代码。
该库处于beta版;请期待一些更改。python 3.5或更高版本正式发布 支持,但the code runs on 2.7 and 3.4 (but not on 3.3) as well。
安装
pip install reproducible
即时教程
假设这是您的代码,它是使用git完全提交的:
importrandomimportpickledefwalk(n):"""A simple random walk generator"""steps=[0]foriinrange(n):steps.append(steps[-1]+random.choice([-1,1]))returnstepsif__name__=='__main__':random.seed(1)results=walk(10)withopen('results.pickle','wb')asf:pickle.dump(results,f)
添加可重复跟踪:
importrandomimportpickleimportreproducibledefwalk(n):"""A simple random walk generator"""steps=[0]foriinrange(n):steps.append(steps[-1]+random.choice([-1,1]))returnstepsif__name__=='__main__':# create a reproducible.Context instance, that will hold all the# tracked data.context=reproducible.Context()# recording git repository state# here we are okay with running our code with uncommitted changes, but# we record a diff of the changes in the tracked data.context.add_repo(path='.',allow_dirty=True,diff=True)# recording parameters; this is not necessarily needed, as the code state# is recorded, but it is convenient.seed=1random.seed(seed)context.add_data('seed',seed)# add_data return the provided value (here 10), so you can do this:n=reproducible.add_data('n',10)results=walk(n)withopen('results.pickle','wb')asf:pickle.dump(results,f)# recording the SHA1 hash of the output filecontext.add_file('results.pickle',category='output')# you can examine the tracked data and add or remove from it at any moment# with `context.data`: it is a simple dictionary. For instance, the# cpu info is quite detailed. Let's remove it to keep the yaml output short.context.data.pop('cpuinfo')# exporting the provenance data to diskcontext.export_yaml('results_prov.yaml')
这是生成的包含跟踪数据的yaml文件输出:
argv:[example_after.py]data:{n:10, seed:1}files:output:results.pickle:{mtime:1531381834.0666547, sha256:395d8846640c012e3e5c642e7737173a1a74120275b37fa2ded13a211df3264e}packages:[gitdb2==2.0.3,GitPython==2.1.10,pip==10.0.1,py-cpuinfo==4.0.0,PyYAML==4.2b4,reproducible==0.1.2,setuptools==39.0.1,smmap2==2.0.3]platform:Darwin-17.6.0-x86_64-i386-64bitpython:branch:''compiler:Clang 9.1.0 (clang-902.0.39.2)implementation:CPythonrevision:''version:['3','7','0']repositories:.:{diff:null, dirty:false, hash:88c1de4ba5fb5cb2564b60245f26d3226ecb20c9, version:gitversion 2.18.0}timestamp:['2018-07-12T07:50:34.033829Z']
另请参见API Reference。
路线图
- 检索GPU信息。
- 更具可配置性。
- 可选地捕获输入、输出(
sys.stderr
,sys.stdout
)。 - 易于禁用/重新启用可重复性
- 外部文件名中的可选SHA256
更改日志
0.3.0版,20190703 这个版本引入了api和逻辑中断更改。
add_file()
现在默认覆盖,category现在是可选参数。context.data()
变成context.data
。Context(repo_path='.', allow_dirty=False, allow_untracked=False, diff=True, cpuinfo=True)
变成Context(cpuinfo=True, pip_packages=True)
:需要调用add_repo()
现在显式地,可以将pip_包查询设为可选。reset()
不再接受任何参数;而是记住__init__()
参数值。- 修复了丢失的
reproducible.add_pip_packages()
。
0.2.4版,20170809
- Python2.7的修补程序——因为我很笨。
0.2.3版,20170809
- 添加
json()
、yaml()
和requirements()
函数来访问结果 以编程方式导出函数。 - yaml输出现在使用
yaml.safe_dump
而不是yaml.dump
生成。 使输出更安全、更简单。
0.2.2版,20170717
- 修复不推荐使用的
save_yaml()
,save_json()
函数。
0.2.1版,20170717
- 将自述文件、许可证添加到pypi包。
0.2.0版,20170717
- 将
save_json()
和save_yaml()
重命名为export_json()
和export_yaml()
。旧名称暂时保留,但有一个弃用警告。 reproducible.function_args()
函数从 功能。reproducible.reset()
清除跟踪数据的函数。reproducible.export_requirements()
从 已检索到已安装包的列表。- 修复从
pip
包导入freeze命令的问题。 <升更新了readme:yaml输出的示例,roadmap,changlog。
random
模块的Random
实例。0.1.2版,20170611
- 各种错误修复。
- 函数
save_json()
和save_yaml()
现在返回它们生成的文件的sha256散列。
0.1.1版,20170608
reproducible.data()
函数访问和修改收集的数据。- 更多单元测试
0.1.0版,20170607
- 第一版:
add_repo()
,add_file()
,add_data()
,add_random_state()
,git_info()
,git_dirty()
,save_json()
,save_yaml()
函数。