From c48429bf79e3f19aa46f80a25eae02e95865351a Mon Sep 17 00:00:00 2001 From: t7phy Date: Tue, 18 Jun 2024 15:48:09 +0200 Subject: [PATCH 1/5] fix the toyFF and add tests --- src/banana/toy.py | 26 +++++++++++++------------- tests/test_toy.py | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/banana/toy.py b/src/banana/toy.py index 300bf88..54fa529 100644 --- a/src/banana/toy.py +++ b/src/banana/toy.py @@ -163,22 +163,22 @@ class toyFF_unpolarized(MockPDF): """ToyFF from 1501.00494, Eqn. 3.3 and 3.4""" def __init__(self): - N_v = 0.401 - N_s = 0.094 - N_g = 0.238 + N_v = 1.00881 + N_s = 17.6255 + N_g = 438.189 - D_u = lambda x: N_v * x ** (-0.963) * (1 - x) ** 1.370 - D_ub = lambda x: N_s * x**0.718 * (1 - x) ** 6.266 - D_g = lambda x: N_g * x**1.943 * (1 - x) ** 8 + xD_u = lambda x: x * N_v * x ** (-0.963) * (1 - x) ** 1.370 + xD_ub = lambda x: x * N_s * x**0.718 * (1 - x) ** 6.266 + xD_g = lambda x: x * N_g * x**1.943 * (1 - x) ** 8 self.xpdf = {} - self.xpdf[-3] = D_ub - self.xpdf[-2] = D_ub - self.xpdf[-1] = D_u - self.xpdf[0] = D_g - self.xpdf[1] = D_ub - self.xpdf[2] = D_u - self.xpdf[3] = D_ub + self.xpdf[-3] = xD_ub + self.xpdf[-2] = xD_ub + self.xpdf[-1] = xD_u + self.xpdf[0] = xD_g + self.xpdf[1] = xD_ub + self.xpdf[2] = xD_u + self.xpdf[3] = xD_ub self.xpdf[21] = self.xpdf[0] self.name = "ToyFF_unpolarized" diff --git a/tests/test_toy.py b/tests/test_toy.py index 973c6c6..5d4b58e 100644 --- a/tests/test_toy.py +++ b/tests/test_toy.py @@ -1,6 +1,8 @@ from banana import toy +from scipy.integrate import quad pdf = toy.mkPDF("", 0) +ff = toy.mkPDF("ToyFF_unpolarized", 0) def test_alpha(): @@ -24,3 +26,15 @@ def test_xf(): for x in [0.1, 0.2]: assert pdf.xfxQ2(pid, x, Q2) == pdf.xfxQ(pid, x, Q2) assert pdf.xfxQ2(pid, 2, Q2) == 0 + + +def test_toyFF(): + """Test the ToyFF_unpolarized with Eqn. 3.4 from 1501.00494.""" + + val_u = round(quad(lambda x: ff.xfxQ2(2, x, 1), 0, 1)[0], 3) + val_d = round(quad(lambda x: ff.xfxQ2(1, x, 1), 0, 1)[0], 3) + val_g = round(quad(lambda x: ff.xfxQ2(21, x, 1), 0, 1)[0], 3) + + assert val_u == 0.401 + assert val_d == 0.094 + assert val_g == 0.238 From 07e81f887ca9a81a04de8712fc7131815ce70704 Mon Sep 17 00:00:00 2001 From: t7phy Date: Tue, 18 Jun 2024 15:54:18 +0200 Subject: [PATCH 2/5] isort and add scipy as dependency --- docs/source/conf.py | 3 ++- pyproject.toml | 1 + src/banana/data/db.py | 1 - tests/test_toy.py | 3 ++- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 0060d88..dfd837b 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -124,7 +124,8 @@ def run_apidoc(_): import sys # pylint: disable=import-outside-toplevel - from sphinx.ext.apidoc import main # pylint: disable=import-outside-toplevel + from sphinx.ext.apidoc import \ + main # pylint: disable=import-outside-toplevel sys.path.append(str(here.parent)) # 'banana' diff --git a/pyproject.toml b/pyproject.toml index 89fb60b..00a6644 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,6 +36,7 @@ PyYAML = "^6.0" click = "^8.0.3" pendulum = "^3.0.0" appdirs = "^1.4.4" +scipy = "^1.11.1" [tool.poetry.group.docs] optional = true diff --git a/src/banana/data/db.py b/src/banana/data/db.py index 26804ec..8c8e3c6 100644 --- a/src/banana/data/db.py +++ b/src/banana/data/db.py @@ -13,7 +13,6 @@ import sqlalchemy from sqlalchemy import Column, DateTime, Float, Integer, String, Text - # from sqlalchemy.sql import func from sqlalchemy.ext.declarative import declarative_base diff --git a/tests/test_toy.py b/tests/test_toy.py index 5d4b58e..68b9cda 100644 --- a/tests/test_toy.py +++ b/tests/test_toy.py @@ -1,6 +1,7 @@ -from banana import toy from scipy.integrate import quad +from banana import toy + pdf = toy.mkPDF("", 0) ff = toy.mkPDF("ToyFF_unpolarized", 0) From 388e1122e46bfdb1a4851367e13322217dda671f Mon Sep 17 00:00:00 2001 From: t7phy Date: Tue, 18 Jun 2024 15:56:28 +0200 Subject: [PATCH 3/5] black --- docs/source/conf.py | 3 +-- src/banana/data/db.py | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index dfd837b..0060d88 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -124,8 +124,7 @@ def run_apidoc(_): import sys # pylint: disable=import-outside-toplevel - from sphinx.ext.apidoc import \ - main # pylint: disable=import-outside-toplevel + from sphinx.ext.apidoc import main # pylint: disable=import-outside-toplevel sys.path.append(str(here.parent)) # 'banana' diff --git a/src/banana/data/db.py b/src/banana/data/db.py index 8c8e3c6..26804ec 100644 --- a/src/banana/data/db.py +++ b/src/banana/data/db.py @@ -13,6 +13,7 @@ import sqlalchemy from sqlalchemy import Column, DateTime, Float, Integer, String, Text + # from sqlalchemy.sql import func from sqlalchemy.ext.declarative import declarative_base From 7abe91e7286a4c2250c1773a8ddbd0e2d5dfaace Mon Sep 17 00:00:00 2001 From: t7phy Date: Tue, 18 Jun 2024 16:04:36 +0200 Subject: [PATCH 4/5] move scipy dep to test group --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 00a6644..5853adf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,7 +36,6 @@ PyYAML = "^6.0" click = "^8.0.3" pendulum = "^3.0.0" appdirs = "^1.4.4" -scipy = "^1.11.1" [tool.poetry.group.docs] optional = true @@ -54,6 +53,7 @@ pytest = "^7.1.3" pytest-cov = "4.0.0" pylint = "^3.1.0" pyfakefs = "^5.2.3" +scipy = "^1.11.1" [tool.poetry.group.dev.dependencies] pdbpp = "^0.10.3" From af435af4db8610afc00122e7ee88320090ef752f Mon Sep 17 00:00:00 2001 From: Felix Hekhorn Date: Wed, 19 Jun 2024 10:09:38 +0300 Subject: [PATCH 5/5] Run poetry lock, fix tests --- poetry.lock | 50 +++++++++++++++++++++++++++++++++++++++++++---- tests/test_toy.py | 15 +++++++------- 2 files changed, 54 insertions(+), 11 deletions(-) diff --git a/poetry.lock b/poetry.lock index 05d6109..582dabf 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1734,6 +1734,48 @@ pygments = ">=2.6.0,<3.0.0" [package.extras] jupyter = ["ipywidgets (>=7.5.1,<8.0.0)"] +[[package]] +name = "scipy" +version = "1.13.1" +description = "Fundamental algorithms for scientific computing in Python" +optional = false +python-versions = ">=3.9" +files = [ + {file = "scipy-1.13.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:20335853b85e9a49ff7572ab453794298bcf0354d8068c5f6775a0eabf350aca"}, + {file = "scipy-1.13.1-cp310-cp310-macosx_12_0_arm64.whl", hash = "sha256:d605e9c23906d1994f55ace80e0125c587f96c020037ea6aa98d01b4bd2e222f"}, + {file = "scipy-1.13.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:cfa31f1def5c819b19ecc3a8b52d28ffdcc7ed52bb20c9a7589669dd3c250989"}, + {file = "scipy-1.13.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f26264b282b9da0952a024ae34710c2aff7d27480ee91a2e82b7b7073c24722f"}, + {file = "scipy-1.13.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:eccfa1906eacc02de42d70ef4aecea45415f5be17e72b61bafcfd329bdc52e94"}, + {file = "scipy-1.13.1-cp310-cp310-win_amd64.whl", hash = "sha256:2831f0dc9c5ea9edd6e51e6e769b655f08ec6db6e2e10f86ef39bd32eb11da54"}, + {file = "scipy-1.13.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:27e52b09c0d3a1d5b63e1105f24177e544a222b43611aaf5bc44d4a0979e32f9"}, + {file = "scipy-1.13.1-cp311-cp311-macosx_12_0_arm64.whl", hash = "sha256:54f430b00f0133e2224c3ba42b805bfd0086fe488835effa33fa291561932326"}, + {file = "scipy-1.13.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e89369d27f9e7b0884ae559a3a956e77c02114cc60a6058b4e5011572eea9299"}, + {file = "scipy-1.13.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a78b4b3345f1b6f68a763c6e25c0c9a23a9fd0f39f5f3d200efe8feda560a5fa"}, + {file = "scipy-1.13.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:45484bee6d65633752c490404513b9ef02475b4284c4cfab0ef946def50b3f59"}, + {file = "scipy-1.13.1-cp311-cp311-win_amd64.whl", hash = "sha256:5713f62f781eebd8d597eb3f88b8bf9274e79eeabf63afb4a737abc6c84ad37b"}, + {file = "scipy-1.13.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:5d72782f39716b2b3509cd7c33cdc08c96f2f4d2b06d51e52fb45a19ca0c86a1"}, + {file = "scipy-1.13.1-cp312-cp312-macosx_12_0_arm64.whl", hash = "sha256:017367484ce5498445aade74b1d5ab377acdc65e27095155e448c88497755a5d"}, + {file = "scipy-1.13.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:949ae67db5fa78a86e8fa644b9a6b07252f449dcf74247108c50e1d20d2b4627"}, + {file = "scipy-1.13.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:de3ade0e53bc1f21358aa74ff4830235d716211d7d077e340c7349bc3542e884"}, + {file = "scipy-1.13.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:2ac65fb503dad64218c228e2dc2d0a0193f7904747db43014645ae139c8fad16"}, + {file = "scipy-1.13.1-cp312-cp312-win_amd64.whl", hash = "sha256:cdd7dacfb95fea358916410ec61bbc20440f7860333aee6d882bb8046264e949"}, + {file = "scipy-1.13.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:436bbb42a94a8aeef855d755ce5a465479c721e9d684de76bf61a62e7c2b81d5"}, + {file = "scipy-1.13.1-cp39-cp39-macosx_12_0_arm64.whl", hash = "sha256:8335549ebbca860c52bf3d02f80784e91a004b71b059e3eea9678ba994796a24"}, + {file = "scipy-1.13.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d533654b7d221a6a97304ab63c41c96473ff04459e404b83275b60aa8f4b7004"}, + {file = "scipy-1.13.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:637e98dcf185ba7f8e663e122ebf908c4702420477ae52a04f9908707456ba4d"}, + {file = "scipy-1.13.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:a014c2b3697bde71724244f63de2476925596c24285c7a637364761f8710891c"}, + {file = "scipy-1.13.1-cp39-cp39-win_amd64.whl", hash = "sha256:392e4ec766654852c25ebad4f64e4e584cf19820b980bc04960bca0b0cd6eaa2"}, + {file = "scipy-1.13.1.tar.gz", hash = "sha256:095a87a0312b08dfd6a6155cbbd310a8c51800fc931b8c0b84003014b874ed3c"}, +] + +[package.dependencies] +numpy = ">=1.22.4,<2.3" + +[package.extras] +dev = ["cython-lint (>=0.12.2)", "doit (>=0.36.0)", "mypy", "pycodestyle", "pydevtool", "rich-click", "ruff", "types-psutil", "typing_extensions"] +doc = ["jupyterlite-pyodide-kernel", "jupyterlite-sphinx (>=0.12.0)", "jupytext", "matplotlib (>=3.5)", "myst-nb", "numpydoc", "pooch", "pydata-sphinx-theme (>=0.15.2)", "sphinx (>=5.0.0)", "sphinx-design (>=0.4.0)"] +test = ["array-api-strict", "asv", "gmpy2", "hypothesis (>=6.30)", "mpmath", "pooch", "pytest", "pytest-cov", "pytest-timeout", "pytest-xdist", "scikit-umfpack", "threadpoolctl"] + [[package]] name = "six" version = "1.16.0" @@ -2096,13 +2138,13 @@ files = [ [[package]] name = "urllib3" -version = "2.2.1" +version = "2.2.2" description = "HTTP library with thread-safe connection pooling, file post, and more." optional = false python-versions = ">=3.8" files = [ - {file = "urllib3-2.2.1-py3-none-any.whl", hash = "sha256:450b20ec296a467077128bff42b73080516e71b56ff59a60a02bef2232c4fa9d"}, - {file = "urllib3-2.2.1.tar.gz", hash = "sha256:d0570876c61ab9e520d776c38acbbb5b05a776d3f9ff98a5c8fd5162a444cf19"}, + {file = "urllib3-2.2.2-py3-none-any.whl", hash = "sha256:a448b2f64d686155468037e1ace9f2d2199776e17f0a46610480d311f73e3472"}, + {file = "urllib3-2.2.2.tar.gz", hash = "sha256:dd505485549a7a552833da5e6063639d0d177c04f23bc3864e41e5dc5f612168"}, ] [package.extras] @@ -2157,4 +2199,4 @@ test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", [metadata] lock-version = "2.0" python-versions = "^3.9.0,<3.13" -content-hash = "484f5f7d6825617d00cb72124447726231cd9a0cd2af300306927b3f92866cc6" +content-hash = "a360b0b1b928328499c677bce5258b57be0a638005f985c2640bd208601324fb" diff --git a/tests/test_toy.py b/tests/test_toy.py index 68b9cda..a8aa800 100644 --- a/tests/test_toy.py +++ b/tests/test_toy.py @@ -1,9 +1,9 @@ +import numpy as np from scipy.integrate import quad from banana import toy pdf = toy.mkPDF("", 0) -ff = toy.mkPDF("ToyFF_unpolarized", 0) def test_alpha(): @@ -31,11 +31,12 @@ def test_xf(): def test_toyFF(): """Test the ToyFF_unpolarized with Eqn. 3.4 from 1501.00494.""" + ff = toy.mkPDF("ToyFF_unpolarized", 0) - val_u = round(quad(lambda x: ff.xfxQ2(2, x, 1), 0, 1)[0], 3) - val_d = round(quad(lambda x: ff.xfxQ2(1, x, 1), 0, 1)[0], 3) - val_g = round(quad(lambda x: ff.xfxQ2(21, x, 1), 0, 1)[0], 3) + val_u = quad(lambda x: ff.xfxQ2(2, x, 1), 0, 1)[0] + val_d = quad(lambda x: ff.xfxQ2(1, x, 1), 0, 1)[0] + val_g = quad(lambda x: ff.xfxQ2(21, x, 1), 0, 1)[0] - assert val_u == 0.401 - assert val_d == 0.094 - assert val_g == 0.238 + np.testing.assert_allclose(val_u, 0.401, atol=1e-4) + np.testing.assert_allclose(val_d, 0.094, atol=1e-4) + np.testing.assert_allclose(val_g, 0.238, atol=1e-4)