Skip to content

Commit e177bd4

Browse files
authored
Merge branch 'master' into CMS_2JET_13TEV
2 parents ccb0504 + 27307c9 commit e177bd4

File tree

8 files changed

+40
-11
lines changed

8 files changed

+40
-11
lines changed

.github/actions/install_conda_pip/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ inputs:
2727
nnpdf-extras:
2828
required: true
2929
description: "Which extras to install"
30-
default: "[qed,tests]"
30+
default: "[qed,tests,hyperopt]"
3131

3232

3333
runs:

conda-recipe/meta.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ build:
1313

1414
requirements:
1515
host:
16-
- python >=3.9,<3.13
16+
- python >=3.10,<3.14
1717
- poetry-core >=1.0.0
1818
- poetry-dynamic-versioning >=1.2.0
1919
- pip
@@ -23,6 +23,7 @@ requirements:
2323
- keras >=3.1
2424
- psutil # to ensure n3fit affinity is with the right processors
2525
- hyperopt
26+
- setuptools <82 # to provide pkg_resources for hyperopt
2627
- mongodb
2728
- pymongo <4
2829
- pyopenssl >=23.2
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class HyperoptDependencyMissing:
2+
# cheap sentinel class, the best we can budget
3+
# Since setuptools updated to 82.0 hyperopt fails due to pkg_resources
4+
pass

n3fit/src/n3fit/hyper_optimization/filetrials.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818
import logging
1919
import pickle
2020

21-
from hyperopt import Trials, space_eval
21+
try:
22+
from hyperopt import Trials, space_eval
23+
except ModuleNotFoundError:
24+
from . import HyperoptDependencyMissing as Trials
25+
26+
space_eval = object()
2227

2328
from validphys.hyperoptplot import HyperoptTrial
2429

n3fit/src/n3fit/hyper_optimization/hyper_scan.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,17 @@
1717
import copy
1818
import logging
1919

20-
import hyperopt
21-
from hyperopt.pyll.base import scope
20+
try:
21+
import hyperopt
22+
from hyperopt.pyll.base import scope
23+
except ModuleNotFoundError:
24+
# TODO a sentinel class that tells the user the hyperopt dependency is missing would be nice
25+
# if you arrive here, yes, the hyperopt dependency is missing (or your setuptools is too new)
26+
from . import HyperoptDependencyMissing as hyperopt
27+
28+
scope = object()
29+
30+
2231
import numpy as np
2332

2433
from n3fit.backends import MetaLayer, MetaModel

n3fit/src/n3fit/hyper_optimization/mongofiletrials.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,14 @@
2424
import subprocess
2525
import time
2626

27-
from bson import SON, ObjectId
28-
from hyperopt.mongoexp import MongoTrials
27+
try:
28+
from bson import SON, ObjectId
29+
from hyperopt.mongoexp import MongoTrials
30+
except ModuleNotFoundError:
31+
SON = object()
32+
from . import HyperoptDependencyMissing as MongoTrials
33+
34+
ObjectId = object()
2935

3036
from n3fit.backends import get_physical_gpus
3137
from n3fit.hyper_optimization.filetrials import space_eval_trial

pyproject.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ tensorflow = "*"
7575
keras = "^3.1"
7676
eko = "^0.15.1"
7777
joblib = "*"
78-
# Hyperopt
79-
hyperopt = "*"
8078
seaborn = "*"
79+
# Hyperopt
80+
hyperopt = {version = "*", optional = true}
81+
# hyperopt needs setuptools pinned to < 82 due to pkg resources
82+
setuptools = {version = "<82", optional = true}
8183
# LHAPDF installation for debugging purposes
8284
# a3b2bbc3ced97675ac3a71df45f55ba = "*"
8385
# Optional dependencies
@@ -111,7 +113,8 @@ qed = ["fiatlux"]
111113
nolha = ["pdfflow", "lhapdf-management"]
112114
torch = ["torch"]
113115
jax = ["jax"]
114-
parallelhyperopt = ["pymongo"]
116+
hyperopt = ["hyperopt", "setuptools"]
117+
parallelhyperopt = ["pymongo", "hyperopt", "setuptools"]
115118

116119
[tool.poetry-dynamic-versioning]
117120
enable = true

validphys2/src/validphys/core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
# Maybe move the cuts logic to its own module?
2424
from validphys import filters, lhaindex
2525
from validphys.fkparser import load_fktable, parse_cfactor
26-
from validphys.hyperoptplot import HyperoptTrial
2726
from validphys.lhapdfset import LHAPDFSet
2827
from validphys.tableloader import parse_exp_mat
2928
from validphys.utils import experiments_to_dataset_inputs, yaml_safe
@@ -747,6 +746,8 @@ def get_all_trials(self, base_params=None):
747746
748747
Each hyperopt trial object will also have a reference to all trials in its own file
749748
"""
749+
from validphys.hyperoptplot import HyperoptTrial
750+
750751
all_trials = []
751752
for trial_file in self.tries_files.values():
752753
with open(trial_file) as tf:

0 commit comments

Comments
 (0)