Skip to content

Commit

Permalink
MAINT: address Ruff issues
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed Aug 7, 2024
1 parent aa5634d commit 29b7a3b
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 30 deletions.
2 changes: 1 addition & 1 deletion docs/appendix/serialization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 3 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions docs/uncertainties.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
16 changes: 8 additions & 8 deletions docs/zz.polarization-fit.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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)"
Expand Down
14 changes: 10 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ line-ending = "lf"

[tool.ruff.lint]
ignore = [
"ANN401",
"ANN",
"COM812",
"CPY001",
"D101",
Expand All @@ -239,6 +239,7 @@ ignore = [
"D416",
"DOC",
"E501",
"FBT",
"FURB101",
"FURB103",
"FURB140",
Expand All @@ -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]
Expand Down Expand Up @@ -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",
Expand All @@ -311,6 +316,7 @@ ignore-names = [
"E703",
"E741",
"N8",
"PD901",
"PGH001",
"PLC2701",
"PLR09",
Expand All @@ -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",
Expand Down
16 changes: 8 additions & 8 deletions src/polarimetry/lhcb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
)
Expand Down Expand Up @@ -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]:
Expand All @@ -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:
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_lhcb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 29b7a3b

Please sign in to comment.