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

Re-style codebase: validphys #1737

Merged
merged 8 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@
fbfd77118d60306d4e0ea84b832088eafb8cb867
# CAll black and isort on the last commit
5d9b9e8da6805abd18910cf09314b29a564728a8
# running black in the root vp folder, closuretest, plotoptions and theorycovariance
b9084ce695c49b5645b82436b19ec6cc3bd30280
a5d7385a79ef242e7eb1b1bf7b3746b6ebd6a0d0
3e8cf70c2d3b36d19fcb764599f6dfa6eb924b77
27f25d037854caa7e15496e4c6fa9d520f365ac9
2 changes: 2 additions & 0 deletions doc/sphinx/source/contributing/python-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ integrated with your editor of choice.
- The [`black` code formatter](https://github.com/psf/black) runs almost
without configuration and produces typically good results. It is good to run
it by default, to avoid spending time on formatting (or arguing about it).
- The [`isort`](https://pycqa.github.io/isort/) library sorts imports
alphabetically, and automatically separated into sections and by type.

## Debugging

Expand Down
17 changes: 16 additions & 1 deletion doc/sphinx/source/contributing/rules.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
```eval_rst
.. _rules:
```

# Code development

Code development is carried out using Github.
Expand Down Expand Up @@ -103,11 +104,25 @@ requests:
configuration](https://github.com/NNPDF/nnpdf/blob/master/.pylintrc) to
catch common problems with Python code.
* New Python code should come formatted with
[`black` tool](https://github.com/psf/black).
[`black` tool](https://github.com/psf/black) with [our default
configuration](https://github.com/NNPDF/nnpdf/blob/master/pyproject.toml)
* The imports in Python code should be sorted using the
[`isort`](https://pycqa.github.io/isort/) tool with [our default
configuration](https://github.com/NNPDF/nnpdf/blob/master/pyproject.toml)
* Changes in compiled code should be tested in debug mode, with
the address sanitizer enabled. This is done with the
`-DCMAKE_BUILD_TYPE=Debug -DENABLE_ASAN=ON` options in `cmake`.

Some commits corresponding to major cosmetic changes have been collected in
[`.git-blame-ignore-revs`](
https://docs.github.com/en/repositories/working-with-files/using-files/viewing-a-file#ignore-commits-in-the-blame-view
). It is possible to configure the local git to ignore these commits when
running `git blame`:
```
git config blame.ignoreRevsFile .git-blame-ignore-revs
```


- Regardless of automated tests, always run code with the new changes
manually. This gives great insight into possible pitfalls and areas of
improvement.
Expand Down
3 changes: 2 additions & 1 deletion validphys2/src/validphys/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#We don't want to import stuff here that could slow down the import times
# We don't want to import stuff here that could slow down the import times
from validphys.version import build_version

__version__ = build_version
1 change: 0 additions & 1 deletion validphys2/src/validphys/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import logging

from reportengine import api

from validphys.app import providers
from validphys.config import Config, Environment

Expand Down
18 changes: 7 additions & 11 deletions validphys2/src/validphys/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,16 @@
The entry point of the validphys application is the ``main`` funcion of this
module.
"""
import sys
import os
import logging
import contextlib

import logging
import os
import sys

import lhapdf
from reportengine import app

from reportengine import app
from validphys import mplstyles, uploadutils
from validphys.config import Config, Environment
from validphys import uploadutils
from validphys import mplstyles


providers = [
"validphys.results",
Expand All @@ -37,7 +34,7 @@
"validphys.correlations",
"validphys.chi2grids",
"validphys.eff_exponents",
"validphys.asy_exponents",
"validphys.asy_exponents",
"validphys.paramfits.dataops",
"validphys.paramfits.plots",
"validphys.theorycovariance.construction",
Expand All @@ -55,14 +52,13 @@
"validphys.n3fit_data",
"validphys.mc2hessian",
"reportengine.report",
"validphys.overfit_metric"
"validphys.overfit_metric",
]

log = logging.getLogger(__name__)


class App(app.App):

environment_class = Environment
config_class = Config

Expand Down
45 changes: 18 additions & 27 deletions validphys2/src/validphys/arclength.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
import scipy.integrate as integrate

from reportengine import collect
from reportengine.checks import check_positive, make_argcheck
from reportengine.figure import figure
from reportengine.table import table
from reportengine.checks import check_positive, make_argcheck

from validphys import plotutils
from validphys.checks import check_pdf_normalize_to
from validphys.core import PDF
from validphys.pdfbases import Basis, check_basis
from validphys.pdfgrids import xgrid, xplotting_grid
from validphys.core import PDF
from validphys.checks import check_pdf_normalize_to
from validphys import plotutils


ArcLengthGrid = namedtuple("ArcLengthGrid", ("pdf", "basis", "flavours", "stats"))

Expand All @@ -36,22 +34,22 @@ def arc_lengths(
):
"""
Compute arc lengths at scale Q

set up a grid with three segments and
compute the arclength for each segment.
Note: the variation of the PDF over the grid
is computed by computing the forward differences
between adjacent grid points.


Parameters
----------

pdf : validphys.core.PDF object

Q : float
scale at which to evaluate PDF

basis : default = "flavour"

flavours : default = None
Expand All @@ -60,9 +58,9 @@ def arc_lengths(
-------

validphys.arclength.ArcLengthGrid object
object that contains the PDF, basis, flavours, and computed
object that contains the PDF, basis, flavours, and computed
arc length statistics.

"""

checked = check_basis(basis, flavours)
Expand Down Expand Up @@ -94,12 +92,8 @@ def arc_length_table(arc_lengths):
"""Return a table with the descriptive statistics of the arc lengths
over members of the PDF."""
arc_length_data = arc_lengths.stats.error_members()
arc_length_columns = [
f"${arc_lengths.basis.elementlabel(fl)}$" for fl in arc_lengths.flavours
]
return (
pd.DataFrame(arc_length_data, columns=arc_length_columns).describe().iloc[1:, :]
)
arc_length_columns = [f"${arc_lengths.basis.elementlabel(fl)}$" for fl in arc_lengths.flavours]
return pd.DataFrame(arc_length_data, columns=arc_length_columns).describe().iloc[1:, :]


@figure
Expand All @@ -116,27 +110,24 @@ def plot_arc_lengths(

for ipdf, arclengths in enumerate(pdfs_arc_lengths):
xvalues = np.array(range(len(arclengths.flavours)))
xlabels = [
"$" + arclengths.basis.elementlabel(fl) + "$" for fl in arclengths.flavours
]

xlabels = ["$" + arclengths.basis.elementlabel(fl) + "$" for fl in arclengths.flavours]

ylower, yupper = arclengths.stats.errorbar68()
yvalues = (ylower + yupper) * 0.5
yerr = np.abs(yupper - ylower) * 0.5


if normalize_to is not None:
norm_cv = pdfs_arc_lengths[normalize_to].stats.central_value()
yvalues = np.divide(yvalues, norm_cv)
yerr = np.divide(yerr, norm_cv)

shift = (ipdf - (len(pdfs_arc_lengths) - 1) / 2.0) / 5.0
ax.errorbar(
xvalues + shift,
yvalues,
yerr=yerr,
fmt='',
linestyle = '',
linestyle='',
label=arclengths.pdf.label,
)
ax.set_xticks(xvalues)
Expand All @@ -152,8 +143,8 @@ def integrability_number(
basis: (str, Basis) = "evolution",
flavours: (list, tuple, type(None)) = None,
):
"""Return \sum_i |x_i*f(x_i)|, x_i = {1e-9, 1e-8, 1e-7}
for selected flavours
"""Return \sum_i |x_i*f(x_i)|, x_i = {1e-9, 1e-8, 1e-7}
for selected flavours
"""
checked = check_basis(basis, flavours)
basis, flavours = checked["basis"], checked["flavours"]
Expand Down
Loading