forked from M-Labs/artiq
1
0
Fork 0

worker: run experiment in output directory

This commit is contained in:
Robert Jördens 2016-04-08 10:21:26 +08:00
parent 7803b68c4d
commit 53cef7e695
2 changed files with 10 additions and 20 deletions

View File

@ -3,11 +3,8 @@ import importlib
import logging
import os
import tempfile
import time
import re
import h5py
from artiq.protocols.sync_struct import Notifier
from artiq.protocols.pc_rpc import AutoTarget, Client, BestEffortClient
@ -148,20 +145,6 @@ class DeviceManager:
self.active_devices.clear()
def get_output_prefix(start_time, rid, name):
dirname = os.path.join("results",
time.strftime("%Y-%m-%d", start_time),
time.strftime("%H-%M", start_time))
filename = "{:09}-{}".format(rid, name)
os.makedirs(dirname, exist_ok=True)
return os.path.join(dirname, filename)
def get_hdf5_output(start_time, rid, name):
prefix = get_output_prefix(start_time, rid, name)
return h5py.File("{}.h5".format(prefix), "w")
class DatasetManager:
def __init__(self, ddb):
self.broadcast = Notifier(dict())

View File

@ -5,11 +5,12 @@ import logging
import traceback
from collections import OrderedDict
import h5py
import artiq
from artiq.protocols import pipe_ipc, pyon
from artiq.tools import multiline_log_config, file_import
from artiq.master.worker_db import (DeviceManager, DatasetManager,
get_hdf5_output)
from artiq.master.worker_db import DeviceManager, DatasetManager
from artiq.language.environment import is_experiment
from artiq.language.core import set_watchdog_factory, TerminationRequested
from artiq.coredevice.core import CompileError, host_only, _render_diagnostic
@ -209,6 +210,11 @@ def main():
exp = get_exp(experiment_file, expid["class_name"])
device_mgr.virtual_devices["scheduler"].set_run_info(
rid, obj["pipeline_name"], expid, obj["priority"])
dirname = os.path.join("results",
time.strftime("%Y-%m-%d", start_time),
time.strftime("%H-%M", start_time))
os.makedirs(dirname, exist_ok=True)
os.chdir(dirname)
exp_inst = exp(
device_mgr, dataset_mgr, enable_processors=True,
**expid["arguments"])
@ -223,7 +229,8 @@ def main():
exp_inst.analyze()
put_object({"action": "completed"})
elif action == "write_results":
with get_hdf5_output(start_time, rid, exp.__name__) as f:
filename = "{:09}-{}.h5".format(rid, exp.__name__)
with h5py.File(filename, "w") as f:
dataset_mgr.write_hdf5(f.create_group("datasets"))
f["artiq_version"] = artiq_version
f["rid"] = rid