Spaces:
Running
Running
Commit
·
2aa3c41
1
Parent(s):
9e00705
Fix param hashing
Browse files- pysr/sr.py +20 -3
pysr/sr.py
CHANGED
|
@@ -12,6 +12,8 @@ from datetime import datetime
|
|
| 12 |
import warnings
|
| 13 |
from multiprocessing import cpu_count
|
| 14 |
from sklearn.base import BaseEstimator, RegressorMixin
|
|
|
|
|
|
|
| 15 |
|
| 16 |
is_julia_warning_silenced = False
|
| 17 |
|
|
@@ -1047,12 +1049,27 @@ class PySRRegressor(BaseEstimator, RegressorMixin):
|
|
| 1047 |
float(weightDoNothing),
|
| 1048 |
]
|
| 1049 |
|
| 1050 |
-
|
| 1051 |
**{k: self.__getattribute__(k) for k in self.surface_parameters},
|
| 1052 |
**self.params,
|
| 1053 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1054 |
if self.params_hash is not None:
|
| 1055 |
-
if
|
| 1056 |
warnings.warn(
|
| 1057 |
"Warning: PySR options have changed since the last run. "
|
| 1058 |
"This is experimental and may not work. "
|
|
@@ -1060,7 +1077,7 @@ class PySRRegressor(BaseEstimator, RegressorMixin):
|
|
| 1060 |
" the saved equations will be in the wrong format.",
|
| 1061 |
)
|
| 1062 |
|
| 1063 |
-
self.params_hash =
|
| 1064 |
|
| 1065 |
options = Main.Options(
|
| 1066 |
binary_operators=Main.eval(str(tuple(binary_operators)).replace("'", "")),
|
|
|
|
| 12 |
import warnings
|
| 13 |
from multiprocessing import cpu_count
|
| 14 |
from sklearn.base import BaseEstimator, RegressorMixin
|
| 15 |
+
from collections import OrderedDict
|
| 16 |
+
from hashlib import sha256
|
| 17 |
|
| 18 |
is_julia_warning_silenced = False
|
| 19 |
|
|
|
|
| 1049 |
float(weightDoNothing),
|
| 1050 |
]
|
| 1051 |
|
| 1052 |
+
params_to_hash = {
|
| 1053 |
**{k: self.__getattribute__(k) for k in self.surface_parameters},
|
| 1054 |
**self.params,
|
| 1055 |
}
|
| 1056 |
+
params_excluded_from_hash = [
|
| 1057 |
+
"niterations",
|
| 1058 |
+
]
|
| 1059 |
+
# Delete these^ from params_to_hash:
|
| 1060 |
+
params_to_hash = {
|
| 1061 |
+
k: v
|
| 1062 |
+
for k, v in params_to_hash.items()
|
| 1063 |
+
if k not in params_excluded_from_hash
|
| 1064 |
+
}
|
| 1065 |
+
|
| 1066 |
+
# Sort params_to_hash by key:
|
| 1067 |
+
params_to_hash = OrderedDict(sorted(params_to_hash.items()))
|
| 1068 |
+
# Hash all parameters:
|
| 1069 |
+
cur_hash = sha256(str(params_to_hash).encode()).hexdigest()
|
| 1070 |
+
|
| 1071 |
if self.params_hash is not None:
|
| 1072 |
+
if cur_hash != self.params_hash:
|
| 1073 |
warnings.warn(
|
| 1074 |
"Warning: PySR options have changed since the last run. "
|
| 1075 |
"This is experimental and may not work. "
|
|
|
|
| 1077 |
" the saved equations will be in the wrong format.",
|
| 1078 |
)
|
| 1079 |
|
| 1080 |
+
self.params_hash = cur_hash
|
| 1081 |
|
| 1082 |
options = Main.Options(
|
| 1083 |
binary_operators=Main.eval(str(tuple(binary_operators)).replace("'", "")),
|