Spaces:
Sleeping
Sleeping
Commit ·
ff68477
1
Parent(s): 7e03bda
Remove dead code left over from holdover-controller iterations
Browse files- environment: unused θ̂ history buffer and _theta_hat_at helper
- sensors: unused PMUStream.arrived(), unused engage() argument
- pll: unused SRFPLL.snapshot()
- unused imports (pyflakes clean)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- pll_cyber/environment.py +1 -11
- pll_cyber/pll.py +1 -10
- pll_cyber/scenarios.py +2 -2
- pll_cyber/sensors.py +2 -6
pll_cyber/environment.py
CHANGED
|
@@ -18,7 +18,6 @@ from __future__ import annotations
|
|
| 18 |
import math
|
| 19 |
import secrets
|
| 20 |
import uuid
|
| 21 |
-
from collections import deque
|
| 22 |
from typing import Any, Dict, List, Optional
|
| 23 |
|
| 24 |
import numpy as np
|
|
@@ -107,7 +106,6 @@ class PLLCyberEnvironment(Environment[PLLAction, PLLObservation, PLLState]):
|
|
| 107 |
self._desync = _DesyncTracker()
|
| 108 |
self._desync_shadow = _DesyncTracker()
|
| 109 |
self._holdover = DisciplinedHoldover()
|
| 110 |
-
self._theta_hist: deque = deque(maxlen=6) # (t0, θ̂ samples) of recent windows
|
| 111 |
|
| 112 |
self._mode = "normal"
|
| 113 |
self._step = 0
|
|
@@ -243,7 +241,6 @@ class PLLCyberEnvironment(Environment[PLLAction, PLLObservation, PLLState]):
|
|
| 243 |
if holdover: # carry the extrapolated frequency ramp into the next window
|
| 244 |
self._holdover.f_hold += self._holdover.rocof * n * DT
|
| 245 |
rs = self._shadow.run(vm[0], vm[1], vm[2])
|
| 246 |
-
self._theta_hist.append((float(out["t"][0]), r.theta_hat))
|
| 247 |
|
| 248 |
connected = self._mode != "disconnected"
|
| 249 |
had_desync = self._desync.first_step is not None
|
|
@@ -267,17 +264,10 @@ class PLLCyberEnvironment(Environment[PLLAction, PLLObservation, PLLState]):
|
|
| 267 |
self._last_window = window
|
| 268 |
return window
|
| 269 |
|
| 270 |
-
def _theta_hat_at(self, t: float) -> Optional[float]:
|
| 271 |
-
for t0, th in reversed(self._theta_hist):
|
| 272 |
-
i = int(round((t - t0) / DT))
|
| 273 |
-
if 0 <= i < len(th):
|
| 274 |
-
return th[i]
|
| 275 |
-
return None
|
| 276 |
-
|
| 277 |
def _update_holdover(self, t_next: float) -> None:
|
| 278 |
"""Engage / steer the PMU-disciplined oscillator before simulating a window."""
|
| 279 |
if not self._holdover.active:
|
| 280 |
-
self._holdover.engage(
|
| 281 |
self._holdover.update(self._pll, self._pmu, t_next)
|
| 282 |
|
| 283 |
def _finish(self) -> None:
|
|
|
|
| 18 |
import math
|
| 19 |
import secrets
|
| 20 |
import uuid
|
|
|
|
| 21 |
from typing import Any, Dict, List, Optional
|
| 22 |
|
| 23 |
import numpy as np
|
|
|
|
| 106 |
self._desync = _DesyncTracker()
|
| 107 |
self._desync_shadow = _DesyncTracker()
|
| 108 |
self._holdover = DisciplinedHoldover()
|
|
|
|
| 109 |
|
| 110 |
self._mode = "normal"
|
| 111 |
self._step = 0
|
|
|
|
| 241 |
if holdover: # carry the extrapolated frequency ramp into the next window
|
| 242 |
self._holdover.f_hold += self._holdover.rocof * n * DT
|
| 243 |
rs = self._shadow.run(vm[0], vm[1], vm[2])
|
|
|
|
| 244 |
|
| 245 |
connected = self._mode != "disconnected"
|
| 246 |
had_desync = self._desync.first_step is not None
|
|
|
|
| 264 |
self._last_window = window
|
| 265 |
return window
|
| 266 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
def _update_holdover(self, t_next: float) -> None:
|
| 268 |
"""Engage / steer the PMU-disciplined oscillator before simulating a window."""
|
| 269 |
if not self._holdover.active:
|
| 270 |
+
self._holdover.engage()
|
| 271 |
self._holdover.update(self._pll, self._pmu, t_next)
|
| 272 |
|
| 273 |
def _finish(self) -> None:
|
pll_cyber/pll.py
CHANGED
|
@@ -26,7 +26,7 @@ from __future__ import annotations
|
|
| 26 |
|
| 27 |
import math
|
| 28 |
from dataclasses import dataclass, field
|
| 29 |
-
from typing import
|
| 30 |
|
| 31 |
TWO_PI = 2.0 * math.pi
|
| 32 |
SQRT3 = math.sqrt(3.0)
|
|
@@ -100,15 +100,6 @@ class SRFPLL:
|
|
| 100 |
self.vd = 1.0
|
| 101 |
self.vq = 0.0
|
| 102 |
|
| 103 |
-
def snapshot(self) -> Dict[str, float]:
|
| 104 |
-
return {
|
| 105 |
-
"theta_hat": self.theta_hat,
|
| 106 |
-
"integrator": self.integrator,
|
| 107 |
-
"omega_hat": self.omega_hat,
|
| 108 |
-
"f_filtered": self.f_filtered,
|
| 109 |
-
"vd_filtered": self.vd_filtered,
|
| 110 |
-
}
|
| 111 |
-
|
| 112 |
def run(
|
| 113 |
self,
|
| 114 |
va: Sequence[float],
|
|
|
|
| 26 |
|
| 27 |
import math
|
| 28 |
from dataclasses import dataclass, field
|
| 29 |
+
from typing import List, Sequence
|
| 30 |
|
| 31 |
TWO_PI = 2.0 * math.pi
|
| 32 |
SQRT3 = math.sqrt(3.0)
|
|
|
|
| 100 |
self.vd = 1.0
|
| 101 |
self.vq = 0.0
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
def run(
|
| 104 |
self,
|
| 105 |
va: Sequence[float],
|
pll_cyber/scenarios.py
CHANGED
|
@@ -8,8 +8,8 @@ parameters, benign grid events, harmonics, PMU latency and all noise streams.
|
|
| 8 |
from __future__ import annotations
|
| 9 |
|
| 10 |
import math
|
| 11 |
-
from dataclasses import dataclass
|
| 12 |
-
from typing import Any, Dict,
|
| 13 |
|
| 14 |
import numpy as np
|
| 15 |
|
|
|
|
| 8 |
from __future__ import annotations
|
| 9 |
|
| 10 |
import math
|
| 11 |
+
from dataclasses import dataclass
|
| 12 |
+
from typing import Any, Dict, Optional
|
| 13 |
|
| 14 |
import numpy as np
|
| 15 |
|
pll_cyber/sensors.py
CHANGED
|
@@ -7,7 +7,7 @@ from __future__ import annotations
|
|
| 7 |
|
| 8 |
from collections import deque
|
| 9 |
from dataclasses import dataclass
|
| 10 |
-
from typing import Deque,
|
| 11 |
|
| 12 |
import numpy as np
|
| 13 |
|
|
@@ -86,10 +86,6 @@ class PMUStream:
|
|
| 86 |
self._v_acc += float(seg.sum())
|
| 87 |
self._v_n += seg.size
|
| 88 |
|
| 89 |
-
def arrived(self, since: float, now: float) -> List[PMUReport]:
|
| 90 |
-
"""Reports that arrived in (since, now]."""
|
| 91 |
-
return [r for r in self.reports if since < r.t_end + self.latency <= now + 1e-9]
|
| 92 |
-
|
| 93 |
def latest(self, now: float) -> Optional[PMUReport]:
|
| 94 |
"""Most recent report that has arrived by time `now`."""
|
| 95 |
for rep in reversed(self.reports):
|
|
@@ -118,7 +114,7 @@ class DisciplinedHoldover:
|
|
| 118 |
self.rocof = 0.0
|
| 119 |
self.last_arrival_check = -1.0
|
| 120 |
|
| 121 |
-
def engage(self
|
| 122 |
self.active = True
|
| 123 |
self.last_arrival_check = -1.0
|
| 124 |
|
|
|
|
| 7 |
|
| 8 |
from collections import deque
|
| 9 |
from dataclasses import dataclass
|
| 10 |
+
from typing import Deque, Optional, Tuple
|
| 11 |
|
| 12 |
import numpy as np
|
| 13 |
|
|
|
|
| 86 |
self._v_acc += float(seg.sum())
|
| 87 |
self._v_n += seg.size
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
def latest(self, now: float) -> Optional[PMUReport]:
|
| 90 |
"""Most recent report that has arrived by time `now`."""
|
| 91 |
for rep in reversed(self.reports):
|
|
|
|
| 114 |
self.rocof = 0.0
|
| 115 |
self.last_arrival_check = -1.0
|
| 116 |
|
| 117 |
+
def engage(self) -> None:
|
| 118 |
self.active = True
|
| 119 |
self.last_arrival_check = -1.0
|
| 120 |
|