Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: cc172699ea91
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6601bebcfe66
Choose a head ref
  • 4 commits
  • 7 files changed
  • 1 contributor

Commits on Feb 21, 2015

  1. Copy the full SHA
    1aec6a0 View commit details
  2. Copy the full SHA
    965dd89 View commit details

Commits on Feb 22, 2015

  1. Copy the full SHA
    ceb02b4 View commit details
  2. Copy the full SHA
    6601beb View commit details
Showing with 116 additions and 71 deletions.
  1. +1 −0 .gitignore
  2. +2 −2 artiq/frontend/artiq_master.py
  3. +103 −0 artiq/master/results.py
  4. +0 −24 artiq/master/rt_results.py
  5. +2 −2 artiq/master/scheduler.py
  6. +3 −38 artiq/master/{db.py → worker_db.py}
  7. +5 −5 artiq/master/worker_impl.py
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -9,3 +9,4 @@ doc/manual/_build
/dist
/*.egg-info
/.coverage
examples/results
4 changes: 2 additions & 2 deletions artiq/frontend/artiq_master.py
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
from artiq.protocols.sync_struct import Publisher
from artiq.protocols.file_db import FlatFileDB, SimpleHistory
from artiq.master.scheduler import Scheduler
from artiq.master.rt_results import RTResults
from artiq.master.results import RTResults, get_last_rid
from artiq.master.repository import Repository
from artiq.tools import verbosity_args, init_logger

@@ -51,7 +51,7 @@ def main():

def run_cb(rid, run_params):
rtr.current_group = run_params["rtr_group"]
scheduler = Scheduler(run_cb)
scheduler = Scheduler(run_cb, get_last_rid() + 1)
scheduler.worker.handlers = {
"req_device": ddb.request,
"req_parameter": pdb.request,
103 changes: 103 additions & 0 deletions artiq/master/results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import os
import time
import re

import numpy
import h5py

from artiq.protocols.sync_struct import Notifier, process_mod


def get_hdf5_output(start_time, rid, name):
dirname = os.path.join("results",
time.strftime("%Y-%m-%d", start_time),
time.strftime("%H-%M", start_time))
filename = "{:09}-{}.h5".format(rid, name)
os.makedirs(dirname, exist_ok=True)
return h5py.File(os.path.join(dirname, filename), "w")


def get_last_rid():
r = -1
try:
day_folders = os.listdir("results")
except:
return r
day_folders = filter(lambda x: re.fullmatch('\d\d\d\d-\d\d-\d\d', x),
day_folders)
for df in day_folders:
day_path = os.path.join("results", df)
try:
minute_folders = os.listdir(day_path)
except:
continue
minute_folders = filter(lambda x: re.fullmatch('\d\d-\d\d', x),
minute_folders)
for mf in minute_folders:
minute_path = os.path.join(day_path, mf)
try:
h5files = os.listdir(minute_path)
except:
continue
for x in h5files:
m = re.fullmatch('(\d\d\d\d\d\d\d\d\d)-.*\.h5', x)
rid = int(m.group(1))
if rid > r:
r = rid
return r


_type_to_hdf5 = {
int: h5py.h5t.STD_I64BE,
float: h5py.h5t.IEEE_F64BE
}

def result_dict_to_hdf5(f, rd):
for name, data in rd.items():
if isinstance(data, list):
el_ty = type(data[0])
for d in data:
if type(d) != el_ty:
raise TypeError("All list elements must have the same"
" type for HDF5 output")
try:
el_ty_h5 = _type_to_hdf5[el_ty]
except KeyError:
raise TypeError("List element type {} is not supported for"
" HDF5 output".format(el_ty))
dataset = f.create_dataset(name, (len(data), ), el_ty_h5)
dataset[:] = data
elif isinstance(data, numpy.ndarray):
f.create_dataset(name, data=data)
else:
ty = type(data)
try:
ty_h5 = _type_to_hdf5[ty]
except KeyError:
raise TypeError("Type {} is not supported for HDF5 output"
.format(ty))
dataset = f.create_dataset(name, (), ty_h5)
dataset[()] = data


class RTResults:
def __init__(self):
self.groups = Notifier(dict())
self.current_group = "default"

def init(self, description):
data = dict()
for rtr in description.keys():
if isinstance(rtr, tuple):
for e in rtr:
data[e] = []
else:
data[rtr] = []
self.groups[self.current_group] = {
"description": description,
"data": data
}

def update(self, mod):
target = self.groups[self.current_group]["data"]
process_mod(target, mod)
24 changes: 0 additions & 24 deletions artiq/master/rt_results.py

This file was deleted.

4 changes: 2 additions & 2 deletions artiq/master/scheduler.py
Original file line number Diff line number Diff line change
@@ -6,10 +6,10 @@


class Scheduler:
def __init__(self, run_cb):
def __init__(self, run_cb, first_rid):
self.run_cb = run_cb
self.worker = Worker()
self.next_rid = 0
self.next_rid = first_rid
self.queue = Notifier([])
self.queue_modified = asyncio.Event()
self.timed = Notifier(dict())
41 changes: 3 additions & 38 deletions artiq/master/db.py → artiq/master/worker_db.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,9 @@
from collections import OrderedDict
import importlib

import numpy
import h5py

from artiq.protocols.sync_struct import Notifier
from artiq.protocols.pc_rpc import Client, BestEffortClient


_type_to_hdf5 = {
int: h5py.h5t.STD_I64BE,
float: h5py.h5t.IEEE_F64BE
}

def _result_dict_to_hdf5(f, rd):
for name, data in rd.items():
if isinstance(data, list):
el_ty = type(data[0])
for d in data:
if type(d) != el_ty:
raise TypeError("All list elements must have the same"
" type for HDF5 output")
try:
el_ty_h5 = _type_to_hdf5[el_ty]
except KeyError:
raise TypeError("List element type {} is not supported for"
" HDF5 output".format(el_ty))
dataset = f.create_dataset(name, (len(data), ), el_ty_h5)
dataset[:] = data
elif isinstance(data, numpy.ndarray):
f.create_dataset(name, data=data)
else:
ty = type(data)
try:
ty_h5 = _type_to_hdf5[ty]
except KeyError:
raise TypeError("Type {} is not supported for HDF5 output"
.format(ty))
dataset = f.create_dataset(name, (), ty_h5)
dataset[()] = data
from artiq.master.results import result_dict_to_hdf5


class ResultDB:
@@ -68,8 +33,8 @@ def set(self, name, value):
self.data[name] = value

def write_hdf5(self, f):
_result_dict_to_hdf5(f, self.realtime_data.read)
_result_dict_to_hdf5(f, self.data.read)
result_dict_to_hdf5(f, self.realtime_data.read)
result_dict_to_hdf5(f, self.data.read)


def _create_device(desc, dbh):
10 changes: 5 additions & 5 deletions artiq/master/worker_impl.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import sys
import time
from inspect import isclass
import traceback

import h5py

from artiq.protocols import pyon
from artiq.tools import file_import
from artiq.master.db import DBHub, ResultDB
from artiq.master.worker_db import DBHub, ResultDB
from artiq.master.results import get_hdf5_output


def get_object():
@@ -80,6 +80,7 @@ def get_unit(file, unit):


def run(rid, run_params):
start_time = time.localtime()
unit = get_unit(run_params["file"], run_params["unit"])

realtime_results = unit.realtime_results()
@@ -115,8 +116,7 @@ def run(rid, run_params):
finally:
dbh.close()

filename = "{:05}-{}.h5".format(rid, unit.__name__)
f = h5py.File(filename, "w")
f = get_hdf5_output(start_time, rid, unit.__name__)
try:
rdb.write_hdf5(f)
finally: