Skip to content

Commit

Permalink
DOC: use multiline aslatex() in notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed May 1, 2024
1 parent 915ff3f commit 096e3eb
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 63 deletions.
15 changes: 12 additions & 3 deletions docs/usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,10 @@
},
"outputs": [],
"source": [
"from ampform.io import aslatex\n",
"\n",
"(symbol, expr), *_ = model.amplitudes.items()\n",
"latex = sp.multiline_latex(symbol, expr)\n",
"Math(latex)"
"Math(aslatex({symbol: expr}, terms_per_line=1))"
]
},
{
Expand Down Expand Up @@ -351,8 +352,16 @@
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"version": "3.8.17"
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
}
},
"nbformat": 4,
Expand Down
25 changes: 7 additions & 18 deletions docs/usage/amplitude.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
"jupyter": {
"source_hidden": true
},
"mystnb": {
"code_prompt_show": "Import Python libraries"
},
"tags": [
"hide-cell"
]
Expand Down Expand Up @@ -225,30 +228,18 @@
"This shows that the main intensity is an **incoherent** sum of the amplitude for each spin projection combination of the initial and final states. The expressions for each of these amplitudes are provided with the {attr}`~.amplitudes` attribute. This is an {class}`~collections.OrderedDict`, so we can inspect the first of these amplitudes as follows:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"(symbol, expression), *_ = model_no_dynamics.amplitudes.items()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"remove-input",
"full-width"
]
},
"outputs": [],
"source": [
"latex = sp.multiline_latex(symbol, expression)\n",
"Math(latex)"
"(symbol, expression), *_ = model_no_dynamics.amplitudes.items()\n",
"Math(aslatex({symbol: expression}, terms_per_line=1))"
]
},
{
Expand All @@ -262,9 +253,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"full-width"
]
"tags": []
},
"outputs": [],
"source": [
Expand Down Expand Up @@ -1078,7 +1067,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.17"
"version": "3.11.8"
}
},
"nbformat": 4,
Expand Down
40 changes: 36 additions & 4 deletions docs/usage/dynamics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@
"jupyter": {
"source_hidden": true
},
"mystnb": {
"code_prompt_show": "Import Python libraries"
},
"tags": [
"hide-input"
]
Expand Down Expand Up @@ -160,8 +163,29 @@
"\n",
"L = sp.Symbol(\"L\", integer=True)\n",
"z = sp.Symbol(\"z\", real=True)\n",
"ff2 = BlattWeisskopfSquared(z, L)\n",
"Math(sp.multiline_latex(ff2, ff2.doit(), environment=\"eqnarray\"))"
"ff2 = BlattWeisskopfSquared(z, L)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"editable": true,
"jupyter": {
"source_hidden": true
},
"slideshow": {
"slide_type": ""
},
"tags": [
"hide-input"
]
},
"outputs": [],
"source": [
"from ampform.io import aslatex\n",
"\n",
"Math(aslatex({ff2: ff2.doit()}))"
]
},
{
Expand Down Expand Up @@ -430,7 +454,7 @@
" meson_radius=1,\n",
" phsp_factor=PhaseSpaceFactorSWave,\n",
")\n",
"Math(sp.multiline_latex(width, width.evaluate(), environment=\"eqnarray\"))"
"Math(aslatex({width: width.evaluate()}))"
]
},
{
Expand Down Expand Up @@ -651,8 +675,16 @@
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"version": "3.8.17"
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
}
},
"nbformat": 4,
Expand Down
17 changes: 11 additions & 6 deletions docs/usage/dynamics/analytic-continuation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@
"jupyter": {
"source_hidden": true
},
"mystnb": {
"code_prompt_show": "Import Python libraries"
},
"tags": [
"hide-input"
]
Expand All @@ -115,6 +118,8 @@
"import sympy as sp\n",
"from IPython.display import Math\n",
"\n",
"from ampform.io import aslatex\n",
"\n",
"warnings.filterwarnings(\"ignore\")"
]
},
Expand Down Expand Up @@ -144,7 +149,7 @@
"\n",
"s, m_a, m_b = sp.symbols(\"s, m_a, m_b\", nonnegative=True)\n",
"q_squared = BreakupMomentumSquared(s, m_a, m_b)\n",
"Math(sp.multiline_latex(q_squared, q_squared.doit(), environment=\"eqnarray\"))"
"Math(aslatex({q_squared: q_squared.evaluate()}))"
]
},
{
Expand All @@ -170,7 +175,7 @@
"from ampform.dynamics import PhaseSpaceFactor\n",
"\n",
"rho = PhaseSpaceFactor(s, m_a, m_b)\n",
"Math(sp.multiline_latex(rho, rho.evaluate(), environment=\"eqnarray\"))"
"Math(aslatex({rho: rho.evaluate()}))"
]
},
{
Expand All @@ -196,7 +201,7 @@
"from ampform.dynamics import PhaseSpaceFactorComplex\n",
"\n",
"rho_c = PhaseSpaceFactorComplex(s, m_a, m_b)\n",
"Math(sp.multiline_latex(rho_c, rho_c.evaluate(), environment=\"eqnarray\"))"
"Math(aslatex({rho_c: rho_c.evaluate()}))"
]
},
{
Expand Down Expand Up @@ -224,7 +229,7 @@
"from ampform.dynamics import EqualMassPhaseSpaceFactor\n",
"\n",
"rho_ac = EqualMassPhaseSpaceFactor(s, m_a, m_b)\n",
"Math(sp.multiline_latex(rho_ac, rho_ac.evaluate(), environment=\"eqnarray\"))"
"Math(aslatex({rho_ac: rho_ac.evaluate()}))"
]
},
{
Expand All @@ -250,7 +255,7 @@
"from ampform.dynamics import PhaseSpaceFactorAbs\n",
"\n",
"rho_hat = PhaseSpaceFactorAbs(s, m_a, m_b)\n",
"Math(sp.multiline_latex(rho_hat, rho_hat.evaluate(), environment=\"eqnarray\"))"
"Math(aslatex({rho_hat: rho_hat.evaluate()}))"
]
},
{
Expand Down Expand Up @@ -289,7 +294,7 @@
"from ampform.dynamics import PhaseSpaceFactorSWave\n",
"\n",
"rho_cm = PhaseSpaceFactorSWave(s, m_a, m_b)\n",
"Math(sp.multiline_latex(rho_cm, rho_cm.evaluate(), environment=\"eqnarray\"))"
"Math(aslatex({rho_cm: rho_cm.evaluate()}))"
]
},
{
Expand Down
31 changes: 22 additions & 9 deletions docs/usage/dynamics/custom.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
"jupyter": {
"source_hidden": true
},
"mystnb": {
"code_prompt_show": "Import Python libraries"
},
"tags": [
"hide-cell"
]
Expand All @@ -83,7 +86,9 @@
"import graphviz\n",
"import qrules\n",
"import sympy as sp\n",
"from IPython.display import display"
"from IPython.display import Math\n",
"\n",
"from ampform.io import aslatex"
]
},
{
Expand Down Expand Up @@ -155,9 +160,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"full-width"
]
"tags": []
},
"outputs": [],
"source": [
Expand Down Expand Up @@ -273,7 +276,7 @@
"metadata": {},
"outputs": [],
"source": [
"display(*sorted(model.parameter_defaults, key=lambda p: p.name))"
"Math(aslatex(model.parameter_defaults))"
]
},
{
Expand Down Expand Up @@ -305,9 +308,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"full-width"
]
"tags": []
},
"outputs": [],
"source": [
Expand All @@ -321,7 +322,7 @@
" heurisch=None,\n",
" manual=None,\n",
")\n",
"integrated_expr.n(1)"
"Math(aslatex(integrated_expr.n(1), terms_per_line=1))"
]
},
{
Expand Down Expand Up @@ -350,6 +351,18 @@
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
}
},
"nbformat": 4,
Expand Down
3 changes: 3 additions & 0 deletions docs/usage/dynamics/k-matrix.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@
"jupyter": {
"source_hidden": true
},
"mystnb": {
"code_prompt_show": "Import Python libraries"
},
"tags": [
"hide-cell"
]
Expand Down
3 changes: 3 additions & 0 deletions docs/usage/helicity/formalism.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
"jupyter": {
"source_hidden": true
},
"mystnb": {
"code_prompt_show": "Import Python libraries"
},
"tags": [
"hide-cell"
]
Expand Down
18 changes: 8 additions & 10 deletions docs/usage/helicity/spin-alignment.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
"jupyter": {
"source_hidden": true
},
"mystnb": {
"code_prompt_show": "Import Python libraries"
},
"tags": [
"hide-cell"
]
Expand Down Expand Up @@ -191,8 +194,8 @@
" for i, (symbol, expr) in enumerate(model.amplitudes.items())\n",
" if i % 5 == 0\n",
" }\n",
" src = aslatex(selected_amplitudes)\n",
" src = src.replace(R\"\\end{array}\", R\"& \\dots \\\\ \\end{array}\")\n",
" src = aslatex(selected_amplitudes, terms_per_line=1)\n",
" src = src.replace(R\"\\end{array}\", R\"\\dots \\\\ \\end{array}\")\n",
" return Math(src)\n",
"\n",
"\n",
Expand Down Expand Up @@ -237,7 +240,7 @@
"builder_123.config.scalar_initial_state_mass = True\n",
"builder_123.config.stable_final_state_ids = [1, 2, 3]\n",
"dpd_model = builder_123.formulate()\n",
"dpd_model.intensity"
"dpd_model.intensity.cleanup()"
]
},
{
Expand Down Expand Up @@ -369,12 +372,7 @@
},
"outputs": [],
"source": [
"latex = sp.multiline_latex(\n",
" sp.Symbol(\"I\"),\n",
" axisangle_model.intensity.evaluate(),\n",
" environment=\"eqnarray\",\n",
")\n",
"Math(latex)"
"Math(aslatex({\"I\": axisangle_model.intensity.evaluate()}, terms_per_line=1))"
]
},
{
Expand Down Expand Up @@ -429,7 +427,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.17"
"version": "3.11.8"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 096e3eb

Please sign in to comment.