Skip to content

Commit 87daeb1

Browse files
authored
Merge pull request #2168 from NNPDF/parallelize-evolution
Parallelize Evolution at the level of `evolven3fit`
2 parents 5f06deb + 196201e commit 87daeb1

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

conda-recipe/meta.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ requirements:
4040
- eko >=0.14.2
4141
- fiatlux
4242
- sphinx >=5.0.2
43+
- joblib
4344
- sphinx_rtd_theme >0.5
4445
- sphinxcontrib-bibtex
4546
- ruamel.yaml <0.18

n3fit/src/evolven3fit/cli.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
def cli_evolven3fit(
5-
configuration_folder, q_fin, q_points, op_card_info, theory_card_info, force, load, dump
5+
configuration_folder, q_fin, q_points, op_card_info, theory_card_info, force, load, dump, ncores
66
):
77
"""Evolves the fitted PDFs.
88
@@ -23,5 +23,13 @@ def cli_evolven3fit(
2323
"""
2424
utils.check_is_a_fit(configuration_folder)
2525
return evolve.evolve_fit(
26-
configuration_folder, q_fin, q_points, op_card_info, theory_card_info, force, load, dump
26+
configuration_folder,
27+
q_fin,
28+
q_points,
29+
op_card_info,
30+
theory_card_info,
31+
force,
32+
load,
33+
dump,
34+
ncores,
2735
)

n3fit/src/evolven3fit/evolve.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import sys
66

77
from ekobox import apply, genpdf, info_file
8+
from joblib import Parallel, delayed
89
import numpy as np
10+
import psutil
911

1012
import eko
1113
from eko import basis_rotation, runner
@@ -22,9 +24,19 @@
2224
"level": logging.DEBUG,
2325
}
2426

27+
NUM_CORES = psutil.cpu_count(logical=False)
28+
2529

2630
def evolve_fit(
27-
fit_folder, q_fin, q_points, op_card_dict, theory_card_dict, force, eko_path, dump_eko=None
31+
fit_folder,
32+
q_fin,
33+
q_points,
34+
op_card_dict,
35+
theory_card_dict,
36+
force,
37+
eko_path,
38+
dump_eko=None,
39+
ncores=1,
2840
):
2941
"""
3042
Evolves all the fitted replica in fit_folder/nnfit
@@ -117,10 +129,16 @@ def evolve_fit(
117129
info["NumFlavors"] = theory.heavy.num_flavs_max_pdf
118130
dump_info_file(usr_path, info)
119131

120-
for replica, pdf_data in initial_PDFs_dict.items():
121-
evolved_blocks = evolve_exportgrid(pdf_data, eko_op, x_grid)
132+
def _wrap_evolve(pdf, replica):
133+
evolved_blocks = evolve_exportgrid(pdf, eko_op, x_grid)
122134
dump_evolved_replica(evolved_blocks, usr_path, int(replica.removeprefix("replica_")))
123135

136+
# Choose the number of cores to be the Minimal value
137+
nb_cores = min(NUM_CORES, abs(ncores))
138+
Parallel(n_jobs=nb_cores)(
139+
delayed(_wrap_evolve)(pdf, r) for r, pdf in initial_PDFs_dict.items()
140+
)
141+
124142
# remove folder:
125143
# The function dump_evolved_replica dumps the replica files in a temporary folder
126144
# We need then to remove it after fixing the position of those replica files

n3fit/src/n3fit/scripts/evolven3fit.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
import pathlib
88
import sys
99

10-
from evolven3fit import cli, eko_utils, evolve, utils
1110
import numpy as np
1211

1312
from eko.runner.managed import solve
13+
from evolven3fit import cli, eko_utils, evolve, utils
1414
from n3fit.io.writer import XGRID
1515
from validphys.loader import FallbackLoader, Loader
1616

@@ -169,6 +169,7 @@ def main():
169169
args.force,
170170
eko_path,
171171
None,
172+
args.n_cores,
172173
)
173174
else:
174175
# If we are in the business of producing an eko, do some checks before starting:

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ reportengine = { git = "https://github.com/NNPDF/reportengine" }
7373
psutil = "*"
7474
tensorflow = "*"
7575
eko = "^0.14.1"
76+
joblib = "*"
7677
# Hyperopt
7778
hyperopt = "*"
7879
seaborn = "*"

0 commit comments

Comments
 (0)