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: 7205985f6984
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: 6773d9e73417
Choose a head ref
  • 5 commits
  • 4 files changed
  • 1 contributor

Commits on Apr 8, 2016

  1. Copy the full SHA
    de002ac View commit details
  2. Copy the full SHA
    1ae8b8f View commit details
  3. Copy the full SHA
    30d557a View commit details
  4. Copy the full SHA
    88495f2 View commit details
  5. thumbnail: add example

    jordens committed Apr 8, 2016
    2
    Copy the full SHA
    6773d9e View commit details
Showing with 61 additions and 31 deletions.
  1. +22 −8 artiq/browser/results.py
  2. +21 −0 artiq/examples/master/repository/thumbnail.py
  3. +4 −17 artiq/master/worker_db.py
  4. +14 −6 artiq/master/worker_impl.py
30 changes: 22 additions & 8 deletions artiq/browser/results.py
Original file line number Diff line number Diff line change
@@ -18,10 +18,20 @@ def hdf5_thumbnail(self, info):
if not (info.isFile() and info.isReadable() and
info.suffix() == "h5"):
return
with h5py.File(info.filePath(), "r") as f:
if "thumbnail" not in f:
try:
f = h5py.File(info.filePath(), "r")
except:
return
with f:
try:
t = f["datasets/thumbnail"]
except KeyError:
return
try:
img = QtGui.QImage.fromData(t.value)
except:
logger.warning("unable to read thumbnail", exc_info=True)
return
img = QtGui.QImage.fromData(f["thumbnail"].value)
pix = QtGui.QPixmap.fromImage(img)
return QtGui.QIcon(pix)

@@ -82,12 +92,17 @@ def list_current_changed(self, current, previous):
if not (info.isFile() and info.isReadable() and
info.suffix() == "h5"):
return
with h5py.File(info.filePath(), "r") as f:
try:
f = h5py.File(info.filePath(), "r")
except:
logger.warning("unable to read HDF5 file", exc_info=True)
with f:
rd = {}
if "datasets" not in f:
try:
group = f["datasets"]
except KeyError:
return
group = f["datasets"]
for k in group:
for k in f["datasets"]:
rd[k] = True, group[k].value
self.datasets.init(rd)

@@ -96,7 +111,6 @@ def select(self, path):
self.rt.expand(idx)
self.rt.scrollTo(idx)
self.rt.setCurrentIndex(idx)
# rl root is signaled
self.rl.setCurrentIndex(self.rl_model.index(path))

def save_state(self):
21 changes: 21 additions & 0 deletions artiq/examples/master/repository/thumbnail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import io

import numpy as np
import matplotlib.pyplot as plt

from artiq.experiment import *


class Thumbnail(EnvExperiment):
def build(self):
pass

def run(self):
pass

def analyze(self):
plt.plot([1, 2, 0, 3, 4])
f = io.BytesIO()
plt.savefig(f, format="PNG")
f.seek(0)
self.set_dataset("thumbnail", np.void(f.read()))
21 changes: 4 additions & 17 deletions artiq/master/worker_db.py
Original file line number Diff line number Diff line change
@@ -3,12 +3,8 @@
import logging
import os
import tempfile
import time
import re

import numpy as np
import h5py

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

@@ -44,7 +40,8 @@ def _last_rid(self):
def _update_cache(self, rid):
contents = str(rid) + "\n"
directory = os.path.abspath(os.path.dirname(self.cache_filename))
with tempfile.NamedTemporaryFile("w", dir=directory, delete=False) as f:
with tempfile.NamedTemporaryFile("w", dir=directory, delete=False
) as f:
f.write(contents)
tmpname = f.name
os.replace(tmpname, self.cache_filename)
@@ -68,7 +65,7 @@ def _last_rid_from_results(self):
except:
continue
minute_folders = filter(lambda x: re.fullmatch('\d\d-\d\d', x),
minute_folders)
minute_folders)
for mf in minute_folders:
minute_path = os.path.join(day_path, mf)
try:
@@ -158,15 +155,6 @@ def close_devices(self):
self.active_devices.clear()


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")


class DatasetManager:
def __init__(self, ddb):
self.broadcast = Notifier(dict())
@@ -200,6 +188,5 @@ def get(self, key):
return self.ddb.get(key)

def write_hdf5(self, f):
g = f.create_group("datasets")
for k, v in self.local.items():
g[k] = v
f[k] = v
20 changes: 14 additions & 6 deletions artiq/master/worker_impl.py
Original file line number Diff line number Diff line change
@@ -5,12 +5,13 @@
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,11 +221,13 @@ def main():
exp_inst.analyze()
put_object({"action": "completed"})
elif action == "write_results":
with get_hdf5_output(start_time, rid, exp.__name__) as f:
dataset_mgr.write_hdf5(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
if "repo_rev" in expid:
f["repo_rev"] = expid["repo_rev"]
f["rid"] = rid
f["start_time"] = start_time
f["expid"] = pyon.encode(expid)
put_object({"action": "completed"})
elif action == "examine":
examine(ExamineDeviceMgr, ParentDatasetDB, obj["file"])