Spaces:
Sleeping
Sleeping
MilesCranmer
commited on
Commit
•
3fcdd9a
1
Parent(s):
ad8ed14
Always overwrite with Meta.parseall version
Browse files- pysr/julia_import.py +8 -10
- pysr/test/test.py +9 -10
pysr/julia_import.py
CHANGED
@@ -58,18 +58,16 @@ elif os.environ["PYSR_AUTOLOAD_EXTENSIONS"] not in {"no", "yes", ""}:
|
|
58 |
|
59 |
from juliacall import Main as jl # type: ignore
|
60 |
|
61 |
-
|
62 |
# Finally, overwrite the seval function to use Meta.parseall
|
63 |
# instead of Meta.parse.
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
pass
|
73 |
|
74 |
jl.seval("using SymbolicRegression")
|
75 |
SymbolicRegression = jl.SymbolicRegression
|
|
|
58 |
|
59 |
from juliacall import Main as jl # type: ignore
|
60 |
|
|
|
61 |
# Finally, overwrite the seval function to use Meta.parseall
|
62 |
# instead of Meta.parse.
|
63 |
+
jl.seval("using PythonCall: PythonCall, Py, pyconvert")
|
64 |
+
jl.seval(
|
65 |
+
"""function PythonCall.pyjlmodule_seval(self::Module, expr::Py)
|
66 |
+
e = Meta.parseall(strip(pyconvert(String, expr)))
|
67 |
+
Py(Base.eval(self, e))
|
68 |
+
end"""
|
69 |
+
)
|
70 |
+
# ^TODO: Overwrite this once PythonCall.jl is updated:
|
|
|
71 |
|
72 |
jl.seval("using SymbolicRegression")
|
73 |
SymbolicRegression = jl.SymbolicRegression
|
pysr/test/test.py
CHANGED
@@ -100,17 +100,16 @@ class TestPipeline(unittest.TestCase):
|
|
100 |
self.assertEqual(model.julia_options_.turbo, True)
|
101 |
|
102 |
def test_multiline_seval(self):
|
103 |
-
|
104 |
-
|
105 |
-
num = jl.seval(
|
106 |
-
"""
|
107 |
-
function my_new_objective(x)
|
108 |
-
x^2
|
109 |
-
end
|
110 |
-
1.5
|
111 |
"""
|
112 |
-
)
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
114 |
|
115 |
def test_high_precision_search_custom_loss(self):
|
116 |
y = 1.23456789 * self.X[:, 0]
|
|
|
100 |
self.assertEqual(model.julia_options_.turbo, True)
|
101 |
|
102 |
def test_multiline_seval(self):
|
103 |
+
# The user should be able to run multiple things in a single seval call:
|
104 |
+
num = jl.seval(
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
"""
|
106 |
+
function my_new_objective(x)
|
107 |
+
x^2
|
108 |
+
end
|
109 |
+
1.5
|
110 |
+
"""
|
111 |
+
)
|
112 |
+
self.assertEqual(num, 1.5)
|
113 |
|
114 |
def test_high_precision_search_custom_loss(self):
|
115 |
y = 1.23456789 * self.X[:, 0]
|