diff --git a/bindings/distrdf/python/DistRDF/Backends/Dask/Backend.py b/bindings/distrdf/python/DistRDF/Backends/Dask/Backend.py index 70ed6e8b7a8c7..a4e32951a7381 100644 --- a/bindings/distrdf/python/DistRDF/Backends/Dask/Backend.py +++ b/bindings/distrdf/python/DistRDF/Backends/Dask/Backend.py @@ -319,10 +319,11 @@ def _process_partial_results(self, cumulative_plots: Dict[int, Any] = {} # Collect all futures in batches that had arrived since the last iteration - for batch in as_completed(future_tasks, with_results=True).batches(): - for future, result in batch: - merged_results = reducer(merged_results, result) if merged_results else result - + for batch in as_completed(future_tasks, with_results=False).batches(): + for future in batch: + result = future.result() + merged_results = reducer(merged_results, result) if merged_results else result + mergeables = merged_results.mergeables for pad_num, (drawable_id, (callbacks_list, index, operation_name)) in enumerate(drawables_info_dict.items(), start=1): diff --git a/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_th1.py b/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_th1.py index 0e9a819102c6d..9efd66e13b890 100644 --- a/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_th1.py +++ b/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_th1.py @@ -265,3 +265,4 @@ def pythonize_th1(klass): _add_indexing_features(klass) inject_clone_releasing_ownership(klass) + klass.Fit.__release_gil__ = True diff --git a/bindings/pyroot/pythonizations/test/CMakeLists.txt b/bindings/pyroot/pythonizations/test/CMakeLists.txt index ad4dd92ca3794..9be01d99e8909 100644 --- a/bindings/pyroot/pythonizations/test/CMakeLists.txt +++ b/bindings/pyroot/pythonizations/test/CMakeLists.txt @@ -59,7 +59,9 @@ ROOT_ADD_PYUNITTEST(pyroot_pyz_ttree_branch ttree_branch.py PYTHON_DEPS numpy) ROOT_ADD_PYUNITTEST(pyroot_pyz_tcolor tcolor.py) # TH1 and subclasses pythonizations -ROOT_ADD_PYUNITTEST(pyroot_pyz_th1_operators th1_operators.py) +ROOT_ADD_PYUNITTEST(pyroot_pyz_th1 th1.py) +# The above tests a deadlock. It should complete in about 1s. If we don't reduce the timeout, we need to wait 1500 s. +set_tests_properties(pyunittests-bindings-pyroot-pythonizations-pyroot-pyz-th1 PROPERTIES TIMEOUT 30) ROOT_ADD_PYUNITTEST(pyroot_pyz_th1_fillN th1_fillN.py PYTHON_DEPS numpy) ROOT_ADD_PYUNITTEST(pyroot_pyz_th2 th2.py) ROOT_ADD_PYUNITTEST(pyroot_pyz_th3 th3.py) diff --git a/bindings/pyroot/pythonizations/test/th1.py b/bindings/pyroot/pythonizations/test/th1.py new file mode 100644 index 0000000000000..5dd7f32e90367 --- /dev/null +++ b/bindings/pyroot/pythonizations/test/th1.py @@ -0,0 +1,70 @@ +import unittest + +import ROOT + + +class TH1Operators(unittest.TestCase): + """ + Test for the __imul__ operator of TH1 and subclasses, which + multiplies the histogram by a constant. + """ + + # Tests + def test_imul(self): + nbins = 64 + h = ROOT.TH1F("testHist", "", nbins, -4, 4) + h.FillRandom("gaus") + + initial_bins = [h.GetBinContent(i) for i in range(nbins)] + c = 2 + + # Multiply in place + h *= c + + # Check new value of bins + for i in range(nbins): + self.assertEqual(h.GetBinContent(i), initial_bins[i] * c) + + +class TH1IMT(unittest.TestCase): + """ + Test a deadlock when IMT is used in conjunction with a fit function in Python. + Since TH1.Fit held the GIL, the fit function could never be evaluated + """ + + @classmethod + def setUpClass(cls): + ROOT.ROOT.EnableImplicitMT(4) + + @classmethod + def tearDownClass(cls): + ROOT.ROOT.DisableImplicitMT() + + def test_fit_python_function(self): + xmin = 0 + xmax = 1 + + h1 = ROOT.TH1F("h1", "", 20, xmin, xmax) + h1.FillRandom("gaus", 1000) + + def func(x, pars): + return pars[0] + pars[1] * x[0] + + my_func = ROOT.TF1("f1", func, xmin, xmax, npar=2, ndim=1) + + my_func.SetParNames( + "A", + "B", + ) + my_func.SetParameter(0, 1) + my_func.SetParameter(1, -1) + + r = h1.Fit(my_func, "SE0Q", "", xmin, xmax) + + self.assertFalse(r.IsEmpty()) + self.assertTrue(r.IsValid()) + self.assertGreater(r.Parameter(0), 0) + + +if __name__ == "__main__": + unittest.main() diff --git a/bindings/pyroot/pythonizations/test/th1_operators.py b/bindings/pyroot/pythonizations/test/th1_operators.py deleted file mode 100644 index 881f89e8baa19..0000000000000 --- a/bindings/pyroot/pythonizations/test/th1_operators.py +++ /dev/null @@ -1,30 +0,0 @@ -import unittest - -import ROOT - - -class TH1Operators(unittest.TestCase): - """ - Test for the __imul__ operator of TH1 and subclasses, which - multiplies the histogram by a constant. - """ - - # Tests - def test_imul(self): - nbins = 64 - h = ROOT.TH1F("testHist", "", nbins, -4, 4) - h.FillRandom("gaus") - - initial_bins = [ h.GetBinContent(i) for i in range(nbins) ] - c = 2 - - # Multiply in place - h *= c - - # Check new value of bins - for i in range(nbins): - self.assertEqual(h.GetBinContent(i), initial_bins[i] * c) - - -if __name__ == '__main__': - unittest.main()