From 29b7a3b28ab0c57809e3d47cc9d8e6ec8fab9efc Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Wed, 7 Aug 2024 12:28:03 +0200 Subject: [PATCH] MAINT: address Ruff issues --- docs/appendix/serialization.ipynb | 2 +- docs/conf.py | 9 +++------ docs/uncertainties.ipynb | 4 ++-- docs/zz.polarization-fit.ipynb | 16 ++++++++-------- pyproject.toml | 14 ++++++++++---- src/polarimetry/lhcb/__init__.py | 16 ++++++++-------- tests/test_lhcb.py | 2 +- 7 files changed, 33 insertions(+), 30 deletions(-) diff --git a/docs/appendix/serialization.ipynb b/docs/appendix/serialization.ipynb index b9462770..d369fa4c 100644 --- a/docs/appendix/serialization.ipynb +++ b/docs/appendix/serialization.ipynb @@ -181,7 +181,7 @@ }, "outputs": [], "source": [ - "def render_kilobytes(path, markdown: bool = False) -> str:\n", + "def render_kilobytes(path) -> str:\n", " byt = os.path.getsize(path)\n", " kb = f\"{1e-3 * byt:.0f}\"\n", " return f\"| {{download}}`{path}` | **{kb} kB** |\\n\"\n", diff --git a/docs/conf.py b/docs/conf.py index 6107d6b8..aff85434 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -73,13 +73,10 @@ def execute_pluto_notebooks() -> None: if "EXECUTE_PLUTO" not in os.environ: return if shutil.which("julia") is None: - msg = ( - "Julia is not installed. Please download it at`" - " https://julialang.org/downloads" - ) + msg = "Julia is not installed. Please download it at https://julialang.org/downloads" raise ValueError(msg) result = subprocess.call( - "julia --project=. ./exportnotebooks.jl", # noqa: S607 + "julia --project=. ./exportnotebooks.jl", cwd="../julia", shell=True, ) @@ -277,7 +274,7 @@ def print(self) -> None: } author = "Mikhail Mikhasenko, Remco de Boer, Miriam Fritsch" autodoc_default_options = { - "exclude-members": ", ".join([ + "exclude-members": ", ".join([ # noqa: FLY002 "default_assumptions", "doit", "evaluate", diff --git a/docs/uncertainties.ipynb b/docs/uncertainties.ipynb index 6b327f78..054b2f60 100644 --- a/docs/uncertainties.ipynb +++ b/docs/uncertainties.ipynb @@ -253,7 +253,7 @@ "\n", "\n", "jax_functions = {}\n", - "original_parameters: dict[str, dict[str, complex | float | int]] = {}\n", + "original_parameters: dict[str, dict[str, complex | int]] = {}\n", "progress_bar = tqdm(desc=\"Lambdifying to JAX\", disable=NO_TQDM, total=len(models))\n", "for title, model in models.items():\n", " progress_bar.set_postfix_str(title)\n", @@ -503,7 +503,7 @@ " outside_value=0,\n", " ).doit()\n", " filter_func = create_function(filter_expr, backend=\"jax\")\n", - " return filter_func(contour_sample) # noqa: F821\n", + " return filter_func(phsp)\n", "\n", "\n", "def draw_dalitz_contour(ax, color: str = \"black\", width: float = 0.1, **kwargs) -> None:\n", diff --git a/docs/zz.polarization-fit.ipynb b/docs/zz.polarization-fit.ipynb index 9f35d68c..57212511 100644 --- a/docs/zz.polarization-fit.ipynb +++ b/docs/zz.polarization-fit.ipynb @@ -145,14 +145,14 @@ "outputs": [], "source": [ "def interpolate_intensity(phsp: DataSample, model_id: int) -> jax.Array:\n", - " x = PHSP[\"sigma1\"]\n", - " y = PHSP[\"sigma2\"]\n", + " x = phsp[\"sigma1\"]\n", + " y = phsp[\"sigma2\"]\n", " return jnp.array(create_interpolated_function(model_id, \"intensity\")(x, y))\n", "\n", "\n", "def interpolate_polarimetry_field(phsp: DataSample, model_id: int) -> jax.Array:\n", - " x = PHSP[\"sigma1\"]\n", - " y = PHSP[\"sigma2\"]\n", + " x = phsp[\"sigma1\"]\n", + " y = phsp[\"sigma2\"]\n", " return jnp.array([\n", " create_interpolated_function(model_id, f\"alpha_{i}\")(x, y) for i in \"xyz\"\n", " ])\n", @@ -239,7 +239,7 @@ "P = (+0.2165, +0.0108, -0.665)\n", "I = compute_polarized_intensity(\n", " *P,\n", - " I0=interpolate_intensity(PHSP, model_id=0),\n", + " I0=interpolate_intensity(model_id=0),\n", " alpha=interpolate_polarimetry_field(PHSP, model_id=0),\n", " phsp=PHSP,\n", ")\n", @@ -792,7 +792,7 @@ "outputs": [], "source": [ "def render_propagated_polarization(\n", - " polarizations: list[tuple[float, float, float]], polar: bool\n", + " polarizations: list[tuple[float, float, float]],\n", ") -> str:\n", " nominal_p = extract_polarization(SYST_FIT_RESULTS_AVERAGED[0])\n", " diff_combinatorics = np.abs(np.array(polarizations) - np.array(nominal_p))\n", @@ -812,13 +812,13 @@ "Polarizations from $\\overline{{\\alpha}}$ in cartesian coordinates:\n", "\n", "$$\n", - "{render_propagated_polarization(PROPAGATED_POLARIZATIONS_CARTESIAN, polar=False)}\n", + "{render_propagated_polarization(PROPAGATED_POLARIZATIONS_CARTESIAN)}\n", "$$\n", "\n", "Polarizations from $\\overline{{\\alpha}}$ in polar coordinates:\n", "\n", "$$\n", - "{render_propagated_polarization(PROPAGATED_POLARIZATIONS_POLAR, polar=True)}\n", + "{render_propagated_polarization(PROPAGATED_POLARIZATIONS_POLAR)}\n", "$$\n", "\"\"\"\n", "Markdown(src)" diff --git a/pyproject.toml b/pyproject.toml index 135b619f..5174254f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -225,7 +225,7 @@ line-ending = "lf" [tool.ruff.lint] ignore = [ - "ANN401", + "ANN", "COM812", "CPY001", "D101", @@ -239,6 +239,7 @@ ignore = [ "D416", "DOC", "E501", + "FBT", "FURB101", "FURB103", "FURB140", @@ -261,6 +262,7 @@ select = ["ALL"] task-tags = ["cspell"] [tool.ruff.lint.flake8-builtins] +builtins-allowed-modules = ["io"] builtins-ignorelist = ["display"] [tool.ruff.lint.flake8-comprehensions] @@ -300,8 +302,11 @@ ignore-names = [ [tool.ruff.lint.per-file-ignores] "**/benchmark.ipynb" = ["F821"] +"**/extensions/*.py" = ["ARG001"] +"**/polarimetry.ipynb" = ["SLF001"] +"**/uncertainties.ipynb" = ["ARG001"] +"**/widget.ipynb" = ["ARG001"] "*.ipynb" = [ - "ANN", "B018", "C408", "C90", @@ -311,6 +316,7 @@ ignore-names = [ "E703", "E741", "N8", + "PD901", "PGH001", "PLC2701", "PLR09", @@ -335,15 +341,15 @@ ignore-names = [ "docs/conf.py" = [ "A00", "D100", + "DTZ005", "S404", + "S60", "T201", ] "src/polarimetry/io.py" = ["S301"] # pickle "tests/*" = [ - "ANN", "C408", "D", - "FBT001", "INP001", "N806", "PGH001", diff --git a/src/polarimetry/lhcb/__init__.py b/src/polarimetry/lhcb/__init__.py index 4372f96e..97feb85c 100644 --- a/src/polarimetry/lhcb/__init__.py +++ b/src/polarimetry/lhcb/__init__.py @@ -253,11 +253,11 @@ def __init__( self._parameters = {str(k): v for k, v in symbolic_parameters.items()} @property - def values(self) -> dict[str, complex | float | int]: + def values(self) -> dict[str, complex | int]: return {k: v.value for k, v in self._parameters.items()} @property - def uncertainties(self) -> dict[str, complex | float | int]: + def uncertainties(self) -> dict[str, complex | int]: return {k: v.uncertainty for k, v in self._parameters.items()} def create_distribution( @@ -276,7 +276,7 @@ def load_model_parameters( decay: ThreeBodyDecay, model_id: int | ModelName = 0, particle_definitions: dict[str, Particle] | None = None, -) -> dict[sp.Indexed | sp.Symbol, complex | float]: +) -> dict[sp.Indexed | sp.Symbol, complex]: parameters = load_model_parameters_with_uncertainties( filename, decay, model_id, particle_definitions ) @@ -306,8 +306,8 @@ def load_model_parameters_with_uncertainties( def _smear_gaussian( - parameter_values: dict[str, complex | float], - parameter_uncertainties: dict[str, complex | float], + parameter_values: dict[str, complex], + parameter_uncertainties: dict[str, complex], size: int, seed: int | None = None, ) -> dict[str, np.ndarray]: @@ -320,8 +320,8 @@ def _smear_gaussian( def _create_gaussian_distribution( - mean: complex | float, - std: complex | float, + mean: complex, + std: complex, size: int, seed: int | None = None, ) -> np.ndarray: @@ -351,7 +351,7 @@ def flip_production_coupling_signs( ) if isinstance(obj, ParameterBootstrap): bootstrap = deepcopy(obj) - bootstrap._parameters = _flip_signs(bootstrap._parameters, subsystem_names) # type: ignore[reportPrivateUsage] + bootstrap._parameters = _flip_signs(bootstrap._parameters, subsystem_names) # type: ignore[reportPrivateUsage] # noqa: SLF001 return bootstrap # type:ignore[return-value] if isinstance(obj, dict): return _flip_signs(obj, subsystem_names) # type:ignore[return-value] diff --git a/tests/test_lhcb.py b/tests/test_lhcb.py index 707e9ff5..a9c2dc8a 100644 --- a/tests/test_lhcb.py +++ b/tests/test_lhcb.py @@ -110,7 +110,7 @@ def _load_builder(model_choice: int | ModelName) -> DalitzPlotDecompositionBuild def _load_parameters( model_choice: int | ModelName, -) -> dict[sp.Indexed | sp.Symbol, complex | float]: +) -> dict[sp.Indexed | sp.Symbol, complex]: model_builder = _load_builder(model_choice) return load_model_parameters( filename=MODEL_FILE,