Пример #1
0
    def _gen(self):
        yield Msg('hxn_next_scan_id')
        yield Msg('configure', self.flyer, **self._configure_kw)
        self._update_md()
        yield Msg('open_run', **self.md)

        for subscan in range(self.flyer.scan_count):
            yield from flyer_plan(self.flyer, subscan=subscan)

        yield Msg('close_run')
Пример #2
0
def stepscan(det, motor):
    yield Msg('open_run')
    for i in range(-5, 5):
        yield Msg('create', name='primary')
        yield Msg('set', motor, i)
        yield Msg('trigger', det)
        yield Msg('read', motor)
        yield Msg('read', det)
        yield Msg('save')
    yield Msg('close_run')
Пример #3
0
def flyer_plan(flyer, subscan, *, name='primary'):
    '''Plan to run a flyer'''
    with elapsed_time_context('checkpoint'):
        yield Msg('checkpoint')
        # start the flyscan
        with elapsed_time_context('flyscan'):
            yield Msg('kickoff',
                      flyer,
                      subscan=subscan,
                      group='fly-kickoff',
                      name=name)
            yield Msg('wait', None, 'fly-kickoff')

            # wait for the collect to be ready
            yield Msg('complete', flyer, group='fly-collect')
            yield Msg('wait', None, 'fly-collect')

        yield Msg('collect', flyer)
Пример #4
0
def test_zmq(fresh_RE):
    # COMPONENT 1
    # Run a 0MQ proxy on a separate process.
    def start_proxy():
        Proxy(5567, 5568).start()

    proxy_proc = multiprocessing.Process(target=start_proxy, daemon=True)
    proxy_proc.start()
    time.sleep(5)  # Give this plenty of time to start up.

    # COMPONENT 2
    # Run a Publisher and a RunEngine in this main process.

    RE = fresh_RE
    p = Publisher(RE, '127.0.0.1:5567')  # noqa

    # COMPONENT 3
    # Run a RemoteDispatcher on another separate process. Pass the documents
    # it receives over a Queue to this process, so we can count them for our
    # test.

    def make_and_start_dispatcher(queue):
        def put_in_queue(name, doc):
            print('putting ', name, 'in queue')
            queue.put((name, doc))

        d = RemoteDispatcher('127.0.0.1:5568')
        d.subscribe('all', put_in_queue)
        print("REMOTE IS READY TO START")
        d._loop.call_later(9, d.stop)
        d.start()

    queue = multiprocessing.Queue()
    dispatcher_proc = multiprocessing.Process(target=make_and_start_dispatcher,
                                              daemon=True,
                                              args=(queue, ))
    dispatcher_proc.start()
    time.sleep(5)  # As above, give this plenty of time to start.

    # Generate two documents. The Publisher will send them to the proxy
    # device over 5567, and the proxy will send them to the
    # RemoteDispatcher over 5568. The RemoteDispatcher will push them into
    # the queue, where we can verify that they round-tripped.

    local_accumulator = []

    def local_cb(name, doc):
        local_accumulator.append((name, doc))

    RE([Msg('open_run'), Msg('close_run')], local_cb)
    time.sleep(1)

    # Get the two documents from the queue (or timeout --- test will fail)
    remote_accumulator = []
    for i in range(2):
        remote_accumulator.append(queue.get(timeout=2))
    p.close()
    proxy_proc.terminate()
    dispatcher_proc.terminate()
    proxy_proc.join()
    dispatcher_proc.join()
    assert remote_accumulator == local_accumulator
Пример #5
0
 def counting_stepscan(det, motor):
     yield Msg('subscribe', None, 'start', c)
     yield from stepscan(det, motor)
Пример #6
0
 def counting_stepscan(det, motor):
     yield Msg("subscribe", None, c, "start")
     yield from stepscan(det, motor)
Пример #7
0
def test_zmq(fresh_RE):
    # COMPONENT 1
    # Run a forwarder device on a separate process.
    # This is a variant of the code in bluesky/examples/forwarder_device.py,
    # but with hard-coded config.

    def forwarder():
        import zmq

        def main(frontend_port, backend_port):
            print('Starting forwarder device...')
            try:
                context = zmq.Context(1)
                # Socket facing clients
                frontend = context.socket(zmq.SUB)
                frontend.bind("tcp://*:%d" % frontend_port)

                frontend.setsockopt_string(zmq.SUBSCRIBE, "")

                # Socket facing services
                backend = context.socket(zmq.PUB)
                backend.bind("tcp://*:%d" % backend_port)

                print('Receiving on %d; publishing on %d' % (frontend_port,
                                                             backend_port))
                zmq.device(zmq.FORWARDER, frontend, backend)
            except Exception as exc:
                print('Exception in forwarder device:', exc)
            finally:
                print('Closing forwarder device...')
                frontend.close()
                backend.close()
                context.term()

        main(5567, 5568)
    forwarder_proc = multiprocessing.Process(target=forwarder, daemon=True)
    forwarder_proc.start()
    time.sleep(5)  # Give this plenty of time to start up.

    # COMPONENT 2
    # Run a Publisher and a RunEngine in this main process.

    RE = fresh_RE
    p = Publisher(RE, '127.0.0.1', 5567)  # noqa

    # COMPONENT 3
    # Run a RemoteDispatcher on another separate process. Pass the documents
    # it receives over a Queue to this process, so we can count them for our
    # test.

    def make_and_start_dispatcher(queue):
        def put_in_queue(name, doc):
            print('putting ', name, 'in queue')
            queue.put((name, doc))
        d = RemoteDispatcher('127.0.0.1', 5568)
        d.subscribe('all', put_in_queue)
        print("REMOTE IS READY TO START")
        d._loop.call_later(9, d.stop)
        d.start()

    queue = multiprocessing.Queue()
    dispatcher_proc = multiprocessing.Process(target=make_and_start_dispatcher,
                                              daemon=True, args=(queue,))
    dispatcher_proc.start()
    time.sleep(5)  # As above, give this plenty of time to start.

    # Generate two documents. The Publisher will send them to the forwarder
    # device over 5567, and the forwarder will send them to the
    # RemoteDispatcher over 5568. The RemoteDispatcher will push them into
    # the queue, where we can verify that they round-tripped.

    local_accumulator = []

    def local_cb(name, doc):
        local_accumulator.append((name, doc))

    RE([Msg('open_run'), Msg('close_run')], local_cb)
    time.sleep(1)

    # Get the two documents from the queue (or timeout --- test will fail)
    remote_accumulator = []
    for i in range(2):
        remote_accumulator.append(queue.get(timeout=2))
    p.close()
    forwarder_proc.terminate()
    dispatcher_proc.terminate()
    forwarder_proc.join()
    dispatcher_proc.join()
    assert remote_accumulator == local_accumulator
Пример #8
0
def simple_scan(motor):
    yield Msg('open_run')
    yield Msg('set', motor, 5)
    yield Msg('read', motor)
    yield Msg('close_run')
Пример #9
0
    def _gen(self):
        # over-rides default gen
        yield Msg('hxn_next_scan_id')
        yield Msg('configure', self.flyer, **self._configure_kw)
        self._update_md()

        if len(self.flyer._subscans) != len(self.slow_steps):
            # fun hack: duplicate the sub-scan configuration for all
            # slow-steps in the flyer. this will allow liveimage to work
            # without modification.
            self.flyer._subscans = ([self.flyer._subscans[0]] *
                                    len(self.slow_steps))

        yield Msg('open_run', **self.md)

        if self.slow_flyer is not None:
            yield Msg('kickoff', self.slow_flyer, group='slowflyer-kickoff')
            yield Msg('wait', None, 'slowflyer-kickoff')

        for subscan, pt in enumerate(iter(self.slow_steps)):
            for mtr, pos in pt.items():
                yield Msg('set', mtr, pos, group='step-motors')
            yield Msg('wait', None, 'step-motors')
            yield from flyer_plan(self.flyer, subscan=subscan)

        if self.slow_flyer is not None:
            yield Msg('complete', self.slow_flyer, group='slowflyer-collect')
            yield Msg('wait', None, 'slowflyer-collect')
            yield Msg('collect', self.slow_flyer)

        yield Msg('close_run')