Skip to content

Commit c579dd7

Browse files
authored
Merge pull request #203 from pathsim/feature/mutable-parameter-decorator
Add mutable decorator for runtime parameter reinitialization
2 parents f18b1d0 + 314b616 commit c579dd7

13 files changed

Lines changed: 483 additions & 2 deletions

File tree

src/pathsim/blocks/converters.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
from ._block import Block
1313
from ..utils.register import Register
1414
from ..events.schedule import Schedule
15+
from ..utils.mutable import mutable
1516

1617

1718
# MIXED SIGNAL BLOCKS ===================================================================
1819

20+
@mutable
1921
class ADC(Block):
2022
"""Models an ideal Analog-to-Digital Converter (ADC).
2123
@@ -104,6 +106,7 @@ def __len__(self):
104106
return 0
105107

106108

109+
@mutable
107110
class DAC(Block):
108111
"""Models an ideal Digital-to-Analog Converter (DAC).
109112

src/pathsim/blocks/ctrl.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
from .dynsys import DynamicalSystem
1515

1616
from ..optim.operator import Operator, DynamicOperator
17+
from ..utils.mutable import mutable
1718

1819

1920
# LTI CONTROL BLOCKS (StateSpace subclasses) ============================================
2021

22+
@mutable
2123
class PT1(StateSpace):
2224
"""First-order lag element (PT1).
2325
@@ -65,6 +67,7 @@ def __init__(self, K=1.0, T=1.0):
6567
)
6668

6769

70+
@mutable
6871
class PT2(StateSpace):
6972
"""Second-order lag element (PT2).
7073
@@ -124,6 +127,7 @@ def __init__(self, K=1.0, T=1.0, d=1.0):
124127
)
125128

126129

130+
@mutable
127131
class LeadLag(StateSpace):
128132
"""Lead-Lag compensator.
129133
@@ -180,6 +184,7 @@ def __init__(self, K=1.0, T1=1.0, T2=1.0):
180184
)
181185

182186

187+
@mutable
183188
class PID(StateSpace):
184189
"""Proportional-Integral-Differentiation (PID) controller.
185190
@@ -253,6 +258,7 @@ def __init__(self, Kp=0, Ki=0, Kd=0, f_max=100):
253258
)
254259

255260

261+
@mutable
256262
class AntiWindupPID(PID):
257263
"""Proportional-Integral-Differentiation (PID) controller with anti-windup mechanism (back-calculation).
258264

src/pathsim/blocks/delay.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
from ._block import Block
1313

1414
from ..utils.adaptivebuffer import AdaptiveBuffer
15+
from ..utils.mutable import mutable
1516

1617

1718
# BLOCKS ================================================================================
1819

20+
@mutable
1921
class Delay(Block):
2022
"""Delays the input signal by a time constant 'tau' in seconds.
2123

src/pathsim/blocks/divider.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
from ._block import Block
1616
from ..utils.register import Register
1717
from ..optim.operator import Operator
18+
from ..utils.mutable import mutable
1819

1920

2021
# MISO BLOCKS ===========================================================================
2122

2223
_ZERO_DIV_OPTIONS = ("warn", "raise", "clamp")
2324

2425

26+
@mutable
2527
class Divider(Block):
2628
"""Multiplies and divides input signals (MISO).
2729

src/pathsim/blocks/filters.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414

1515
from .lti import StateSpace
1616
from ..utils.register import Register
17+
from ..utils.mutable import mutable
1718

1819

1920
# FILTER BLOCKS =========================================================================
2021

22+
@mutable
2123
class ButterworthLowpassFilter(StateSpace):
2224
"""Direct implementation of a low pass butterworth filter block.
2325
@@ -52,6 +54,7 @@ def __init__(self, Fc=100, n=2):
5254
super().__init__(omega_c*A, omega_c*B, C, D)
5355

5456

57+
@mutable
5558
class ButterworthHighpassFilter(StateSpace):
5659
"""Direct implementation of a high pass butterworth filter block.
5760
@@ -85,6 +88,7 @@ def __init__(self, Fc=100, n=2):
8588
super().__init__(omega_c*A, omega_c*B, C, D)
8689

8790

91+
@mutable
8892
class ButterworthBandpassFilter(StateSpace):
8993
"""Direct implementation of a bandpass butterworth filter block.
9094
@@ -119,6 +123,7 @@ def __init__(self, Fc=[50, 100], n=2):
119123
super().__init__(*tf2ss(num, den))
120124

121125

126+
@mutable
122127
class ButterworthBandstopFilter(StateSpace):
123128
"""Direct implementation of a bandstop butterworth filter block.
124129
@@ -153,6 +158,7 @@ def __init__(self, Fc=[50, 100], n=2):
153158
super().__init__(*tf2ss(num, den))
154159

155160

161+
@mutable
156162
class AllpassFilter(StateSpace):
157163
"""Direct implementation of a first order allpass filter, or a cascade
158164
of n 1st order allpass filters

src/pathsim/blocks/fir.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
import numpy as np
1111
from collections import deque
1212

13-
from ._block import Block
13+
from ._block import Block
1414
from ..utils.register import Register
15-
from ..events.schedule import Schedule
15+
from ..events.schedule import Schedule
16+
from ..utils.mutable import mutable
1617

1718

1819
# FIR FILTER BLOCK ======================================================================
1920

21+
@mutable
2022
class FIR(Block):
2123
"""Models a discrete-time Finite-Impulse-Response (FIR) filter.
2224

src/pathsim/blocks/lti.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from ..utils.deprecation import deprecated
2323

2424
from ..optim.operator import DynamicOperator
25+
from ..utils.mutable import mutable
2526

2627

2728
# LTI BLOCKS ============================================================================
@@ -169,6 +170,7 @@ def step(self, t, dt):
169170
return self.engine.step(f, dt)
170171

171172

173+
@mutable
172174
class TransferFunctionPRC(StateSpace):
173175
"""This block defines a LTI (MIMO for pole residue) transfer function.
174176
@@ -227,6 +229,7 @@ class TransferFunction(TransferFunctionPRC):
227229
pass
228230

229231

232+
@mutable
230233
class TransferFunctionZPG(StateSpace):
231234
"""This block defines a LTI (SISO) transfer function.
232235
@@ -281,6 +284,7 @@ def __init__(self, Zeros=[], Poles=[-1], Gain=1.0):
281284
super().__init__(sp_SS.A, sp_SS.B, sp_SS.C, sp_SS.D)
282285

283286

287+
@mutable
284288
class TransferFunctionNumDen(StateSpace):
285289
"""This block defines a LTI (SISO) transfer function.
286290

src/pathsim/blocks/samplehold.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99

1010
from ._block import Block
1111
from ..events.schedule import Schedule
12+
from ..utils.mutable import mutable
1213

1314

1415
# MIXED SIGNAL BLOCKS ===================================================================
1516

17+
@mutable
1618
class SampleHold(Block):
1719
"""Samples the inputs periodically and produces them at the output.
1820

src/pathsim/blocks/sources.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from ._block import Block
1515
from ..utils.register import Register
1616
from ..utils.deprecation import deprecated
17+
from ..utils.mutable import mutable
1718
from ..events.schedule import Schedule, ScheduleList
1819
from .._constants import TOLERANCE
1920

@@ -169,6 +170,7 @@ def update(self, t):
169170

170171
# SPECIAL CONTINUOUS SOURCE BLOCKS ======================================================
171172

173+
@mutable
172174
class TriangleWaveSource(Source):
173175
"""Source block that generates an analog triangle wave
174176
@@ -214,6 +216,7 @@ def _triangle_wave(self, t, f):
214216
return 2 * abs(t*f - np.floor(t*f + 0.5)) - 1
215217

216218

219+
@mutable
217220
class SinusoidalSource(Source):
218221
"""Source block that generates a sinusoid wave
219222
@@ -289,6 +292,7 @@ def _gaussian(self, t, f_max):
289292
return np.exp(-(t/tau)**2)
290293

291294

295+
@mutable
292296
class SinusoidalPhaseNoiseSource(Block):
293297
"""Sinusoidal source with cumulative and white phase noise.
294298
@@ -703,6 +707,7 @@ class ChirpSource(ChirpPhaseNoiseSource):
703707

704708
# SPECIAL DISCRETE SOURCE BLOCKS ========================================================
705709

710+
@mutable
706711
class PulseSource(Block):
707712
"""Generates a periodic pulse waveform with defined rise and fall times.
708713
@@ -909,6 +914,7 @@ class Pulse(PulseSource):
909914
pass
910915

911916

917+
@mutable
912918
class ClockSource(Block):
913919
"""Discrete time clock source block.
914920
@@ -970,6 +976,7 @@ class Clock(ClockSource):
970976

971977

972978

979+
@mutable
973980
class SquareWaveSource(Block):
974981
"""Discrete time square wave source.
975982

src/pathsim/blocks/spectrum.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515

1616
from ..utils.realtimeplotter import RealtimePlotter
1717
from ..utils.deprecation import deprecated
18+
from ..utils.mutable import mutable
1819

1920
from .._constants import COLORS_ALL
2021

2122

2223
# BLOCKS FOR DATA RECORDING =============================================================
2324

25+
@mutable
2426
class Spectrum(Block):
2527
"""Block for fourier spectrum analysis (spectrum analyzer).
2628

0 commit comments

Comments
 (0)