docs: update documentation files and fix linting issues

This commit is contained in:
2026-07-07 13:32:48 +03:00
parent 9bf1e1333e
commit be3e288e0d
27 changed files with 423 additions and 250 deletions
+24 -21
View File
@@ -52,11 +52,11 @@ or only quality tests (`pytest -m quality`) for fast feedback during development
import numpy as np
import pytest
# ---------------------------------------------------------------------------
# Property tests: positivity
# ---------------------------------------------------------------------------
@pytest.mark.property
def _test_positive_values(component, W, component_name="Component"):
"""Component must return positive values at all W in the physical range.
@@ -82,9 +82,9 @@ def _test_positive_values(component, W, component_name="Component"):
f"W range: [{W_arr.min():.3f}, {W_arr.max():.3f}], "
f"result range: [{np.nanmin(result):.6f}, {np.nanmax(result):.6f}]"
)
assert not np.any(np.isinf(result)), (
f"{component_name}: Inf values found in output."
)
assert not np.any(
np.isinf(result)
), f"{component_name}: Inf values found in output."
assert np.all(result > 0), (
f"{component_name}: non-positive values found. "
f"Min = {np.min(result):.10f} at W = {W_arr[np.argmin(result)][0]:.4f}"
@@ -92,7 +92,9 @@ def _test_positive_values(component, W, component_name="Component"):
@pytest.mark.property
def _test_non_negative_values(component, W, component_name="Component", allow_zero=True):
def _test_non_negative_values(
component, W, component_name="Component", allow_zero=True
):
"""Component must return non-negative values (allows zero at physical boundaries).
Use this for components that can legitimately be zero (e.g., phase_space
@@ -106,17 +108,16 @@ def _test_non_negative_values(component, W, component_name="Component", allow_ze
W_arr = np.asarray(W, dtype=float)
result = component(W_arr)
assert not np.any(np.isnan(result)), (
f"{component_name}: NaN values found in output."
)
assert not np.any(np.isinf(result)), (
f"{component_name}: Inf values found in output."
)
assert not np.any(
np.isnan(result)
), f"{component_name}: NaN values found in output."
assert not np.any(
np.isinf(result)
), f"{component_name}: Inf values found in output."
if allow_zero:
assert np.all(result >= 0), (
f"{component_name}: negative values found. "
f"Min = {np.min(result):.10f}"
f"{component_name}: negative values found. " f"Min = {np.min(result):.10f}"
)
else:
assert np.all(result > 0), (
@@ -129,15 +130,16 @@ def _test_non_negative_values(component, W, component_name="Component", allow_ze
# Property tests: shape preservation
# ---------------------------------------------------------------------------
@pytest.mark.quality
def _test_output_shape_preserved(component, W, component_name="Component"):
"""Output shape must match input shape — no flattening or reshaping."""
W_arr = np.asarray(W, dtype=float)
result = component(W_arr)
assert isinstance(result, np.ndarray), (
f"{component_name}: output is {type(result)}, expected np.ndarray"
)
assert isinstance(
result, np.ndarray
), f"{component_name}: output is {type(result)}, expected np.ndarray"
assert result.shape == W_arr.shape, (
f"{component_name}: shape mismatch. "
f"Input {W_arr.shape} → Output {result.shape}"
@@ -152,15 +154,14 @@ def _test_scalar_input_returns_array(component, W_scalar, component_name="Compon
f"{component_name}: single-element input returned {type(result)}, "
f"expected np.ndarray"
)
assert result.ndim == 1, (
f"{component_name}: expected 1D output, got {result.ndim}D"
)
assert result.ndim == 1, f"{component_name}: expected 1D output, got {result.ndim}D"
# ---------------------------------------------------------------------------
# Property tests: numerical stability
# ---------------------------------------------------------------------------
@pytest.mark.quality
def _test_no_nan_across_range(component, W, component_name="Component"):
"""No NaN values across the entire energy range."""
@@ -208,6 +209,7 @@ def _test_full_range_stability(component, W, component_name="Component"):
# Property tests: type correctness
# ---------------------------------------------------------------------------
@pytest.mark.quality
def _test_output_is_ndarray(component, W, component_name="Component"):
"""Output must be numpy.ndarray for any valid input."""
@@ -224,6 +226,7 @@ def _test_output_is_ndarray(component, W, component_name="Component"):
# Parametrized test templates for quick component integration
# ---------------------------------------------------------------------------
def make_positive_test(component_class, test_params, component_name=None):
"""Factory function to create a parametrized positivity test.
@@ -258,7 +261,7 @@ def make_positive_test(component_class, test_params, component_name=None):
@pytest.mark.parametrize("W", W_values)
def test_positive(component_params, W_arr):
comp = component_class(**component_params)
test_positive_values(comp, W_arr, component_name)
_test_positive_values(comp, W_arr, component_name)
return test_positive
@@ -278,6 +281,6 @@ def make_stability_test(component_class, test_params, component_name=None):
@pytest.mark.parametrize("W", W_values)
def test_stability(component_params, W_arr):
comp = component_class(**component_params)
test_full_range_stability(comp, W_arr, component_name)
_test_full_range_stability(comp, W_arr, component_name)
return test_stability