예제 #1
0
    def __init__(self, repo_backend, worker_handlers):
        self.repo_backend = repo_backend
        self.worker_handlers = worker_handlers

        self.cur_rev = self.repo_backend.get_head_rev()
        self.repo_backend.request_rev(self.cur_rev)
        self.explist = Notifier(dict())
        self._scanning = False

        self.status = Notifier({"scanning": False, "cur_rev": self.cur_rev})
예제 #2
0
    def __init__(self, ddb):
        self._broadcaster = Notifier(dict())
        self.local = dict()
        self.archive = dict()

        self.ddb = ddb
        self._broadcaster.publish = ddb.update
예제 #3
0
파일: databases.py 프로젝트: m-labs/artiq
    def __init__(self, persist_file, autosave_period=30):
        self.persist_file = persist_file
        self.autosave_period = autosave_period

        try:
            file_data = pyon.load_file(self.persist_file)
        except FileNotFoundError:
            file_data = dict()
        self.data = Notifier({k: (True, v) for k, v in file_data.items()})
예제 #4
0
    def __init__(self, ridc, worker_handlers, experiment_db):
        self.notifier = Notifier(dict())

        self._pipelines = dict()
        self._worker_handlers = worker_handlers
        self._experiment_db = experiment_db
        self._terminated = False

        self._ridc = ridc
        self._deleter = Deleter(self._pipelines)
예제 #5
0
    def __init__(self, persist_file, autosave_period=30):
        self.persist_file = persist_file
        self.autosave_period = autosave_period

        try:
            file_data = pyon.load_file(self.persist_file)
        except FileNotFoundError:
            file_data = dict()
        self.data = Notifier({
            k: make_dataset(persist=True,
                            value=v["value"],
                            hdf5_options=v["hdf5_options"])
            for k, v in file_data.items()
        })
예제 #6
0
 def setUp(self):
     self.context = Context()
     self.root = SubscriberRoot("ndscan.", self.context)
     self.datasets = Notifier({
         "ndscan.axes": (False, "[]"),
         "ndscan.channels": (False,
                             json.dumps({
                                 "foo": {
                                     "description": "Foo",
                                     "path": "foo",
                                     "type": "int",
                                     "unit": ""
                                 },
                                 "bar": {
                                     "description": "Bar",
                                     "path": "foo",
                                     "type": "int",
                                     "unit": ""
                                 }
                             })),
         ("ndscan." + SCHEMA_REVISION_KEY): (False, SCHEMA_REVISION),
     })
     self.pending_mods = []
     self.datasets.publish = lambda a: self.pending_mods.append(a)
예제 #7
0
파일: databases.py 프로젝트: m-labs/artiq
 def __init__(self, backing_file):
     self.backing_file = backing_file
     self.data = Notifier(device_db_from_file(self.backing_file))
예제 #8
0
    def __init__(self,
                 channels: List[int] = None,
                 num_hw_channels: int = 8,
                 get_temperature: bool = False,
                 get_pressure: bool = False,
                 skip_threshold_nm: float = 10.,
                 install_callback: bool = True,
                 start_publisher: bool = True,
                 publisher_host: str = "*",
                 publisher_port: int = 3281,
                 event_loop: Any = None):
        self.hf_dll = HFDLL()
        channels = channels if channels is not None else [
            i for i in range(1, 9)
        ]
        self._channels = list(set(["ch{}".format(c) for c in channels]))
        self._get_temperature = get_temperature
        self._get_pressure = get_pressure

        self._mode_dict = dict()
        for k, v in self.hf_dll.const.items():
            if k[0:13] == "cmiWavelength" and int(k[13:]) <= num_hw_channels:
                self._mode_dict.update({v: "ch{}".format(k[13:])})
        if self._get_temperature:
            self._mode_dict.update({self.hf_dll.const["cmiTemperature"]: "T"})
        if self._get_pressure:
            self._mode_dict.update({self.hf_dll.const["cmiPressure"]: "p"})

        self._update_valid_modes()

        self._skip_threshold_nm = skip_threshold_nm

        self._callback_installed = False
        self._wavemeter_callback_type = WINFUNCTYPE(c_int, c_long, c_int,
                                                    c_double)
        self._wavemeter_callback_object = self._wavemeter_callback_type(
            self._wavemeter_callback)

        self.wm_status_dict = {
            "autocal_countdown": 0,
            "calibration_timestamp": -1
        }
        self.status_notifier = Notifier(self.wm_status_dict)

        self._autocal_running = False
        self._stop_autocal = True
        self._autocal_timestamp = -1
        self._autocal_retry_interval = 10

        self.latest_data = {n: [(0, -1.)] for n in self._mode_dict.values()}
        # since latest_data can be an error code, store last valid value separately
        # (avoids jump detection getting triggered after each error)
        self._latest_valid_value = {n: -1. for n in self._mode_dict.values()}

        self.notifiers = {
            n: Notifier(self.latest_data[n])
            for n in self._mode_dict.values()
        }
        self.notifiers.update({"status": self.status_notifier})
        self.publisher = Publisher(self.notifiers)
        self._publisher_host = publisher_host
        self._publisher_port = publisher_port

        # one (thread safe) lock per channel to prevent values from stacking up (discard new while channel is busy)
        self._locks = {n: Lock() for n in self._mode_dict.values()}
        self._queue = None  # Janus uses asyncio.get_current_loop() as of version 0.5
        # -> Queue needs to be created from within _new_value_loop

        # interferogram export variables (index is 0 or 1 for the two different interferometers)
        self._pattern_export_enabled = [
            False, False
        ]  # stores whether export has been enabled
        self._pattern_item_type = [None, None]  # data type (ctypes class)
        self._pattern_item_count = [-1, -1]  # number of data points

        self._event_loop = event_loop if event_loop is not None else asyncio.get_event_loop(
        )
        self._event_loop.create_task(self._new_value_loop())
        if install_callback:
            self.install_wavemeter_callback()
        if start_publisher:
            self._event_loop.create_task(self.start_publisher())
예제 #9
0
    def __init__(self):

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

        self.config = load_config(args, "_server")
        self.lasers = self.config["lasers"].keys()

        for laser in self.lasers:
            self.config["lasers"][laser]["lock_ready"] = False

        # connect to hardware
        self.wlm = WLM(args.simulation)

        if self.config.get("osas", "wlm") != "wlm":
            self.osas = NiOSA(self.config["osas"], args.simulation)

        self.exp_min = self.wlm.get_exposure_min()
        self.exp_max = self.wlm.get_exposure_max()
        self.num_ccds = self.wlm.get_num_ccds()

        if self.config["switch"]["type"] == "internal":
            self.switch = self.wlm.get_switch()
        elif self.config["switch"]["type"] == "leoni":
            self.switch = LeoniSwitch(
                self.config["switch"]["ip"], args.simulation)
        else:
            raise ValueError("Unrecognised switch type: {}".format(
                self.config["switch"]["type"]))

        # measurement queue, processed by self.measurement_task
        self.measurement_ids = task_id_generator()
        self.measurements_queued = asyncio.Event()
        self.queue = []

        self.wake_locks = {laser: asyncio.Event() for laser in self.lasers}

        # schedule initial frequency/osa readings all lasers
        self.measurements_queued.set()
        for laser in self.lasers:
            self.queue.append({
                "laser": laser,
                "priority": 0,
                "expiry": time.time(),
                "id": next(self.measurement_ids),
                "get_osa_trace": True,
                "done": asyncio.Event()
            })

        # "notify" interface
        self.laser_db = Notifier(self.config["lasers"])
        self.freq_db = Notifier({laser: {
            "freq": None,
            "status": WLMMeasurementStatus.ERROR,
            "timestamp": 0
        } for laser in self.lasers})
        self.osa_db = Notifier({laser: {
            "trace": None,
            "timestamp": 0
        } for laser in self.lasers})

        self.server_notify = Publisher({
            "laser_db": self.laser_db,  # laser settings
            "freq_db": self.freq_db,  # most recent frequency measurements
            "osa_db": self.osa_db  # most recent osa traces
        })

        # "control" interface
        self.control_interface = ControlInterface(self)
        self.server_control = RPCServer({"control": self.control_interface},
                                        allow_parallel=True)

        self.running = False
예제 #10
0
    def __init__(self,
                 output_min: float = -10.,
                 output_max: float = 10.,
                 warning_margin: float = 0.05,
                 integrator_timeout: int = 10000,
                 cp: float = 0.,
                 ci: float = 0.,
                 setpoint: float = -1.,
                 output_sensitivity: float = 0.,
                 output_offset: float = 0.,
                 integrator_cutoff: float = 0.,
                 startup_locked: bool = False,
                 aux_output_min: float = -10.,
                 aux_output_max: float = 10.,
                 **kwargs):
        super().__init__(**kwargs)
        self.output_min = output_min
        self.output_max = output_max
        self.output_high_alert = output_max - warning_margin * (output_max -
                                                                output_min)
        self.output_low_alert = output_min + warning_margin * (output_max -
                                                               output_min)
        self.integrator_timeout = integrator_timeout
        self.integrator_cutoff = integrator_cutoff

        self.aux_output_min = aux_output_min
        self.aux_output_max = aux_output_max

        if output_offset < output_min or output_offset > output_max:
            logger.warning(
                "Output offset ({}) outside output range ({} < output < {})".
                format(output_offset, output_min, output_max))

        self._status_dict = {
            "latest_value": 0.,
            "latest_timestamp": -1,
            "locked": False,
            "setpoint": setpoint,
            "setpoint_noscan": setpoint,
            "cp": cp,
            "ci": ci,
            "integrator": 0.,
            "output": 0.,
            "output_offset": output_offset,
            "output_rail_warning": False,
            "aux_output": 0.,
            "scanning": False,
            "output_sensitivity": output_sensitivity
        }

        self.status_notifier = Notifier(self._status_dict)

        self._previous_timestamp = -integrator_timeout  # ensure first value is ignored by the integrator
        self._previous_value = 0.

        # lock to keep values from piling up - new values are dropped if the previous update isn't complete
        self._asyncio_lock = asyncio.Lock()

        self._sensitivity_measurement_running = False
        self._sensitivity_measurement_avg_sum = 0
        self._sensitivity_measurement_avg_numvalues = 0

        if startup_locked:
            self.relock()