Skip to content

Commit 90f467f

Browse files
authored
FIX: stabilize numerical integral (#490)
* DOC: improve Riemann sheet plot * DX: benchmark evaluation time of integral over Riemann sheets * DX: reduce resolution of Riemann sheet plot * DX: suppress `RemovedInSphinx10Warning` warning * ENH: make `quad_vec` call lambdification more extendable * FIX: remove default `limit=50` in `quad_vec()` call * FIX: remove `type()` call that was used for testing * MAINT: apply Prettier formatting to notebooks
1 parent 2044f9a commit 90f467f

17 files changed

Lines changed: 102 additions & 88 deletions

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ repos:
1313
- id: check-useless-excludes
1414

1515
- repo: https://github.com/ComPWA/policy
16-
rev: 0.8.2
16+
rev: b122464266f519d41284e4a51673fb1232d1fd0b
1717
hooks:
1818
- id: check-dev-files
1919
args:

docs/conf.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
import inspect
55
import os
66
import sys
7+
import warnings
78
from dataclasses import is_dataclass
89

10+
import requests
11+
from sphinx.deprecation import RemovedInSphinx10Warning
912
from sphinx_api_relink.helpers import (
1013
get_branch_name,
1114
get_execution_mode,
@@ -20,6 +23,8 @@
2023
sys.path.insert(0, os.path.abspath("."))
2124
from _extend_docstrings import extend_docstrings # noqa: PLC2701
2225

26+
warnings.filterwarnings("ignore", category=RemovedInSphinx10Warning)
27+
2328

2429
def _get_excluded_members() -> list[str]:
2530
default_exclusions = {
@@ -61,6 +66,14 @@ def _get_dataclasses(module):
6166
return dataclass_list
6267

6368

69+
def _get_scipy_url() -> str:
70+
url = f"https://docs.scipy.org/doc/scipy-{pin('scipy')}/"
71+
r = requests.get(url)
72+
if r.status_code != 200: # noqa: PLR2004
73+
return "https://docs.scipy.org/doc/scipy"
74+
return url
75+
76+
6477
extend_docstrings()
6578
set_intersphinx_version_remapping({
6679
"ipython": {
@@ -278,6 +291,7 @@ def _get_dataclasses(module):
278291
"numpy": (f"https://numpy.org/doc/{pin_minor('numpy')}", None),
279292
"python": ("https://docs.python.org/3", None),
280293
"qrules": (f"https://qrules.readthedocs.io/{pin('qrules')}", None),
294+
"scipy": (_get_scipy_url(), None),
281295
"spb": (
282296
f"https://sympy-plot-backends.readthedocs.io/en/v{pin('sympy-plot-backends')}",
283297
None,

docs/usage.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"# Usage\n",
88
"\n",
99
"```{autolink-concat}\n",
10+
"\n",
1011
"```"
1112
]
1213
},

docs/usage/amplitude.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"# Formulate amplitude model\n",
88
"\n",
99
"```{autolink-concat}\n",
10+
"\n",
1011
"```"
1112
]
1213
},
@@ -493,7 +494,7 @@
493494
"cell_type": "markdown",
494495
"metadata": {},
495496
"source": [
496-
"To set dynamics for specific resonances, use {meth}`.DynamicsSelector.assign` on the same {attr}`.HelicityAmplitudeBuilder.dynamics` attribute. You can set the dynamics to be any kind of {class}`~sympy.core.expr.Expr`, as long as you keep track of which {class}`~sympy.core.symbol.Symbol` names you use (see {doc}`/usage/dynamics/custom`).\n",
497+
"To set dynamics for specific resonances, use {meth}`.DynamicsSelector.assign` on the same {attr}`.HelicityAmplitudeBuilder.dynamics` attribute. You can set the dynamics to be any kind of {class}`~sympy.core.expr.Expr`, as long as you keep track of which {class}`~sympy.core.symbol.Symbol` names you use (see {doc}`/usage/dynamics/custom`).\n",
497498
"\n",
498499
"AmpForm does provide a few common {mod}`.dynamics` functions, which can be constructed as {class}`~sympy.core.expr.Expr` with the correct {class}`~sympy.core.symbol.Symbol` names using {meth}`.DynamicsSelector.assign`. This function takes specific {mod}`.dynamics.builder` functions and classes, such as {class}`.RelativisticBreitWignerBuilder`, which can create {func}`.relativistic_breit_wigner` functions for specific resonances. Here's an example for a relativistic Breit-Wigner _with form factor_ for the intermediate resonances and use a Blatt-Weisskopf barrier factor for the production decay:"
499500
]

docs/usage/dynamics.ipynb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"metadata": {},
66
"source": [
77
"# Dynamics\n",
8+
"\n",
89
"```{autolink-concat}\n",
10+
"\n",
911
"```"
1012
]
1113
},
@@ -33,6 +35,7 @@
3335
"```\n",
3436
"\n",
3537
"```{autolink-skip}\n",
38+
"\n",
3639
"```"
3740
]
3841
},

docs/usage/dynamics/analytic-continuation.ipynb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"metadata": {},
66
"source": [
77
"# Analytic continuation\n",
8+
"\n",
89
"```{autolink-concat}\n",
10+
"\n",
911
"```"
1012
]
1113
},
@@ -623,6 +625,7 @@
623625
"metadata": {},
624626
"source": [
625627
"```{autolink-skip}\n",
628+
"\n",
626629
"```"
627630
]
628631
},

docs/usage/dynamics/custom.ipynb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"metadata": {},
66
"source": [
77
"# Custom dynamics\n",
8+
"\n",
89
"```{autolink-concat}\n",
10+
"\n",
911
"```"
1012
]
1113
},

docs/usage/dynamics/k-matrix.ipynb

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
{
22
"cells": [
3-
{
4-
"cell_type": "markdown",
5-
"metadata": {},
6-
"source": [
7-
"```{autolink-concat}\n",
8-
"```"
9-
]
10-
},
113
{
124
"cell_type": "markdown",
135
"metadata": {},
146
"source": [
157
"# K-matrix\n",
168
"\n",
9+
"```{autolink-concat}\n",
10+
"\n",
11+
"```\n",
12+
"\n",
1713
"<!-- cspell:ignore amma -->"
1814
]
1915
},
@@ -32,6 +28,7 @@
3228
":::\n",
3329
"\n",
3430
"```{autolink-skip}\n",
31+
"\n",
3532
"```"
3633
]
3734
},
@@ -93,15 +90,6 @@
9390
"warnings.filterwarnings(\"ignore\")"
9491
]
9592
},
96-
{
97-
"cell_type": "code",
98-
"execution_count": null,
99-
"metadata": {},
100-
"outputs": [],
101-
"source": [
102-
"type(plt.subplots()[0].canvas)"
103-
]
104-
},
10593
{
10694
"cell_type": "markdown",
10795
"metadata": {},

docs/usage/dynamics/riemann-sheets.ipynb

Lines changed: 10 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,16 @@
11
{
22
"cells": [
3-
{
4-
"cell_type": "code",
5-
"execution_count": null,
6-
"metadata": {
7-
"hideCode": true,
8-
"hideOutput": true,
9-
"hidePrompt": true,
10-
"jupyter": {
11-
"source_hidden": true
12-
},
13-
"tags": [
14-
"remove-cell",
15-
"skip-execution"
16-
]
17-
},
18-
"outputs": [],
19-
"source": [
20-
"# WARNING: advised to install a specific version, e.g. ampform==0.1.2\n",
21-
"%pip install -q ampform[doc,viz] IPython"
22-
]
23-
},
24-
{
25-
"cell_type": "code",
26-
"execution_count": null,
27-
"metadata": {
28-
"hideCode": true,
29-
"hideOutput": true,
30-
"hidePrompt": true,
31-
"jupyter": {
32-
"source_hidden": true
33-
},
34-
"tags": [
35-
"remove-cell"
36-
]
37-
},
38-
"outputs": [],
39-
"source": [
40-
"import os\n",
41-
"\n",
42-
"STATIC_WEB_PAGE = {\"EXECUTE_NB\", \"READTHEDOCS\"}.intersection(os.environ)"
43-
]
44-
},
453
{
464
"cell_type": "markdown",
475
"metadata": {},
486
"source": [
7+
"# Continuation into other Riemann sheets\n",
8+
"\n",
499
"```{autolink-concat}\n",
10+
"\n",
5011
"```"
5112
]
5213
},
53-
{
54-
"cell_type": "markdown",
55-
"metadata": {},
56-
"source": [
57-
"# Continuation into other Riemann sheets"
58-
]
59-
},
6014
{
6115
"cell_type": "markdown",
6216
"metadata": {},
@@ -522,8 +476,8 @@
522476
},
523477
"outputs": [],
524478
"source": [
525-
"x = np.linspace(0, 8, num=300)\n",
526-
"y = np.linspace(1e-3, 1, num=100)\n",
479+
"x = np.linspace(0, 6, num=150)\n",
480+
"y = np.linspace(1e-3, 1, num=40)\n",
527481
"X, Y = np.meshgrid(x, y)\n",
528482
"Zn = X - Y * 1j\n",
529483
"Zp = X + Y * 1j"
@@ -542,6 +496,7 @@
542496
},
543497
"outputs": [],
544498
"source": [
499+
"%%time\n",
545500
"T1n = evaluate(T1_func, Zn**2)\n",
546501
"T1p = evaluate(T1_func, Zp**2)\n",
547502
"\n",
@@ -563,14 +518,15 @@
563518
"source_hidden": true
564519
},
565520
"tags": [
521+
"full-width",
566522
"hide-input"
567523
]
568524
},
569525
"outputs": [],
570526
"source": [
571-
"fig, axes = plt.subplots(figsize=(11, 4), ncols=2, sharey=True)\n",
527+
"fig, axes = plt.subplots(figsize=(13, 4), ncols=2, sharey=True)\n",
572528
"ax1, ax2 = axes.ravel()\n",
573-
"fig.subplots_adjust(wspace=0.1)\n",
529+
"fig.subplots_adjust(wspace=0.05)\n",
574530
"fig.suptitle(R\"$s_{thr1}<s_{thr2}<m_{res}$\", fontsize=20)\n",
575531
"ax1.set_title(\"I and II\", y=0.88)\n",
576532
"ax2.set_title(\"I and III\", y=0.88)\n",
@@ -598,7 +554,7 @@
598554
" ax.axvline(parameters[m0], **linestyle_res)\n",
599555
"\n",
600556
"ax1.legend(fontsize=11, loc=\"lower left\")\n",
601-
"cbar = fig.colorbar(mesh, ax=axes)\n",
557+
"cbar = fig.colorbar(mesh, ax=axes, pad=0.01)\n",
602558
"cbar.ax.set_ylabel(R\"$\\mathrm{Im} T(s)$\")\n",
603559
"fig.show()"
604560
]

docs/usage/helicity/formalism.ipynb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"metadata": {},
66
"source": [
77
"# Helicity versus canonical\n",
8+
"\n",
89
"```{autolink-concat}\n",
10+
"\n",
911
"```"
1012
]
1113
},

0 commit comments

Comments
 (0)