MilesCranmer commited on
Commit
e0c7f38
1 Parent(s): 47510a9

Have PySR generate Project.toml from Python

Browse files
Files changed (3) hide show
  1. Project.toml +0 -6
  2. TODO.md +1 -0
  3. pysr/sr.py +29 -3
Project.toml DELETED
@@ -1,6 +0,0 @@
1
- [deps]
2
- SymbolicRegression = "8254be44-1295-4e6a-a16d-46603ac705cb"
3
-
4
- [compat]
5
- SymbolicRegression = "0.6.19"
6
- julia = "1.5"
 
 
 
 
 
 
 
TODO.md CHANGED
@@ -60,6 +60,7 @@
60
  - [x] Record density over complexity. Favor equations that have a density we have not explored yet. Want the final density to be evenly distributed.
61
  - [x] Do printing from Python side. Then we can do simplification and pretty-printing.
62
  - [x] Sympy printing
 
63
  - [ ] Sort these todo lists by priority
64
 
65
  - [ ] Automatically convert log, log10, log2, pow to the correct operators.
 
60
  - [x] Record density over complexity. Favor equations that have a density we have not explored yet. Want the final density to be evenly distributed.
61
  - [x] Do printing from Python side. Then we can do simplification and pretty-printing.
62
  - [x] Sympy printing
63
+ - [x] Store Project.toml inside PySR's python code, rather than copied to site-packages.
64
  - [ ] Sort these todo lists by priority
65
 
66
  - [ ] Automatically convert log, log10, log2, pow to the correct operators.
pysr/sr.py CHANGED
@@ -957,10 +957,15 @@ class CallableEquation:
957
 
958
 
959
  def _get_julia_project(julia_project):
960
- pkg_directory = Path(__file__).parents[1]
961
  if julia_project is None:
962
- return pkg_directory
963
- return Path(julia_project)
 
 
 
 
 
 
964
 
965
 
966
  def silence_julia_warning():
@@ -1007,3 +1012,24 @@ To silence this warning, you can run pysr.silence_julia_warning() after importin
1007
  Main = _Main
1008
 
1009
  return Main
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
957
 
958
 
959
  def _get_julia_project(julia_project):
 
960
  if julia_project is None:
961
+ # Create temp directory:
962
+ tmp_dir = tempfile.mkdtemp()
963
+ tmp_dir = Path(tmp_dir)
964
+ # Create Project.toml in temp dir:
965
+ _write_project_file(tmp_dir)
966
+ return tmp_dir
967
+ else:
968
+ return Path(julia_project)
969
 
970
 
971
  def silence_julia_warning():
 
1012
  Main = _Main
1013
 
1014
  return Main
1015
+
1016
+
1017
+ def _write_project_file(tmp_dir):
1018
+ """This writes a Julia Project.toml to a temporary directory
1019
+
1020
+ The reason we need this is because sometimes Python will compile a project to binary,
1021
+ and then Julia can't read the Project.toml file. It is more reliable to have Python
1022
+ simply create the Project.toml from scratch.
1023
+ """
1024
+
1025
+ project_toml = """
1026
+ [deps]
1027
+ SymbolicRegression = "8254be44-1295-4e6a-a16d-46603ac705cb"
1028
+
1029
+ [compat]
1030
+ SymbolicRegression = "0.6.19"
1031
+ julia = "1.5"
1032
+ """
1033
+
1034
+ project_toml_path = tmp_dir / "Project.toml"
1035
+ project_toml_path.write_text(project_toml)