Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 27, 2023
1 parent 7ccaffe commit ac34984
Show file tree
Hide file tree
Showing 21 changed files with 38 additions and 93 deletions.
9 changes: 6 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ repos:
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.7.0
hooks:
- id: nbqa-black
additional_dependencies:
- black>=22.1.0
- id: nbqa-pyupgrade
args:
- --py37-plus
Expand All @@ -67,6 +64,11 @@ repos:
rev: 23.9.1
hooks:
- id: black
- id: black-jupyter
args:
- --line-length=85
types_or:
- jupyter

- repo: https://github.com/asottile/blacken-docs
rev: 1.16.0
Expand Down Expand Up @@ -122,6 +124,7 @@ repos:
cell.attachments
cell.metadata.code_folding
cell.metadata.id
cell.metadata.pycharm
cell.metadata.user_expressions
metadata.celltoolbar
metadata.colab.name
Expand Down
1 change: 1 addition & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
],
"unwantedRecommendations": [
"bungcip.better-toml",
"davidanson.vscode-markdownlint",
"ms-python.flake8",
"ms-python.isort",
"ms-python.mypy-type-checker",
Expand Down
12 changes: 3 additions & 9 deletions docs/adr/001/sympy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,7 @@
"\n",
"import sympy as sp\n",
"\n",
"x, A1, mu1, sigma1, A2, mu2, sigma2 = sp.symbols(\n",
" \"x, A1, mu1, sigma1, A2, mu2, sigma2\"\n",
")\n",
"x, A1, mu1, sigma1, A2, mu2, sigma2 = sp.symbols(\"x, A1, mu1, sigma1, A2, mu2, sigma2\")\n",
"gaussian1 = (\n",
" A1 / (sigma1 * sp.sqrt(2.0 * math.pi)) * sp.exp(-((x - mu1) ** 2) / (2 * sigma1))\n",
")\n",
Expand Down Expand Up @@ -595,9 +593,7 @@
}
],
"source": [
"numpy_gauss_sum = sp.lambdify(\n",
" (x, A1, mu1, sigma1, A2, mu2, sigma2), gauss_sum, \"numpy\"\n",
")\n",
"numpy_gauss_sum = sp.lambdify((x, A1, mu1, sigma1, A2, mu2, sigma2), gauss_sum, \"numpy\")\n",
"print(inspect.getsource(numpy_gauss_sum))"
]
},
Expand Down Expand Up @@ -687,9 +683,7 @@
"\n",
"\n",
"def native_jax_gauss_sum(x_, A1_, mu1_, sigma1_, A2_, mu2_, sigma2_):\n",
" return jax_gaussian(x_, A1_, mu1_, sigma1_) + jax_gaussian(\n",
" x_, A2_, mu2_, sigma2_\n",
" )"
" return jax_gaussian(x_, A1_, mu1_, sigma1_) + jax_gaussian(x_, A2_, mu2_, sigma2_)"
]
},
{
Expand Down
8 changes: 2 additions & 6 deletions docs/adr/002/composition.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@
" ff02 = blatt_weisskopf(q0_squared, meson_radius, angular_momentum)\n",
" width = gamma0 * (mass0 / mass) * (ff2 / ff02)\n",
" width = width * sp.sqrt(q_squared / q0_squared)\n",
" return (\n",
" relativistic_breit_wigner(mass, mass0, width) * mass0 * gamma0 * sp.sqrt(ff2)\n",
" )"
" return relativistic_breit_wigner(mass, mass0, width) * mass0 * gamma0 * sp.sqrt(ff2)"
]
},
{
Expand Down Expand Up @@ -364,9 +362,7 @@
"outputs": [],
"source": [
"class DynamicsBuilder(Protocol):\n",
" def __call__(\n",
" self, graph: StateTransitionGraph, edge_id: int\n",
" ) -> DynamicsExpression:\n",
" def __call__(self, graph: StateTransitionGraph, edge_id: int) -> DynamicsExpression:\n",
" ..."
]
},
Expand Down
5 changes: 1 addition & 4 deletions docs/adr/002/function.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,7 @@
" width = width * sp.sqrt(q_squared / q0_squared)\n",
" # Expression\n",
" return (\n",
" RelativisticBreitWigner(mass, mass0, width)\n",
" * mass0\n",
" * gamma0\n",
" * sp.sqrt(ff2)\n",
" RelativisticBreitWigner(mass, mass0, width) * mass0 * gamma0 * sp.sqrt(ff2)\n",
" )\n",
"\n",
" @classmethod\n",
Expand Down
3 changes: 1 addition & 2 deletions docs/report/001.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,7 @@
" arg = expr.args[0]\n",
" x = self._print(arg)\n",
" return (\n",
" f\"select([less({x}, 0), True], [1j * sqrt(-{x}), sqrt({x})],\"\n",
" \" default=nan,)\"\n",
" f\"select([less({x}, 0), True], [1j * sqrt(-{x}), sqrt({x})], default=nan,)\"\n",
" )"
]
},
Expand Down
4 changes: 1 addition & 3 deletions docs/report/002.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -836,9 +836,7 @@
"intensity = LambdifiedFunction(sympy_model, backend=\"jax\")\n",
"data_converter = HelicityTransformer(model.adapter)\n",
"rng = TFUniformRealNumberGenerator(seed=0)\n",
"phsp_sample = generate_phsp(\n",
" 10_000, model.adapter.reaction_info, random_generator=rng\n",
")\n",
"phsp_sample = generate_phsp(10_000, model.adapter.reaction_info, random_generator=rng)\n",
"phsp_set = data_converter.transform(phsp_sample)"
]
},
Expand Down
13 changes: 4 additions & 9 deletions docs/report/003.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,7 @@
"\n",
"iplt.plot(\n",
" plot_domain,\n",
" lambda *args, **kwargs: y_factor\n",
" * np_chew_mandelstam_s_wave(*args, **kwargs).real,\n",
" lambda *args, **kwargs: y_factor * np_chew_mandelstam_s_wave(*args, **kwargs).real,\n",
" controls=controls,\n",
" ylim=ylim,\n",
" alpha=0.7,\n",
Expand All @@ -458,8 +457,7 @@
")\n",
"iplt.plot(\n",
" plot_domain,\n",
" lambda *args, **kwargs: y_factor\n",
" * np_chew_mandelstam_s_wave(*args, **kwargs).imag,\n",
" lambda *args, **kwargs: y_factor * np_chew_mandelstam_s_wave(*args, **kwargs).imag,\n",
" controls=controls,\n",
" ylim=ylim,\n",
" alpha=0.7,\n",
Expand Down Expand Up @@ -739,8 +737,7 @@
"outputs": [],
"source": [
"sigma = {\n",
" l_val: (s_domain - s_thr_val) / np.pi * integral_values[l_val]\n",
" for l_val in l_values\n",
" l_val: (s_domain - s_thr_val) / np.pi * integral_values[l_val] for l_val in l_values\n",
"}\n",
"sigma_scaled = {l_val: 16 * np.pi * sigma[l_val] for l_val in l_values}"
]
Expand Down Expand Up @@ -1064,9 +1061,7 @@
"s_values = np.linspace(-0.15, 1.4, num=200)\n",
"fig, axes = plt.subplots(nrows=2, figsize=(6, 7), sharex=True)\n",
"ax1, ax2 = axes\n",
"fig.suptitle(\n",
" f\"Symbolic dispersion integrals for $m_1={m1_val:.2f}, m_2={m2_val:.2f}$\"\n",
")\n",
"fig.suptitle(f\"Symbolic dispersion integrals for $m_1={m1_val:.2f}, m_2={m2_val:.2f}$\")\n",
"for ax in axes:\n",
" ax.axhline(0, linewidth=0.5, c=\"black\")\n",
" ax.axvline(s_thr_val, **threshold_style)\n",
Expand Down
4 changes: 1 addition & 3 deletions docs/report/005.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,7 @@
],
"source": [
"K_symbol = sp.IndexedBase(\"K\", shape=(n_channels, n_channels))\n",
"K = sp.Matrix(\n",
" [[K_symbol[i, j] for j in range(n_channels)] for i in range(n_channels)]\n",
")\n",
"K = sp.Matrix([[K_symbol[i, j] for j in range(n_channels)] for i in range(n_channels)])\n",
"display(K_symbol[i, j], K)"
]
},
Expand Down
6 changes: 1 addition & 5 deletions docs/report/008.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,7 @@
"source": [
"def replace_indexed_symbols(expression: sp.Expr) -> sp.Expr:\n",
" return expression.subs(\n",
" {\n",
" s: to_symbol(s)\n",
" for s in expression.free_symbols\n",
" if isinstance(s, sp.Indexed)\n",
" }\n",
" {s: to_symbol(s) for s in expression.free_symbols if isinstance(s, sp.Indexed)}\n",
" )"
]
},
Expand Down
4 changes: 1 addition & 3 deletions docs/report/009.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -921,9 +921,7 @@
" c=color,\n",
" rotation=+90,\n",
" )\n",
" threshold_indicators.append(\n",
" (line_thr, line_diff, text_thr, text_diff)\n",
" )\n",
" threshold_indicators.append((line_thr, line_diff, text_thr, text_diff))\n",
" for i, (_, line_diff, _, text_diff) in enumerate(threshold_indicators):\n",
" m_a = kwargs[f\"m_a{i}\"]\n",
" m_b = kwargs[f\"m_b{i}\"]\n",
Expand Down
6 changes: 3 additions & 3 deletions docs/report/010.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,9 @@
" m = sp.Symbol(\"m\", real=True)\n",
" epsilon = sp.Symbol(\"epsilon\", real=True)\n",
" i = sp.Symbol(\"i\", integer=True, negative=False)\n",
" expr = f_vector(\n",
" n_resonances, n_channels, angular_momentum=angular_momentum\n",
" ).doit()[i, 0]\n",
" expr = f_vector(n_resonances, n_channels, angular_momentum=angular_momentum).doit()[\n",
" i, 0\n",
" ]\n",
" expr = symplot.substitute_indexed_symbols(expr)\n",
" expr = expr.subs(m, m + epsilon * sp.I)\n",
" np_expr, sliders = symplot.prepare_sliders(expr, m)\n",
Expand Down
4 changes: 1 addition & 3 deletions docs/report/013.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,7 @@
" intensity_func = create_function(substituted_expression, backend=\"jax\")\n",
" intensities_all = np.array(intensity_func(phsp).real)\n",
" intensities_k = compute_sub_intensities(model, \"K^*\", phsp, full_expression)\n",
" intensities_delta = compute_sub_intensities(\n",
" model, \"Delta^*\", phsp, full_expression\n",
" )\n",
" intensities_delta = compute_sub_intensities(model, \"Delta^*\", phsp, full_expression)\n",
" intensities_lambda = compute_sub_intensities(\n",
" model, \"Lambda^*\", phsp, full_expression\n",
" )\n",
Expand Down
4 changes: 1 addition & 3 deletions docs/report/014.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -853,9 +853,7 @@
"display(\n",
" *[\n",
" graphviz.Source(\n",
" qrules.io.asdot(\n",
" g, collapse_graphs=True, size=4, render_resonance_id=True\n",
" )\n",
" qrules.io.asdot(g, collapse_graphs=True, size=4, render_resonance_id=True)\n",
" )\n",
" for g in reaction_two_resonances.transition_groups\n",
" ]\n",
Expand Down
4 changes: 1 addition & 3 deletions docs/report/015.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,7 @@
" particle_name = state.particle.latex\n",
" s = sp.Rational(state.particle.spin)\n",
" m = sp.Rational(state.spin_projection)\n",
" display(\n",
" Math(Rf\"|s_{i},m_{i}\\rangle=|{s},{m}\\rangle \\quad ({particle_name})\")\n",
" )\n",
" display(Math(Rf\"|s_{i},m_{i}\\rangle=|{s},{m}\\rangle \\quad ({particle_name})\"))\n",
" if functor is formulate_rotation_chain:\n",
" args = (transition, i)\n",
" else:\n",
Expand Down
4 changes: 1 addition & 3 deletions docs/report/017.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,7 @@
"@implement_doit_method\n",
"class Kibble(UnevaluatedExpression):\n",
" def __new__(cls, sigma1, sigma2, sigma3, m0, m1, m2, m3, **hints) -> Kibble:\n",
" return create_expression(\n",
" cls, sigma1, sigma2, sigma3, m0, m1, m2, m3, **hints\n",
" )\n",
" return create_expression(cls, sigma1, sigma2, sigma3, m0, m1, m2, m3, **hints)\n",
"\n",
" def evaluate(self) -> sp.Expr:\n",
" sigma1, sigma2, sigma3, m0, m1, m2, m3 = self.args\n",
Expand Down
8 changes: 2 additions & 6 deletions docs/report/018.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,7 @@
" initial_state_mass=reaction.initial_state[-1].mass,\n",
" final_state_masses={i: p.mass for i, p in reaction.final_state.items()},\n",
")\n",
"transformer = SympyDataTransformer.from_sympy(\n",
" model.kinematic_variables, backend=\"jax\"\n",
")\n",
"transformer = SympyDataTransformer.from_sympy(model.kinematic_variables, backend=\"jax\")\n",
"phsp = phsp_generator.generate(1_000_000, rng)\n",
"phsp = transformer(phsp)"
]
Expand Down Expand Up @@ -354,9 +352,7 @@
"\n",
" Z_weights = griddata(np.transpose([x, y]), weights, (X, Y))\n",
" Z_unweighted, x_edges, y_edges = jnp.histogram2d(x, y, bins=n_bins)\n",
" Z_weighted, x_edges, y_edges = jnp.histogram2d(\n",
" x, y, bins=n_bins, weights=weights\n",
" )\n",
" Z_weighted, x_edges, y_edges = jnp.histogram2d(x, y, bins=n_bins, weights=weights)\n",
" # https://numpy.org/doc/stable/reference/generated/numpy.histogram2d.html\n",
" Z_unweighted = Z_unweighted.T\n",
" Z_weighted = Z_weighted.T\n",
Expand Down
4 changes: 1 addition & 3 deletions docs/report/020.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -812,9 +812,7 @@
],
"source": [
"minuit2 = Minuit2()\n",
"fit_result_with_caching = minuit2.optimize(\n",
" estimator_with_caching, initial_parameters\n",
")\n",
"fit_result_with_caching = minuit2.optimize(estimator_with_caching, initial_parameters)\n",
"fit_result_with_caching"
]
},
Expand Down
23 changes: 5 additions & 18 deletions docs/report/021.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,7 @@
" child1, child2 = decay_products[chain_id]\n",
" for resonance in resonance_list:\n",
" src += create_html_table_row(\n",
" Rf\"\\({resonance.particle.latex} \\to\"\n",
" Rf\" {child1.latex} {child2.latex}\\)\",\n",
" Rf\"\\({resonance.particle.latex} \\to {child1.latex} {child2.latex}\\)\",\n",
" jp(resonance.particle),\n",
" int(1e3 * resonance.particle.mass),\n",
" int(1e3 * resonance.particle.width),\n",
Expand Down Expand Up @@ -512,9 +511,7 @@
" _ν = sp.Symbol(R\"\\nu^{\\prime}\", rational=True)\n",
" _λ = sp.Symbol(R\"\\lambda^{\\prime}\", rational=True)\n",
" return PoolSum(\n",
" A_K[_ν, _λ]\n",
" * Wigner.d(half, λ_Λc, _ν, ζ_0_11)\n",
" * Wigner.d(half, _λ, λ_p, ζ_1_11)\n",
" A_K[_ν, _λ] * Wigner.d(half, λ_Λc, _ν, ζ_0_11) * Wigner.d(half, _λ, λ_p, ζ_1_11)\n",
" + A_Λ[_ν, _λ]\n",
" * Wigner.d(half, λ_Λc, _ν, ζ_0_21)\n",
" * Wigner.d(half, _λ, λ_p, ζ_1_21)\n",
Expand Down Expand Up @@ -2424,16 +2421,8 @@
"for res_list in resonance_particles.values():\n",
" for res in res_list:\n",
" coupling_sliders[res.name] = (\n",
" [\n",
" s\n",
" for n, s in sliders.items()\n",
" if n.endswith(\"_real\") and res.latex in n\n",
" ],\n",
" [\n",
" s\n",
" for n, s in sliders.items()\n",
" if n.endswith(\"_imag\") and res.latex in n\n",
" ],\n",
" [s for n, s in sliders.items() if n.endswith(\"_real\") and res.latex in n],\n",
" [s for n, s in sliders.items() if n.endswith(\"_imag\") and res.latex in n],\n",
" [\n",
" HTMLMath(f\"${latex[n[:-5]]}$\")\n",
" for n in sliders\n",
Expand Down Expand Up @@ -2513,9 +2502,7 @@
" else:\n",
" mesh.set_array(intensity)\n",
" if quiver is None:\n",
" quiver = ax2.quiver(\n",
" Xα, Yα, αx, αz, abs_α, cmap=plt.cm.viridis_r, clim=(0, 1)\n",
" )\n",
" quiver = ax2.quiver(Xα, Yα, αx, αz, abs_α, cmap=plt.cm.viridis_r, clim=(0, 1))\n",
" c_bar = fig.colorbar(quiver, ax=ax2, pad=0.01, fraction=0.0473)\n",
" c_bar.ax.set_ylabel(R\"$\\left|\\vec\\alpha\\right|$\")\n",
" else:\n",
Expand Down
4 changes: 1 addition & 3 deletions docs/report/022.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,7 @@
}
],
"source": [
"B_arrays = jnp.array(\n",
" [[B_funcs[τ, ρ](GRID_SAMPLE) for ρ in range(4)] for τ in range(4)]\n",
")\n",
"B_arrays = jnp.array([[B_funcs[τ, ρ](GRID_SAMPLE) for ρ in range(4)] for τ in range(4)])\n",
"B_norm = B_arrays / B_arrays[0, 0]\n",
"B_arrays.shape"
]
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ target-version = [
]

[tool.nbqa.addopts]
black = ["--line-length=85"]
ruff = [
"--extend-ignore=A003",
"--extend-ignore=B008",
Expand Down

0 comments on commit ac34984

Please sign in to comment.