예제 #1
0
class WavemeterArtiqUpdater:
    """
    Simple loop to push new values from the wavemeter server to ARTIQ datasets. Subscribes to a list of channels and
    appends their name to a common prefix to determine the target dataset.

    :param channels: list of channels to handle entries can be of the form <n>, 'ch<n>', 'T', or 'p'
    :param host_artiq: host running the ARTIQ master
    :param port_artiq: port of the ARTIQ master's RPC server
    :param host_wavemeter_pub: host of the wavemeter publisher
    :param port_wavemeter_pub: port of the wavemeter publisher
    :param dataset_name_prefix: prefix for the target dataset names
    :param event_loop: asyncio event loop for the subscribers (defaults to asyncio.get_event_loop())
    """
    def __init__(self, channels: List[Any], host_artiq: str = "::1", port_artiq: int = 3251,
                 host_wavemeter_pub: str = "::1", port_wavemeter_pub: int = 3281,
                 dataset_name_prefix: str = "wavemeter.", event_loop: Any = None):

        self._rpc_client = None
        self._loop = asyncio.get_event_loop() if event_loop is None else event_loop

        self.channels = []
        for ch in channels:
            try:  # accept integer (or string lacking the "ch" prefix) as channel argument
                self.channels.append("ch{}".format(int(ch)))
            except ValueError:
                self.channels.append(ch)

        self.channels = list(set(self.channels))  # remove duplicates

        self.host_artiq = host_artiq
        self.port_artiq = port_artiq
        self.host_wavemeter_pub = host_wavemeter_pub
        self.port_wavemeter_pub = port_wavemeter_pub

        self._wavemeter_clients = []

        self.dataset_name_prefix = dataset_name_prefix

    def run(self):
        self._rpc_client = Client(self.host_artiq, self.port_artiq, "master_dataset_db")

        def callback_factory(client, dataset):
            def callback():
                self._rpc_client.set(dataset, client.value)
            return callback

        for channel in self.channels:
            client = WavemeterClient(channel=channel, host=self.host_wavemeter_pub, port=self.port_wavemeter_pub,
                                     event_loop=self._loop)

            client._new_value_callback = callback_factory(client, self.dataset_name_prefix + channel)

            self._wavemeter_clients.append(client)

        try:
            self._loop.run_forever()
        finally:
            self._rpc_client.close_rpc()
            for cl in self._wavemeter_clients:
                cl.close_subscriber()
예제 #2
0
def main():
    args = get_argparser().parse_args()
    action = args.action.replace("-", "_")
    if action == "show":
        if args.what == "schedule":
            _show_dict(args, "schedule", _show_schedule)
        elif args.what == "log":
            _show_log(args)
        elif args.what == "ccb":
            _show_ccb(args)
        elif args.what == "devices":
            _show_dict(args, "devices", _show_devices)
        elif args.what == "datasets":
            _show_dict(args, "datasets", _show_datasets)
        else:
            raise ValueError
    else:
        port = 3251 if args.port is None else args.port
        target_name = {
            "submit": "master_schedule",
            "delete": "master_schedule",
            "set_dataset": "master_dataset_db",
            "del_dataset": "master_dataset_db",
            "scan_devices": "master_device_db",
            "scan_repository": "master_experiment_db",
            "ls": "master_experiment_db"
        }[action]
        remote = Client(args.server, port, target_name)
        try:
            globals()["_action_" + action](remote, args)
        finally:
            remote.close_rpc()
예제 #3
0
def main():
    args = get_argparser().parse_args()
    init_logger_from_args(args)

    next_poll_time = time.monotonic()
    while True:
        time.sleep(max(0, next_poll_time - time.monotonic()))
        next_poll_time += args.poll_time

        measurements = []
        for server in args.server:
            try:
                client = RPCClient(server, 3251, timeout=args.timeout)
                lasers = client.get_laser_db()
                for laser in lasers:
                    meas = client.get_freq(laser,
                                           age=args.poll_time,
                                           priority=3,
                                           get_osa_trace=False,
                                           blocking=True,
                                           mute=False,
                                           offset_mode=False)
                    status, freq, _ = meas

                    if status != WLMMeasurementStatus.OKAY:
                        logger.info("{}: measurement error")
                        continue

                    f_ref = lasers[laser]["f_ref"]
                    delta = freq - lasers[laser]["f_ref"]
                    measurements.append({
                        "measurement": laser,
                        "fields": {
                            "freq": freq,
                            "f_ref": f_ref,
                            "detuning": delta
                        }
                    })
                    logger.info("{}: freq {} THz, f_ref {} THz, "
                                "detuning {} MHz".format(
                                    laser, freq, f_ref, delta))
            except OSError:
                logger.warning("Error querying server {}".format(server))
            finally:
                client.close_rpc()
        if not measurements:
            continue

        try:
            influx = influxdb.InfluxDBClient(host=args.host_db,
                                             database=args.database,
                                             username=args.user_db,
                                             password=args.password_db)

            influx.write_points(measurements)
        finally:
            influx.close()
예제 #4
0
def main():
    # initialize application
    args = get_argparser().parse_args()
    widget_log_handler = log.init_log(args, "dashboard")

    # load any plugin modules first (to register argument_ui classes, etc.)
    if args.plugin_modules:
        for mod in args.plugin_modules:
            importlib.import_module(mod)

    if args.db_file is None:
        args.db_file = os.path.join(
            get_user_config_dir(),
            "artiq_dashboard_{server}_{port}.pyon".format(
                server=args.server.replace(":", "."), port=args.port_notify))

    app = QtWidgets.QApplication(["ARTIQ Dashboard"])
    loop = QEventLoop(app)
    asyncio.set_event_loop(loop)
    atexit.register(loop.close)
    smgr = state.StateManager(args.db_file)

    # create connections to master
    rpc_clients = dict()
    for target in "schedule", "experiment_db", "dataset_db", "device_db":
        client = AsyncioClient()
        loop.run_until_complete(
            client.connect_rpc(args.server, args.port_control,
                               "master_" + target))
        atexit.register(client.close_rpc)
        rpc_clients[target] = client

    config = Client(args.server, args.port_control, "master_config")
    try:
        server_name = config.get_name()
    finally:
        config.close_rpc()

    disconnect_reported = False

    def report_disconnect():
        nonlocal disconnect_reported
        if not disconnect_reported:
            logging.error("connection to master lost, "
                          "restart dashboard to reconnect")
        disconnect_reported = True

    sub_clients = dict()
    for notifier_name, modelf in (("explist", explorer.Model),
                                  ("explist_status", explorer.StatusUpdater),
                                  ("datasets", datasets.Model),
                                  ("schedule", schedule.Model)):
        subscriber = ModelSubscriber(notifier_name, modelf, report_disconnect)
        loop.run_until_complete(
            subscriber.connect(args.server, args.port_notify))
        atexit_register_coroutine(subscriber.close)
        sub_clients[notifier_name] = subscriber

    broadcast_clients = dict()
    for target in "log", "ccb":
        client = Receiver(target, [], report_disconnect)
        loop.run_until_complete(
            client.connect(args.server, args.port_broadcast))
        atexit_register_coroutine(client.close)
        broadcast_clients[target] = client

    # initialize main window
    main_window = MainWindow(
        args.server if server_name is None else server_name)
    smgr.register(main_window)
    mdi_area = MdiArea()
    mdi_area.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
    mdi_area.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
    main_window.setCentralWidget(mdi_area)

    # create UI components
    expmgr = experiments.ExperimentManager(main_window,
                                           sub_clients["datasets"],
                                           sub_clients["explist"],
                                           sub_clients["schedule"],
                                           rpc_clients["schedule"],
                                           rpc_clients["experiment_db"])
    smgr.register(expmgr)
    d_shortcuts = shortcuts.ShortcutsDock(main_window, expmgr)
    smgr.register(d_shortcuts)
    d_explorer = explorer.ExplorerDock(expmgr, d_shortcuts,
                                       sub_clients["explist"],
                                       sub_clients["explist_status"],
                                       rpc_clients["schedule"],
                                       rpc_clients["experiment_db"],
                                       rpc_clients["device_db"])
    smgr.register(d_explorer)

    d_datasets = datasets.DatasetsDock(sub_clients["datasets"],
                                       rpc_clients["dataset_db"])
    smgr.register(d_datasets)

    d_applets = applets_ccb.AppletsCCBDock(main_window,
                                           sub_clients["datasets"],
                                           extra_substitutes={
                                               "server": args.server,
                                               "port_notify": args.port_notify,
                                               "port_control":
                                               args.port_control,
                                           })
    atexit_register_coroutine(d_applets.stop)
    smgr.register(d_applets)
    broadcast_clients["ccb"].notify_cbs.append(d_applets.ccb_notify)

    d_ttl_dds = moninj.MonInj(rpc_clients["schedule"])
    loop.run_until_complete(d_ttl_dds.start(args.server, args.port_notify))
    atexit_register_coroutine(d_ttl_dds.stop)

    d_schedule = schedule.ScheduleDock(rpc_clients["schedule"],
                                       sub_clients["schedule"])
    smgr.register(d_schedule)

    logmgr = log.LogDockManager(main_window)
    smgr.register(logmgr)
    broadcast_clients["log"].notify_cbs.append(logmgr.append_message)
    widget_log_handler.callback = logmgr.append_message

    # lay out docks
    right_docks = [
        d_explorer, d_shortcuts, d_ttl_dds.ttl_dock, d_ttl_dds.dds_dock,
        d_ttl_dds.dac_dock, d_datasets, d_applets
    ]
    main_window.addDockWidget(QtCore.Qt.RightDockWidgetArea, right_docks[0])
    for d1, d2 in zip(right_docks, right_docks[1:]):
        main_window.tabifyDockWidget(d1, d2)
    main_window.addDockWidget(QtCore.Qt.BottomDockWidgetArea, d_schedule)

    # load/initialize state
    if os.name == "nt":
        # HACK: show the main window before creating applets.
        # Otherwise, the windows of those applets that are in detached
        # QDockWidgets fail to be embedded.
        main_window.show()
    smgr.load()
    smgr.start()
    atexit_register_coroutine(smgr.stop)

    # work around for https://github.com/m-labs/artiq/issues/1307
    d_ttl_dds.ttl_dock.show()
    d_ttl_dds.dds_dock.show()

    # create first log dock if not already in state
    d_log0 = logmgr.first_log_dock()
    if d_log0 is not None:
        main_window.tabifyDockWidget(d_schedule, d_log0)

    if server_name is not None:
        server_description = server_name + " ({})".format(args.server)
    else:
        server_description = args.server
    logging.info("ARTIQ dashboard version: %s", artiq_version)
    logging.info("ARTIQ dashboard connected to moninj_proxy (%s)",
                 server_description)
    # run
    main_window.show()
    loop.run_until_complete(main_window.exit_request.wait())
예제 #5
0
def main():

    args = get_argparser().parse_args()
    init_logger_from_args(args)

    servers = {
        idx: {
            "host": ip,
            "notify": 3250,
            "control": 3251
        }
        for idx, ip in enumerate(args.server)}

    while True:

        measurements = []

        for _, server in servers.items():
            try:
                client = RPCClient(server["host"], server["control"])
                lasers = client.get_laser_db()
                for laser in lasers:
                    meas = client.get_freq(laser,
                                           age=args.poll_time,
                                           priority=3,
                                           get_osa_trace=False,
                                           blocking=True,
                                           mute=False,
                                           offset_mode=False)
                    status, freq, _ = meas

                    if status != WLMMeasurementStatus.OKAY:
                        logger.info("{}: measurement error")
                        continue

                    f_ref = lasers[laser]["f_ref"]
                    delta = freq - lasers[laser]["f_ref"]
                    measurements.append({
                        "measurement": laser,
                        "fields": {
                            "freq": freq,
                            "f_ref": f_ref,
                            "detuning": delta
                        }
                    })
                    logger.info("{}: freq {} THz, f_ref {} THz, "
                                "detuning {} MHz".format(laser,
                                                         freq,
                                                         f_ref,
                                                         delta))
            except OSError:
                logger.warning("Error querying server {}".format(server))
            finally:
                client.close_rpc()

        if measurements == []:
            time.sleep(args.poll_time)
            continue

        try:
            influx = influxdb.InfluxDBClient(
                host="10.255.6.4",
                database=args.database,
                username="******",
                password="******")

            influx.write_points(measurements)
        finally:
            influx.close()
        time.sleep(args.poll_time)
예제 #6
0
def main():
    # connect to labrad
    acxn = connection()
    acxn.connect()
    acxn.add_on_connect("ParameterVault", parameter_vault_connect)
    acxn.add_on_disconnect("ParameterVault", parameter_vault_disconnect)
    # connect to laser room labrad
    laser_room_acxn = connection()
    laser_room_acxn.connect(host=laser_room_ip_address,
                            password=lase_room_password,
                            tls_mode="off")
    # initialize application
    args = get_argparser().parse_args()
    widget_log_handler = log.init_log(args, "dashboard")

    if args.db_file is None:
        args.db_file = os.path.join(
            get_user_config_dir(),
            "artiq_dashboard_{server}_{port}.pyon".format(
                server=args.server.replace(":", "."), port=args.port_notify))

    app = QtWidgets.QApplication(["ARTIQ Dashboard"])
    loop = QEventLoop(app)
    asyncio.set_event_loop(loop)
    atexit.register(loop.close)
    smgr = state.StateManager(args.db_file)

    # create connections to master
    rpc_clients = dict()
    for target in "schedule", "experiment_db", "dataset_db":
        client = AsyncioClient()
        loop.run_until_complete(
            client.connect_rpc(args.server, args.port_control,
                               "master_" + target))
        atexit.register(client.close_rpc)
        rpc_clients[target] = client

    config = Client(args.server, args.port_control, "master_config")
    try:
        server_name = config.get_name()
    finally:
        config.close_rpc()

    disconnect_reported = False

    def report_disconnect():
        nonlocal disconnect_reported
        if not disconnect_reported:
            logging.error("connection to master lost, "
                          "restart dashboard to reconnect")
        disconnect_reported = True

    sub_clients = dict()
    for notifier_name, modelf in (("explist", explorer.Model),
                                  ("explist_status", explorer.StatusUpdater),
                                  ("datasets", datasets.Model),
                                  ("schedule", schedule.Model)):
        subscriber = ModelSubscriber(notifier_name, modelf, report_disconnect)
        loop.run_until_complete(
            subscriber.connect(args.server, args.port_notify))
        atexit_register_coroutine(subscriber.close)
        sub_clients[notifier_name] = subscriber

    broadcast_clients = dict()
    for target in "log", "ccb":
        client = Receiver(target, [], report_disconnect)
        loop.run_until_complete(
            client.connect(args.server, args.port_broadcast))
        atexit_register_coroutine(client.close)
        broadcast_clients[target] = client

    # initialize main window
    tabs = TabWidget()
    main_main_window = MainWindow(
        args.server if server_name is None else server_name)
    main_window = MainWindow(
        args.server if server_name is None else server_name)
    main_main_window.setCentralWidget(tabs)
    smgr.register(tabs)
    smgr.register(main_main_window)
    smgr.register(main_window, "sortoflikeamainwindowbutnotquite")
    mdi_area = MdiArea()
    mdi_area.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
    mdi_area.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
    main_window.setCentralWidget(mdi_area)

    # create UI components
    expmgr = experiments.ExperimentManager(main_window, sub_clients["explist"],
                                           sub_clients["schedule"],
                                           rpc_clients["schedule"],
                                           rpc_clients["experiment_db"])
    smgr.register(expmgr)
    # d_shortcuts = shortcuts.ShortcutsDock(main_window, expmgr)
    # smgr.register(d_shortcuts)
    d_pmt = pmt_control.PMTControlDock(acxn)
    smgr.register(d_pmt)
    d_parameter_editor = parameter_editor.ParameterEditorDock(acxn=acxn)
    smgr.register(d_parameter_editor)
    needs_parameter_vault.append(d_parameter_editor)
    d_explorer = explorer.ExplorerDock(expmgr, None, sub_clients["explist"],
                                       sub_clients["explist_status"],
                                       rpc_clients["schedule"],
                                       rpc_clients["experiment_db"])
    smgr.register(d_explorer)

    d_datasets = datasets.DatasetsDock(sub_clients["datasets"],
                                       rpc_clients["dataset_db"])
    smgr.register(d_datasets)

    d_applets = applets_ccb.AppletsCCBDock(main_window,
                                           sub_clients["datasets"])
    atexit_register_coroutine(d_applets.stop)
    smgr.register(d_applets)
    broadcast_clients["ccb"].notify_cbs.append(d_applets.ccb_notify)

    d_ttl_dds = moninj.MonInj()
    loop.run_until_complete(d_ttl_dds.start(args.server, args.port_notify))
    atexit_register_coroutine(d_ttl_dds.stop)

    d_schedule = schedule.ScheduleDock(rpc_clients["schedule"],
                                       sub_clients["schedule"])
    smgr.register(d_schedule)

    logmgr = log.LogDockManager(main_window)
    smgr.register(logmgr)
    broadcast_clients["log"].notify_cbs.append(logmgr.append_message)
    widget_log_handler.callback = logmgr.append_message

    # lay out docks
    right_docks = [
        d_explorer,
        d_pmt,
        d_parameter_editor,
        d_ttl_dds.ttl_dock,  #d_ttl_dds.dds_dock,
        d_ttl_dds.dac_dock,
        d_datasets,
        d_applets
    ]
    main_window.addDockWidget(QtCore.Qt.RightDockWidgetArea, right_docks[0])
    for d1, d2 in zip(right_docks, right_docks[1:]):
        main_window.tabifyDockWidget(d1, d2)
    main_window.addDockWidget(QtCore.Qt.BottomDockWidgetArea, d_schedule)

    tabs.addTab(main_window, "Control")
    laser_room_tab = LaserRoomTab()
    smgr.register(laser_room_tab)
    tabs.addTab(laser_room_tab, "Laser Room")
    # temp_controller_tab = TempControllerTab()
    # smgr.register(temp_controller_tab)
    # tabs.addTab(temp_controller_tab, "Temperature Controller")
    histograms_tab = ReadoutHistograms(acxn, smgr)
    smgr.register(histograms_tab)
    needs_parameter_vault.append(histograms_tab)
    tabs.addTab(histograms_tab, "Readout")
    drift_tracker_tab = DriftTracker(laser_room_acxn)
    smgr.register(drift_tracker_tab)
    tabs.addTab(drift_tracker_tab, "Drift Tracker")
    pulse_sequence_tab = PulseSequenceTab()
    smgr.register(pulse_sequence_tab)
    tabs.addTab(pulse_sequence_tab, "Pulse Sequence")

    smgr.load()
    smgr.start()
    atexit_register_coroutine(smgr.stop)

    # load/initialize state
    if os.name == "nt":
        # HACK: show the main window before creating applets.
        # Otherwise, the windows of those applets that are in detached
        # QDockWidgets fail to be embedded.
        main_window.show()

    # work around for https://github.com/m-labs/artiq/issues/1307
    d_ttl_dds.ttl_dock.show()
    d_ttl_dds.dds_dock.show()

    # create first log dock if not already in state
    d_log0 = logmgr.first_log_dock()
    if d_log0 is not None:
        main_window.tabifyDockWidget(d_schedule, d_log0)

    if server_name is not None:
        server_description = server_name + " ({})".format(args.server)
    else:
        server_description = args.server
    logging.info("ARTIQ dashboard %s connected to %s", artiq_version,
                 server_description)

    main_main_window.show()
    loop.run_until_complete(main_main_window.exit_request.wait())