Exemplo n.º 1
0
def main():
    world_size = 2
    exp = Experiment('mp_test')
    mp.spawn(example,
             args=(world_size, exp, func),
             nprocs=world_size,
             daemon=True)
Exemplo n.º 2
0
    def reset(self) -> Experiment:
        """
        将工作目录中的文件恢复到某个commit
        恢复快照的 git 流程:
            git branch experiment
            git add . & git commit -m ... // 保证文件最新,防止冲突报错,这一步由 Experiment() 代为完成
            git checkout <commit-id> // 恢复文件到 <commit-id>
            git checkout -b reset // 将当前状态附到新的临时分支 reset 上
            git branch experiment // 切换回 experiment 分支
            git add . & git commit -m ... // 将当前状态重新提交到最新
                // 此时experiment 中最新的commit 为恢复的<commit-id>
            git branch -D reset  // 删除临时分支
            git branch master // 最终回到原来分支,保证除文件变动外git状态完好
        Returns:
            An Experiment represents this reset operation
        """
        commit = self.commit

        old_path = os.getcwd()
        os.chdir(commit.tree.abspath)
        exp = Experiment('Reset')

        repo = self.repo
        from thexp.utils.repository import branch
        with branch(commit.repo, _GITKEY.thexp_branch) as new_branch:
            repo.git.checkout(commit.hexsha)
            repo.git.checkout('-b', 'reset')
            repo.head.reference = new_branch
            repo.git.add('.')
            ncommit = repo.index.commit("Reset from {}".format(commit.hexsha))
            repo.git.branch('-d', 'reset')
        exp.add_plugin(
            'reset',
            {
                'test_name': self.name,  # 从哪个状态恢复
                'from': exp.commit.hexsha,  # reset 运行时的快照
                'where': commit.hexsha,  # 恢复到哪一次 commit,是恢复前的保存的状态
                'to':
                ncommit.hexsha,  # 对恢复后的状态再次进行提交,此时 from 和 to 两次提交状态应该完全相同
            })

        exp.end()
        os.chdir(old_path)
        return exp
Exemplo n.º 3
0
    def archive(self) -> Experiment:
        """
        将某次 test 对应 commit 的文件打包,相关命令为
            git archive -o <filename> <commit-hash>

        Returns:
            An Experiment represents this archive operation
        """
        commit = self.commit

        old_path = os.getcwd()
        os.chdir(commit.tree.abspath)
        exp = Experiment('Archive')

        revert_path = exp.makedir('archive')
        revert_fn = os.path.join(revert_path, "code.zip")
        exp.add_plugin('archive', {'file': revert_fn, 'test_name': self.name})
        with open(revert_fn, 'wb') as w:
            self.repo.archive(w, commit)

        exp.end()
        os.chdir(old_path)
        return exp
Exemplo n.º 4
0
"""

"""
import sys
sys.path.insert(0, "../")
from thexp import __VERSION__
print(__VERSION__)
import time

from thexp import Experiment

exp = Experiment("expname")
print(exp.make_exp_dir("explevel"))
print(exp.makedir("testlevel"))

from thexp import Params

params = Params()
exp.add_plugin(
    "params", dict(_param_hash=params.hash(),
                   data=params.inner_dict.jsonify()))

from thexp import Logger

logger = Logger()
fn = logger.add_log_dir(exp.makedir('logger'))
exp.add_plugin('logger', dict(fn=fn, ))

time.sleep(1)
try:
    raise Exception("dddd")
Exemplo n.º 5
0
"""

"""
import sys
sys.path.insert(0, "../")
from thexp import __VERSION__
print(__VERSION__)

from thexp import Experiment, globs

exp = Experiment("expname")

# glob.add_value("key",'value','user')
# glob.add_value("key",'value','exp')
# glob.add_value("key",'value','repository')
globs['a'] = 4

from pprint import pprint
pprint(globs.items())
pprint(exp.config_items())