diff --git a/.constraints/py3.10.txt b/.constraints/py3.10.txt index 19afe77..23417c2 100644 --- a/.constraints/py3.10.txt +++ b/.constraints/py3.10.txt @@ -5,7 +5,7 @@ # pip-compile --extra=dev --no-annotate --output-file=.constraints/py3.10.txt --strip-extras --unsafe-package=pip --unsafe-package=setuptools --unsafe-package=strong2020-salamanca # accessible-pygments==0.0.4 -alabaster==0.7.15 +alabaster==0.7.16 anyio==4.2.0 argon2-cffi==23.1.0 argon2-cffi-bindings==21.2.0 @@ -40,10 +40,10 @@ executing==2.0.1 fastjsonschema==2.19.1 filelock==3.13.1 flake8==6.1.0 -fonttools==4.47.0 +fonttools==4.47.2 fqdn==1.5.1 gitdb==4.0.11 -gitpython==3.1.40 +gitpython==3.1.41 greenlet==3.0.3 identify==2.5.33 idna==3.6 @@ -58,7 +58,7 @@ ipywidgets==8.1.1 isoduration==20.11.0 isort==5.13.2 jedi==0.19.1 -jinja2==3.1.2 +jinja2==3.1.3 json5==0.9.14 jsonpointer==2.4 jsonschema==4.20.0 @@ -68,7 +68,7 @@ jupyter-client==8.6.0 jupyter-core==5.7.1 jupyter-events==0.9.0 jupyter-lsp==2.2.1 -jupyter-server==2.12.2 +jupyter-server==2.12.3 jupyter-server-mathjax==0.2.6 jupyter-server-terminals==0.5.1 jupyterlab==4.0.10 @@ -81,7 +81,7 @@ jupyterlab-server==2.25.2 jupyterlab-widgets==3.0.9 kiwisolver==1.4.5 livereload==2.6.3 -lsprotocol==2023.0.0 +lsprotocol==2023.0.1 markdown-it-py==2.2.0 markupsafe==2.1.3 matplotlib==3.8.2 @@ -130,7 +130,7 @@ python-json-logger==2.0.7 python-lsp-jsonrpc==1.1.2 python-lsp-ruff==2.0.1 python-lsp-server==1.9.0 -pytoolconfig==1.2.6 +pytoolconfig==1.3.0 pyyaml==6.0.1 pyzmq==25.1.2 referencing==0.32.1 diff --git a/.constraints/py3.11.txt b/.constraints/py3.11.txt index b16c434..7f8bbb5 100644 --- a/.constraints/py3.11.txt +++ b/.constraints/py3.11.txt @@ -5,7 +5,7 @@ # pip-compile --extra=dev --no-annotate --output-file=.constraints/py3.11.txt --strip-extras --unsafe-package=pip --unsafe-package=setuptools --unsafe-package=strong2020-salamanca # accessible-pygments==0.0.4 -alabaster==0.7.15 +alabaster==0.7.16 anyio==4.2.0 argon2-cffi==23.1.0 argon2-cffi-bindings==21.2.0 @@ -39,10 +39,10 @@ executing==2.0.1 fastjsonschema==2.19.1 filelock==3.13.1 flake8==6.1.0 -fonttools==4.47.0 +fonttools==4.47.2 fqdn==1.5.1 gitdb==4.0.11 -gitpython==3.1.40 +gitpython==3.1.41 greenlet==3.0.3 identify==2.5.33 idna==3.6 @@ -57,7 +57,7 @@ ipywidgets==8.1.1 isoduration==20.11.0 isort==5.13.2 jedi==0.19.1 -jinja2==3.1.2 +jinja2==3.1.3 json5==0.9.14 jsonpointer==2.4 jsonschema==4.20.0 @@ -67,7 +67,7 @@ jupyter-client==8.6.0 jupyter-core==5.7.1 jupyter-events==0.9.0 jupyter-lsp==2.2.1 -jupyter-server==2.12.2 +jupyter-server==2.12.3 jupyter-server-mathjax==0.2.6 jupyter-server-terminals==0.5.1 jupyterlab==4.0.10 @@ -80,7 +80,7 @@ jupyterlab-server==2.25.2 jupyterlab-widgets==3.0.9 kiwisolver==1.4.5 livereload==2.6.3 -lsprotocol==2023.0.0 +lsprotocol==2023.0.1 markdown-it-py==2.2.0 markupsafe==2.1.3 matplotlib==3.8.2 @@ -129,7 +129,7 @@ python-json-logger==2.0.7 python-lsp-jsonrpc==1.1.2 python-lsp-ruff==2.0.1 python-lsp-server==1.9.0 -pytoolconfig==1.2.6 +pytoolconfig==1.3.0 pyyaml==6.0.1 pyzmq==25.1.2 referencing==0.32.1 diff --git a/.constraints/py3.12.txt b/.constraints/py3.12.txt index 19c0562..856e61c 100644 --- a/.constraints/py3.12.txt +++ b/.constraints/py3.12.txt @@ -5,7 +5,7 @@ # pip-compile --extra=dev --no-annotate --output-file=.constraints/py3.12.txt --strip-extras --unsafe-package=pip --unsafe-package=setuptools --unsafe-package=strong2020-salamanca # accessible-pygments==0.0.4 -alabaster==0.7.15 +alabaster==0.7.16 anyio==4.2.0 argon2-cffi==23.1.0 argon2-cffi-bindings==21.2.0 @@ -39,10 +39,10 @@ executing==2.0.1 fastjsonschema==2.19.1 filelock==3.13.1 flake8==6.1.0 -fonttools==4.47.0 +fonttools==4.47.2 fqdn==1.5.1 gitdb==4.0.11 -gitpython==3.1.40 +gitpython==3.1.41 greenlet==3.0.3 identify==2.5.33 idna==3.6 @@ -57,7 +57,7 @@ ipywidgets==8.1.1 isoduration==20.11.0 isort==5.13.2 jedi==0.19.1 -jinja2==3.1.2 +jinja2==3.1.3 json5==0.9.14 jsonpointer==2.4 jsonschema==4.20.0 @@ -67,7 +67,7 @@ jupyter-client==8.6.0 jupyter-core==5.7.1 jupyter-events==0.9.0 jupyter-lsp==2.2.1 -jupyter-server==2.12.2 +jupyter-server==2.12.3 jupyter-server-mathjax==0.2.6 jupyter-server-terminals==0.5.1 jupyterlab==4.0.10 @@ -80,7 +80,7 @@ jupyterlab-server==2.25.2 jupyterlab-widgets==3.0.9 kiwisolver==1.4.5 livereload==2.6.3 -lsprotocol==2023.0.0 +lsprotocol==2023.0.1 markdown-it-py==2.2.0 markupsafe==2.1.3 matplotlib==3.8.2 @@ -129,7 +129,7 @@ python-json-logger==2.0.7 python-lsp-jsonrpc==1.1.2 python-lsp-ruff==2.0.1 python-lsp-server==1.9.0 -pytoolconfig==1.2.6 +pytoolconfig==1.3.0 pyyaml==6.0.1 pyzmq==25.1.2 referencing==0.32.1 diff --git a/.constraints/py3.8.txt b/.constraints/py3.8.txt index a677554..d1a85fc 100644 --- a/.constraints/py3.8.txt +++ b/.constraints/py3.8.txt @@ -41,10 +41,10 @@ executing==2.0.1 fastjsonschema==2.19.1 filelock==3.13.1 flake8==6.1.0 -fonttools==4.47.0 +fonttools==4.47.2 fqdn==1.5.1 gitdb==4.0.11 -gitpython==3.1.40 +gitpython==3.1.41 greenlet==3.0.3 identify==2.5.33 idna==3.6 @@ -60,7 +60,7 @@ ipywidgets==8.1.1 isoduration==20.11.0 isort==5.13.2 jedi==0.19.1 -jinja2==3.1.2 +jinja2==3.1.3 json5==0.9.14 jsonpointer==2.4 jsonschema==4.20.0 @@ -70,7 +70,7 @@ jupyter-client==8.6.0 jupyter-core==5.7.1 jupyter-events==0.9.0 jupyter-lsp==2.2.1 -jupyter-server==2.12.2 +jupyter-server==2.12.3 jupyter-server-mathjax==0.2.6 jupyter-server-terminals==0.5.1 jupyterlab==4.0.10 @@ -83,7 +83,7 @@ jupyterlab-server==2.25.2 jupyterlab-widgets==3.0.9 kiwisolver==1.4.5 livereload==2.6.3 -lsprotocol==2023.0.0 +lsprotocol==2023.0.1 markdown-it-py==2.2.0 markupsafe==2.1.3 matplotlib==3.7.4 @@ -134,7 +134,7 @@ python-json-logger==2.0.7 python-lsp-jsonrpc==1.1.2 python-lsp-ruff==2.0.1 python-lsp-server==1.9.0 -pytoolconfig==1.2.6 +pytoolconfig==1.3.0 pytz==2023.3.post1 pyyaml==6.0.1 pyzmq==25.1.2 diff --git a/.constraints/py3.9.txt b/.constraints/py3.9.txt index 6952168..6a862ad 100644 --- a/.constraints/py3.9.txt +++ b/.constraints/py3.9.txt @@ -5,7 +5,7 @@ # pip-compile --extra=dev --no-annotate --output-file=.constraints/py3.9.txt --strip-extras --unsafe-package=pip --unsafe-package=setuptools --unsafe-package=strong2020-salamanca # accessible-pygments==0.0.4 -alabaster==0.7.15 +alabaster==0.7.16 anyio==4.2.0 argon2-cffi==23.1.0 argon2-cffi-bindings==21.2.0 @@ -40,10 +40,10 @@ executing==2.0.1 fastjsonschema==2.19.1 filelock==3.13.1 flake8==6.1.0 -fonttools==4.47.0 +fonttools==4.47.2 fqdn==1.5.1 gitdb==4.0.11 -gitpython==3.1.40 +gitpython==3.1.41 greenlet==3.0.3 identify==2.5.33 idna==3.6 @@ -59,7 +59,7 @@ ipywidgets==8.1.1 isoduration==20.11.0 isort==5.13.2 jedi==0.19.1 -jinja2==3.1.2 +jinja2==3.1.3 json5==0.9.14 jsonpointer==2.4 jsonschema==4.20.0 @@ -69,7 +69,7 @@ jupyter-client==8.6.0 jupyter-core==5.7.1 jupyter-events==0.9.0 jupyter-lsp==2.2.1 -jupyter-server==2.12.2 +jupyter-server==2.12.3 jupyter-server-mathjax==0.2.6 jupyter-server-terminals==0.5.1 jupyterlab==4.0.10 @@ -82,7 +82,7 @@ jupyterlab-server==2.25.2 jupyterlab-widgets==3.0.9 kiwisolver==1.4.5 livereload==2.6.3 -lsprotocol==2023.0.0 +lsprotocol==2023.0.1 markdown-it-py==2.2.0 markupsafe==2.1.3 matplotlib==3.8.2 @@ -131,7 +131,7 @@ python-json-logger==2.0.7 python-lsp-jsonrpc==1.1.2 python-lsp-ruff==2.0.1 python-lsp-server==1.9.0 -pytoolconfig==1.2.6 +pytoolconfig==1.3.0 pyyaml==6.0.1 pyzmq==25.1.2 referencing==0.32.1 diff --git a/.gitignore b/.gitignore index ff2e5d6..fd936a0 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ data/ .eggs/ .fuse_* dist/ +node_modules/ version.py # Temporary files diff --git a/.vscode/settings.json b/.vscode/settings.json index c037b7f..a7e7fdb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -14,7 +14,7 @@ }, "[python]": { "editor.codeActionsOnSave": { - "source.organizeImports": true + "source.organizeImports": "explicit" }, "editor.defaultFormatter": "ms-python.black-formatter", "editor.rulers": [88] diff --git a/docs/lecture17.ipynb b/docs/lecture17.ipynb index 80daf3c..6049e75 100755 --- a/docs/lecture17.ipynb +++ b/docs/lecture17.ipynb @@ -17,7 +17,7 @@ }, "outputs": [], "source": [ - "%pip install -q ampform plotly sympy" + "%pip install -q ampform>=0.14.8 plotly sympy" ] }, { @@ -39,14 +39,13 @@ "from __future__ import annotations\n", "\n", "import warnings\n", - "from typing import Callable\n", + "from typing import Any, Callable\n", "\n", "import numpy as np\n", "import plotly.graph_objects as go\n", "import sympy as sp\n", "from ampform.io import aslatex\n", - "from ampform.sympy import UnevaluatedExpression, implement_doit_method\n", - "from ampform.sympy.math import create_expression\n", + "from ampform.sympy import unevaluated\n", "from IPython.display import Math\n", "from plotly.colors import DEFAULT_PLOTLY_COLORS\n", "from plotly.subplots import make_subplots\n", @@ -303,42 +302,29 @@ }, "outputs": [], "source": [ - "@implement_doit_method\n", - "class SignedSqrt(UnevaluatedExpression):\n", - " is_commutative = True\n", - " is_real = False\n", - "\n", - " def __new__(cls, z, **hints) -> SignedSqrt:\n", - " return create_expression(cls, z, **hints)\n", + "@unevaluated(real=False)\n", + "class SignedSqrt(sp.Expr):\n", + " z: Any\n", + " _latex_repr_ = R\"\\sqrt[+]{{{z}}}\"\n", "\n", " def evaluate(self) -> sp.Expr:\n", - " z = self.args[0]\n", + " z = self.z\n", " return sp.sqrt(abs(z)) * sp.exp(sp.I * PosArg(z) / 2)\n", "\n", - " def _latex(self, printer, *args) -> str:\n", - " z = printer._print(self.args[0])\n", - " return Rf\"\\sqrt[+]{{{z}}}\"\n", - "\n", - "\n", - "@implement_doit_method\n", - "class PosArg(UnevaluatedExpression):\n", - " is_commutative = True\n", "\n", - " def __new__(cls, z, **hints) -> SignedSqrt:\n", - " return create_expression(cls, z, **hints)\n", + "@unevaluated\n", + "class PosArg(sp.Expr):\n", + " z: Any\n", + " _latex_repr_ = R\"\\arg^+\\left({z}\\right)\"\n", "\n", " def evaluate(self) -> sp.Expr:\n", - " z = self.args[0]\n", + " z = self.z\n", " arg = sp.arg(z)\n", " return sp.Piecewise(\n", " (arg + 2 * sp.pi, sp.im(z) < 0),\n", " (arg, True),\n", " )\n", "\n", - " def _latex(self, printer, *args) -> str:\n", - " z = printer._print(self.args[0])\n", - " return Rf\"\\arg^+\\left({z}\\right)\"\n", - "\n", "\n", "z = sp.Symbol(\"z\", complex=True)\n", "Math(aslatex({e: e.evaluate() for e in [SignedSqrt(z), PosArg(z)]}))" @@ -387,13 +373,18 @@ }, "outputs": [], "source": [ - "@implement_doit_method\n", - "class G(UnevaluatedExpression):\n", - " is_commutative = True\n", - " is_real = False\n", - "\n", - " def __new__(cls, s, m, g0, sign=+1, **hints) -> Sigma:\n", - " return create_expression(cls, s, m, g0, sign, **hints)\n", + "@unevaluated(real=False)\n", + "class G(sp.Expr):\n", + " s: Any\n", + " m: Any\n", + " g0: Any\n", + " sign: int = +1\n", + "\n", + " def _latex_repr_(self, printer, *args) -> str:\n", + " s = printer._print(self.args[0])\n", + " sign = self.args[-1]\n", + " number = \"I\" if sign < 0 else \"II\"\n", + " return f\"G_{{{number}}}({s})\"\n", "\n", " def evaluate(self) -> sp.Expr:\n", " s, m, g0, sign = self.args\n", @@ -404,29 +395,17 @@ " (G(s, m, g0, sign=-1) + 2 * sp.I * sigma / (16 * sp.pi), True),\n", " )\n", "\n", - " def _latex(self, printer, *args) -> str:\n", - " s = printer._print(self.args[0])\n", - " sign = self.args[-1]\n", - " number = \"I\" if sign < 0 else \"II\"\n", - " return f\"G_{{{number}}}({s})\"\n", - "\n", - "\n", - "@implement_doit_method\n", - "class Sigma(UnevaluatedExpression):\n", - " is_commutative = True\n", - " is_real = False\n", "\n", - " def __new__(cls, s, m, **hints) -> Sigma:\n", - " return create_expression(cls, s, m, **hints)\n", + "@unevaluated(real=False)\n", + "class Sigma(sp.Expr):\n", + " s: Any\n", + " m: Any\n", + " _latex_repr_ = R\"\\sigma\\left({s}\\right)\"\n", "\n", " def evaluate(self) -> sp.Expr:\n", " s, m = self.args\n", " return SignedSqrt(1 - 4 * m**2 / s)\n", "\n", - " def _latex(self, printer, *args) -> str:\n", - " s = printer._print(self.args[0])\n", - " return Rf\"\\sigma\\left({s}\\right)\"\n", - "\n", "\n", "s, g0 = sp.symbols(\"s g0\", complex=True)\n", "m = sp.Symbol(\"m\", real=True, nonnegative=True)\n", @@ -532,51 +511,56 @@ }, "outputs": [], "source": [ - "@implement_doit_method\n", - "class S(UnevaluatedExpression):\n", - " is_commutative = True\n", - " is_real = False\n", - "\n", - " def __new__(cls, s, m, Mρ, GV, fπ, g0, sign=+1, **hints) -> Sigma:\n", - " return create_expression(cls, s, m, Mρ, GV, fπ, g0, sign, **hints)\n", - "\n", - " def evaluate(self) -> sp.Expr:\n", - " s, m, Mρ, GV, fπ, g0, sign = self.args\n", - " return 1 - 2 * sp.I * Sigma(s, m) / (16 * sp.pi) * T(*self.args)\n", - "\n", - " def _latex(self, printer, *args) -> str:\n", + "@unevaluated(real=False)\n", + "class S(sp.Expr):\n", + " s: Any\n", + " m: Any\n", + " Mρ: Any\n", + " GV: Any\n", + " fπ: Any\n", + " g0: Any\n", + " sign: int = +1\n", + "\n", + " def _latex_repr_(self, printer, *args) -> str:\n", " s = printer._print(self.args[0])\n", " sign = self.args[-1]\n", " number = \"I\" if sign < 0 else \"II\"\n", " return f\"S_{{{number}}}({s})\"\n", "\n", - "\n", - "@implement_doit_method\n", - "class T(UnevaluatedExpression):\n", - " is_commutative = True\n", - " is_real = False\n", - "\n", - " def __new__(cls, s, m, Mρ, GV, fπ, g0, sign=+1, **hints) -> Sigma:\n", - " return create_expression(cls, s, m, Mρ, GV, fπ, g0, sign, **hints)\n", - "\n", " def evaluate(self) -> sp.Expr:\n", " s, m, Mρ, GV, fπ, g0, sign = self.args\n", - " return 1 / (1 / V1(s, m, Mρ, GV, fπ) - G(s, m, g0, sign))\n", + " return 1 - 2 * sp.I * Sigma(s, m) / (16 * sp.pi) * T(*self.args)\n", + "\n", + "\n", + "@unevaluated(real=False)\n", + "class T(sp.Expr):\n", + " s: Any\n", + " m: Any\n", + " Mρ: Any\n", + " GV: Any\n", + " fπ: Any\n", + " g0: Any\n", + " sign: int = +1\n", "\n", - " def _latex(self, printer, *args) -> str:\n", + " def _latex_repr_(self, printer, *args) -> str:\n", " s = printer._print(self.args[0])\n", " sign = self.args[-1]\n", " number = \"I\" if sign < 0 else \"II\"\n", " return f\"T_{{{number}}}({s})\"\n", "\n", + " def evaluate(self) -> sp.Expr:\n", + " s, m, Mρ, GV, fπ, g0, sign = self.args\n", + " return 1 / (1 / V1(s, m, Mρ, GV, fπ) - G(s, m, g0, sign))\n", "\n", - "@implement_doit_method\n", - "class V1(UnevaluatedExpression):\n", - " is_commutative = True\n", - " is_real = False\n", "\n", - " def __new__(cls, s, m, Mρ, GV, fπ, **hints) -> Sigma:\n", - " return create_expression(cls, s, m, Mρ, GV, fπ, **hints)\n", + "@unevaluated(real=False)\n", + "class V1(sp.Expr):\n", + " s: Any\n", + " m: Any\n", + " Mρ: Any\n", + " GV: Any\n", + " fπ: Any\n", + " _latex_repr_ = R\"V_1\\left({s}\\right)\"\n", "\n", " def evaluate(self) -> sp.Expr:\n", " s, m, Mρ, GV, fπ = self.args\n", @@ -584,17 +568,11 @@ " 1 - GV**2 / fπ**2 * 2 * s / (s - Mρ**2)\n", " ) - GV**2 / fπ**4 * p2(s, m) * h(Mρ**2 / (2 * p2(s, m)))\n", "\n", - " def _latex(self, printer, *args) -> str:\n", - " s = printer._print(self.args[0])\n", - " return Rf\"V_1\\left({s}\\right)\"\n", - "\n", "\n", - "@implement_doit_method\n", - "class h(UnevaluatedExpression):\n", - " is_commutative = True\n", - "\n", - " def __new__(cls, a, **hints) -> Sigma:\n", - " return create_expression(cls, a, **hints)\n", + "@unevaluated\n", + "class h(sp.Expr):\n", + " a: Any\n", + " _latex_repr_ = R\"h\\left({a}\\right)\"\n", "\n", " def evaluate(self) -> sp.Expr:\n", " a = self.args[0]\n", @@ -604,26 +582,17 @@ " evaluate=False,\n", " ) + a * (2 + 3 * a + a**2) * sp.log(1 + 2 / a)\n", "\n", - " def _latex(self, printer, *args) -> str:\n", - " a = printer._print(self.args[0])\n", - " return Rf\"h\\left({a}\\right)\"\n", - "\n", - "\n", - "@implement_doit_method\n", - "class p2(UnevaluatedExpression):\n", - " is_commutative = True\n", "\n", - " def __new__(cls, s, m, **hints) -> Sigma:\n", - " return create_expression(cls, s, m, **hints)\n", + "@unevaluated\n", + "class p2(sp.Expr):\n", + " s: Any\n", + " m: Any\n", + " _latex_repr_ = R\"p^2\\left({s}\\right)\"\n", "\n", " def evaluate(self) -> sp.Expr:\n", " s, m = self.args\n", " return s / 4 - m**2\n", "\n", - " def _latex(self, printer, *args) -> str:\n", - " s = printer._print(self.args[0])\n", - " return Rf\"p^2\\left({s}\\right)\"\n", - "\n", "\n", "a, Mρ, GV, fπ = sp.symbols(\"a m_rho, G_V f_pi\")\n", "_exprs = [\n",