AutonLabTruth commited on
Commit
a58c3d5
·
1 Parent(s): 0aafc34

Completed Refactoring of sr.py

Browse files
Files changed (1) hide show
  1. pysr/sr.py +19 -13
pysr/sr.py CHANGED
@@ -247,24 +247,35 @@ def pysr(X=None, y=None, weights=None,
247
  create_julia_files(dataset_filename, def_datasets, def_hyperparams, fractionReplaced, hyperparam_filename,
248
  ncyclesperiteration, niterations, npop, pkg_filename, runfile_filename, topn, verbosity)
249
 
250
- command = [
251
- f'julia', f'-O{julia_optimization:d}',
252
- f'-p', f'{procs}',
253
- str(runfile_filename),
254
- ]
255
- if timeout is not None:
256
- command = [f'timeout', f'{timeout}'] + command
 
 
257
 
 
258
  global global_n_features
259
  global global_equation_file
260
  global global_variable_names
261
  global global_extra_sympy_mappings
262
-
263
  global_n_features = X.shape[1]
264
  global_equation_file = equation_file
265
  global_variable_names = variable_names
266
  global_extra_sympy_mappings = extra_sympy_mappings
267
 
 
 
 
 
 
 
 
 
 
268
  print("Running on", ' '.join(command))
269
  process = subprocess.Popen(command, stdout=subprocess.PIPE, bufsize=1, shell=True)
270
  try:
@@ -279,11 +290,6 @@ def pysr(X=None, y=None, weights=None,
279
  print("Killing process... will return when done.")
280
  process.kill()
281
 
282
- if delete_tempfiles:
283
- shutil.rmtree(tmpdir)
284
-
285
- return get_hof()
286
-
287
 
288
  def create_julia_files(dataset_filename, def_datasets, def_hyperparams, fractionReplaced, hyperparam_filename,
289
  ncyclesperiteration, niterations, npop, pkg_filename, runfile_filename, topn, verbosity):
 
247
  create_julia_files(dataset_filename, def_datasets, def_hyperparams, fractionReplaced, hyperparam_filename,
248
  ncyclesperiteration, niterations, npop, pkg_filename, runfile_filename, topn, verbosity)
249
 
250
+ final_pysr_process(julia_optimization, procs, runfile_filename, timeout)
251
+
252
+ set_globals(X, equation_file, extra_sympy_mappings, variable_names)
253
+
254
+ if delete_tempfiles:
255
+ shutil.rmtree(tmpdir)
256
+
257
+ return get_hof()
258
+
259
 
260
+ def set_globals(X, equation_file, extra_sympy_mappings, variable_names):
261
  global global_n_features
262
  global global_equation_file
263
  global global_variable_names
264
  global global_extra_sympy_mappings
 
265
  global_n_features = X.shape[1]
266
  global_equation_file = equation_file
267
  global_variable_names = variable_names
268
  global_extra_sympy_mappings = extra_sympy_mappings
269
 
270
+
271
+ def final_pysr_process(julia_optimization, procs, runfile_filename, timeout):
272
+ command = [
273
+ f'julia', f'-O{julia_optimization:d}',
274
+ f'-p', f'{procs}',
275
+ str(runfile_filename),
276
+ ]
277
+ if timeout is not None:
278
+ command = [f'timeout', f'{timeout}'] + command
279
  print("Running on", ' '.join(command))
280
  process = subprocess.Popen(command, stdout=subprocess.PIPE, bufsize=1, shell=True)
281
  try:
 
290
  print("Killing process... will return when done.")
291
  process.kill()
292
 
 
 
 
 
 
293
 
294
  def create_julia_files(dataset_filename, def_datasets, def_hyperparams, fractionReplaced, hyperparam_filename,
295
  ncyclesperiteration, niterations, npop, pkg_filename, runfile_filename, topn, verbosity):