MilesCranmer commited on
Commit
5af6354
1 Parent(s): 925fb38

Clean up more unused code

Browse files
pysr/export_torch.py CHANGED
@@ -17,16 +17,12 @@ def _reduce(fn):
17
 
18
  torch_initialized = False
19
  torch = None
20
- _global_func_lookup = None
21
- _Node = None
22
  SingleSymPyModule = None
23
 
24
 
25
  def _initialize_torch():
26
  global torch_initialized
27
  global torch
28
- global _global_func_lookup
29
- global _Node
30
  global SingleSymPyModule
31
 
32
  # Way to lazy load torch, only if this is called,
@@ -148,7 +144,7 @@ def _initialize_torch():
148
  args.append(arg_)
149
  return self._torch_func(*args)
150
 
151
- class SingleSymPyModule(torch.nn.Module):
152
  """SympyTorch code from https://github.com/patrick-kidger/sympytorch"""
153
 
154
  def __init__(
@@ -177,6 +173,8 @@ def _initialize_torch():
177
  symbols = {symbol: X[:, i] for i, symbol in enumerate(self.symbols_in)}
178
  return self._node(symbols)
179
 
 
 
180
 
181
  def sympy2torch(expression, symbols_in, selection=None, extra_torch_mappings=None):
182
  """Returns a module for a given sympy expression with trainable parameters;
 
17
 
18
  torch_initialized = False
19
  torch = None
 
 
20
  SingleSymPyModule = None
21
 
22
 
23
  def _initialize_torch():
24
  global torch_initialized
25
  global torch
 
 
26
  global SingleSymPyModule
27
 
28
  # Way to lazy load torch, only if this is called,
 
144
  args.append(arg_)
145
  return self._torch_func(*args)
146
 
147
+ class _SingleSymPyModule(torch.nn.Module):
148
  """SympyTorch code from https://github.com/patrick-kidger/sympytorch"""
149
 
150
  def __init__(
 
173
  symbols = {symbol: X[:, i] for i, symbol in enumerate(self.symbols_in)}
174
  return self._node(symbols)
175
 
176
+ SingleSymPyModule = _SingleSymPyModule
177
+
178
 
179
  def sympy2torch(expression, symbols_in, selection=None, extra_torch_mappings=None):
180
  """Returns a module for a given sympy expression with trainable parameters;
pysr/feynman_problems.py CHANGED
@@ -92,7 +92,7 @@ class FeynmanProblem(Problem):
92
  ret.append(p)
93
  except Exception as e:
94
  traceback.print_exc()
95
- print(f"FAILED ON ROW {i}")
96
  ind += 1
97
  return ret
98
 
@@ -168,7 +168,6 @@ def do_feynman_experiments(
168
  problems = FeynmanProblem.mk_problems(
169
  first=first, gen=True, dp=dp, data_dir=data_dir
170
  )
171
- indx = range(len(problems))
172
  ids = []
173
  predictions = []
174
  true_equations = []
 
92
  ret.append(p)
93
  except Exception as e:
94
  traceback.print_exc()
95
+ print(f"FAILED ON ROW {i} with {e}")
96
  ind += 1
97
  return ret
98
 
 
168
  problems = FeynmanProblem.mk_problems(
169
  first=first, gen=True, dp=dp, data_dir=data_dir
170
  )
 
171
  ids = []
172
  predictions = []
173
  true_equations = []
pysr/sr.py CHANGED
@@ -400,7 +400,6 @@ def pysr(
400
  kwargs = {**dict(equation_file=equation_file), **kwargs}
401
 
402
  pkg_directory = kwargs["pkg_directory"]
403
- manifest_file = None
404
  if kwargs["julia_project"] is not None:
405
  manifest_filepath = Path(kwargs["julia_project"]) / "Manifest.toml"
406
  else:
 
400
  kwargs = {**dict(equation_file=equation_file), **kwargs}
401
 
402
  pkg_directory = kwargs["pkg_directory"]
 
403
  if kwargs["julia_project"] is not None:
404
  manifest_filepath = Path(kwargs["julia_project"]) / "Manifest.toml"
405
  else:
test/test.py CHANGED
@@ -48,10 +48,10 @@ class TestPipeline(unittest.TestCase):
48
  w[w >= 0.5] = 1.0
49
 
50
  # Double equation when weights are 0:
51
- y += (1 - w) * y
52
  # Thus, pysr needs to use the weights to find the right equation!
53
 
54
- equations = pysr(
55
  self.X,
56
  y,
57
  weights=w,
@@ -140,7 +140,7 @@ class TestFeatureSelection(unittest.TestCase):
140
  X,
141
  select_k_features=2,
142
  use_custom_variable_names=True,
143
- variable_names=[f"x{i}" for i in range(5)],
144
  y=y,
145
  )
146
  self.assertTrue((2 in selection) and (3 in selection))
 
48
  w[w >= 0.5] = 1.0
49
 
50
  # Double equation when weights are 0:
51
+ y = (2 - w) * y
52
  # Thus, pysr needs to use the weights to find the right equation!
53
 
54
+ pysr(
55
  self.X,
56
  y,
57
  weights=w,
 
140
  X,
141
  select_k_features=2,
142
  use_custom_variable_names=True,
143
+ variable_names=var_names,
144
  y=y,
145
  )
146
  self.assertTrue((2 in selection) and (3 in selection))