From f80a0ba89e9bb9b5e93693dca4abbf17b56658bf Mon Sep 17 00:00:00 2001 From: Olivier Mattelaer Date: Mon, 23 Nov 2026 09:13:37 +0100 Subject: [PATCH] Certify G scaling of the helicity masks on Python 3.14 helicity_coupling_degrees recognised numeric literals with ast.Num, which Python 3.14 removed. The AttributeError was caught as an unsupported expression, so every coupling came out of unknown degree and no NLO output certified homogeneous_G: with a dynamical scale each Born and real-emission call relearned its helicity mask at every change of alpha_s. Test numeric literals as ast.Constant instead. The existing coupling-degree test already failed on Python 3.14; the new test hides the removed aliases so that CI on older Pythons catches a reintroduction. Co-Authored-By: Claude Opus 5.5 --- UpdateNotes.txt | 5 +++++ madgraph/iolibs/born_support.py | 15 +++++++++++---- .../iolibs/test_real_helicity_filter.py | 15 +++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/UpdateNotes.txt b/UpdateNotes.txt index 9a2b33bd4d..bb4246cd6f 100644 --- a/UpdateNotes.txt +++ b/UpdateNotes.txt @@ -5,6 +5,11 @@ ANNOUNCEMENT: A new LTS (based on the current 3.5.X) is starting now and will act as the stable release for the coming years. 0.4.0 (XX/XX/XX): + OM: NLO outputs made with Python 3.14 never certified the G scaling of the helicity + masks (helicity_signature.json mode exact_compact_state instead of homogeneous_G): + the coupling-degree analysis used ast.Num, removed in Python 3.14, so every coupling + came out of unknown degree. With a dynamical scale each Born and real-emission call + then relearned its helicity mask, summing all helicities, at every change of alpha_s. OM: madevent rejected every phase-space point with a dynamical factorisation scale below 2 GeV whenever lpp was not 0, a floor that only makes sense for hadron PDFs: it silently cut the threshold region, e.g. 27% of PbPb > a a > ta+ ta- at 5.52 TeV diff --git a/madgraph/iolibs/born_support.py b/madgraph/iolibs/born_support.py index 1024bb49cb..085161c4ce 100644 --- a/madgraph/iolibs/born_support.py +++ b/madgraph/iolibs/born_support.py @@ -378,9 +378,15 @@ def variable(name): finally: visiting.remove(name) + def number(node): + # Numeric literals are ast.Constant nodes; ast.Num, its deprecated + # alias, no longer exists in Python 3.14, where every coupling then + # came out of unknown degree and no output certified G scaling. + return (isinstance(node, ast.Constant) and not isinstance(node.value, bool) + and isinstance(node.value, (int, float, complex))) + def expression(node): - # Num also recognizes numeric Constant nodes on Python >= 3.8. - if isinstance(node, ast.Num): + if number(node): return Fraction(0) if isinstance(node, ast.Name): return variable(node.id) @@ -397,8 +403,9 @@ def expression(node): return left-right if isinstance(node.op, (ast.Add, ast.Sub)) and left == right: return left - if isinstance(node.op, ast.Pow) and isinstance(node.right, ast.Num): - return left*Fraction(node.right.n) + if (isinstance(node.op, ast.Pow) and number(node.right) + and not isinstance(node.right.value, complex)): + return left*Fraction(node.right.value) if isinstance(node, ast.Call): name = node.func.id if isinstance(node.func, ast.Name) else ( node.func.attr if isinstance(node.func, ast.Attribute) and diff --git a/tests/unit_tests/iolibs/test_real_helicity_filter.py b/tests/unit_tests/iolibs/test_real_helicity_filter.py index 19cfaefeba..2ad53f3ea8 100644 --- a/tests/unit_tests/iolibs/test_real_helicity_filter.py +++ b/tests/unit_tests/iolibs/test_real_helicity_filter.py @@ -1,5 +1,6 @@ """Numerical checks of the generated real-emission helicity loop.""" +import ast import copy from pathlib import Path import re @@ -7,6 +8,7 @@ import subprocess import tempfile import unittest +from unittest import mock from madgraph.iolibs import born_support as support from madgraph.core.base_objects import ModelVariable, ParamCardVariable @@ -141,6 +143,19 @@ def test_sm_and_heft_coupling_degrees(self): with self.subTest(model=model_name, coupling=name): self.assertEqual(degrees[name], degree) + def test_coupling_degrees_without_removed_ast_aliases(self): + # Python 3.14 removed ast.Num and the other literal aliases of + # ast.Constant. Using one made every coupling degree unknown, so no + # output certified G scaling. Hide them here on any Python version. + class Python314Ast: + def __getattr__(self, name): + if name in ('Num', 'Str', 'Bytes', 'NameConstant', 'Ellipsis'): + raise AttributeError(name) + return getattr(ast, name) + + with mock.patch.object(support, 'ast', Python314Ast()): + self.test_sm_and_heft_coupling_degrees() + def run_driver(self, ncomb, nsqamps, driver, members=None, signature=None, include_real=True, diagram_weights=False): template = (ROOT/'madgraph/iolibs/template_files/'