From 30d557a4f8f159ce8b98a5b8cd94e147b25a38fc Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Fri, 8 Apr 2016 10:21:26 +0800 Subject: [PATCH] worker: run experiment in output directory --- artiq/master/worker_db.py | 17 ----------------- artiq/master/worker_impl.py | 13 ++++++++++--- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/artiq/master/worker_db.py b/artiq/master/worker_db.py index 025aaab82..096b2bf20 100644 --- a/artiq/master/worker_db.py +++ b/artiq/master/worker_db.py @@ -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 @@ -158,20 +155,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()) diff --git a/artiq/master/worker_impl.py b/artiq/master/worker_impl.py index aadd7ebeb..3c1bb41eb 100644 --- a/artiq/master/worker_impl.py +++ b/artiq/master/worker_impl.py @@ -5,12 +5,13 @@ import logging import traceback from collections import OrderedDict +import h5py + import artiq from artiq.protocols import pipe_ipc, pyon from artiq.protocols.packed_exceptions import raise_packed_exc 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 @@ -201,6 +202,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"]) @@ -215,7 +221,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