From 53cef7e695e7fd6f7be092fa5a7c30360b536d32 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 fec38ef5b..1262d120e 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 @@ -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()) diff --git a/artiq/master/worker_impl.py b/artiq/master/worker_impl.py index 1acd63a12..7df76e5f0 100644 --- a/artiq/master/worker_impl.py +++ b/artiq/master/worker_impl.py @@ -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