AutonLabTruth commited on
Commit
371f4fe
·
1 Parent(s): a58c3d5

Added the auxiliary file features ready to merge

Browse files
Files changed (1) hide show
  1. pysr/sr.py +33 -6
pysr/sr.py CHANGED
@@ -192,8 +192,8 @@ def pysr(X=None, y=None, weights=None,
192
 
193
  """
194
  raise_depreciation_errors(limitPowComplexity, threads)
195
- X_filename, dataset_filename, hyperparam_filename, operator_filename, pkg_filename, runfile_filename, tmpdir, \
196
- weights_filename, y_filename = set_paths(tempdir)
197
 
198
  if isinstance(X, pd.DataFrame):
199
  variable_names = list(X.columns)
@@ -241,10 +241,11 @@ def pysr(X=None, y=None, weights=None,
241
  warmupMaxsize, weightAddNode, weightDeleteNode, weightDoNothing,
242
  weightInsertNode, weightMutateConstant, weightMutateOperator,
243
  weightRandomize, weightSimplify, weights)
 
244
 
245
  def_datasets = make_datasets_julia_str(X, X_filename, weights, weights_filename, y, y_filename)
246
 
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)
@@ -257,6 +258,13 @@ def pysr(X=None, y=None, weights=None,
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
@@ -291,15 +299,18 @@ def final_pysr_process(julia_optimization, procs, runfile_filename, timeout):
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):
296
  with open(hyperparam_filename, 'w') as f:
297
  print(def_hyperparams, file=f)
298
  with open(dataset_filename, 'w') as f:
299
  print(def_datasets, file=f)
 
 
300
  with open(runfile_filename, 'w') as f:
301
  print(f'@everywhere include("{_escape_filename(hyperparam_filename)}")', file=f)
302
  print(f'@everywhere include("{_escape_filename(dataset_filename)}")', file=f)
 
303
  print(f'@everywhere include("{_escape_filename(pkg_filename)}")', file=f)
304
  print(
305
  f'fullRun({niterations:d}, npop={npop:d}, ncyclesperiteration={ncyclesperiteration:d}, fractionReplaced={fractionReplaced:f}f0, verbosity=round(Int32, {verbosity:f}), topn={topn:d})',
@@ -497,15 +508,31 @@ def set_paths(tempdir):
497
  # System-independent paths
498
  pkg_directory = Path(__file__).parents[1] / 'julia'
499
  pkg_filename = pkg_directory / "sr.jl"
500
- operator_filename = pkg_directory / "operators.jl"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
501
  tmpdir = Path(tempfile.mkdtemp(dir=tempdir))
502
  hyperparam_filename = tmpdir / f'hyperparams.jl'
503
  dataset_filename = tmpdir / f'dataset.jl'
 
504
  runfile_filename = tmpdir / f'runfile.jl'
505
  X_filename = tmpdir / "X.csv"
506
  y_filename = tmpdir / "y.csv"
507
  weights_filename = tmpdir / "weights.csv"
508
- return X_filename, dataset_filename, hyperparam_filename, operator_filename, pkg_filename, runfile_filename, tmpdir, weights_filename, y_filename
 
509
 
510
 
511
  def check_assertions(X, binary_operators, unary_operators, use_custom_variable_names, variable_names, weights, y):
 
192
 
193
  """
194
  raise_depreciation_errors(limitPowComplexity, threads)
195
+ auxiliary_filename, X_filename, dataset_filename, hyperparam_filename, julia_auxiliary_filenames, operator_filename \
196
+ ,pkg_filename, runfile_filename, tmpdir, weights_filename, y_filename = set_paths(tempdir)
197
 
198
  if isinstance(X, pd.DataFrame):
199
  variable_names = list(X.columns)
 
241
  warmupMaxsize, weightAddNode, weightDeleteNode, weightDoNothing,
242
  weightInsertNode, weightMutateConstant, weightMutateOperator,
243
  weightRandomize, weightSimplify, weights)
244
+ def_auxiliary = make_auxiliary_julia_str(julia_auxiliary_filenames)
245
 
246
  def_datasets = make_datasets_julia_str(X, X_filename, weights, weights_filename, y, y_filename)
247
 
248
+ create_julia_files(auxiliary_filename, dataset_filename, def_auxiliary, def_datasets, def_hyperparams, fractionReplaced, hyperparam_filename,
249
  ncyclesperiteration, niterations, npop, pkg_filename, runfile_filename, topn, verbosity)
250
 
251
  final_pysr_process(julia_optimization, procs, runfile_filename, timeout)
 
258
  return get_hof()
259
 
260
 
261
+ def make_auxiliary_julia_str(julia_auxiliary_filenames):
262
+ def_auxiliary = '\n'.join([
263
+ f"""include("{_escape_filename(aux_fname)}")""" for aux_fname in julia_auxiliary_filenames
264
+ ])
265
+ return def_auxiliary
266
+
267
+
268
  def set_globals(X, equation_file, extra_sympy_mappings, variable_names):
269
  global global_n_features
270
  global global_equation_file
 
299
  process.kill()
300
 
301
 
302
+ def create_julia_files(auxiliary_filename, dataset_filename, def_auxiliary, def_datasets, def_hyperparams, fractionReplaced, hyperparam_filename,
303
  ncyclesperiteration, niterations, npop, pkg_filename, runfile_filename, topn, verbosity):
304
  with open(hyperparam_filename, 'w') as f:
305
  print(def_hyperparams, file=f)
306
  with open(dataset_filename, 'w') as f:
307
  print(def_datasets, file=f)
308
+ with open(auxiliary_filename, 'w') as f:
309
+ print(def_auxiliary, file=f)
310
  with open(runfile_filename, 'w') as f:
311
  print(f'@everywhere include("{_escape_filename(hyperparam_filename)}")', file=f)
312
  print(f'@everywhere include("{_escape_filename(dataset_filename)}")', file=f)
313
+ print(f'@everywhere include("{_escape_filename(auxiliary_filename)}")', file=f)
314
  print(f'@everywhere include("{_escape_filename(pkg_filename)}")', file=f)
315
  print(
316
  f'fullRun({niterations:d}, npop={npop:d}, ncyclesperiteration={ncyclesperiteration:d}, fractionReplaced={fractionReplaced:f}f0, verbosity=round(Int32, {verbosity:f}), topn={topn:d})',
 
508
  # System-independent paths
509
  pkg_directory = Path(__file__).parents[1] / 'julia'
510
  pkg_filename = pkg_directory / "sr.jl"
511
+ operator_filename = pkg_directory / "Operators.jl"
512
+ julia_auxiliaries = [
513
+ "Equation.jl", "ProgramConstants.jl",
514
+ "LossFunctions.jl", "Utils.jl", "EvaluateEquation.jl",
515
+ "MutationFunctions.jl", "SimplifyEquation.jl", "PopMember.jl",
516
+ "HallOfFame.jl", "CheckConstraints.jl", "Mutate.jl",
517
+ "Population.jl", "RegularizedEvolution.jl", "SingleIteration.jl",
518
+ "ConstantOptimization.jl"
519
+ ]
520
+ julia_auxiliary_filenames = [
521
+ pkg_directory / fname
522
+ for fname in julia_auxiliaries
523
+ ]
524
+
525
+
526
  tmpdir = Path(tempfile.mkdtemp(dir=tempdir))
527
  hyperparam_filename = tmpdir / f'hyperparams.jl'
528
  dataset_filename = tmpdir / f'dataset.jl'
529
+ auxiliary_filename = tmpdir / f'auxiliary.jl'
530
  runfile_filename = tmpdir / f'runfile.jl'
531
  X_filename = tmpdir / "X.csv"
532
  y_filename = tmpdir / "y.csv"
533
  weights_filename = tmpdir / "weights.csv"
534
+ return auxiliary_filename, X_filename, dataset_filename, hyperparam_filename, julia_auxiliary_filenames, \
535
+ operator_filename, pkg_filename, runfile_filename, tmpdir, weights_filename, y_filename
536
 
537
 
538
  def check_assertions(X, binary_operators, unary_operators, use_custom_variable_names, variable_names, weights, y):