MilesCranmer commited on
Commit
c1a7eb6
1 Parent(s): 46ce389

Clean up use of global

Browse files
Files changed (1) hide show
  1. pysr/sr.py +8 -11
pysr/sr.py CHANGED
@@ -135,7 +135,6 @@ def pysr(
135
  tempdir=None,
136
  delete_tempfiles=True,
137
  julia_project=None,
138
- user_input=True,
139
  update=True,
140
  temp_equation_file=False,
141
  output_jax_format=False,
@@ -248,8 +247,6 @@ def pysr(
248
  :type delete_tempfiles: bool
249
  :param julia_project: a Julia environment location containing a Project.toml (and potentially the source code for SymbolicRegression.jl). Default gives the Python package directory, where a Project.toml file should be present from the install.
250
  :type julia_project: str/None
251
- :param user_input: Whether to ask for user input or not for installing (to be used for automated scripts). Will choose to install when asked.
252
- :type user_input: bool
253
  :param update: Whether to automatically update Julia packages.
254
  :type update: bool
255
  :param temp_equation_file: Whether to put the hall of fame file in the temp directory. Deletion is then controlled with the delete_tempfiles argument.
@@ -439,18 +436,19 @@ Required dependencies are not installed or built. Run the following code in the
439
  from julia import Pkg
440
 
441
  Pkg.activate(f"{_escape_filename(julia_project)}")
442
- try:
443
- Pkg.resolve()
444
- except RuntimeError as e:
445
- raise ImportError(
446
- f"""
 
447
  Required dependencies are not installed or built. Run the following code in the Python REPL:
448
 
449
  >>> import pysr
450
  >>> pysr.install()
451
-
452
  Tried to activate project {julia_project} but failed."""
453
- ) from e
454
  Main.eval("using SymbolicRegression")
455
 
456
  Main.plus = Main.eval("(+)")
@@ -629,7 +627,6 @@ def _handle_constraints(binary_operators, unary_operators, constraints):
629
 
630
 
631
  def _create_inline_operators(binary_operators, unary_operators):
632
- global Main
633
  for op_list in [binary_operators, unary_operators]:
634
  for i, op in enumerate(op_list):
635
  is_user_defined_operator = "(" in op
 
135
  tempdir=None,
136
  delete_tempfiles=True,
137
  julia_project=None,
 
138
  update=True,
139
  temp_equation_file=False,
140
  output_jax_format=False,
 
247
  :type delete_tempfiles: bool
248
  :param julia_project: a Julia environment location containing a Project.toml (and potentially the source code for SymbolicRegression.jl). Default gives the Python package directory, where a Project.toml file should be present from the install.
249
  :type julia_project: str/None
 
 
250
  :param update: Whether to automatically update Julia packages.
251
  :type update: bool
252
  :param temp_equation_file: Whether to put the hall of fame file in the temp directory. Deletion is then controlled with the delete_tempfiles argument.
 
436
  from julia import Pkg
437
 
438
  Pkg.activate(f"{_escape_filename(julia_project)}")
439
+ if update:
440
+ try:
441
+ Pkg.resolve()
442
+ except RuntimeError as e:
443
+ raise ImportError(
444
+ f"""
445
  Required dependencies are not installed or built. Run the following code in the Python REPL:
446
 
447
  >>> import pysr
448
  >>> pysr.install()
449
+
450
  Tried to activate project {julia_project} but failed."""
451
+ ) from e
452
  Main.eval("using SymbolicRegression")
453
 
454
  Main.plus = Main.eval("(+)")
 
627
 
628
 
629
  def _create_inline_operators(binary_operators, unary_operators):
 
630
  for op_list in [binary_operators, unary_operators]:
631
  for i, op in enumerate(op_list):
632
  is_user_defined_operator = "(" in op