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

docs: increase page width #39

Merged
merged 3 commits into from
Aug 3, 2021
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
23 changes: 6 additions & 17 deletions demo/ampform.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@
" evenly_spaced_interval = np.linspace(0, 1, len(intermediate_states))\n",
" colors = [cm.rainbow(x) for x in evenly_spaced_interval]\n",
" for i, p in enumerate(intermediate_states):\n",
" ax.axvline(\n",
" x=p.mass, linestyle=\"dotted\", label=p.name, color=colors[i]\n",
" )\n",
" ax.axvline(x=p.mass, linestyle=\"dotted\", label=p.name, color=colors[i])\n",
"\n",
"\n",
"def render_side_by_side(reaction, render_final_state_id=False):\n",
Expand All @@ -138,8 +136,7 @@
" graphviz.Source(dot).render(f\"reaction_{i}\", format=\"svg\")\n",
"\n",
" image_paths = [\n",
" f\"reaction_{i}.svg\"\n",
" for i in range(len(reaction.transition_groups))\n",
" f\"reaction_{i}.svg\" for i in range(len(reaction.transition_groups))\n",
" ]\n",
" html_source = '<div style=\"white-space: nowrap\">\\n'\n",
" for path in image_paths:\n",
Expand All @@ -154,9 +151,7 @@
" new_expression = expression\n",
" for node in sp.preorder_traversal(expression):\n",
" if isinstance(node, sp.Float):\n",
" new_expression = new_expression.subs(\n",
" node, round(node, ndigits)\n",
" )\n",
" new_expression = new_expression.subs(node, round(node, ndigits))\n",
" return new_expression"
]
},
Expand Down Expand Up @@ -353,9 +348,7 @@
"outputs": [],
"source": [
"builder = ampform.get_builder(reaction)\n",
"builder.set_dynamics(\n",
" \"a(2)(1320)+\", create_relativistic_breit_wigner_with_ff\n",
")\n",
"builder.set_dynamics(\"a(2)(1320)+\", create_relativistic_breit_wigner_with_ff)\n",
"builder.set_dynamics(\"a(0)(980)0\", create_analytic_breit_wigner)\n",
"model = builder.formulate()"
]
Expand Down Expand Up @@ -527,13 +520,9 @@
"intensity = LambdifiedFunction(sympy_model, backend=\"jax\")\n",
"data_converter = HelicityTransformer(model.adapter)\n",
"initial_state_mass = reaction.initial_state[-1].mass\n",
"final_state_masses = {\n",
" i: p.mass for i, p in reaction.final_state.items()\n",
"}\n",
"final_state_masses = {i: p.mass for i, p in reaction.final_state.items()}\n",
"\n",
"phsp_sample = generate_phsp(\n",
" 100_000, initial_state_mass, final_state_masses\n",
")\n",
"phsp_sample = generate_phsp(100_000, initial_state_mass, final_state_masses)\n",
"data_sample = generate_data(\n",
" 2_000,\n",
" initial_state_mass,\n",
Expand Down
68 changes: 17 additions & 51 deletions demo/analytic-continuation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,7 @@
},
"outputs": [],
"source": [
"from ampform.dynamics import (\n",
" _analytic_continuation,\n",
" phase_space_factor_abs,\n",
")\n",
"from ampform.dynamics import _analytic_continuation, phase_space_factor_abs\n",
"\n",
"rho_ac_math = _analytic_continuation(\n",
" sp.Symbol(R\"\\hat{\\rho}\"), s, s_threshold=(m_a + m_b) ** 2\n",
Expand Down Expand Up @@ -594,9 +591,7 @@
"\n",
"m_a_val = 1.8\n",
"m_b_val = 0.5\n",
"rho_scaled_s_subs = sp.Subs(\n",
" rho_scaled_s, (m_a, m_b), (m_a_val, m_b_val)\n",
")\n",
"rho_scaled_s_subs = sp.Subs(rho_scaled_s, (m_a, m_b), (m_a_val, m_b_val))\n",
"Math(fR\"16\\pi\\rho(s) = {sp.latex(rho_scaled_s_subs)}\")"
]
},
Expand All @@ -613,9 +608,7 @@
},
"outputs": [],
"source": [
"np_rho_scaled_s = sp.lambdify(\n",
" s_symbol, rho_scaled_s_subs.doit(), \"numpy\"\n",
")\n",
"np_rho_scaled_s = sp.lambdify(s_symbol, rho_scaled_s_subs.doit(), \"numpy\")\n",
"\n",
"s_thr = (m_a_val + m_b_val) ** 2\n",
"s_diff = abs(m_a_val - m_b_val) ** 2\n",
Expand Down Expand Up @@ -761,18 +754,14 @@
"\n",
"q_c_symbol = sp.Symbol(\"q_{c}(m)\")\n",
"q_c_subs = q_c.subs(4 * q_squared, 4 * q_squared_symbol)\n",
"rho_c_subs = rho_c.subs(\n",
" ComplexSqrt(q_squared), ComplexSqrt(q_squared_symbol)\n",
")\n",
"rho_c_subs = rho_c.subs(ComplexSqrt(q_squared), ComplexSqrt(q_squared_symbol))\n",
"\n",
"q_c_latex = fR\"{sp.latex(q_c_symbol)} = {sp.latex(q_c)}\"\n",
"rho_c_latex = fR\"\\rho_c(m) = {sp.latex(rho_c_subs)}\"\n",
"display(\n",
" Math(q_c_latex),\n",
" Math(rho_c_latex),\n",
" Math(\n",
" fR\"{sp.latex(complex_sqrt)} = {sp.latex(complex_sqrt.evaluate())}\"\n",
" ),\n",
" Math(fR\"{sp.latex(complex_sqrt)} = {sp.latex(complex_sqrt.evaluate())}\"),\n",
")"
]
},
Expand Down Expand Up @@ -814,9 +803,7 @@
},
"outputs": [],
"source": [
"np_rho_c, sliders = symplot.prepare_sliders(\n",
" plot_symbol=m, expression=rho_c\n",
")\n",
"np_rho_c, sliders = symplot.prepare_sliders(plot_symbol=m, expression=rho_c)\n",
"np_rho_ac = sp.lambdify((m, m_a, m_b), rho_analytic, \"numpy\")\n",
"np_breakup_momentum = sp.lambdify(\n",
" (m, m_a, m_b), ComplexSqrt(q_squared), \"numpy\"\n",
Expand Down Expand Up @@ -957,9 +944,7 @@
},
"outputs": [],
"source": [
"def breakup_momentum(\n",
" s: sp.Symbol, m_a: sp.Symbol, m_b: sp.Symbol\n",
") -> sp.Expr:\n",
"def breakup_momentum(s: sp.Symbol, m_a: sp.Symbol, m_b: sp.Symbol) -> sp.Expr:\n",
" q_squared = breakup_momentum_squared(s, m_a, m_b)\n",
" return ComplexSqrt(q_squared)\n",
"\n",
Expand Down Expand Up @@ -1096,9 +1081,7 @@
" )\n",
")\n",
"\n",
"just_below_threshold = widgets.Button(\n",
" description=\"just below threshold\"\n",
")\n",
"just_below_threshold = widgets.Button(description=\"just below threshold\")\n",
"just_below_threshold.on_click(\n",
" lambda ev: sliders.set_values(\n",
" m0=1.04,\n",
Expand All @@ -1122,9 +1105,7 @@
" figsize=(8, 8),\n",
" gridspec_kw={\"width_ratios\": [1.8, 1]},\n",
")\n",
"fig.suptitle(\n",
" \"Relativistic Breit-Wigners with different phase space factors\"\n",
")\n",
"fig.suptitle(\"Relativistic Breit-Wigners with different phase space factors\")\n",
"fig.canvas.toolbar_visible = False\n",
"\n",
"for ax_left, ax_right in all_axes:\n",
Expand Down Expand Up @@ -1343,9 +1324,7 @@
" q = breakup_momentum(s, m1, m2)\n",
" left_term = sp.Mul(\n",
" 2 * q / sp.sqrt(s),\n",
" sp.log(\n",
" (m1 ** 2 + m2 ** 2 - s + 2 * sp.sqrt(s) * q) / (2 * m1 * m2)\n",
" ),\n",
" sp.log((m1 ** 2 + m2 ** 2 - s + 2 * sp.sqrt(s) * q) / (2 * m1 * m2)),\n",
" evaluate=False,\n",
" )\n",
" right_term = m1 ** 2 - m2 ** 2\n",
Expand Down Expand Up @@ -1430,9 +1409,7 @@
},
"outputs": [],
"source": [
"chew_mandelstam_s_wave_prime = chew_mandelstam_s_wave_expr.subs(\n",
" s, s_plus\n",
")\n",
"chew_mandelstam_s_wave_prime = chew_mandelstam_s_wave_expr.subs(s, s_plus)\n",
"np_chew_mandelstam_s_wave, sliders_cm = symplot.prepare_sliders(\n",
" expression=chew_mandelstam_s_wave_prime,\n",
" plot_symbol=s_prime,\n",
Expand Down Expand Up @@ -1639,9 +1616,7 @@
" 2\n",
" * breakup_momentum_squared(s_prime, m1, m2): 2\n",
" * sp.Symbol(\"q_a^{2}\"),\n",
" phase_space_factor(s_prime, m1, m2): sp.Symbol(\n",
" R\"\\rho_a(s^{\\prime})\"\n",
" ),\n",
" phase_space_factor(s_prime, m1, m2): sp.Symbol(R\"\\rho_a(s^{\\prime})\"),\n",
" s_thr: sp.Symbol(R\"s_\\mathrm{thr}\"),\n",
" }\n",
")\n",
Expand Down Expand Up @@ -1687,16 +1662,12 @@
"source": [
"def integral(s, L, epsilon, m1, m2, q0):\n",
" values_real, errors_real = scipy.integrate.quad(\n",
" lambda s_prime: np_integrand(\n",
" s, s_prime, L, epsilon, m1, m2, q0\n",
" ).real,\n",
" lambda s_prime: np_integrand(s, s_prime, L, epsilon, m1, m2, q0).real,\n",
" a=s_thr_val,\n",
" b=np.inf,\n",
" )\n",
" values_imag, errors_imag = scipy.integrate.quad(\n",
" lambda s_prime: np_integrand(\n",
" s, s_prime, L, epsilon, m1, m2, q0\n",
" ).imag,\n",
" lambda s_prime: np_integrand(s, s_prime, L, epsilon, m1, m2, q0).imag,\n",
" a=s_thr_val,\n",
" b=np.inf,\n",
" )\n",
Expand Down Expand Up @@ -1733,8 +1704,7 @@
"}\n",
"\n",
"sigma = {\n",
" L: (s_domain - s_thr_val) / np.pi * integral_values[L]\n",
" for L in l_values\n",
" L: (s_domain - s_thr_val) / np.pi * integral_values[L] for L in l_values\n",
"}\n",
"sigma_scaled = {L: 16 * np.pi * sigma[L] for L in l_values}"
]
Expand Down Expand Up @@ -1793,14 +1763,10 @@
" figsize=0.6 * np.array([10, 5 * len(l_values)]),\n",
" tight_layout=True,\n",
")\n",
"fig.suptitle(\n",
" f\"Dispersion integrals for $m_1={m1_val:.2f}, m_2={m2_val:.2f}$\"\n",
")\n",
"fig.suptitle(f\"Dispersion integrals for $m_1={m1_val:.2f}, m_2={m2_val:.2f}$\")\n",
"for ax, L in zip(axes, l_values):\n",
" ax.axhline(0, linewidth=0.5, c=\"black\")\n",
" ax.axvline(\n",
" s_thr_val, c=\"grey\", linewidth=0.5, label=R\"$s_\\mathrm{thr}$\"\n",
" )\n",
" ax.axvline(s_thr_val, c=\"grey\", linewidth=0.5, label=R\"$s_\\mathrm{thr}$\")\n",
" ax.plot(\n",
" s_domain,\n",
" sigma_scaled[L].real,\n",
Expand Down
4 changes: 1 addition & 3 deletions docs/adr/001/operators.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,7 @@
"\n",
"\n",
"asMagicNumber = (\n",
" lambda x: x\n",
" if isinstance(x, MagicNumber)\n",
" else Constant(x) # noqa: E731\n",
" lambda x: x if isinstance(x, MagicNumber) else Constant(x) # noqa: E731\n",
")\n",
"asMagicNumber(2).eval()"
]
Expand Down
21 changes: 5 additions & 16 deletions docs/adr/001/sympy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9390,10 +9390,7 @@
"def gaussian(x, A, mu, sigma):\n",
" return (\n",
" A\n",
" / (\n",
" sigma\n",
" * tf.sqrt(tf.constant(2.0, dtype=tf.float64) * math.pi)\n",
" )\n",
" / (sigma * tf.sqrt(tf.constant(2.0, dtype=tf.float64) * math.pi))\n",
" * tf.exp(\n",
" -tf.pow(\n",
" -tf.constant(0.5, dtype=tf.float64) * (x - mu) / sigma,\n",
Expand All @@ -9404,9 +9401,7 @@
"\n",
"\n",
"def native_tf_gauss_sum(x_, A1_, mu1_, sigma1_, A2_, mu2_, sigma2_):\n",
" return gaussian(x_, A1_, mu1_, sigma1_) + gaussian(\n",
" x_, A2_, mu2_, sigma2_\n",
" )\n",
" return gaussian(x_, A1_, mu1_, sigma1_) + gaussian(x_, A2_, mu2_, sigma2_)\n",
"\n",
"\n",
"# @jx.pmap\n",
Expand Down Expand Up @@ -9455,9 +9450,7 @@
"\n",
"def call_native_tf():\n",
" func = native_tf_gauss_sum\n",
" params = tuple(\n",
" tf.Variable(v, dtype=tf.float64) for v in parameter_values\n",
" )\n",
" params = tuple(tf.Variable(v, dtype=tf.float64) for v in parameter_values)\n",
"\n",
" def wrapper():\n",
" return func(tf_x, *params)\n",
Expand Down Expand Up @@ -9504,9 +9497,7 @@
")\n",
"print(\n",
" \"sympy numpy lambdify\",\n",
" timeit.timeit(\n",
" evaluate_with_parameters(numpy_gauss_sum), number=100\n",
" ),\n",
" timeit.timeit(evaluate_with_parameters(numpy_gauss_sum), number=100),\n",
")\n",
"print(\n",
" \"sympy jax lambdify\",\n",
Expand All @@ -9516,9 +9507,7 @@
"\n",
"print(\n",
" \"native jax\",\n",
" timeit.timeit(\n",
" evaluate_with_parameters(native_jax_gauss_sum), number=100\n",
" ),\n",
" timeit.timeit(evaluate_with_parameters(native_jax_gauss_sum), number=100),\n",
")"
]
},
Expand Down
14 changes: 3 additions & 11 deletions docs/adr/002/composition.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,7 @@
"def relativistic_breit_wigner(\n",
" mass: sp.Symbol, mass0: sp.Symbol, gamma0: sp.Symbol\n",
") -> sp.Expr:\n",
" return (\n",
" gamma0\n",
" * mass0\n",
" / (mass0 ** 2 - mass ** 2 - gamma0 * mass0 * sp.I)\n",
" )"
" return gamma0 * mass0 / (mass0 ** 2 - mass ** 2 - gamma0 * mass0 * sp.I)"
]
},
{
Expand Down Expand Up @@ -1983,12 +1979,8 @@
"source": [
"m, m0, w0 = sp.symbols(R\"m m_0 \\Gamma\")\n",
"evaluated_bw = relativistic_breit_wigner(m, 1.0, 0.3)\n",
"sp.plot(\n",
" sp.Abs(evaluated_bw), (m, 0, 2), axis_center=(0, 0), ylim=(0, 1)\n",
")\n",
"sp.plot(\n",
" sp.arg(evaluated_bw), (m, 0, 2), axis_center=(0, 0), ylim=(0, sp.pi)\n",
")\n",
"sp.plot(sp.Abs(evaluated_bw), (m, 0, 2), axis_center=(0, 0), ylim=(0, 1))\n",
"sp.plot(sp.arg(evaluated_bw), (m, 0, 2), axis_center=(0, 0), ylim=(0, sp.pi))\n",
"relativistic_breit_wigner(m, m0, w0)"
]
},
Expand Down
16 changes: 4 additions & 12 deletions docs/adr/002/expr.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@
"\n",
" @classmethod\n",
" @abstractmethod\n",
" def from_graph(\n",
" cls, graph: StateTransitionGraph, edge_id: int\n",
" ) -> sp.Basic:\n",
" def from_graph(cls, graph: StateTransitionGraph, edge_id: int) -> sp.Basic:\n",
" pass"
]
},
Expand Down Expand Up @@ -149,9 +147,7 @@
" return {self.mass0, self.gamma0}\n",
"\n",
" def doit(self, **hints: Any) -> sp.Expr:\n",
" return RelativisticBreitWigner(\n",
" *self.args, **hints, evaluate=True\n",
" )\n",
" return RelativisticBreitWigner(*self.args, **hints, evaluate=True)\n",
"\n",
" def evaluate(self) -> sp.Expr:\n",
" return (\n",
Expand Down Expand Up @@ -235,12 +231,8 @@
"\n",
" def evaluate(self) -> sp.Expr:\n",
" # Computed variables\n",
" q_squared = two_body_momentum_squared(\n",
" self.mass, self.m_a, self.m_b\n",
" )\n",
" q0_squared = two_body_momentum_squared(\n",
" self.mass0, self.m_a, self.m_b\n",
" )\n",
" q_squared = two_body_momentum_squared(self.mass, self.m_a, self.m_b)\n",
" q0_squared = two_body_momentum_squared(self.mass0, self.m_a, self.m_b)\n",
" ff2 = blatt_weisskopf(\n",
" q_squared, self.meson_radius, self.angular_momentum\n",
" )\n",
Expand Down
Loading