MilesCranmer commited on
Commit
c7034da
β€’
1 Parent(s): 48d465b

Import auxiliaries after operators defined

Browse files
julia/{operators.jl β†’ Operators.jl} RENAMED
File without changes
julia/sr.jl CHANGED
@@ -2,22 +2,6 @@ import Optim
2
  import Printf: @printf
3
  import Random: shuffle!, randperm
4
 
5
- include("Equation.jl")
6
- include("ProgramConstants.jl")
7
- include("LossFunctions.jl")
8
- include("Utils.jl")
9
- include("EvaluateEquation.jl")
10
- include("MutationFunctions.jl")
11
- include("SimplifyEquation.jl")
12
- include("PopMember.jl")
13
- include("HallOfFame.jl")
14
- include("CheckConstraints.jl")
15
- include("Mutate.jl")
16
- include("Population.jl")
17
- include("RegularizedEvolution.jl")
18
- include("SingleIteration.jl")
19
- include("ConstantOptimization.jl")
20
-
21
  function fullRun(niterations::Integer;
22
  npop::Integer=300,
23
  ncyclesperiteration::Integer=3000,
 
2
  import Printf: @printf
3
  import Random: shuffle!, randperm
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  function fullRun(niterations::Integer;
6
  npop::Integer=300,
7
  ncyclesperiteration::Integer=3000,
pysr/sr.py CHANGED
@@ -254,11 +254,24 @@ def pysr(X=None, y=None, weights=None,
254
  # System-independent paths
255
  pkg_directory = Path(__file__).parents[1] / 'julia'
256
  pkg_filename = pkg_directory / "sr.jl"
257
- operator_filename = pkg_directory / "operators.jl"
 
 
 
 
 
 
 
 
 
 
 
 
258
 
259
  tmpdir = Path(tempfile.mkdtemp(dir=tempdir))
260
  hyperparam_filename = tmpdir / f'hyperparams.jl'
261
  dataset_filename = tmpdir / f'dataset.jl'
 
262
  runfile_filename = tmpdir / f'runfile.jl'
263
  X_filename = tmpdir / "X.csv"
264
  y_filename = tmpdir / "y.csv"
@@ -395,6 +408,10 @@ end"""
395
 
396
  def_hyperparams += op_runner
397
 
 
 
 
 
398
  def_datasets = """using DelimitedFiles"""
399
 
400
  np.savetxt(X_filename, X, delimiter=',')
@@ -420,9 +437,13 @@ const varMap = {'["' + '", "'.join(variable_names) + '"]'}"""
420
  with open(dataset_filename, 'w') as f:
421
  print(def_datasets, file=f)
422
 
 
 
 
423
  with open(runfile_filename, 'w') as f:
424
  print(f'@everywhere include("{_escape_filename(hyperparam_filename)}")', file=f)
425
  print(f'@everywhere include("{_escape_filename(dataset_filename)}")', file=f)
 
426
  print(f'@everywhere include("{_escape_filename(pkg_filename)}")', file=f)
427
  print(f'fullRun({niterations:d}, npop={npop:d}, ncyclesperiteration={ncyclesperiteration:d}, fractionReplaced={fractionReplaced:f}f0, verbosity=round(Int32, {verbosity:f}), topn={topn:d})', file=f)
428
  print(f'rmprocs(nprocs)', file=f)
 
254
  # System-independent paths
255
  pkg_directory = Path(__file__).parents[1] / 'julia'
256
  pkg_filename = pkg_directory / "sr.jl"
257
+ operator_filename = pkg_directory / "Operators.jl"
258
+ julia_auxiliaries = [
259
+ "Equation.jl", "ProgramConstants.jl",
260
+ "LossFunctions.jl", "Utils.jl", "EvaluateEquation.jl",
261
+ "MutationFunctions.jl", "SimplifyEquation.jl", "PopMember.jl",
262
+ "HallOfFame.jl", "CheckConstraints.jl", "Mutate.jl",
263
+ "Population.jl", "RegularizedEvolution.jl", "SingleIteration.jl",
264
+ "ConstantOptimization.jl"
265
+ ]
266
+ julia_auxiliary_filenames = [
267
+ pkg_directory / fname
268
+ for fname in julia_auxiliaries
269
+ ]
270
 
271
  tmpdir = Path(tempfile.mkdtemp(dir=tempdir))
272
  hyperparam_filename = tmpdir / f'hyperparams.jl'
273
  dataset_filename = tmpdir / f'dataset.jl'
274
+ auxiliary_filename = tmpdir / f'auxiliary.jl'
275
  runfile_filename = tmpdir / f'runfile.jl'
276
  X_filename = tmpdir / "X.csv"
277
  y_filename = tmpdir / "y.csv"
 
408
 
409
  def_hyperparams += op_runner
410
 
411
+ def_auxiliary = '\n'.join([
412
+ f"""include("{_escape_filename(aux_fname)}")""" for aux_fname in julia_auxiliary_filenames
413
+ ])
414
+
415
  def_datasets = """using DelimitedFiles"""
416
 
417
  np.savetxt(X_filename, X, delimiter=',')
 
437
  with open(dataset_filename, 'w') as f:
438
  print(def_datasets, file=f)
439
 
440
+ with open(auxiliary_filename, 'w') as f:
441
+ print(def_auxiliary, file=f)
442
+
443
  with open(runfile_filename, 'w') as f:
444
  print(f'@everywhere include("{_escape_filename(hyperparam_filename)}")', file=f)
445
  print(f'@everywhere include("{_escape_filename(dataset_filename)}")', file=f)
446
+ print(f'@everywhere include("{_escape_filename(auxiliary_filename)}")', file=f)
447
  print(f'@everywhere include("{_escape_filename(pkg_filename)}")', file=f)
448
  print(f'fullRun({niterations:d}, npop={npop:d}, ncyclesperiteration={ncyclesperiteration:d}, fractionReplaced={fractionReplaced:f}f0, verbosity=round(Int32, {verbosity:f}), topn={topn:d})', file=f)
449
  print(f'rmprocs(nprocs)', file=f)