deepsource-autofix[bot] commited on
Commit
3fb2dca
1 Parent(s): 7acfb32

Format code with black

Browse files

This commit fixes the style issues introduced in 7acfb32 according to the output
from black.

Details: https://deepsource.io/gh/MilesCranmer/PySR/transform/42920b26-add2-4718-9b08-113f6a24afb0/

benchmarks/hyperparamopt.py CHANGED
@@ -267,6 +267,7 @@ def merge_trials(trials1, trials2_slice):
267
 
268
 
269
  import glob
 
270
  path = TRIALS_FOLDER + "/*.pkl"
271
  n_prior_trials = len(list(glob.glob(path)))
272
 
 
267
 
268
 
269
  import glob
270
+
271
  path = TRIALS_FOLDER + "/*.pkl"
272
  n_prior_trials = len(list(glob.glob(path)))
273
 
benchmarks/print_best_model.py CHANGED
@@ -6,12 +6,13 @@ import hyperopt
6
  from hyperopt import hp, fmin, tpe, Trials
7
 
8
 
9
- #Change the following code to your file
10
  ################################################################################
11
  # TODO: Declare a folder to hold all trials objects
12
- TRIALS_FOLDER = 'trials2'
13
  ################################################################################
14
 
 
15
  def merge_trials(trials1, trials2_slice):
16
  """Merge two hyperopt trials objects
17
 
@@ -23,43 +24,43 @@ def merge_trials(trials1, trials2_slice):
23
  """
24
  max_tid = 0
25
  if len(trials1.trials) > 0:
26
- max_tid = max([trial['tid'] for trial in trials1.trials])
27
 
28
  for trial in trials2_slice:
29
- tid = trial['tid'] + max_tid + 1
30
  hyperopt_trial = Trials().new_trial_docs(
31
- tids=[None],
32
- specs=[None],
33
- results=[None],
34
- miscs=[None])
35
  hyperopt_trial[0] = trial
36
- hyperopt_trial[0]['tid'] = tid
37
- hyperopt_trial[0]['misc']['tid'] = tid
38
- for key in hyperopt_trial[0]['misc']['idxs'].keys():
39
- hyperopt_trial[0]['misc']['idxs'][key] = [tid]
40
- trials1.insert_trial_docs(hyperopt_trial)
41
  trials1.refresh()
42
  return trials1
43
 
 
44
  np.random.seed()
45
 
46
  # Load up all runs:
47
  import glob
48
- path = TRIALS_FOLDER + '/*.pkl'
 
49
  files = 0
50
  for fname in glob.glob(path):
51
 
52
- trials_obj = pkl.load(open(fname, 'rb'))
53
- n_trials = trials_obj['n']
54
- trials_obj = trials_obj['trials']
55
- if files == 0:
56
  trials = trials_obj
57
  else:
58
  trials = merge_trials(trials, trials_obj.trials[-n_trials:])
59
  files += 1
60
 
61
 
62
- print(files, 'trials merged')
63
 
64
 
65
  best_loss = np.inf
@@ -70,22 +71,20 @@ except NameError:
70
  raise NameError("No trials loaded. Be sure to set the right folder")
71
 
72
  # for trial in trials:
73
- # if trial['result']['status'] == 'ok':
74
- # loss = trial['result']['loss']
75
- # if loss < best_loss:
76
- # best_loss = loss
77
- # best_trial = trial
78
 
79
  # print(best_loss, best_trial['misc']['vals'])
80
- #trials = sorted(trials, key=lambda x: (x['result']['loss'] if trials['result']['status'] == 'ok' else float('inf')))
81
 
82
  clean_trials = []
83
  for trial in trials:
84
- clean_trials.append((trial['result']['loss'], trial['misc']['vals']))
85
 
86
  clean_trials = sorted(clean_trials, key=lambda x: x[0])
87
 
88
  for trial in clean_trials:
89
  print(trial)
90
-
91
-
 
6
  from hyperopt import hp, fmin, tpe, Trials
7
 
8
 
9
+ # Change the following code to your file
10
  ################################################################################
11
  # TODO: Declare a folder to hold all trials objects
12
+ TRIALS_FOLDER = "trials2"
13
  ################################################################################
14
 
15
+
16
  def merge_trials(trials1, trials2_slice):
17
  """Merge two hyperopt trials objects
18
 
 
24
  """
25
  max_tid = 0
26
  if len(trials1.trials) > 0:
27
+ max_tid = max([trial["tid"] for trial in trials1.trials])
28
 
29
  for trial in trials2_slice:
30
+ tid = trial["tid"] + max_tid + 1
31
  hyperopt_trial = Trials().new_trial_docs(
32
+ tids=[None], specs=[None], results=[None], miscs=[None]
33
+ )
 
 
34
  hyperopt_trial[0] = trial
35
+ hyperopt_trial[0]["tid"] = tid
36
+ hyperopt_trial[0]["misc"]["tid"] = tid
37
+ for key in hyperopt_trial[0]["misc"]["idxs"].keys():
38
+ hyperopt_trial[0]["misc"]["idxs"][key] = [tid]
39
+ trials1.insert_trial_docs(hyperopt_trial)
40
  trials1.refresh()
41
  return trials1
42
 
43
+
44
  np.random.seed()
45
 
46
  # Load up all runs:
47
  import glob
48
+
49
+ path = TRIALS_FOLDER + "/*.pkl"
50
  files = 0
51
  for fname in glob.glob(path):
52
 
53
+ trials_obj = pkl.load(open(fname, "rb"))
54
+ n_trials = trials_obj["n"]
55
+ trials_obj = trials_obj["trials"]
56
+ if files == 0:
57
  trials = trials_obj
58
  else:
59
  trials = merge_trials(trials, trials_obj.trials[-n_trials:])
60
  files += 1
61
 
62
 
63
+ print(files, "trials merged")
64
 
65
 
66
  best_loss = np.inf
 
71
  raise NameError("No trials loaded. Be sure to set the right folder")
72
 
73
  # for trial in trials:
74
+ # if trial['result']['status'] == 'ok':
75
+ # loss = trial['result']['loss']
76
+ # if loss < best_loss:
77
+ # best_loss = loss
78
+ # best_trial = trial
79
 
80
  # print(best_loss, best_trial['misc']['vals'])
81
+ # trials = sorted(trials, key=lambda x: (x['result']['loss'] if trials['result']['status'] == 'ok' else float('inf')))
82
 
83
  clean_trials = []
84
  for trial in trials:
85
+ clean_trials.append((trial["result"]["loss"], trial["misc"]["vals"]))
86
 
87
  clean_trials = sorted(clean_trials, key=lambda x: x[0])
88
 
89
  for trial in clean_trials:
90
  print(trial)