forked from M-Labs/artiq
worker: run experiment in output directory
This commit is contained in:
parent
1ae8b8ffd1
commit
30d557a4f8
|
@ -3,11 +3,8 @@ import importlib
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import h5py
|
|
||||||
|
|
||||||
from artiq.protocols.sync_struct import Notifier
|
from artiq.protocols.sync_struct import Notifier
|
||||||
from artiq.protocols.pc_rpc import AutoTarget, Client, BestEffortClient
|
from artiq.protocols.pc_rpc import AutoTarget, Client, BestEffortClient
|
||||||
|
|
||||||
|
@ -158,20 +155,6 @@ class DeviceManager:
|
||||||
self.active_devices.clear()
|
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:
|
class DatasetManager:
|
||||||
def __init__(self, ddb):
|
def __init__(self, ddb):
|
||||||
self.broadcast = Notifier(dict())
|
self.broadcast = Notifier(dict())
|
||||||
|
|
|
@ -5,12 +5,13 @@ import logging
|
||||||
import traceback
|
import traceback
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
import h5py
|
||||||
|
|
||||||
import artiq
|
import artiq
|
||||||
from artiq.protocols import pipe_ipc, pyon
|
from artiq.protocols import pipe_ipc, pyon
|
||||||
from artiq.protocols.packed_exceptions import raise_packed_exc
|
from artiq.protocols.packed_exceptions import raise_packed_exc
|
||||||
from artiq.tools import multiline_log_config, file_import
|
from artiq.tools import multiline_log_config, file_import
|
||||||
from artiq.master.worker_db import (DeviceManager, DatasetManager,
|
from artiq.master.worker_db import DeviceManager, DatasetManager
|
||||||
get_hdf5_output)
|
|
||||||
from artiq.language.environment import is_experiment
|
from artiq.language.environment import is_experiment
|
||||||
from artiq.language.core import set_watchdog_factory, TerminationRequested
|
from artiq.language.core import set_watchdog_factory, TerminationRequested
|
||||||
from artiq.coredevice.core import CompileError, host_only, _render_diagnostic
|
from artiq.coredevice.core import CompileError, host_only, _render_diagnostic
|
||||||
|
@ -201,6 +202,11 @@ def main():
|
||||||
exp = get_exp(experiment_file, expid["class_name"])
|
exp = get_exp(experiment_file, expid["class_name"])
|
||||||
device_mgr.virtual_devices["scheduler"].set_run_info(
|
device_mgr.virtual_devices["scheduler"].set_run_info(
|
||||||
rid, obj["pipeline_name"], expid, obj["priority"])
|
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(
|
exp_inst = exp(
|
||||||
device_mgr, dataset_mgr, enable_processors=True,
|
device_mgr, dataset_mgr, enable_processors=True,
|
||||||
**expid["arguments"])
|
**expid["arguments"])
|
||||||
|
@ -215,7 +221,8 @@ def main():
|
||||||
exp_inst.analyze()
|
exp_inst.analyze()
|
||||||
put_object({"action": "completed"})
|
put_object({"action": "completed"})
|
||||||
elif action == "write_results":
|
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"))
|
dataset_mgr.write_hdf5(f.create_group("datasets"))
|
||||||
f["artiq_version"] = artiq_version
|
f["artiq_version"] = artiq_version
|
||||||
f["rid"] = rid
|
f["rid"] = rid
|
||||||
|
|
Loading…
Reference in New Issue