Skip to content

Commit

Permalink
Address comments from Code Review RE Python tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
Radonirinaunimi committed Nov 6, 2024
1 parent af0d387 commit e7c2e88
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 53 deletions.
38 changes: 21 additions & 17 deletions pineappl_py/docs/source/advanced.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,15 @@
")\n",
"from pineappl.pids import PidBasis\n",
"\n",
"def generate_grid(calls: int) -> pineappl.grid.Grid:\n",
" \"\"\"Generate the grid.\"\"\"\n",
" # create a new luminosity function for the $\\gamma\\gamma$ initial state\n",
" channels = [Channel([([22, 22], 1.0)])]\n",
" # only LO $\\alpha_\\mathrm{s}^0 \\alpha^2 \\log^0(\\xi_\\mathrm{R}) \\log^0(\\xi_\\mathrm{F}) \\log^0(\\xi_\\mathrm{G})$$\n",
" orders = [Order(0, 2, 0, 0, 0)]\n",
" bins = np.arange(0, 2.4, 0.1)\n",
"\n",
"def grid_specs(\n",
" orders: list[Order],\n",
" channels: list[Channel],\n",
" bins: np.ndarray,\n",
") -> Grid:\n",
" \"\"\"Construct the PineAPPL grid based on various specifications. These include\n",
" the types of kinematics involved, the types of convolutions required by the\n",
" involved hadrons, and the interpolations required by each kinematic variables.\n",
" \"\"\"\n",
" ### Define the specs that define the Grid ###\n",
" kinematics = [\n",
" Kinematics.Scale(0), # Scale\n",
Expand Down Expand Up @@ -393,7 +394,7 @@
" conv_object = Conv(conv_type=conv_type, pid=2212)\n",
" convolutions = [conv_object, conv_object]\n",
"\n",
" grid = Grid(\n",
" return Grid(\n",
" pid_basis=PidBasis.Evol,\n",
" channels=channels,\n",
" orders=orders,\n",
Expand All @@ -404,6 +405,17 @@
" scale_funcs=scale_funcs,\n",
" )\n",
"\n",
"def generate_grid(calls: int) -> Grid:\n",
" \"\"\"Generate the grid.\"\"\"\n",
" # create a new luminosity function for the $\\gamma\\gamma$ initial state\n",
" channels = [Channel([([22, 22], 1.0)])]\n",
" # only LO $\\alpha_\\mathrm{s}^0 \\alpha^2 \\log^0(\\xi_\\mathrm{R}) \\log^0(\\xi_\\mathrm{F}) \\log^0(\\xi_\\mathrm{A})$$\n",
" orders = [Order(0, 2, 0, 0, 0)]\n",
" bins = np.arange(0, 2.4, 0.1)\n",
"\n",
" # Instantiate the PineAPPL Grid\n",
" grid = grid_specs(orders, channels, bins)\n",
"\n",
" # fill the grid with phase-space points\n",
" print(f\"Generating {calls} events, please wait...\")\n",
" fill_grid(grid, calls)\n",
Expand Down Expand Up @@ -502,14 +514,6 @@
"\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cb155b03-7ad5-41e9-bd21-3d9cd3d17585",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
8 changes: 4 additions & 4 deletions pineappl_py/docs/source/introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -457,12 +457,12 @@
" white-space: pre-wrap;\n",
"}\n",
"</style>\n",
"<small>shape: (7, 6)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>index</th><th>as</th><th>a</th><th>lf</th><th>lr</th><th>lg</th></tr><tr><td>u32</td><td>i64</td><td>i64</td><td>i64</td><td>i64</td><td>i64</td></tr></thead><tbody><tr><td>0</td><td>0</td><td>2</td><td>0</td><td>0</td><td>0</td></tr><tr><td>1</td><td>1</td><td>2</td><td>0</td><td>0</td><td>0</td></tr><tr><td>2</td><td>1</td><td>2</td><td>1</td><td>0</td><td>0</td></tr><tr><td>3</td><td>1</td><td>2</td><td>0</td><td>1</td><td>0</td></tr><tr><td>4</td><td>0</td><td>3</td><td>0</td><td>0</td><td>0</td></tr><tr><td>5</td><td>0</td><td>3</td><td>1</td><td>0</td><td>0</td></tr><tr><td>6</td><td>0</td><td>3</td><td>0</td><td>1</td><td>0</td></tr></tbody></table></div>"
"<small>shape: (7, 6)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>index</th><th>as</th><th>a</th><th>lf</th><th>lr</th><th>la</th></tr><tr><td>u32</td><td>i64</td><td>i64</td><td>i64</td><td>i64</td><td>i64</td></tr></thead><tbody><tr><td>0</td><td>0</td><td>2</td><td>0</td><td>0</td><td>0</td></tr><tr><td>1</td><td>1</td><td>2</td><td>0</td><td>0</td><td>0</td></tr><tr><td>2</td><td>1</td><td>2</td><td>1</td><td>0</td><td>0</td></tr><tr><td>3</td><td>1</td><td>2</td><td>0</td><td>1</td><td>0</td></tr><tr><td>4</td><td>0</td><td>3</td><td>0</td><td>0</td><td>0</td></tr><tr><td>5</td><td>0</td><td>3</td><td>1</td><td>0</td><td>0</td></tr><tr><td>6</td><td>0</td><td>3</td><td>0</td><td>1</td><td>0</td></tr></tbody></table></div>"
],
"text/plain": [
"shape: (7, 6)\n",
"┌───────┬─────┬─────┬─────┬─────┬─────┐\n",
"│ index ┆ as ┆ a ┆ lf ┆ lr ┆ lg\n",
"│ index ┆ as ┆ a ┆ lf ┆ lr ┆ la\n",
"│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │\n",
"│ u32 ┆ i64 ┆ i64 ┆ i64 ┆ i64 ┆ i64 │\n",
"╞═══════╪═════╪═════╪═════╪═════╪═════╡\n",
Expand All @@ -489,7 +489,7 @@
"\n",
"df_orders = pl.DataFrame(\n",
" np.array(orders),\n",
" schema=[\"as\", \"a\", \"lf\", \"lr\", \"lg\"]\n",
" schema=[\"as\", \"a\", \"lf\", \"lr\", \"la\"]\n",
")\n",
"df_orders.with_row_index()"
]
Expand All @@ -502,7 +502,7 @@
"The table above lists the perturbative orders contained in the\n",
"grid where the powers of the strong coupling $a_s$, the electroweak\n",
"coupling $a$, the factorization $\\ell_F = \\log(\\mu_F^2/Q^2)$, renormalization $\\ell_R=\\log(\\mu_R^2/Q^2)$,\n",
"and fragmentation $\\ell_g=\\log(\\mu_G^2/Q^2)$\n",
"and fragmentation $\\ell_A=\\log(\\mu_A^2/Q^2)$\n",
"logs are shown. For instance, the first index shows that the grid \n",
"contains a leading-order (LO) which has the coupling $a_s^2$."
]
Expand Down
59 changes: 27 additions & 32 deletions pineappl_py/tests/test_boc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,52 +12,47 @@ def test_init(self):

class TestKinematics:
@pytest.mark.parametrize(
"kintype, argument, expected_type",
"kintype, argument",
[
("Scale", 0, Kinematics),
("Scale", 1, Kinematics),
("Scale", 2, Kinematics),
("X", 0, Kinematics),
("X", 1, Kinematics),
("X", 2, Kinematics),
("Scale", 0),
("Scale", 1),
("Scale", 2),
("X", 0),
("X", 1),
("X", 2),
],
)
def test_init(self, kintype: str, argument: int, expected_type: Kinematics):
def test_init(self, kintype: str, argument: int):
kin_method = getattr(Kinematics, kintype)
result = kin_method(argument)
assert isinstance(result, expected_type)
assert isinstance(result, Kinematics)


class TestScaleFuncForm:
@pytest.mark.parametrize(
"scaletype, argument, expected_type",
"scaletype, argument",
[
("NoScale", [0], ScaleFuncForm),
("Scale", [0], ScaleFuncForm),
("QuadraticSum", [0, 1], ScaleFuncForm),
("QuadraticMean", [0, 1], ScaleFuncForm),
("QuadraticSumOver4", [0, 1], ScaleFuncForm),
("LinearMean", [0, 1], ScaleFuncForm),
("LinearSum", [0, 1], ScaleFuncForm),
("ScaleMax", [0, 1], ScaleFuncForm),
("ScaleMin", [0, 1], ScaleFuncForm),
("Prod", [0, 1], ScaleFuncForm),
("S2plusS1half", [0, 1], ScaleFuncForm),
("Pow4Sum", [0, 1], ScaleFuncForm),
("WgtAvg", [0, 1], ScaleFuncForm),
("S2plusS1fourth", [0, 1], ScaleFuncForm),
("ExpProd2", [0, 1], ScaleFuncForm),
("NoScale", [0]),
("Scale", [0]),
("QuadraticSum", [0, 1]),
("QuadraticMean", [0, 1]),
("QuadraticSumOver4", [0, 1]),
("LinearMean", [0, 1]),
("LinearSum", [0, 1]),
("ScaleMax", [0, 1]),
("ScaleMin", [0, 1]),
("Prod", [0, 1]),
("S2plusS1half", [0, 1]),
("Pow4Sum", [0, 1]),
("WgtAvg", [0, 1]),
("S2plusS1fourth", [0, 1]),
("ExpProd2", [0, 1]),
],
)
def test_init(
self,
scaletype: ScaleFuncForm,
argument: list,
expected_type: ScaleFuncForm,
):
def test_init(self, scaletype: ScaleFuncForm, argument: list):
scale_method = getattr(ScaleFuncForm, scaletype)
result = scale_method(*argument)
assert isinstance(result, expected_type)
assert isinstance(result, ScaleFuncForm)


class TestOrder:
Expand Down

0 comments on commit e7c2e88

Please sign in to comment.