Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add relocking #403

Open
wants to merge 177 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
177 commits
Select commit Hold shift + click to select a range
cba643c
add gui for relocking
bleykauf May 16, 2024
8859652
remove unused parameters and arguments
bleykauf May 16, 2024
fec4ffc
simplify relocking panel
bleykauf May 16, 2024
8baace0
use custom spinboxes in relock panel
bleykauf May 16, 2024
a126a4d
create and link relocking parameters
bleykauf May 16, 2024
0b3f357
fix setting percentages
bleykauf May 21, 2024
e992ae1
add relocking watcher to gateware
bleykauf May 21, 2024
a04fd59
adapt acquisition process
bleykauf May 21, 2024
4c081a8
fix attribute error
bleykauf May 21, 2024
0730522
connect relocking in LinienModule
bleykauf May 21, 2024
fc6c239
add plotting of thresholds
bleykauf May 21, 2024
7ab2d54
fix default parameter
bleykauf May 23, 2024
01fe24b
connect more gui elements and parameters
bleykauf May 23, 2024
3b44ef9
shorten some variable names
bleykauf May 23, 2024
d5a3849
clarify debug message
bleykauf May 23, 2024
47e205a
set relocking connections programmatically
bleykauf May 23, 2024
96a5dc5
fix typing errors
bleykauf May 23, 2024
3a11321
fix plotting of watch lock thresholds
bleykauf May 24, 2024
d2d8d2a
update readme and changelog
bleykauf May 24, 2024
d81dea8
fix link in chnagelog
bleykauf May 24, 2024
d9000bb
remove debugging message
bleykauf May 24, 2024
01a1de5
improve layout of right panel
bleykauf May 24, 2024
e32a21a
fix vertical resolution
bleykauf May 24, 2024
389a3d9
Merge branch 'develop' into feature/add-relock
bleykauf May 27, 2024
536a4ee
use voltage for threshold values
bleykauf May 27, 2024
fb4026d
fix plotting of control thresholds
bleykauf May 27, 2024
8bf4179
update gateware
bleykauf May 28, 2024
ff5ef96
fix plotting of horizontal thresholds
bleykauf May 28, 2024
08d3c2b
widen sweep bar
bleykauf May 28, 2024
2a4e9ab
fix gui
bleykauf May 28, 2024
39b7a09
Merge branch 'develop' into feature/add-relock
bleykauf May 29, 2024
65bedb1
update changelog
bleykauf May 29, 2024
b5148ba
Merge branch 'develop' into feature/add-relock
bleykauf May 29, 2024
e2233b6
Merge branch 'develop' into feature/add-relock
bleykauf May 30, 2024
36b29f9
rotate threshold lines
bleykauf May 31, 2024
7833b3a
Merge branch 'develop' into feature/add-relock
bleykauf Aug 20, 2024
b5dc925
Merge branch 'develop' into feature/add-relock
bleykauf Aug 21, 2024
923db3e
update copyright notice
bleykauf Aug 21, 2024
673c2d5
remove unused attributes
bleykauf Aug 21, 2024
95f572e
fix color settings for threshold lines
bleykauf Aug 22, 2024
082a5fb
remove exposed_is_locked from control
bleykauf Aug 22, 2024
3686786
extend y plot range
bleykauf Aug 22, 2024
59a8d70
update chagenlog
bleykauf Aug 22, 2024
65d2bfb
add date to changelog
bleykauf Aug 22, 2024
3d2990c
improve typehinting
bleykauf Aug 22, 2024
fe39efa
add typehints for autolock
bleykauf Aug 22, 2024
94dc171
fix typehints
bleykauf Aug 22, 2024
49ef02f
fix typehints
bleykauf Aug 22, 2024
bd82be1
simplify assignment
bleykauf Aug 22, 2024
0be15a1
fix typehints
bleykauf Aug 22, 2024
8687093
fix typing errors
bleykauf Aug 26, 2024
20076c6
fixed formatting
bleykauf Aug 26, 2024
6f8172f
do not expose autolock stopping
bleykauf Aug 26, 2024
dbc6f10
better typehints
bleykauf Aug 26, 2024
d1c1906
remove (unused) target line
bleykauf Aug 26, 2024
a0ee443
remove (unused) parameter autolock_initial_sweep_amplitude
bleykauf Aug 26, 2024
e41d8d3
simplify approacher
bleykauf Aug 26, 2024
a3dc1de
fix typing errors
bleykauf Aug 26, 2024
1416706
fix typo
bleykauf Aug 27, 2024
92df784
improve formatting and annotations
bleykauf Aug 27, 2024
e473d45
remove unused argument allow_sweep_speed_change
bleykauf Aug 27, 2024
5ff252d
refactor approacher and optimizer
bleykauf Aug 28, 2024
c98eabd
fix typing errors
bleykauf Aug 28, 2024
8048fc0
fix path to Approacher in tests
bleykauf Aug 28, 2024
2d868be
configure pytest
bleykauf Aug 29, 2024
2671595
improve typing
bleykauf Aug 29, 2024
c1e0dd5
refactor approacher
bleykauf Aug 29, 2024
3c36076
Revert "configure pytest"
bleykauf Aug 29, 2024
376fa5e
fix typo
bleykauf Sep 2, 2024
4886486
refactor autolock
bleykauf Sep 3, 2024
34d7da9
fix attribute error in tests
bleykauf Sep 3, 2024
66928fd
refactor algorithm selection
bleykauf Sep 3, 2024
873fa54
Merge develop branch
bleykauf Sep 3, 2024
41d8cd8
fix changelog
bleykauf Sep 3, 2024
e176327
fix some tests
bleykauf Sep 3, 2024
c2b06e9
fix algorihm selection
bleykauf Sep 3, 2024
df077a3
configure logging handlers in entry points
bleykauf Sep 4, 2024
2d31c4e
fix autolock
bleykauf Sep 4, 2024
2c46212
fix tests
bleykauf Sep 4, 2024
a39ab25
fix algorithm selection test
bleykauf Sep 5, 2024
9e25979
simplify test spectrum generation
bleykauf Sep 9, 2024
ea0d1cc
fix max_val
bleykauf Sep 9, 2024
64b2cc4
simplify autolock test
bleykauf Sep 9, 2024
61f66fb
use fake controls in more tests
bleykauf Sep 9, 2024
a245fcf
subdivide tests
bleykauf Sep 9, 2024
b89337f
use fake controls in more tests
bleykauf Sep 9, 2024
68ddb61
do not print version
bleykauf Sep 9, 2024
3e46a5f
rename method to fix attribute error
bleykauf Sep 9, 2024
35d37d0
remove autolock_percentage parameter
bleykauf Sep 9, 2024
9f5835a
simplify mouse events
bleykauf Sep 10, 2024
4681e46
Revert "simplify mouse events"
bleykauf Sep 10, 2024
e2b59ec
remove double-check of selection_running
bleykauf Sep 10, 2024
3c6532a
rename plotting widget
bleykauf Sep 10, 2024
d3acba6
removed autolock_selection parameter
bleykauf Sep 11, 2024
93f7744
better names for qt elements
bleykauf Sep 11, 2024
e73ede4
link parameters and controls
bleykauf Sep 11, 2024
0b27f43
simplify lock_panel
bleykauf Sep 11, 2024
89e7d64
reorganize optimization_panel
bleykauf Sep 11, 2024
2e43bd9
removed optimization_selection parameter
bleykauf Sep 11, 2024
634c666
reorganize lock_status_panel
bleykauf Sep 11, 2024
3d70714
remove autolock_watching parameter
bleykauf Sep 11, 2024
dcf618c
remove _task_running method
bleykauf Sep 11, 2024
7aab49c
use better names for lock controls
bleykauf Sep 11, 2024
607d8b5
consolidate lock status elements
bleykauf Sep 11, 2024
1ea0d20
create enum for lock status and prepare callbacks
bleykauf Sep 11, 2024
9d1c0ed
remove autolock_preparing parameter
bleykauf Sep 11, 2024
585f8c2
remove autolock_preparing parameter
bleykauf Sep 11, 2024
837ae55
Merge branch 'feature/add-relock' of https://github.com/linien-org/li…
bleykauf Sep 11, 2024
34bb48e
fix typing and improve attribute names
bleykauf Sep 11, 2024
64a2715
do not fail autolock when stopped
bleykauf Sep 12, 2024
04ceaa0
refactor simple/manual lock
bleykauf Sep 12, 2024
db9b56a
replace autolock_ parameters with autolock_status
bleykauf Sep 12, 2024
35355a1
move exposed_start_manual_lock to BaseService class
bleykauf Sep 12, 2024
310f8dd
use AutolockStatus for GUI
bleykauf Sep 12, 2024
9b9b115
fix attribute error
bleykauf Sep 23, 2024
b63bdce
fix missing return statement
bleykauf Sep 23, 2024
6a06405
use value attribute of autolock status enums and parameter
bleykauf Sep 24, 2024
6d99bb6
fix comparison with enum
bleykauf Sep 24, 2024
794ce83
revert AutolockStatus back to IntEnum
bleykauf Sep 24, 2024
9e75738
remove debugging statements
bleykauf Sep 24, 2024
08a8756
some debugging
bleykauf Sep 24, 2024
98efc46
Revert "some debugging"
bleykauf Sep 24, 2024
17faf8b
use 'double' value for comparison of enums
bleykauf Sep 24, 2024
5276c00
fix logging and define logging level at entry points
bleykauf Sep 24, 2024
b36de8e
move enums to own module
bleykauf Sep 24, 2024
1f83977
fix import
bleykauf Sep 24, 2024
198d1c5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 24, 2024
b90000a
fix another import
bleykauf Sep 24, 2024
dfb23ac
Merge branch 'feature/add-relock' of https://github.com/linien-org/li…
bleykauf Sep 24, 2024
1de2727
fix yet another import
bleykauf Sep 24, 2024
3e1deb2
fix yet another import
bleykauf Sep 24, 2024
2677d6c
fix autolock gui
bleykauf Sep 24, 2024
846b9ca
fix display of line selection widget
bleykauf Sep 25, 2024
da74fb5
harmonize interface of robust autolock
bleykauf Sep 25, 2024
6f3c4ec
Revert "harmonize interface of robust autolock"
bleykauf Sep 25, 2024
5ca44c3
use constant for number of required spectra
bleykauf Sep 25, 2024
8e5ff97
set typehint for AUTOLOCK_ALGORITHMS
bleykauf Sep 25, 2024
618a033
use autolock_determine_offset isntead of method arguments for autolock
bleykauf Sep 25, 2024
ebb59a1
use Autolock for manual lock as well
bleykauf Sep 25, 2024
36e1634
fix attribute errors
bleykauf Sep 25, 2024
605c388
change gui for manual/auto lock
bleykauf Sep 25, 2024
9d72739
set autolock_target_position in simple autolock
bleykauf Sep 25, 2024
d6f0abc
fix check for manual mode
bleykauf Sep 26, 2024
c42d35c
fix check for manual mode in relock
bleykauf Sep 26, 2024
e254a33
configure displayed and hidden elements for locking gui
bleykauf Sep 26, 2024
0a28600
integrate LockStatusWidget into LockingPanel
bleykauf Sep 26, 2024
11f9c8b
rotate control thresholds when locking
bleykauf Sep 26, 2024
542ecdb
write lock_lost signa lto parameter
bleykauf Sep 27, 2024
fd6c5f6
add AutolockStatus.LOST
bleykauf Sep 27, 2024
8d7fec3
add parameters enabling lock watching for individual channels
bleykauf Sep 27, 2024
37a0088
fix attribute errors
bleykauf Sep 27, 2024
b67f467
use exposed_write_registers consistently
bleykauf Sep 27, 2024
55079a7
fix callback for slow PID visibility
bleykauf Sep 27, 2024
177e90c
use ui2param for locking panel
bleykauf Sep 27, 2024
ccd8890
remove ready method
bleykauf Sep 27, 2024
74e2516
write registers for watching lock
bleykauf Sep 27, 2024
e73e4d3
fix f-string
bleykauf Sep 27, 2024
36af66b
fix value error and add conversion for threshold values
bleykauf Sep 27, 2024
c613dab
change conversion
bleykauf Sep 27, 2024
6b451b2
Revert "change conversion"
bleykauf Sep 27, 2024
6725366
temporarily remove settings for control registers
bleykauf Sep 27, 2024
84c9a00
use twos_complement for thresholds
bleykauf Sep 27, 2024
afcf424
fix twos_complement for thresholds
bleykauf Sep 27, 2024
cefb43a
change conversion
bleykauf Sep 27, 2024
e0018dc
limit values
bleykauf Sep 27, 2024
e84c895
remove twos_complement
bleykauf Sep 27, 2024
56d9dc7
fix typehint
bleykauf Oct 18, 2024
e76a3a7
fix typehint
bleykauf Oct 18, 2024
5dd14a7
increase width of CSRStorage for relock settings
bleykauf Oct 18, 2024
17e9968
Remove lock_lost paramter
bleykauf Oct 18, 2024
fac44d9
only check for lost lock if lock is running
bleykauf Oct 18, 2024
aa278c6
more specific error handling
bleykauf Oct 18, 2024
c255a87
improve locking buttons
bleykauf Oct 18, 2024
0c23d03
add relock button
bleykauf Oct 18, 2024
d4d73fc
add relock button (gui components)
bleykauf Oct 18, 2024
1ac40b4
convert should_watch to int
bleykauf Oct 18, 2024
0406ddc
fix attribute error
bleykauf Oct 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
* Added loss of lock detection and automatic relocking by @bleykauf in https://github.com/linien-org/linien/pull/403

### Changed
* Color settings are now named by @bleykauf in https://github.com/linien-org/linien/pull/426
* Replaced parameters `autolock_running`, `autolock_failed`, `autolock_locked`, `autolock_retrying` with `autolock_status`

### Deprecated
* Unused parameters `autolock_initial_sweep_amplitude`, `autolock_watching`, `autolock_preparing` were removed.
* Removed parameters `autolock_selection` and `optimization_selection` that were only used by the GUI.
* Deprecated `exposed_start_lock`, use `exposed_start_manual_lock` instead.
* Deprecated parameter `automatic_mode`, use `autolock_mode_preference` instead.

### Fixed
* Corrected scripting examples by @kongmunist in https://github.com/linien-org/linien/pull/428

## [2.1.0] - 2024-08-15


## [2.1.0]

### Added
* Show differences when local and remote parameters do not match by @bleykauf in https://github.com/linien-org/linien/pull/400
* Show voltage on the x-axis when sweeping by @bleykauf in https://github.com/linien-org/linien/pull/404
* Added loss-of-lock detection and automatic relocking by @bleykauf in https://github.com/linien-org/linien/pull/403

### Changed
* Switched to Tableau color scheme and make colors consistent, i.e. signals have the same color while sweeping and when locked. By @bleykauf in https://github.com/linien-org/linien/pull/419.
Expand Down Expand Up @@ -177,9 +191,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

* The parameters that deal with the sweep / ramp have been renamed:
* "center" is now "sweep_center"
* "ramp_amplitude", "ramp_speed" and * * "autolock_initial_ramp_amplitude" are now "sweep_amplitude" and * "sweep_speed" and "autolock_initial_sweep_amplitude", respectively
There is a new boolean parameter "sweep_pause".
* `center` is now `sweep_center`
* `ramp_amplitude`, `ramp_speed` and `autolock_initial_ramp_amplitude` are now `sweep_amplitude` and `sweep_speed` and `autolock_initial_sweep_amplitude`, respectively
* There is a new boolean parameter `sweep_pause`.


## [0.4.3] - 2021-06-22
Expand Down
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ Features
automatically lock to it. This algorithm is built to be noise and jitter tolerant.
- **IQ demodulation**: Optimize demodulation phase in an instant
- **Noise analysis**: Record power spectral density (PSD) of the error signal for analyzing noise of the locked laser and for optimizing PID parameters
- **Lock detection**: Linien is capable of detecting loss of lock (temporarily disabled, use [v0.3.2](https://github.com/linien-org/linien/releases/tag/v0.3.2) if you rely in this feature
- **Automatic relocking**: if lock is lost, it relocks autonomously (temporarily disabled, use [v0.3.2](https://github.com/linien-org/linien/releases/tag/v0.3.2) if you rely in this feature)
- **Lock detection**: Linien is capable of detecting loss of lock
- **Automatic relocking**: if lock is lost, it relocks autonomously
- **Machine learning** is used to tune the spectroscopy parameters in order to optimize the signal
- **Remote-controllable**: the client libraries can be used to control or monitor the spectroscopy lock with Python.
- **Combined FMS+MTS**: Linien supports dual-channel spectroscopy that can be
Expand Down Expand Up @@ -256,7 +256,7 @@ print(c.parameters.modulation_frequency.value / MHz)
c.parameters.modulation_amplitude.value = 1 * Vpp
# in the line above, we set a parameter. This is not written directly to the
# FPGA, though. In order to do this, we have to call write_registers():
c.connection.root.write_registers()
c.connection.root.exposed_write_registers()

# additionally set ANALOG_OUT_1 to 1.2 volts DC (you can use this to control other devices of your experiment)
c.parameters.analog_out_1.value = 1.2 / ANALOG_OUT_V
Expand All @@ -272,7 +272,7 @@ c.parameters.gpio_n_out.value = 0b11110000 # 4 on, 4 off
c.parameters.gpio_p_out.value = 0b01010101 # 4 on, 4 off

# again, we have to call write_registers in order to write the data to the FPGA
c.connection.root.write_registers()
c.connection.root.exposed_write_registers()

# it is also possible to set up a callback function that is called whenever a
# parameter changes (remember to call `check_for_changed_parameters()` periodically)
Expand Down Expand Up @@ -317,7 +317,7 @@ plt.show()

For a full list of parameters that can be controlled or accessed have a
look at
[parameters.py](https://github.com/linien-org/linien/blob/master/linien-server/linien_server/parameters.py). Remember that changed parameters are not written to the FPGA unless `c.connection.root.write_registers()` is called.
[parameters.py](https://github.com/linien-org/linien/blob/master/linien-server/linien_server/parameters.py). Remember that changed parameters are not written to the FPGA unless `c.connection.root.exposed_write_registers()` is called.

### Run the autolock

Expand All @@ -329,7 +329,7 @@ import numpy as np

from linien_client.connection import LinienClient
from linien_client.device import Device
from linien_common.common import AutolockMode
from linien_common.enums import AutolockMode

from matplotlib import pyplot as plt
from time import sleep
Expand Down Expand Up @@ -499,8 +499,13 @@ Copyright © 2014-2015 Robert Jördens\
Copyright © 2018-2022 Benjamin Wiegand\
Copyright © 2021-2024 Bastian Leykauf\
Copyright © 2022 Christian Freier\
<<<<<<< HEAD
Copyright © 2023-2024 Doron Behar

=======
Copyright © 2023-2024 Doron Behar\
Copyright © 2024 Andy Kong
>>>>>>> develop

Linien is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Expand Down
15 changes: 14 additions & 1 deletion gateware/linien_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with Linien. If not, see <http://www.gnu.org/licenses/>.

from linien_common.common import OutputChannel
from linien_common.enums import OutputChannel
from migen import (
Array,
Cat,
Expand All @@ -38,6 +38,7 @@
from .logic.limit import LimitCSR
from .logic.modulate import Modulate
from .logic.pid import PID
from .logic.relocking import RelockWatcher
from .logic.sweep import SweepCSR
from .lowlevel.analog import PitayaAnalog
from .lowlevel.crg import CRG
Expand Down Expand Up @@ -90,6 +91,7 @@ def init_submodules(self, width, signal_width):
self.submodules.limit_fast2 = LimitCSR(width=width, guard=5)
self.submodules.pid = PID(width=signal_width)
self.submodules.autolock = FPGAAutolock(width=width, max_delay=8191)
self.submodules.relock_watcher = RelockWatcher(width=width)

def connect_pid(self):
# pid is not started directly by `request_lock` signal. Instead, `request_lock`
Expand Down Expand Up @@ -163,6 +165,7 @@ def __init__(self, platform):
width, signal_width, coeff_width, chain_factor_bits, platform
)
self.connect_everything(width, signal_width, coeff_width, chain_factor_bits)
self.connect_relock_watcher()

def init_submodules(
self, width, signal_width, coeff_width, chain_factor_bits, platform
Expand Down Expand Up @@ -411,6 +414,16 @@ def connect_everything(self, width, signal_width, coeff_width, chain_factor_bits
self.logic.limit_fast2.x.eq(fast_outs[1]),
]

def connect_relock_watcher(self):
self.comb += [
self.logic.relock_watcher.locked.eq(
self.logic.autolock.lock_running.status
),
self.logic.relock_watcher.error_signal.eq(self.logic.pid.input),
self.logic.relock_watcher.monitor_signal.eq(self.fast_b.adc),
self.logic.relock_watcher.control_signal.eq(self.logic.pid.pid_out),
]


class DummyID(Module, AutoCSR):
def __init__(self):
Expand Down
9 changes: 5 additions & 4 deletions gateware/logic/autolock.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
# You should have received a copy of the GNU General Public License
# along with Linien. If not, see <http://www.gnu.org/licenses/>.

from linien_common.common import AUTOLOCK_MAX_N_INSTRUCTIONS, AutolockMode
from linien_common.common import AUTOLOCK_MAX_N_INSTRUCTIONS
from linien_common.enums import AutolockMode
from migen import Array, If, Module, Signal, bits_for
from misoc.interconnect.csr import AutoCSR, CSRStatus, CSRStorage

Expand Down Expand Up @@ -70,7 +71,7 @@ def __init__(self, width=14, N_points=16383, max_delay=16383):

class SimpleAutolock(Module, AutoCSR):
"""
The operation of fast autolock is simple: wait until the sweep has reached a certain
The operation of this autolock is simple: wait until the sweep has reached a certain
point and turn on the lock. This method is well suited for systems with not too much
jitter.
"""
Expand Down Expand Up @@ -118,8 +119,8 @@ def __init__(self, width=14, N_points=16383, max_delay=16383):
peak_height_bit, x_data_length_bit = self.init_csr(N_points)
self.init_inout_signals(width)

# is the autolock actively trying to detect peaks? This is set to true
# if lock is requested and once the sweep is at start
# Is the autolock actively trying to detect peaks? This is set to true if lock
# is requested and once the sweep is at start.
watching = Signal()

# the following signals are property of the peak that the autolock is trying to
Expand Down
84 changes: 84 additions & 0 deletions gateware/logic/relocking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# This file is part of Linien and based on redpid.
#
# Copyright (C) 2016-2024 Linien Authors (https://github.com/linien-org/linien#license)

#
# Linien is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Linien is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Linien. If not, see <http://www.gnu.org/licenses/>.

from migen import If, Module, Signal
from misoc.interconnect.csr import AutoCSR, CSRStatus, CSRStorage


class RelockWatcher(Module, AutoCSR):
def __init__(self, width=14, coeff_width=14):
self.locked = Signal()
self.should_watch = Signal()

self.error_signal = Signal((width, True))
self.control_signal = Signal((width, True))
self.monitor_signal = Signal((width, True))

self.lock_lost = CSRStatus()

channels = (
("control", self.control_signal),
("error", self.error_signal),
("monitor", self.monitor_signal),
)
lock_lost_signal = Signal()
for channel_name, channel in channels:
channel_watcher = RelockWatcherChannel(width)
setattr(self.submodules, channel_name, channel_watcher)
should_watch_name = "should_watch_" + channel_name
should_watch_csr = CSRStorage(width, name=should_watch_name)
setattr(self, should_watch_name, should_watch_csr)
min_name = "min_" + channel_name
min_csr = CSRStorage(width, name=min_name)
setattr(self, min_name, min_csr)
max_name = "max_" + channel_name
max_csr = CSRStorage(width, name=max_name)
setattr(self, max_name, max_csr)

self.comb += [
channel_watcher.input.eq(channel),
channel_watcher.locked.eq(self.locked),
channel_watcher.should_watch.eq(should_watch_csr.storage),
channel_watcher.min.eq(min_csr.storage),
channel_watcher.max.eq(max_csr.storage),
]

lock_lost_signal |= channel_watcher.lock_lost

self.comb += [self.lock_lost.status.eq(lock_lost_signal)]


class RelockWatcherChannel(Module):
def __init__(self, width):
self.locked = Signal()
self.lock_lost = Signal()

self.should_watch = Signal()
self.min = Signal((width, True))
self.max = Signal((width, True))
self.input = Signal((width, True))

self.sync += [
If(
self.locked & self.should_watch,
If(
(self.input > self.max) | (self.input < self.min),
self.lock_lost.eq(1),
),
).Else(self.lock_lost.eq(0))
]
18 changes: 0 additions & 18 deletions linien-client/linien_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,7 @@

import importlib.metadata
import logging
from logging.handlers import RotatingFileHandler

from linien_common.config import LOG_FILE_PATH

__version__ = importlib.metadata.version("linien-client") # noqa: F401

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

file_handler = RotatingFileHandler(str(LOG_FILE_PATH), maxBytes=1000000, backupCount=10)
file_handler.setLevel(logging.DEBUG)
file_formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
file_handler.setFormatter(file_formatter)
logger.addHandler(file_handler)

console_handler = logging.StreamHandler()
console_handler.setLevel(logging.DEBUG)
console_formatter = logging.Formatter("%(name)-30s %(levelname)-8s %(message)s")
console_handler.setFormatter(console_formatter)
logger.addHandler(console_handler)
1 change: 0 additions & 1 deletion linien-client/linien_client/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
from .remote_parameters import RemoteParameters

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)


class ServiceWithAuth(rpyc.Service):
Expand Down
3 changes: 1 addition & 2 deletions linien-client/linien_client/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from .device import Device

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)


def read_remote_version(
Expand All @@ -50,7 +49,7 @@ def read_remote_version(
connect_kwargs={"password": device.password},
) as conn:
result = conn.run(
'python3 -c "import linien_server; print(linien_server.__version__);"',
'python3 -c "import linien_server;"',
out_stream=out_stream,
err_stream=out_stream,
warn=True,
Expand Down
1 change: 0 additions & 1 deletion linien-client/linien_client/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from linien_common.config import SERVER_PORT, USER_DATA_PATH

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)


def generate_random_key():
Expand Down
12 changes: 6 additions & 6 deletions linien-client/linien_client/remote_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ def add_callback(self, callback: Callable, call_immediately: bool = False):
Register a callback function that is called whenever the parameter changes.
"""

if self.name not in self.parent._callbacks and not self.use_cache:
if self.name not in self.parent.callbacks and not self.use_cache:
# Make sure that the server knows that we want to be notified about changes.
# Parameters that use the cache are already registered, see `__init__`.
self.parent._listeners_pending_remote_registration.append(self.name)

self.parent._callbacks.setdefault(self.name, [])
self.parent._callbacks[self.name].append(callback)
self.parent.callbacks.setdefault(self.name, [])
self.parent.callbacks[self.name].append(callback)

if call_immediately:
callback(self.value)
Expand Down Expand Up @@ -106,7 +106,7 @@ def __init__(self, remote: LinienControlService, uuid: str, use_cache: bool):
self._async_listener_registering: Union[AsyncResult, None] = None

self._listeners_pending_remote_registration: List[str] = []
self._callbacks: Dict[str, List[Callable]] = {}
self.callbacks: Dict[str, List[Callable]] = {}

# mimic functionality of `parameters.Parameters`:
all_parameters = self.remote.exposed_init_parameter_sync(self.uuid)
Expand Down Expand Up @@ -201,8 +201,8 @@ def check_for_changed_parameters(self) -> None:

# Iterate over all changed parameters and call their callback functions.
for param_name, value in queue:
if param_name in self._callbacks:
for callback in self._callbacks[param_name]:
if param_name in self.callbacks:
for callback in self.callbacks[param_name]:
callback(value)

if (
Expand Down
18 changes: 0 additions & 18 deletions linien-common/linien_common/__init__.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
import logging
from logging.handlers import RotatingFileHandler

import importlib_metadata

from .config import LOG_FILE_PATH

__version__ = importlib_metadata.version("linien-common") # noqa: F401

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

file_handler = RotatingFileHandler(str(LOG_FILE_PATH), maxBytes=1000000, backupCount=10)
file_handler.setLevel(logging.DEBUG)
file_formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
file_handler.setFormatter(file_formatter)
logger.addHandler(file_handler)

console_handler = logging.StreamHandler()
console_handler.setLevel(logging.DEBUG)
console_formatter = logging.Formatter("%(name)-30s %(levelname)-8s %(message)s")
console_handler.setFormatter(console_formatter)
logger.addHandler(console_handler)
Loading
Loading