From f9381f32150ae91ec74e790032253ef2b4fc16d6 Mon Sep 17 00:00:00 2001 From: Joe Britton Date: Mon, 2 Feb 2015 19:03:03 -0700 Subject: [PATCH 1/9] pdq2: moved code out of __init__ into compound --- artiq/devices/pdq2/__init__.py | 144 +-------------------------------- artiq/devices/pdq2/compound.py | 143 ++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+), 143 deletions(-) create mode 100644 artiq/devices/pdq2/compound.py diff --git a/artiq/devices/pdq2/__init__.py b/artiq/devices/pdq2/__init__.py index 5ad2180c0..f15b0f8c8 100644 --- a/artiq/devices/pdq2/__init__.py +++ b/artiq/devices/pdq2/__init__.py @@ -1,143 +1 @@ -from artiq.language.core import * -from artiq.language.db import * -from artiq.language.units import * -from artiq.coredevice import rtio - - -frame_setup = 20*ns -trigger_duration = 50*ns -frame_wait = 20*ns -sample_period = 10*us # FIXME: check this - - -class SegmentSequenceError(Exception): - pass - - -class FrameActiveError(Exception): - pass - - -class FrameCloseError(Exception): - pass - - -class _Segment: - def __init__(self, frame, sn, duration, host_data): - self.core = frame.core - self.frame = frame - self.sn = sn - self.duration = duration - self.host_data = host_data - - @kernel - def advance(self): - if self.frame.pdq.current_frame != self.frame.fn: - raise FrameActiveError - if self.frame.pdq.next_sn != self.sn: - raise SegmentSequenceError - self.frame.pdq.next_sn += 1 - - t = time_to_cycles(now()) - self.frame.pdq.trigger.on(t) - self.frame.pdq.trigger.off(t + time_to_cycles(trigger_duration)) - delay(self.duration) - - -class _Frame: - def __init__(self, core): - self.core = core - self.segment_count = 0 - self.closed = False - - def append(self, t, u, trigger=False, name=None): - if self.closed: - raise FrameCloseError - sn = self.segment_count - duration = (t[-1] - t[0])*sample_period - segment = _Segment(self, sn, duration, (t, u, trigger)) - if name is None: - # TODO - raise NotImplementedError("Anonymous segments are not supported yet") - else: - if hasattr(self, name): - raise NameError("Segment name already exists") - setattr(self, name, segment) - self.segment_count += 1 - - def close(self): - if self.closed: - raise FrameCloseError - self.closed = True - - @kernel - def begin(self): - if self.pdq.current_frame >= 0: - raise FrameActiveError - self.pdq.current_frame = self.fn - self.pdq.next_sn = 0 - - t = (time_to_cycles(now()) - - time_to_cycles(frame_setup + trigger_duration + frame_wait)) - self.pdq.frame0.set_value(t, self.fn & 1) - self.pdq.frame1.set_value(t, (self.fn & 2) >> 1) - self.pdq.frame2.set_value(t, (self.fn & 4) >> 2) - t += time_to_cycles(frame_setup) - self.pdq.trigger.on(t) - self.pdq.trigger.off(t + time_to_cycles(trigger_duration)) - - @kernel - def advance(self): - # TODO - raise NotImplementedError - - @kernel - def finish(self): - if self.pdq.current_frame != self.fn: - raise FrameActiveError - if self.pdq.next_sn != self.segment_count: - raise FrameActiveError - self.pdq.current_frame = -1 - self.pdq.next_sn = -1 - - def _prepare(self, pdq, fn): - if not self.closed: - raise FrameCloseError - self.pdq = pdq - self.fn = fn - - def _invalidate(self): - del self.pdq - del self.fn - - -class CompoundPDQ2(AutoDB): - class DBKeys: - ids = Argument() - rtio_trigger = Argument() - rtio_frame = Argument() - - def build(self): - self.trigger = rtio.LLRTIOOut(core=self.core, channel=self.rtio_trigger) - self.frame0 = rtio.LLRTIOOut(core=self.core, channel=self.rtio_frame[0]) - self.frame1 = rtio.LLRTIOOut(core=self.core, channel=self.rtio_frame[1]) - self.frame2 = rtio.LLRTIOOut(core=self.core, channel=self.rtio_frame[2]) - - self.frames = [] - self.current_frame = -1 - self.next_sn = -1 - - def create_frame(self): - return _Frame(self.core) - - def prepare(self, *frames): - # prevent previous frames and their segments from - # being (incorrectly) used again - for frame in self.frames: - frame._invalidate() - - self.frames = list(frames) - for fn, frame in enumerate(frames): - frame._prepare(self, fn) - - # TODO: upload to PDQ2 devices +from .compound import CompoundPDQ2 \ No newline at end of file diff --git a/artiq/devices/pdq2/compound.py b/artiq/devices/pdq2/compound.py new file mode 100644 index 000000000..f5e814830 --- /dev/null +++ b/artiq/devices/pdq2/compound.py @@ -0,0 +1,143 @@ +from artiq.language.core import * +from artiq.language.db import * +from artiq.language.units import * +from artiq.coredevice import rtio + + +frame_setup = 20*ns +trigger_duration = 50*ns +frame_wait = 20*ns +sample_period = 10*us # FIXME: check this + + +class SegmentSequenceError(Exception): + pass + + +class FrameActiveError(Exception): + pass + + +class FrameCloseError(Exception): + pass + + +class _Segment: + def __init__(self, frame, sn, duration, host_data): + self.core = frame.core + self.frame = frame + self.sn = sn + self.duration = duration + self.host_data = host_data + + @kernel + def advance(self): + if self.frame.pdq.current_frame != self.frame.fn: + raise FrameActiveError + if self.frame.pdq.next_sn != self.sn: + raise SegmentSequenceError + self.frame.pdq.next_sn += 1 + + t = time_to_cycles(now()) + self.frame.pdq.trigger.on(t) + self.frame.pdq.trigger.off(t + time_to_cycles(trigger_duration)) + delay(self.duration) + + +class _Frame: + def __init__(self, core): + self.core = core + self.segment_count = 0 + self.closed = False + + def append(self, t, u, trigger=False, name=None): + if self.closed: + raise FrameCloseError + sn = self.segment_count + duration = (t[-1] - t[0])*sample_period + segment = _Segment(self, sn, duration, (t, u, trigger)) + if name is None: + # TODO + raise NotImplementedError("Anonymous segments are not supported yet") + else: + if hasattr(self, name): + raise NameError("Segment name already exists") + setattr(self, name, segment) + self.segment_count += 1 + + def close(self): + if self.closed: + raise FrameCloseError + self.closed = True + + @kernel + def begin(self): + if self.pdq.current_frame >= 0: + raise FrameActiveError + self.pdq.current_frame = self.fn + self.pdq.next_sn = 0 + + t = (time_to_cycles(now()) + - time_to_cycles(frame_setup + trigger_duration + frame_wait)) + self.pdq.frame0.set_value(t, self.fn & 1) + self.pdq.frame1.set_value(t, (self.fn & 2) >> 1) + self.pdq.frame2.set_value(t, (self.fn & 4) >> 2) + t += time_to_cycles(frame_setup) + self.pdq.trigger.on(t) + self.pdq.trigger.off(t + time_to_cycles(trigger_duration)) + + @kernel + def advance(self): + # TODO + raise NotImplementedError + + @kernel + def finish(self): + if self.pdq.current_frame != self.fn: + raise FrameActiveError + if self.pdq.next_sn != self.segment_count: + raise FrameActiveError + self.pdq.current_frame = -1 + self.pdq.next_sn = -1 + + def _prepare(self, pdq, fn): + if not self.closed: + raise FrameCloseError + self.pdq = pdq + self.fn = fn + + def _invalidate(self): + del self.pdq + del self.fn + + +class CompoundPDQ2(AutoDB): + class DBKeys: + ids = Argument() + rtio_trigger = Argument() + rtio_frame = Argument() + + def build(self): + self.trigger = rtio.LLRTIOOut(core=self.core, channel=self.rtio_trigger) + self.frame0 = rtio.LLRTIOOut(core=self.core, channel=self.rtio_frame[0]) + self.frame1 = rtio.LLRTIOOut(core=self.core, channel=self.rtio_frame[1]) + self.frame2 = rtio.LLRTIOOut(core=self.core, channel=self.rtio_frame[2]) + + self.frames = [] + self.current_frame = -1 + self.next_sn = -1 + + def create_frame(self): + return _Frame(self.core) + + def prepare(self, *frames): + # prevent previous frames and their segments from + # being (incorrectly) used again + for frame in self.frames: + frame._invalidate() + + self.frames = list(frames) + for fn, frame in enumerate(frames): + frame._prepare(self, fn) + + # TODO: upload to PDQ2 devices \ No newline at end of file From 1eb079aefe0bab87529b4798e94e733fe72ad32b Mon Sep 17 00:00:00 2001 From: Joe Britton Date: Mon, 2 Feb 2015 19:03:17 -0700 Subject: [PATCH 2/9] add __init__.py for lda --- artiq/devices/lda/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/artiq/devices/lda/__init__.py b/artiq/devices/lda/__init__.py index e69de29bb..59c74f3a7 100644 --- a/artiq/devices/lda/__init__.py +++ b/artiq/devices/lda/__init__.py @@ -0,0 +1 @@ +from .driver import Lda \ No newline at end of file From 9fbb08ef2916c6de7666d3b26aed89d23c4b0575 Mon Sep 17 00:00:00 2001 From: Joe Britton Date: Mon, 2 Feb 2015 19:03:03 -0700 Subject: [PATCH 3/9] pdq2: moved code out of __init__ into compound --- artiq/devices/pdq2/__init__.py | 144 +-------------------------------- artiq/devices/pdq2/compound.py | 143 ++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+), 143 deletions(-) create mode 100644 artiq/devices/pdq2/compound.py diff --git a/artiq/devices/pdq2/__init__.py b/artiq/devices/pdq2/__init__.py index 5ad2180c0..f15b0f8c8 100644 --- a/artiq/devices/pdq2/__init__.py +++ b/artiq/devices/pdq2/__init__.py @@ -1,143 +1 @@ -from artiq.language.core import * -from artiq.language.db import * -from artiq.language.units import * -from artiq.coredevice import rtio - - -frame_setup = 20*ns -trigger_duration = 50*ns -frame_wait = 20*ns -sample_period = 10*us # FIXME: check this - - -class SegmentSequenceError(Exception): - pass - - -class FrameActiveError(Exception): - pass - - -class FrameCloseError(Exception): - pass - - -class _Segment: - def __init__(self, frame, sn, duration, host_data): - self.core = frame.core - self.frame = frame - self.sn = sn - self.duration = duration - self.host_data = host_data - - @kernel - def advance(self): - if self.frame.pdq.current_frame != self.frame.fn: - raise FrameActiveError - if self.frame.pdq.next_sn != self.sn: - raise SegmentSequenceError - self.frame.pdq.next_sn += 1 - - t = time_to_cycles(now()) - self.frame.pdq.trigger.on(t) - self.frame.pdq.trigger.off(t + time_to_cycles(trigger_duration)) - delay(self.duration) - - -class _Frame: - def __init__(self, core): - self.core = core - self.segment_count = 0 - self.closed = False - - def append(self, t, u, trigger=False, name=None): - if self.closed: - raise FrameCloseError - sn = self.segment_count - duration = (t[-1] - t[0])*sample_period - segment = _Segment(self, sn, duration, (t, u, trigger)) - if name is None: - # TODO - raise NotImplementedError("Anonymous segments are not supported yet") - else: - if hasattr(self, name): - raise NameError("Segment name already exists") - setattr(self, name, segment) - self.segment_count += 1 - - def close(self): - if self.closed: - raise FrameCloseError - self.closed = True - - @kernel - def begin(self): - if self.pdq.current_frame >= 0: - raise FrameActiveError - self.pdq.current_frame = self.fn - self.pdq.next_sn = 0 - - t = (time_to_cycles(now()) - - time_to_cycles(frame_setup + trigger_duration + frame_wait)) - self.pdq.frame0.set_value(t, self.fn & 1) - self.pdq.frame1.set_value(t, (self.fn & 2) >> 1) - self.pdq.frame2.set_value(t, (self.fn & 4) >> 2) - t += time_to_cycles(frame_setup) - self.pdq.trigger.on(t) - self.pdq.trigger.off(t + time_to_cycles(trigger_duration)) - - @kernel - def advance(self): - # TODO - raise NotImplementedError - - @kernel - def finish(self): - if self.pdq.current_frame != self.fn: - raise FrameActiveError - if self.pdq.next_sn != self.segment_count: - raise FrameActiveError - self.pdq.current_frame = -1 - self.pdq.next_sn = -1 - - def _prepare(self, pdq, fn): - if not self.closed: - raise FrameCloseError - self.pdq = pdq - self.fn = fn - - def _invalidate(self): - del self.pdq - del self.fn - - -class CompoundPDQ2(AutoDB): - class DBKeys: - ids = Argument() - rtio_trigger = Argument() - rtio_frame = Argument() - - def build(self): - self.trigger = rtio.LLRTIOOut(core=self.core, channel=self.rtio_trigger) - self.frame0 = rtio.LLRTIOOut(core=self.core, channel=self.rtio_frame[0]) - self.frame1 = rtio.LLRTIOOut(core=self.core, channel=self.rtio_frame[1]) - self.frame2 = rtio.LLRTIOOut(core=self.core, channel=self.rtio_frame[2]) - - self.frames = [] - self.current_frame = -1 - self.next_sn = -1 - - def create_frame(self): - return _Frame(self.core) - - def prepare(self, *frames): - # prevent previous frames and their segments from - # being (incorrectly) used again - for frame in self.frames: - frame._invalidate() - - self.frames = list(frames) - for fn, frame in enumerate(frames): - frame._prepare(self, fn) - - # TODO: upload to PDQ2 devices +from .compound import CompoundPDQ2 \ No newline at end of file diff --git a/artiq/devices/pdq2/compound.py b/artiq/devices/pdq2/compound.py new file mode 100644 index 000000000..f5e814830 --- /dev/null +++ b/artiq/devices/pdq2/compound.py @@ -0,0 +1,143 @@ +from artiq.language.core import * +from artiq.language.db import * +from artiq.language.units import * +from artiq.coredevice import rtio + + +frame_setup = 20*ns +trigger_duration = 50*ns +frame_wait = 20*ns +sample_period = 10*us # FIXME: check this + + +class SegmentSequenceError(Exception): + pass + + +class FrameActiveError(Exception): + pass + + +class FrameCloseError(Exception): + pass + + +class _Segment: + def __init__(self, frame, sn, duration, host_data): + self.core = frame.core + self.frame = frame + self.sn = sn + self.duration = duration + self.host_data = host_data + + @kernel + def advance(self): + if self.frame.pdq.current_frame != self.frame.fn: + raise FrameActiveError + if self.frame.pdq.next_sn != self.sn: + raise SegmentSequenceError + self.frame.pdq.next_sn += 1 + + t = time_to_cycles(now()) + self.frame.pdq.trigger.on(t) + self.frame.pdq.trigger.off(t + time_to_cycles(trigger_duration)) + delay(self.duration) + + +class _Frame: + def __init__(self, core): + self.core = core + self.segment_count = 0 + self.closed = False + + def append(self, t, u, trigger=False, name=None): + if self.closed: + raise FrameCloseError + sn = self.segment_count + duration = (t[-1] - t[0])*sample_period + segment = _Segment(self, sn, duration, (t, u, trigger)) + if name is None: + # TODO + raise NotImplementedError("Anonymous segments are not supported yet") + else: + if hasattr(self, name): + raise NameError("Segment name already exists") + setattr(self, name, segment) + self.segment_count += 1 + + def close(self): + if self.closed: + raise FrameCloseError + self.closed = True + + @kernel + def begin(self): + if self.pdq.current_frame >= 0: + raise FrameActiveError + self.pdq.current_frame = self.fn + self.pdq.next_sn = 0 + + t = (time_to_cycles(now()) + - time_to_cycles(frame_setup + trigger_duration + frame_wait)) + self.pdq.frame0.set_value(t, self.fn & 1) + self.pdq.frame1.set_value(t, (self.fn & 2) >> 1) + self.pdq.frame2.set_value(t, (self.fn & 4) >> 2) + t += time_to_cycles(frame_setup) + self.pdq.trigger.on(t) + self.pdq.trigger.off(t + time_to_cycles(trigger_duration)) + + @kernel + def advance(self): + # TODO + raise NotImplementedError + + @kernel + def finish(self): + if self.pdq.current_frame != self.fn: + raise FrameActiveError + if self.pdq.next_sn != self.segment_count: + raise FrameActiveError + self.pdq.current_frame = -1 + self.pdq.next_sn = -1 + + def _prepare(self, pdq, fn): + if not self.closed: + raise FrameCloseError + self.pdq = pdq + self.fn = fn + + def _invalidate(self): + del self.pdq + del self.fn + + +class CompoundPDQ2(AutoDB): + class DBKeys: + ids = Argument() + rtio_trigger = Argument() + rtio_frame = Argument() + + def build(self): + self.trigger = rtio.LLRTIOOut(core=self.core, channel=self.rtio_trigger) + self.frame0 = rtio.LLRTIOOut(core=self.core, channel=self.rtio_frame[0]) + self.frame1 = rtio.LLRTIOOut(core=self.core, channel=self.rtio_frame[1]) + self.frame2 = rtio.LLRTIOOut(core=self.core, channel=self.rtio_frame[2]) + + self.frames = [] + self.current_frame = -1 + self.next_sn = -1 + + def create_frame(self): + return _Frame(self.core) + + def prepare(self, *frames): + # prevent previous frames and their segments from + # being (incorrectly) used again + for frame in self.frames: + frame._invalidate() + + self.frames = list(frames) + for fn, frame in enumerate(frames): + frame._prepare(self, fn) + + # TODO: upload to PDQ2 devices \ No newline at end of file From 66ec1a2a0b0d8bee68fe1e42da8ff59b4346ae13 Mon Sep 17 00:00:00 2001 From: Joe Britton Date: Mon, 2 Feb 2015 19:03:17 -0700 Subject: [PATCH 4/9] add __init__.py for lda --- artiq/devices/lda/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/artiq/devices/lda/__init__.py b/artiq/devices/lda/__init__.py index e69de29bb..59c74f3a7 100644 --- a/artiq/devices/lda/__init__.py +++ b/artiq/devices/lda/__init__.py @@ -0,0 +1 @@ +from .driver import Lda \ No newline at end of file From 7e7b5742382b302648f62c808f75ab44e0a1f8ba Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 3 Feb 2015 10:07:37 +0800 Subject: [PATCH 5/9] doc/writing_a_driver: use logging.getLogger --- doc/manual/writing_a_driver.rst | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/doc/manual/writing_a_driver.rst b/doc/manual/writing_a_driver.rst index 4fe512f0e..a709908aa 100644 --- a/doc/manual/writing_a_driver.rst +++ b/doc/manual/writing_a_driver.rst @@ -121,9 +121,14 @@ The program below exemplifies how to use logging: :: import argparse import logging + from artiq.tools import verbosity_args, init_logger + # get a logger that prints the module name + logger = logging.getLogger(__name__) + + def get_argparser(): parser = argparse.ArgumentParser(description="Logging example") parser.add_argument("--someargument", @@ -137,11 +142,11 @@ The program below exemplifies how to use logging: :: args = get_argparser().parse_args() init_logger(args) # This initializes logging system log level according to -v/-q args - logging.debug("this is a debug message") - logging.info("this is an info message") - logging.warning("this is a warning message") - logging.error("this is an error message") - logging.critical("this is a critical message") + logger.debug("this is a debug message") + logger.info("this is an info message") + logger.warning("this is a warning message") + logger.error("this is an error message") + logger.critical("this is a critical message") if __name__ == "__main__": main() From 0ff84c6534a9e6e46abd7575d375d66d269e0e60 Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Mon, 2 Feb 2015 14:36:11 -0700 Subject: [PATCH 6/9] setup.py: it's python-datetutil in pypi etc --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d38ea1bae..2e70b4ef0 100755 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ setup( license="BSD", install_requires=[ "sphinx", "sphinx-argparse", "pyserial", "numpy", "scipy", - "dateutil", "prettytable" + "python-dateutil", "prettytable" ], extras_require={}, dependency_links=[], From 272c01f9a3a7495c39aea5fe987a7c8d08de5c7d Mon Sep 17 00:00:00 2001 From: Yann Sionneau Date: Tue, 3 Feb 2015 15:06:45 +0100 Subject: [PATCH 7/9] asyncio: Use ProactorEventLoop on Windows --- artiq/frontend/artiq_master.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/artiq/frontend/artiq_master.py b/artiq/frontend/artiq_master.py index 8f53f61b5..804c554d4 100755 --- a/artiq/frontend/artiq_master.py +++ b/artiq/frontend/artiq_master.py @@ -3,6 +3,7 @@ import asyncio import argparse import atexit +import os from artiq.protocols.pc_rpc import Server from artiq.protocols.sync_struct import Publisher @@ -40,7 +41,11 @@ def main(): repository = Repository() explist = FlatFileDB("explist.pyon") - loop = asyncio.get_event_loop() + if os.name == 'nt': + loop = asyncio.ProactorEventLoop() + asyncio.set_event_loop(loop) + else: + loop = asyncio.get_event_loop() atexit.register(lambda: loop.close()) def run_cb(rid, run_params): From be02693771623a272d3606a940bdde02f912bd73 Mon Sep 17 00:00:00 2001 From: Joe Britton Date: Mon, 2 Feb 2015 19:03:03 -0700 Subject: [PATCH 8/9] pdq2: moved code out of __init__ into compound --- artiq/devices/pdq2/__init__.py | 144 +-------------------------------- artiq/devices/pdq2/compound.py | 143 ++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+), 143 deletions(-) create mode 100644 artiq/devices/pdq2/compound.py diff --git a/artiq/devices/pdq2/__init__.py b/artiq/devices/pdq2/__init__.py index 5ad2180c0..f15b0f8c8 100644 --- a/artiq/devices/pdq2/__init__.py +++ b/artiq/devices/pdq2/__init__.py @@ -1,143 +1 @@ -from artiq.language.core import * -from artiq.language.db import * -from artiq.language.units import * -from artiq.coredevice import rtio - - -frame_setup = 20*ns -trigger_duration = 50*ns -frame_wait = 20*ns -sample_period = 10*us # FIXME: check this - - -class SegmentSequenceError(Exception): - pass - - -class FrameActiveError(Exception): - pass - - -class FrameCloseError(Exception): - pass - - -class _Segment: - def __init__(self, frame, sn, duration, host_data): - self.core = frame.core - self.frame = frame - self.sn = sn - self.duration = duration - self.host_data = host_data - - @kernel - def advance(self): - if self.frame.pdq.current_frame != self.frame.fn: - raise FrameActiveError - if self.frame.pdq.next_sn != self.sn: - raise SegmentSequenceError - self.frame.pdq.next_sn += 1 - - t = time_to_cycles(now()) - self.frame.pdq.trigger.on(t) - self.frame.pdq.trigger.off(t + time_to_cycles(trigger_duration)) - delay(self.duration) - - -class _Frame: - def __init__(self, core): - self.core = core - self.segment_count = 0 - self.closed = False - - def append(self, t, u, trigger=False, name=None): - if self.closed: - raise FrameCloseError - sn = self.segment_count - duration = (t[-1] - t[0])*sample_period - segment = _Segment(self, sn, duration, (t, u, trigger)) - if name is None: - # TODO - raise NotImplementedError("Anonymous segments are not supported yet") - else: - if hasattr(self, name): - raise NameError("Segment name already exists") - setattr(self, name, segment) - self.segment_count += 1 - - def close(self): - if self.closed: - raise FrameCloseError - self.closed = True - - @kernel - def begin(self): - if self.pdq.current_frame >= 0: - raise FrameActiveError - self.pdq.current_frame = self.fn - self.pdq.next_sn = 0 - - t = (time_to_cycles(now()) - - time_to_cycles(frame_setup + trigger_duration + frame_wait)) - self.pdq.frame0.set_value(t, self.fn & 1) - self.pdq.frame1.set_value(t, (self.fn & 2) >> 1) - self.pdq.frame2.set_value(t, (self.fn & 4) >> 2) - t += time_to_cycles(frame_setup) - self.pdq.trigger.on(t) - self.pdq.trigger.off(t + time_to_cycles(trigger_duration)) - - @kernel - def advance(self): - # TODO - raise NotImplementedError - - @kernel - def finish(self): - if self.pdq.current_frame != self.fn: - raise FrameActiveError - if self.pdq.next_sn != self.segment_count: - raise FrameActiveError - self.pdq.current_frame = -1 - self.pdq.next_sn = -1 - - def _prepare(self, pdq, fn): - if not self.closed: - raise FrameCloseError - self.pdq = pdq - self.fn = fn - - def _invalidate(self): - del self.pdq - del self.fn - - -class CompoundPDQ2(AutoDB): - class DBKeys: - ids = Argument() - rtio_trigger = Argument() - rtio_frame = Argument() - - def build(self): - self.trigger = rtio.LLRTIOOut(core=self.core, channel=self.rtio_trigger) - self.frame0 = rtio.LLRTIOOut(core=self.core, channel=self.rtio_frame[0]) - self.frame1 = rtio.LLRTIOOut(core=self.core, channel=self.rtio_frame[1]) - self.frame2 = rtio.LLRTIOOut(core=self.core, channel=self.rtio_frame[2]) - - self.frames = [] - self.current_frame = -1 - self.next_sn = -1 - - def create_frame(self): - return _Frame(self.core) - - def prepare(self, *frames): - # prevent previous frames and their segments from - # being (incorrectly) used again - for frame in self.frames: - frame._invalidate() - - self.frames = list(frames) - for fn, frame in enumerate(frames): - frame._prepare(self, fn) - - # TODO: upload to PDQ2 devices +from .compound import CompoundPDQ2 \ No newline at end of file diff --git a/artiq/devices/pdq2/compound.py b/artiq/devices/pdq2/compound.py new file mode 100644 index 000000000..f5e814830 --- /dev/null +++ b/artiq/devices/pdq2/compound.py @@ -0,0 +1,143 @@ +from artiq.language.core import * +from artiq.language.db import * +from artiq.language.units import * +from artiq.coredevice import rtio + + +frame_setup = 20*ns +trigger_duration = 50*ns +frame_wait = 20*ns +sample_period = 10*us # FIXME: check this + + +class SegmentSequenceError(Exception): + pass + + +class FrameActiveError(Exception): + pass + + +class FrameCloseError(Exception): + pass + + +class _Segment: + def __init__(self, frame, sn, duration, host_data): + self.core = frame.core + self.frame = frame + self.sn = sn + self.duration = duration + self.host_data = host_data + + @kernel + def advance(self): + if self.frame.pdq.current_frame != self.frame.fn: + raise FrameActiveError + if self.frame.pdq.next_sn != self.sn: + raise SegmentSequenceError + self.frame.pdq.next_sn += 1 + + t = time_to_cycles(now()) + self.frame.pdq.trigger.on(t) + self.frame.pdq.trigger.off(t + time_to_cycles(trigger_duration)) + delay(self.duration) + + +class _Frame: + def __init__(self, core): + self.core = core + self.segment_count = 0 + self.closed = False + + def append(self, t, u, trigger=False, name=None): + if self.closed: + raise FrameCloseError + sn = self.segment_count + duration = (t[-1] - t[0])*sample_period + segment = _Segment(self, sn, duration, (t, u, trigger)) + if name is None: + # TODO + raise NotImplementedError("Anonymous segments are not supported yet") + else: + if hasattr(self, name): + raise NameError("Segment name already exists") + setattr(self, name, segment) + self.segment_count += 1 + + def close(self): + if self.closed: + raise FrameCloseError + self.closed = True + + @kernel + def begin(self): + if self.pdq.current_frame >= 0: + raise FrameActiveError + self.pdq.current_frame = self.fn + self.pdq.next_sn = 0 + + t = (time_to_cycles(now()) + - time_to_cycles(frame_setup + trigger_duration + frame_wait)) + self.pdq.frame0.set_value(t, self.fn & 1) + self.pdq.frame1.set_value(t, (self.fn & 2) >> 1) + self.pdq.frame2.set_value(t, (self.fn & 4) >> 2) + t += time_to_cycles(frame_setup) + self.pdq.trigger.on(t) + self.pdq.trigger.off(t + time_to_cycles(trigger_duration)) + + @kernel + def advance(self): + # TODO + raise NotImplementedError + + @kernel + def finish(self): + if self.pdq.current_frame != self.fn: + raise FrameActiveError + if self.pdq.next_sn != self.segment_count: + raise FrameActiveError + self.pdq.current_frame = -1 + self.pdq.next_sn = -1 + + def _prepare(self, pdq, fn): + if not self.closed: + raise FrameCloseError + self.pdq = pdq + self.fn = fn + + def _invalidate(self): + del self.pdq + del self.fn + + +class CompoundPDQ2(AutoDB): + class DBKeys: + ids = Argument() + rtio_trigger = Argument() + rtio_frame = Argument() + + def build(self): + self.trigger = rtio.LLRTIOOut(core=self.core, channel=self.rtio_trigger) + self.frame0 = rtio.LLRTIOOut(core=self.core, channel=self.rtio_frame[0]) + self.frame1 = rtio.LLRTIOOut(core=self.core, channel=self.rtio_frame[1]) + self.frame2 = rtio.LLRTIOOut(core=self.core, channel=self.rtio_frame[2]) + + self.frames = [] + self.current_frame = -1 + self.next_sn = -1 + + def create_frame(self): + return _Frame(self.core) + + def prepare(self, *frames): + # prevent previous frames and their segments from + # being (incorrectly) used again + for frame in self.frames: + frame._invalidate() + + self.frames = list(frames) + for fn, frame in enumerate(frames): + frame._prepare(self, fn) + + # TODO: upload to PDQ2 devices \ No newline at end of file From f9942ebce979abc72717d1cdf1287e4739f02101 Mon Sep 17 00:00:00 2001 From: Joe Britton Date: Mon, 2 Feb 2015 19:03:17 -0700 Subject: [PATCH 9/9] add __init__.py for lda --- artiq/devices/lda/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/artiq/devices/lda/__init__.py b/artiq/devices/lda/__init__.py index e69de29bb..59c74f3a7 100644 --- a/artiq/devices/lda/__init__.py +++ b/artiq/devices/lda/__init__.py @@ -0,0 +1 @@ +from .driver import Lda \ No newline at end of file