MilesCranmer commited on
Commit
3fe50ab
1 Parent(s): 3cbb7c6

Update documentation on backend modifications

Browse files
Files changed (1) hide show
  1. docs/backend.md +60 -14
docs/backend.md CHANGED
@@ -7,22 +7,68 @@ This package is accessed with [`juliacall`](https://github.com/JuliaPy/PythonCal
7
  PySR gives you access to everything in SymbolicRegression.jl, but there are some specific use-cases which require modifications to the backend itself.
8
  Generally you can do this as follows:
9
 
10
- 1. Clone a copy of the backend:
11
- ```
 
 
 
12
  git clone https://github.com/MilesCranmer/SymbolicRegression.jl
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  ```
14
- 2. Edit the source code in `src/` to your requirements:
15
- - The documentation for the backend is given [here](https://astroautomata.com/SymbolicRegression.jl/dev/).
16
- - Throughout the package, you will often see template functions which typically use a symbol `T` (such as in the string `where {T<:Real}`). Here, `T` is simply the datatype of the input data and stored constants, such as `Float32` or `Float64`. Writing functions in this way lets us write functions generic to types, while still having access to the specific type specified at compilation time.
17
- - Expressions are stored as binary trees, using the `Node{T}` type, described [here](https://astroautomata.com/SymbolicRegression.jl/dev/types/#SymbolicRegression.CoreModule.EquationModule.Node).
18
- - Parts of the code which are typically edited by users include:
19
- - [`src/LossFunctions.jl`](https://github.com/MilesCranmer/SymbolicRegression.jl/blob/master/src/LossFunctions.jl), particularly the function `eval_loss`. This function assigns a loss to a given expression, using `eval_tree_array` to evaluate it, and `loss` to compute the loss with respect to the dataset.
20
- - [`src/CheckConstraints.jl`](https://github.com/MilesCranmer/SymbolicRegression.jl/blob/master/src/CheckConstraints.jl), particularly the function `check_constraints`. This function checks whether a given expression satisfies constraints, such as having a complexity lower than `maxsize`, and whether it contains any forbidden nestings of functions.
21
- - Note that all expressions, *even intermediate expressions*, must comply with constraints. Therefore, make sure that evolution can still reach your desired expression (with one mutation at a time), before setting a hard constraint. In other cases you might want to instead put in the loss function.
22
- - [`src/Options.jl`](https://github.com/MilesCranmer/SymbolicRegression.jl/blob/master/src/Options.jl), as well as the struct definition in [`src/OptionsStruct.jl`](https://github.com/MilesCranmer/SymbolicRegression.jl/blob/master/src/OptionsStruct.jl). This file specifies all the options used in the search: an instance of `Options` is typically available throughout every function in `SymbolicRegression.jl`. If you add new functionality to the backend, and wish to make it parameterizable (including from PySR), you should specify it in the options.
23
- - For reference, the main loop itself is found in the `equation_search` function inside [`src/SymbolicRegression.jl`](https://github.com/MilesCranmer/SymbolicRegression.jl/blob/master/src/SymbolicRegression.jl).
24
- 3. Specify the directory of `SymbolicRegression.jl` to PySR by setting `julia_project` in the `PySRRegressor` object, and run `.fit` when you're ready. That's it! No compilation or build steps required.
25
- - Note that it will automatically update your project by default; to turn this off, set `update=False`.
26
 
27
  If you get comfortable enough with the backend, you might consider using the Julia package directly: the API is given on the [SymbolicRegression.jl documentation](https://astroautomata.com/SymbolicRegression.jl/dev/).
28
 
 
7
  PySR gives you access to everything in SymbolicRegression.jl, but there are some specific use-cases which require modifications to the backend itself.
8
  Generally you can do this as follows:
9
 
10
+ ## 1. Check out the source code
11
+
12
+ Clone a copy of the backend as well as PySR:
13
+
14
+ ```bash
15
  git clone https://github.com/MilesCranmer/SymbolicRegression.jl
16
+ git clone https://github.com/MilesCranmer/PySR
17
+ ```
18
+
19
+ You may wish to check out the specific versions, which you can do with:
20
+
21
+ ```bash
22
+ cd PySR
23
+ git checkout <version>
24
+
25
+ # You can see the current backend version in `pysr/juliapkg.json`
26
+ cd ../SymbolicRegression.jl
27
+ git checkout <backend_version>
28
+ ```
29
+
30
+ ## 2. Edit the source to your requirements
31
+
32
+ The main search code can be found in `src/SymbolicRegression.jl`.
33
+
34
+ Here are some tips:
35
+
36
+ - The documentation for the backend is given [here](https://astroautomata.com/SymbolicRegression.jl/dev/).
37
+ - Throughout the package, you will often see template functions which typically use a symbol `T` (such as in the string `where {T<:Real}`). Here, `T` is simply the datatype of the input data and stored constants, such as `Float32` or `Float64`. Writing functions in this way lets us write functions generic to types, while still having access to the specific type specified at compilation time.
38
+ - Expressions are stored as binary trees, using the `Node{T}` type, described [here](https://astroautomata.com/SymbolicRegression.jl/dev/types/#SymbolicRegression.CoreModule.EquationModule.Node).
39
+ - For reference, the main loop itself is found in the `equation_search` function inside [`src/SymbolicRegression.jl`](https://github.com/MilesCranmer/SymbolicRegression.jl/blob/master/src/SymbolicRegression.jl).
40
+ - Parts of the code which are typically edited by users include:
41
+ - [`src/CheckConstraints.jl`](https://github.com/MilesCranmer/SymbolicRegression.jl/blob/master/src/CheckConstraints.jl), particularly the function `check_constraints`. This function checks whether a given expression satisfies constraints, such as having a complexity lower than `maxsize`, and whether it contains any forbidden nestings of functions.
42
+ - Note that all expressions, *even intermediate expressions*, must comply with constraints. Therefore, make sure that evolution can still reach your desired expression (with one mutation at a time), before setting a hard constraint. In other cases you might want to instead put in the loss function.
43
+ - [`src/Options.jl`](https://github.com/MilesCranmer/SymbolicRegression.jl/blob/master/src/Options.jl), as well as the struct definition in [`src/OptionsStruct.jl`](https://github.com/MilesCranmer/SymbolicRegression.jl/blob/master/src/OptionsStruct.jl). This file specifies all the options used in the search: an instance of `Options` is typically available throughout every function in `SymbolicRegression.jl`. If you add new functionality to the backend, and wish to make it parameterizable (including from PySR), you should specify it in the options.
44
+
45
+ ## 3. Let PySR use the modified backend
46
+
47
+ Once you have made your changes, you should edit the `pysr/juliapkg.json` file
48
+ in the PySR repository to point to this local copy.
49
+ Do this by removing the `"version"` key and adding a `"dev"` and `"path"` key:
50
+
51
+ ```json
52
+ ...
53
+ "packages": {
54
+ "SymbolicRegression": {
55
+ "uuid": "8254be44-1295-4e6a-a16d-46603ac705cb",
56
+ "dev": true,
57
+ "path": "/path/to/SymbolicRegression.jl"
58
+ },
59
+ ...
60
  ```
61
+
62
+ You can then install PySR with this modified backend by running:
63
+
64
+ ```bash
65
+ cd PySR
66
+ pip install .
67
+ ```
68
+
69
+ For more information on `juliapkg.json`, see [`pyjuliapkg`](https://github.com/JuliaPy/pyjuliapkg).
70
+
71
+ ## Additional notes
 
72
 
73
  If you get comfortable enough with the backend, you might consider using the Julia package directly: the API is given on the [SymbolicRegression.jl documentation](https://astroautomata.com/SymbolicRegression.jl/dev/).
74