Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce docformatter and ruff #405

Merged
merged 7 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
37 changes: 15 additions & 22 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,24 @@ repos:
hooks:
- id: pycln
args: [--config=pyproject.toml]
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.8.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.5
hooks:
- id: black
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/PyCQA/docformatter
rev: v1.7.5
hooks:
- id: docformatter
additional_dependencies: [tomli]
args: [--in-place, --config, ./pyproject.toml]
- repo: https://github.com/asottile/blacken-docs
rev: 1.18.0
hooks:
- id: blacken-docs
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
args: ["--profile", "black"]
- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
hooks:
- id: pyupgrade
- repo: https://github.com/pycqa/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle
files: ^src/
args: ["--add-ignore=D107,D105"]
additional_dependencies:
- toml
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
hooks:
Expand All @@ -53,14 +46,14 @@ repos:
- repo: local
hooks:
- id: fmt
name: fmt
name: cargo fmt
description: Format Rust files with cargo fmt.
entry: cargo fmt --
language: system
files: ^crates/.*\.rs$
args: []
- id: clippy
name: clippy
name: cargo clippy
description: Check Rust files with cargo clippy.
entry: cargo clippy --all-targets --all-features -- -Dclippy::all
pass_filenames: false
Expand Down
5 changes: 2 additions & 3 deletions benchmarks/CT14_bench.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
Benchmark CT14 pdf family
"""Benchmark CT14 pdf family.

- as far as I understand, the llo family uses LO splitting functions with LO alphas evolution,
whereas the lo family uses LO splitting functions with NLO alphas evolution
Expand All @@ -25,7 +24,7 @@


class BenchmarkCT14(Runner):
"""Benchmark CT14 pdfs"""
"""Benchmark CT14 pdfs."""

external = "LHAPDF"

Expand Down
7 changes: 2 additions & 5 deletions benchmarks/CT18_bench.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
"""
Benchmark CT18 pdf family

"""
"""Benchmark CT18 pdf family."""

from banana import register

Expand All @@ -23,7 +20,7 @@


class BenchmarkCT18(Runner):
"""Benchmark CT18 pdfs"""
"""Benchmark CT18 pdfs."""

external = "LHAPDF"

Expand Down
4 changes: 2 additions & 2 deletions benchmarks/DSSV_bench.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Benchmark DSSV pdf family.

Note that the PDF set is private, but can be obtained from the
authors upon request.
Note that the PDF set is private, but can be obtained from the authors
upon request.
"""

from banana import register
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/FF_LHAPDF_bench.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Benchmark FFs from LHAPDF"""
"""Benchmark FFs from LHAPDF."""

from banana import register

Expand Down
7 changes: 2 additions & 5 deletions benchmarks/HERA20_bench.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
"""
Benchmark HERAPDF2.0 pdf family

"""
"""Benchmark HERAPDF2.0 pdf family."""

from banana import register

Expand All @@ -27,7 +24,7 @@


class BenchmarkHERA20(Runner):
"""Benchmark HERA20 pdfs"""
"""Benchmark HERA20 pdfs."""

external = "LHAPDF"

Expand Down
16 changes: 6 additions & 10 deletions benchmarks/NNPDF_bench.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Benchmark NNPDF pdf family
"""
"""Benchmark NNPDF pdf family."""

from banana import register

Expand All @@ -11,9 +9,7 @@


class BenchmarkNNPDF(Runner):
"""
Globally set the external program to LHAPDF
"""
"""Globally set the external program to LHAPDF."""

external = "LHAPDF"

Expand Down Expand Up @@ -49,7 +45,7 @@ def skip_pdfs(self, _theory):


class BenchmarkNNPDF31(BenchmarkNNPDF):
"""Benchmark NNPDF3.1"""
"""Benchmark NNPDF3.1."""

def benchmark_nlo(self, Q0=1.65, mugrid=(10,)):
theory_card = {
Expand All @@ -64,7 +60,7 @@ def benchmark_nlo(self, Q0=1.65, mugrid=(10,)):


class BenchmarkNNPDF31_luxqed(BenchmarkNNPDF):
"""Benchmark NNPDF3.1_luxqed"""
"""Benchmark NNPDF3.1_luxqed."""

def benchmark_nnlo(self, Q0=1.65, mugrid=(10,)):
theory_card = {
Expand All @@ -91,7 +87,7 @@ def benchmark_nnlo(self, Q0=1.65, mugrid=(10,)):


class BenchmarkNNPDF40(BenchmarkNNPDF):
"""Benchmark NNPDF4.0"""
"""Benchmark NNPDF4.0."""

def benchmark_nlo(self, Q0=1.65, mugrid=(10,)):
theory_card = {
Expand Down Expand Up @@ -119,7 +115,7 @@ def benchmark_nnlo(self, Q0=1.65, mugrid=(10,)):


class BenchmarkNNPDFpol11(BenchmarkNNPDF):
"""Benchmark NNPDFpol11"""
"""Benchmark NNPDFpol11."""

def benchmark(self, Q0=1.65, mugrid=(10,)):
theory_card = {
Expand Down
42 changes: 19 additions & 23 deletions benchmarks/apfel_bench.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Benchmark EKO to Apfel
"""
"""Benchmark EKO to Apfel."""

import numpy as np
from banana import register
Expand All @@ -21,9 +19,7 @@ def tolist(input_dict):


class ApfelBenchmark(Runner):
"""
Globally set the external program to Apfel
"""
"""Globally set the external program to Apfel."""

external = "apfel"

Expand All @@ -37,7 +33,7 @@ def skip_pdfs(_theory):


class BenchmarkVFNS(ApfelBenchmark):
"""Benchmark VFNS"""
"""Benchmark VFNS."""

vfns_theory = {
"FNS": "ZM-VFNS",
Expand All @@ -59,7 +55,7 @@ class BenchmarkVFNS(ApfelBenchmark):
vfns_theory = tolist(vfns_theory)

def benchmark_plain(self, pto):
"""Plain configuration"""
"""Plain configuration."""

th = self.vfns_theory.copy()
th.update({"PTO": [pto]})
Expand All @@ -68,7 +64,7 @@ def benchmark_plain(self, pto):
)

def benchmark_sv(self, pto, svmode):
"""Scale Variation"""
"""Scale Variation."""

th = self.vfns_theory.copy()
th.update(
Expand All @@ -86,7 +82,7 @@ def benchmark_sv(self, pto, svmode):
)

def benchmark_kthr(self, pto):
"""Threshold scale different from heavy quark mass"""
"""Threshold scale different from heavy quark mass."""

th = self.vfns_theory.copy()
th.update(
Expand All @@ -101,10 +97,10 @@ def benchmark_kthr(self, pto):
)

def benchmark_msbar(self, pto):
"""
MSbar heavy quark mass scheme
when passing kthr != 1 both apfel and eko use ``kThr * msbar``,
as thr scale, where ``msbar`` is the usual ms_bar solution.
"""MSbar heavy quark mass scheme when passing kthr != 1 both apfel and
eko use ``kThr * msbar``, as thr scale, where ``msbar`` is the usual
ms_bar solution.

However apfel and eko manage the alpha_s thr differently:
apfel uses the given mass parameters as thr multiplied by the kthr,
while in eko only the already computed thr matters, so the
Expand Down Expand Up @@ -132,7 +128,7 @@ def benchmark_msbar(self, pto):


class BenchmarkFFNS(ApfelBenchmark):
"""Benckmark FFNS"""
"""Benckmark FFNS."""

ffns_theory = {
"FNS": "FFNS",
Expand All @@ -150,7 +146,7 @@ class BenchmarkFFNS(ApfelBenchmark):
ffns_theory = tolist(ffns_theory)

def benchmark_plain(self, pto):
"""Plain configuration"""
"""Plain configuration."""

th = self.ffns_theory.copy()
th.update({"PTO": [pto]})
Expand All @@ -159,7 +155,7 @@ def benchmark_plain(self, pto):
)

def benchmark_plain_pol(self, pto):
"""Plain configuration"""
"""Plain configuration."""

th = self.ffns_theory.copy()
th.update({"PTO": [pto]})
Expand All @@ -169,7 +165,7 @@ def benchmark_plain_pol(self, pto):
self.run(cartesian_product(th), operators.build(op), ["ToyLH"])

def benchmark_sv(self, pto, svmode):
"""Scale Variation"""
"""Scale Variation."""

ts = []
th = self.ffns_theory.copy()
Expand Down Expand Up @@ -198,7 +194,7 @@ def benchmark_sv(self, pto, svmode):


class BenchmarkFFNS_qed(ApfelBenchmark):
"""Benckmark FFNS"""
"""Benckmark FFNS."""

ffns_theory = {
"Qref": 91.1870,
Expand All @@ -223,7 +219,7 @@ class BenchmarkFFNS_qed(ApfelBenchmark):
ffns_theory = tolist(ffns_theory)

def benchmark_plain(self, pto, qed):
"""Plain configuration"""
"""Plain configuration."""

th = self.ffns_theory.copy()
th.update({"PTO": [pto], "QED": [qed]})
Expand All @@ -240,7 +236,7 @@ def benchmark_plain(self, pto, qed):
)

def benchmark_sv(self, pto, qed, svmode):
"""Scale Variation"""
"""Scale Variation."""

ts = []
th = self.ffns_theory.copy()
Expand Down Expand Up @@ -277,7 +273,7 @@ def benchmark_sv(self, pto, qed, svmode):


class BenchmarkVFNS_qed(ApfelBenchmark):
"""Benckmark FFNS"""
"""Benckmark FFNS."""

vfns_theory = {
"Qref": 91.1870,
Expand All @@ -301,7 +297,7 @@ class BenchmarkVFNS_qed(ApfelBenchmark):
vfns_theory = tolist(vfns_theory)

def benchmark_plain(self, pto, qed):
"""Plain configuration"""
"""Plain configuration."""

th = self.vfns_theory.copy()
th.update({"PTO": [pto], "QED": [qed]})
Expand Down
8 changes: 5 additions & 3 deletions benchmarks/eko/benchmark_alphaem.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""This module benchmarks alpha_em against alphaQED23 and validphys.

alphaQED23 can be obtained from http://www-com.physik.hu-berlin.de/~fjeger/software.html .
alphaQED23 can be obtained from
http://www-com.physik.hu-berlin.de/~fjeger/software.html
.
"""

import numpy as np
Expand All @@ -14,7 +16,7 @@
@pytest.mark.isolated
class BenchmarkCouplings:
def test_alphaQED_high(self):
"""testing aginst alphaQED23 for high Q values"""
"""Testing aginst alphaQED23 for high Q values."""
alphaQED23 = np.array(
[
0.0075683,
Expand Down Expand Up @@ -90,7 +92,7 @@ def test_alphaQED_low(self):
np.testing.assert_allclose(alphaQED23, alpha_eko, rtol=3.2e-3)

def test_validphys(self):
"""testing aginst validphys"""
"""Testing aginst validphys."""
alpha_vp = np.array(
[
0.007408255774054356,
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/eko/benchmark_msbar_evolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ def benchmark_APFEL_msbar_solution(
)

def benchmark_msbar_solution_kthr(self, theory_card: TheoryCard):
"""
With this test you can see that in EKO
the solution value of mb is not affected by "kbThr",
since mb is searched with an Nf=5 larger range.
"""With this test you can see that in EKO the solution value of mb is
not affected by "kbThr", since mb is searched with an Nf=5 larger
range.

While in Apfel this doesn't happen.
"""
update_theory(theory_card)
Expand Down
Loading
Loading