AutonLabTruth commited on
Commit
59765a8
1 Parent(s): e2a7e95

Changed Verbosity to enable complete silence mode and created full experiment function

Browse files
Files changed (3) hide show
  1. julia/sr.jl +3 -1
  2. pysr/Problems.py +25 -4
  3. pysr/sr.py +2 -1
julia/sr.jl CHANGED
@@ -31,7 +31,9 @@ function fullRun(niterations::Integer;
31
  @sync for i=1:npopulations
32
  @async allPops[i] = @spawnat :any run(fetch(allPops[i]), ncyclesperiteration, curmaxsize, copy(frequencyComplexity)/sum(frequencyComplexity), verbosity=verbosity)
33
  end
34
- println("Started!")
 
 
35
  cycles_complete = npopulations * niterations
36
  if warmupMaxsize != 0
37
  curmaxsize += 1
 
31
  @sync for i=1:npopulations
32
  @async allPops[i] = @spawnat :any run(fetch(allPops[i]), ncyclesperiteration, curmaxsize, copy(frequencyComplexity)/sum(frequencyComplexity), verbosity=verbosity)
33
  end
34
+ if verbosity > 0
35
+ println("Started!")
36
+ end
37
  cycles_complete = npopulations * niterations
38
  if warmupMaxsize != 0
39
  curmaxsize += 1
pysr/Problems.py CHANGED
@@ -1,7 +1,7 @@
1
  import numpy as np
2
  import csv
3
  import traceback
4
-
5
 
6
  class Problem:
7
  """
@@ -94,13 +94,34 @@ def run_on_problem(problem, verbosity=0):
94
  Takes in a problem and returns a tuple: (equations, best predicted equation, actual equation)
95
  """
96
  from time import time
97
- from . import pysr, best
98
  starting = time()
99
  equations = pysr(problem.X, problem.y, variable_names=problem.variable_names, verbosity=verbosity)
100
  timing = time()-starting
101
  others = {"equations": equations, "time": timing}
102
  return best(equations), problem.form, others
103
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  if __name__ == "__main__":
105
- ret = FeynmanProblem.mk_problems(first=100, gen=True)
106
- print(ret)
 
1
  import numpy as np
2
  import csv
3
  import traceback
4
+ from sr import pysr, best
5
 
6
  class Problem:
7
  """
 
94
  Takes in a problem and returns a tuple: (equations, best predicted equation, actual equation)
95
  """
96
  from time import time
 
97
  starting = time()
98
  equations = pysr(problem.X, problem.y, variable_names=problem.variable_names, verbosity=verbosity)
99
  timing = time()-starting
100
  others = {"equations": equations, "time": timing}
101
  return best(equations), problem.form, others
102
 
103
+
104
+ def do_feynman_experiments(first=100, verbosity=0, dp=500, output_file_path="experiments/FeynmanExperiment.csv", data_dir="datasets/FeynmanEquations.csv"):
105
+ from tqdm import tqdm
106
+ problems = FeynmanProblem.mk_problems(first=first, gen=True, dp=dp, data_dir=data_dir)
107
+ indx = range(len(problems))
108
+ ids = []
109
+ predictions = []
110
+ true_equations = []
111
+ time_takens = []
112
+ for problem in tqdm(problems):
113
+ prediction, true_equation, others = run_on_problem(problem, verbosity)
114
+ ids.append(problem.eq_id)
115
+ predictions.append(prediction)
116
+ true_equations.append(true_equation)
117
+ time_takens.append(others['time'])
118
+ with open(output_file_path, 'a') as f:
119
+ writer = csv.writer(outcsv, delimiter=',')
120
+ writer.writerow(['ID', 'Predicted', 'True', 'Time'])
121
+ for i in range(len(ids)):
122
+ writer.writerow([ids[i], predictions[i], true_equations[i], time_takens[i]])
123
+ return
124
+
125
+
126
  if __name__ == "__main__":
127
+ do_feynman_experiments(first=4)
 
pysr/sr.py CHANGED
@@ -306,7 +306,8 @@ def _final_pysr_process(julia_optimization, procs, runfile_filename, timeout, **
306
  ]
307
  if timeout is not None:
308
  command = [f'timeout', f'{timeout}'] + command
309
- print("Running on", ' '.join(command))
 
310
  process = subprocess.Popen(command, stdout=subprocess.PIPE, bufsize=1)
311
  try:
312
  while True:
 
306
  ]
307
  if timeout is not None:
308
  command = [f'timeout', f'{timeout}'] + command
309
+ if kwargs['verbosity'] > 0:
310
+ print("Running on", ' '.join(command))
311
  process = subprocess.Popen(command, stdout=subprocess.PIPE, bufsize=1)
312
  try:
313
  while True: