Spaces:
Running
Running
MilesCranmer
commited on
Commit
•
32cadad
1
Parent(s):
06aebb6
Update docs to use `seval`
Browse files- docs/examples.md +5 -7
- pysr/test/test.py +2 -2
docs/examples.md
CHANGED
@@ -189,12 +189,10 @@ where $p_i$ is the $i$th prime number, and $x$ is the input feature.
|
|
189 |
Let's see if we can discover this using
|
190 |
the [Primes.jl](https://github.com/JuliaMath/Primes.jl) package.
|
191 |
|
192 |
-
First, let's
|
193 |
-
(here, with 8 threads and `-O3`):
|
194 |
|
195 |
```python
|
196 |
-
import
|
197 |
-
jl = pysr.julia_helpers.init_julia(julia_kwargs={"threads": 8, "optimize": 3})
|
198 |
```
|
199 |
|
200 |
`jl` stores the Julia runtime.
|
@@ -203,7 +201,7 @@ Now, let's run some Julia code to add the Primes.jl
|
|
203 |
package to the PySR environment:
|
204 |
|
205 |
```python
|
206 |
-
jl.
|
207 |
import Pkg
|
208 |
Pkg.add("Primes")
|
209 |
""")
|
@@ -213,13 +211,13 @@ This imports the Julia package manager, and uses it to install
|
|
213 |
`Primes.jl`. Now let's import `Primes.jl`:
|
214 |
|
215 |
```python
|
216 |
-
jl.
|
217 |
```
|
218 |
|
219 |
Now, we define a custom operator:
|
220 |
|
221 |
```python
|
222 |
-
jl.
|
223 |
function p(i::T) where T
|
224 |
if (0.5 < i < 1000)
|
225 |
return T(Primes.prime(round(Int, i)))
|
|
|
189 |
Let's see if we can discover this using
|
190 |
the [Primes.jl](https://github.com/JuliaMath/Primes.jl) package.
|
191 |
|
192 |
+
First, let's get the Julia backend:
|
|
|
193 |
|
194 |
```python
|
195 |
+
from pysr import jl
|
|
|
196 |
```
|
197 |
|
198 |
`jl` stores the Julia runtime.
|
|
|
201 |
package to the PySR environment:
|
202 |
|
203 |
```python
|
204 |
+
jl.seval("""
|
205 |
import Pkg
|
206 |
Pkg.add("Primes")
|
207 |
""")
|
|
|
211 |
`Primes.jl`. Now let's import `Primes.jl`:
|
212 |
|
213 |
```python
|
214 |
+
jl.seval("import Primes")
|
215 |
```
|
216 |
|
217 |
Now, we define a custom operator:
|
218 |
|
219 |
```python
|
220 |
+
jl.seval("""
|
221 |
function p(i::T) where T
|
222 |
if (0.5 < i < 1000)
|
223 |
return T(Primes.prime(round(Int, i)))
|
pysr/test/test.py
CHANGED
@@ -229,11 +229,11 @@ class TestPipeline(unittest.TestCase):
|
|
229 |
early_stop_condition=None,
|
230 |
)
|
231 |
# Check that the the julia state is saved:
|
232 |
-
from pysr
|
233 |
|
234 |
# We should have that the model state is now a Float32 hof:
|
235 |
jl.test_state = regressor.raw_julia_state_
|
236 |
-
self.assertTrue(jl.
|
237 |
# This should exit almost immediately, and use the old equations
|
238 |
regressor.fit(X, y)
|
239 |
|
|
|
229 |
early_stop_condition=None,
|
230 |
)
|
231 |
# Check that the the julia state is saved:
|
232 |
+
from pysr import jl
|
233 |
|
234 |
# We should have that the model state is now a Float32 hof:
|
235 |
jl.test_state = regressor.raw_julia_state_
|
236 |
+
self.assertTrue(jl.seval("typeof(test_state[2]).parameters[1] == Float32"))
|
237 |
# This should exit almost immediately, and use the old equations
|
238 |
regressor.fit(X, y)
|
239 |
|