Skip to content

Commit 15f8478

Browse files
committed
load hyperotp results with vp api
1 parent 64fea5d commit 15f8478

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

n3fit/src/n3fit/model_trainer.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ def __init__(
113113
theoryid=None,
114114
lux_params=None,
115115
replicas=None,
116+
trials=None,
116117
):
117118
"""
118119
Parameters
@@ -153,6 +154,8 @@ def __init__(
153154
if not give, the photon is not generated
154155
replicas: list
155156
list with the replicas ids to be fitted
157+
trials: str
158+
name of the file containing the trials defining the methodology
156159
"""
157160
# Save all input information
158161
self.exp_info = list(exp_info)
@@ -169,6 +172,7 @@ def __init__(
169172
self.lux_params = lux_params
170173
self.replicas = replicas
171174
self.experiments_data = experiments_data
175+
self.trials=trials
172176

173177
# Initialise internal variables which define behaviour
174178
if debug:
@@ -853,7 +857,6 @@ def hyperparametrizable(self, params):
853857
# Reset the internal state of the backend every time this function is called
854858
print("")
855859
clear_backend_state()
856-
857860
# When doing hyperopt some entries in the params dictionary
858861
# can bring with them overriding arguments
859862
if self.mode_hyperopt:
@@ -867,7 +870,7 @@ def hyperparametrizable(self, params):
867870
else:
868871
with open(params['hyperopt_res'], 'r') as file:
869872
hyperopt_params = json.load(file)
870-
873+
import pdb; pdb.set_trace()
871874
# Preprocess some hyperparameters
872875
if self.mode_hyperopt:
873876
epochs = int(params["epochs"])

n3fit/src/n3fit/performfit.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def performfit(
3636
load=None,
3737
hyperscanner=None,
3838
hyperopt=None,
39+
trials,
3940
kfold_parameters,
4041
tensorboard=None,
4142
debug=False,
@@ -115,6 +116,8 @@ def performfit(
115116
dictionary containing the details of the hyperscanner
116117
hyperopt: int
117118
if given, number of hyperopt iterations to run
119+
trials: str
120+
file containing trials defining the methodology
118121
kfold_parameters: None, dict
119122
dictionary with kfold settings used in hyperopt.
120123
tensorboard: None, dict
@@ -197,6 +200,7 @@ def performfit(
197200
theoryid=theoryid,
198201
lux_params=fiatlux,
199202
replicas=replica_idxs,
203+
trials=trials,
200204
)
201205

202206
# This is just to give a descriptive name to the fit function

n3fit/src/n3fit/scripts/n3fit_exec.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import re
1010
import shutil
1111
import sys
12+
import pandas as pd
1213

1314
from ruamel.yaml import error
1415

@@ -18,6 +19,8 @@
1819
from validphys.config import Config, ConfigError, Environment, EnvironmentError_
1920
from validphys.core import FitSpec
2021
from validphys.utils import yaml_safe
22+
from validphys.api import API
23+
from validphys.hyperoptplot import generate_dictionary
2124

2225
N3FIT_FIXED_CONFIG = dict(use_cuts='internal', use_t0=True, actions_=[], allow_legacy_names=False)
2326

@@ -234,7 +237,16 @@ def produce_hyperscanner(self, parameters, hyperscan_config=None, hyperopt=None)
234237
"db_path": db_path,
235238
}
236239
return HyperScanner(parameters, hyperscan_config, **extra_args)
237-
240+
241+
def produce_trials(self, trials_file):
242+
hyperscan = API.hyperscan(hyperscan=trials_file)
243+
dict_trials = generate_dictionary(hyperscan.tries_files[1].parent,"average")
244+
hyperopt_dataframe = pd.DataFrame(dict_trials)
245+
n_termalization = 400
246+
n_best = 10
247+
best = hyperopt_dataframe[n_termalization:].sort_values('loss')[:n_best]
248+
return best.to_dict(orient='list')
249+
238250

239251
class N3FitApp(App):
240252
"""The class which parsers and performs the fit"""

0 commit comments

Comments
 (0)