Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 20 additions & 2 deletions tests/test_saevik2011_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import math
from collections import defaultdict
from dataclasses import replace
from functools import lru_cache

import check_saevik2011 as sv
import numpy as np
Expand Down Expand Up @@ -297,8 +298,8 @@ def __init__(self, name):
def cache_clear(self):
cleared.append(self.name)

monkeypatch.setattr(sv, "gate_values", Spy("gate"))
monkeypatch.setattr(sv, "split_values", Spy("split"))
monkeypatch.setattr(sv, "_gate_values", Spy("gate"))
monkeypatch.setattr(sv, "_split_values", Spy("split"))
monkeypatch.setattr(sv, "cable", Spy("cable"))
monkeypatch.setattr(sv, "TENDONS", sv.TENDONS)
monkeypatch.setattr(sv, "K_ANCHOR_N_M", sv.K_ANCHOR_N_M)
Expand All @@ -309,6 +310,23 @@ def cache_clear(self):
assert cleared == ["cable", "gate", "split"]


def test_default_and_explicit_mu_share_one_cached_result(monkeypatch):
# The report calls gate_values() and audit_values calls gate_values(mu):
# both must reach one cache entry (they were two, and the SV11 predictions
# ran twice per report).
calls = []

@lru_cache(maxsize=2)
def counted(mu):
calls.append(mu)
return {"mu": mu}

monkeypatch.setattr(sv, "_gate_values", counted)
assert sv.gate_values() is sv.gate_values(sv.MU_DECLARED)
assert sv.gate_values(mu=0.2) is sv.gate_values()
assert calls == [sv.MU_DECLARED]


def test_held_inlet_keeps_the_contact_zone_curvature():
# A station in the held inlet takes the held curvature as its history, so
# the normalised shape reproduces the beam's contact-zone curvature.
Expand Down
19 changes: 16 additions & 3 deletions tests/test_validation_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest
import run_validation

import cablexsec as cx
from cablexsec._numba import HAVE_NUMBA

#: Long friction histories run pure Python without numba (minutes per case).
Expand All @@ -17,6 +18,10 @@
pytestmark = pytest.mark.analytical_sanity


def _menard():
return cx.load_cable(cx.menard2023_yaml_path(), geometry_override=None)


@needs_numba
def test_changed_wire_bending_fails_reported_comparison(monkeypatch):
original = run_validation.cx.compute_stress
Expand All @@ -28,7 +33,10 @@ def incorrect_bending(*args, **kwargs):
)

monkeypatch.setattr(run_validation.cx, "compute_stress", incorrect_bending)
row = next(r for r in run_validation._rows() if r.ident == "σ_B")
# The row's own builder, as _rows() calls it: building the whole report
# for one row was the longest test of the suite.
row = run_validation._sigma_b_row(_menard())
assert row.ident == "σ_B"
assert row.status == "FAIL"
# Every state (mu = 0, stuck, slipping) reports the doubled bending.
values = [float(part.split()[-1].rstrip("%")) for part in row.value.split(";")]
Expand All @@ -37,7 +45,8 @@ def incorrect_bending(*args, **kwargs):

@needs_numba
def test_bending_work_report_compares_identical_measured_paths_and_units():
rows = {r.ident: r for r in run_validation._rows()}
rows = {r.ident: r for r in run_validation._bm1_rows(_menard())}
assert set(rows) == {"BM1-loop", "BM1-ID"}
row = rows["BM1-loop"]
assert "matched experimental" in row.target
# The clamping is identified on the measured work of range (a), not taken
Expand All @@ -50,7 +59,11 @@ def test_bending_work_report_compares_identical_measured_paths_and_units():
assert "within 10%" in row.target
assert row.status == "FAIL"
assert rows["BM1-ID"].status == "FAIL"
assert "BM1-loop-uniform" not in rows and "CH-GJ" not in rows
# The retired rows stay out of the report (the recorded report equals
# _rows(); the CI checks that it is current).
report = run_validation.OUT.read_text(encoding="utf-8")
for retired in ("BM1-loop-uniform", "CH-GJ"):
assert f"| {retired} |" not in report


_XSEC = run_validation.Row(
Expand Down
20 changes: 16 additions & 4 deletions validation/scripts/check_saevik2011.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ def use_anchor(k_anchor_N_m: float | None) -> None:

def _clear_results() -> None:
"""Drop every cached result that depends on the module settings."""
gate_values.cache_clear()
split_values.cache_clear()
_gate_values.cache_clear()
_split_values.cache_clear()


@dataclass(frozen=True)
Expand Down Expand Up @@ -654,9 +654,16 @@ def plane_stations() -> tuple[str, ...]:
return tuple(s for s, _x, az in stations() if az in (0.0, 180.0))


@lru_cache(maxsize=2)
def gate_values(mu: float = MU_DECLARED) -> dict:
"""SV11-PLANE and SV11-GJ metrics, bending-plane stations only (cached)."""
return _gate_values(float(mu))


# The caches are keyed on the value of mu: lru_cache on the public functions
# keyed ``gate_values()`` and ``gate_values(MU_DECLARED)`` apart, so the
# report's SV11 rows computed every prediction twice.
@lru_cache(maxsize=2)
def _gate_values(mu: float) -> dict:
plane = plane_stations()
results = [predict_case(c, mu, only=plane) for c in load_cases()]
return {
Expand Down Expand Up @@ -913,7 +920,6 @@ def common(lc: int, v: dict, kind: str) -> float:
SMALL_ANGLE_CASES = (7, 8) # 0.5 and 1 deg


@lru_cache(maxsize=1)
def split_values(mu: float = MU_DECLARED) -> dict:
"""Where the termination increment of SV11 comes from (reported rows).

Expand All @@ -924,7 +930,13 @@ def split_values(mu: float = MU_DECLARED) -> dict:
unchanged; LC 14 and SV11-GJ against the registered correction.
(c) Reach of SV11-PLANE: slip demand ``a_max`` of the correction at the
small angles and the load cases whose sectional ratio is outside the band.
Cached on the value of mu.
"""
return _split_values(float(mu))


@lru_cache(maxsize=1)
def _split_values(mu: float) -> dict:
plane = plane_stations()
reg = gate_values(mu)
ef = metrics(
Expand Down
Loading
Loading