Johann Brehmer commited on
Commit
a2003c2
1 Parent(s): 6b04774

Escaped backslash in operator file

Browse files
Files changed (1) hide show
  1. pysr/sr.py +9 -12
pysr/sr.py CHANGED
@@ -249,8 +249,15 @@ def pysr(X=None, y=None, weights=None,
249
  y = eval(eval_str)
250
  print("Running on", eval_str)
251
 
252
- # Absolute paths are necessary for Windows support
253
  pkg_directory = Path(__file__).parents[1] / 'julia'
 
 
 
 
 
 
 
254
 
255
  def_hyperparams = ""
256
 
@@ -307,8 +314,7 @@ const bin_constraints = ["""
307
  first = False
308
  constraints_str += "]"
309
 
310
-
311
- def_hyperparams += f"""include("{pkg_directory}/operators.jl")
312
  {constraints_str}
313
  const binops = {'[' + ', '.join(binary_operators) + ']'}
314
  const unaops = {'[' + ', '.join(unary_operators) + ']'}
@@ -402,15 +408,6 @@ const weights = convert(Array{Float32, 1}, """f"{weight_str})"
402
  def_hyperparams += f"""
403
  const varMap = {'["' + '", "'.join(variable_names) + '"]'}"""
404
 
405
- # Get temporary directory in a system-independent way
406
- tmpdirname = tempfile.mkdtemp(dir=tempdir)
407
- tmpdir = Path(tmpdirname)
408
-
409
- hyperparam_filename = tmpdir / f'.hyperparams_{rand_string}.jl'
410
- dataset_filename = tmpdir / f'.dataset_{rand_string}.jl'
411
- runfile_filename = tmpdir / f'.runfile_{rand_string}.jl'
412
- pkg_filename = pkg_directory / "sr.jl"
413
-
414
  with open(hyperparam_filename, 'w') as f:
415
  print(def_hyperparams, file=f)
416
 
 
249
  y = eval(eval_str)
250
  print("Running on", eval_str)
251
 
252
+ # System-independent paths
253
  pkg_directory = Path(__file__).parents[1] / 'julia'
254
+ pkg_filename = pkg_directory / "sr.jl"
255
+ operator_filename = pkg_directory / "operators.jl"
256
+
257
+ tmpdir = Path(tempfile.mkdtemp(dir=tempdir))
258
+ hyperparam_filename = tmpdir / f'.hyperparams_{rand_string}.jl'
259
+ dataset_filename = tmpdir / f'.dataset_{rand_string}.jl'
260
+ runfile_filename = tmpdir / f'.runfile_{rand_string}.jl'
261
 
262
  def_hyperparams = ""
263
 
 
314
  first = False
315
  constraints_str += "]"
316
 
317
+ def_hyperparams += f"""include("{_escape_filename(operator_filename)}")
 
318
  {constraints_str}
319
  const binops = {'[' + ', '.join(binary_operators) + ']'}
320
  const unaops = {'[' + ', '.join(unary_operators) + ']'}
 
408
  def_hyperparams += f"""
409
  const varMap = {'["' + '", "'.join(variable_names) + '"]'}"""
410
 
 
 
 
 
 
 
 
 
 
411
  with open(hyperparam_filename, 'w') as f:
412
  print(def_hyperparams, file=f)
413