Skip to content

Commit 897e22e

Browse files
ehsun-shclaude
andcommitted
Apply ruff format, which CI has been failing on for four commits
CI runs `ruff check` and `ruff format --check`; I had only been running the first locally before each push, so formatting drift accumulated unnoticed while every local gate reported green. Four consecutive pushes were red for this and nothing else -- no test or type failure among them. The lesson is about the gate, not the formatting: a local check that is a subset of the CI check will pass while CI fails, and reporting "green" from the subset is reporting something that was not verified. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent cbb8168 commit 897e22e

8 files changed

Lines changed: 14 additions & 33 deletions

File tree

examples/export_ui_data.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,7 @@ def main() -> None:
166166
"counts": np.asarray(histogram.counts).astype(int).tolist(),
167167
"inphase_edges": np.asarray(histogram.inphase_edges).round(5).tolist(),
168168
"quadrature_edges": np.asarray(histogram.quadrature_edges).round(5).tolist(),
169-
"reference": [
170-
[float(p.real), float(p.imag)] for p in np.asarray(histogram.reference)
171-
],
169+
"reference": [[float(p.real), float(p.imag)] for p in np.asarray(histogram.reference)],
172170
},
173171
"eye": {
174172
"counts": np.asarray(eye.counts).astype(int).tolist(),

src/oosim/components/coherent.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,7 @@ def run(self, ctx: SimulationContext, inputs: dict[str, Signal]) -> dict[str, Si
356356
default_offset = 0 if self.matched_filter else sps // 2
357357
offset = default_offset if self.sample_offset < 0 else int(self.sample_offset)
358358
if not 0 <= offset < sps:
359-
raise ValueError(
360-
f"{self.label}: sample_offset must be in [0, {sps}), got {offset}"
361-
)
359+
raise ValueError(f"{self.label}: sample_offset must be in [0, {sps}), got {offset}")
362360

363361
complex_baseband = np.asarray(current_i.samples).astype(np.float64) + 1j * np.asarray(
364362
current_q.samples
@@ -370,9 +368,7 @@ def run(self, ctx: SimulationContext, inputs: dict[str, Signal]) -> dict[str, Si
370368
# every symbol instant but its own — so the neighbours contribute
371369
# nothing to this decision — and it is simultaneously matched to the
372370
# transmitted pulse, which is what makes it optimal against noise.
373-
taps = root_raised_cosine(
374-
self.roll_off, int(self.filter_span), ctx.samples_per_symbol
375-
)
371+
taps = root_raised_cosine(self.roll_off, int(self.filter_span), ctx.samples_per_symbol)
376372
complex_baseband = circular_filter(complex_baseband, taps)
377373

378374
symbols = complex_baseband.reshape(-1, sps)[:, offset]

src/oosim/components/electrical.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,7 @@ def run(self, ctx: SimulationContext, inputs: dict[str, Signal]) -> dict[str, Si
207207
# results. Doing it the other way round would pre-distort a rectangle and
208208
# then smear the correction.
209209
if self.pulse_shaping:
210-
taps = root_raised_cosine(
211-
self.roll_off, int(self.filter_span), ctx.samples_per_symbol
212-
)
210+
taps = root_raised_cosine(self.roll_off, int(self.filter_span), ctx.samples_per_symbol)
213211
waveform = shape_symbols(values, ctx.samples_per_symbol, taps)
214212
else:
215213
waveform = np.repeat(values, ctx.samples_per_symbol)

src/oosim/dsp.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
SYMMETRY_TILT = 0.1
2222

2323

24-
def root_raised_cosine(
25-
roll_off: float, span_symbols: int, samples_per_symbol: int
26-
) -> np.ndarray:
24+
def root_raised_cosine(roll_off: float, span_symbols: int, samples_per_symbol: int) -> np.ndarray:
2725
"""Root-raised-cosine impulse response, normalised to unit energy.
2826
2927
A rectangular symbol has a sinc spectrum, which never ends: it is fine for a

src/oosim/modulation.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ def bits_to_indices(bits: np.ndarray, bits_per_symbol: int) -> np.ndarray:
7474
raise ValueError(f"bits_per_symbol must be >= 1, got {bits_per_symbol}")
7575
if bits.shape[0] % bits_per_symbol:
7676
raise ValueError(
77-
f"{bits.shape[0]} bits does not divide into whole symbols of "
78-
f"{bits_per_symbol} bits"
77+
f"{bits.shape[0]} bits does not divide into whole symbols of {bits_per_symbol} bits"
7978
)
8079

8180
grouped = bits.astype(np.int64).reshape(-1, bits_per_symbol)

tests/test_coherent.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,7 @@ def _beat(signal_state: tuple[complex, complex], lo_state: tuple[complex, comple
317317
ctx = SimulationContext(
318318
bit_rate=10e9, samples_per_symbol=4, sequence_length=64, seed=1, precision="double"
319319
)
320-
receiver = CoherentReceiver(
321-
responsivity=1.0, shot_noise=False, thermal_noise=False, label="rx"
322-
)
320+
receiver = CoherentReceiver(responsivity=1.0, shot_noise=False, thermal_noise=False, label="rx")
323321
n = ctx.num_samples
324322
f0 = C_LIGHT / 1550e-9
325323

@@ -424,9 +422,7 @@ def test_offset_removal_never_makes_the_measurement_worse() -> None:
424422
symbols it becomes radians — turning a 14% EVM into a meaningless one. The
425423
fix is to keep the correction only when it helps, and this asserts it.
426424
"""
427-
_, uncorrected, _ = _run(
428-
bits_per_symbol=4, predistort=False, remove_frequency_offset=False
429-
)
425+
_, uncorrected, _ = _run(bits_per_symbol=4, predistort=False, remove_frequency_offset=False)
430426
_, corrected, _ = _run(bits_per_symbol=4, predistort=False, remove_frequency_offset=True)
431427

432428
assert corrected.evm <= uncorrected.evm + 1e-12
@@ -531,7 +527,7 @@ def test_shot_noise_scales_the_way_the_formula_says() -> None:
531527
def test_snr_is_linear_in_received_power() -> None:
532528
_, low, _ = _run(bits_per_symbol=2, tx_dbm=-40.0, shot_noise=True, sequence_length=8192)
533529
_, high, _ = _run(bits_per_symbol=2, tx_dbm=-37.0, shot_noise=True, sequence_length=8192)
534-
assert high.snr / low.snr == pytest.approx(10.0 ** 0.3, rel=0.08)
530+
assert high.snr / low.snr == pytest.approx(10.0**0.3, rel=0.08)
535531

536532

537533
def test_mer_is_the_evm_stated_in_decibels() -> None:

tests/test_dualpol.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,9 @@ def test_power_is_conserved_from_the_combiner_to_the_rotator() -> None:
464464
combined = PolarizationCombiner(label="pbc").run(
465465
ctx, {"x": cw(0.7, 0.0, ctx), "y": cw(0.4, 0.0, ctx)}
466466
)["out"]
467-
rotated = PolarizationRotator(angle=33.0, phase=48.0, label="rot").run(
468-
ctx, {"in": combined}
469-
)["out"]
467+
rotated = PolarizationRotator(angle=33.0, phase=48.0, label="rot").run(ctx, {"in": combined})[
468+
"out"
469+
]
470470

471471
assert rotated.signal_power() == pytest.approx(0.7**2 + 0.4**2, rel=1e-12)
472472
assert math.isclose(combined.signal_power(), rotated.signal_power(), rel_tol=1e-12)

tests/test_shaping.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,7 @@ def build(
162162
PRBSGenerator(order=23.0, bits_per_symbol=float(bits_per_symbol), label="prbs")
163163
)
164164
mapper = graph.add(
165-
QAMMapper(
166-
bits_per_symbol=float(bits_per_symbol), differential=differential, label="map"
167-
)
165+
QAMMapper(bits_per_symbol=float(bits_per_symbol), differential=differential, label="map")
168166
)
169167
reference = graph.add(
170168
QAMMapper(bits_per_symbol=float(bits_per_symbol), differential=False, label="ref")
@@ -181,9 +179,7 @@ def build(
181179
modulator = graph.add(IQModulator(label="mod"))
182180
lo = graph.add(CWLaser(power=13.0, linewidth=0.0, label="lo"))
183181
receiver = graph.add(CoherentReceiver(shot_noise=False, thermal_noise=False, label="rx"))
184-
sampler = graph.add(
185-
IQSampler(matched_filter=pulse_shaping, roll_off=roll_off, label="smp")
186-
)
182+
sampler = graph.add(IQSampler(matched_filter=pulse_shaping, roll_off=roll_off, label="smp"))
187183

188184
graph.connect(prbs["out"], mapper["in"])
189185
graph.connect(prbs["out"], reference["in"])

0 commit comments

Comments
 (0)