-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(BREAKING) Rewrite Julia interface with PyJulia -> JuliaCall; other changes #535
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Could you make an issue about converting |
cjdoris
reviewed
Jan 27, 2024
cjdoris
reviewed
Jan 27, 2024
MilesCranmer
commented
Jan 28, 2024
MilesCranmer
changed the title
Rewrite Julia interface with PyJulia -> JuliaCall
(Breaking) Rewrite Julia interface with PyJulia -> JuliaCall
Feb 5, 2024
Still some random issues it seems... Not sure if these are a blocker because PyJulia has had worse issues but still some build weirdness. I ran into this one time (can't reproduce): [ins] In [1]: from pysr import PySRRegressor, jl
ERROR: ArgumentError: Package PythonCall [6099a3de-0909-46bc-b1f4-468b9a2dfc0d] is required but does not seem to be installed:
- Run `Pkg.instantiate()` to install all recorded dependencies.
Stacktrace:
[1] _require(pkg::Base.PkgId, env::String)
@ Base ./loading.jl:1920
[2] __require_prelocked(uuidkey::Base.PkgId, env::String)
@ Base ./loading.jl:1806
[3] #invoke_in_world#3
@ Base ./essentials.jl:921 [inlined]
[4] invoke_in_world
@ Base ./essentials.jl:918 [inlined]
[5] _require_prelocked(uuidkey::Base.PkgId, env::String)
@ Base ./loading.jl:1797
[6] macro expansion
@ Base ./loading.jl:1784 [inlined]
[7] macro expansion
@ Base ./lock.jl:267 [inlined]
[8] __require(into::Module, mod::Symbol)
@ Base ./loading.jl:1747
[9] #invoke_in_world#3
@ Base ./essentials.jl:921 [inlined]
[10] invoke_in_world
@ Base ./essentials.jl:918 [inlined]
[11] require(into::Module, mod::Symbol)
@ Base ./loading.jl:1740
[12] top-level scope
@ none:8---------------------------------------------------------------------------
Exception Traceback (most recent call last)
Cell In[1], line 1
----> 1 from pysr import PySRRegressor, jl
File ~/PermaDocuments/SymbolicRegressionMonorepo/.venv/lib/python3.10/site-packages/pysr/__init__.py:4
1 # This must be imported as early as possible to prevent
2 # library linking issues caused by numpy/pytorch/etc. importing
3 # old libraries:
----> 4 from .julia_import import jl, SymbolicRegression # isort:skip
6 from . import sklearn_monkeypatch
7 from .deprecated import best, best_callable, best_row, best_tex, install, pysr
File ~/PermaDocuments/SymbolicRegressionMonorepo/.venv/lib/python3.10/site-packages/pysr/julia_import.py:59
53 elif os.environ["PYSR_AUTOLOAD_EXTENSIONS"] not in {"no", "yes", ""}:
54 warnings.warn(
55 "PYSR_AUTOLOAD_EXTENSIONS environment variable is set to something other than 'yes' or 'no' or ''."
56 )
---> 59 from juliacall import Main as jl # type: ignore
62 # Finally, overwrite the seval function to use Meta.parseall
63 # instead of Meta.parse.
64 # TODO: Overwrite this once PythonCall.jl is updated:
65 def seval(s: str):
File ~/PermaDocuments/SymbolicRegressionMonorepo/.venv/lib/python3.10/site-packages/juliacall/__init__.py:228
224 raise Exception('PythonCall.jl did not start properly')
226 CONFIG['inited'] = True
--> 228 init()
230 def load_ipython_extension(ip):
231 import juliacall.ipython
File ~/PermaDocuments/SymbolicRegressionMonorepo/.venv/lib/python3.10/site-packages/juliacall/__init__.py:224, in init()
222 res = jl_eval(script.encode('utf8'))
223 if res is None:
--> 224 raise Exception('PythonCall.jl did not start properly')
226 CONFIG['inited'] = True
Exception: PythonCall.jl did not start properly but seems like I couldn't solve it without deleting my environment and starting over. |
Thanks both for your tips again! I'm very excited to get this through!! 😃 |
This was referenced Feb 12, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I managed to get a PythonCall.jl/JuliaCall version of PySR working!
Tagging @mkitti @cjdoris in case you are curious. Any suggestions about implementation are very appreciated :)
Detailed changes:
eval
->seval
Vector
when calling SymbolicRegression.jl functions (otherwise would get passed asPyList{Any}
; see Working with type instabilities, coming from PyJulia JuliaPy/PythonCall.jl#441)equation_search
code withjl.PythonCall.GC.disable()
to avoid multithreading-related segfaults (Bus error with multithreading linear algebra JuliaPy/PythonCall.jl#298)np.str_
tostr
before passing tovariable_names
, otherwise it becomes aPyArray
and not aString
(@cjdoris might be worth adding a workaround, it seems like PyJulia does this automatically)python -m pysr install
. The install process is done by JuliaCall at import time.pysr.install()
andpython -m pysr install
because JuliaCall now handles this.python -m pysr install
will not give a warning and do nothing.julia_project
argument (ignored; no effect). The user now needs to set this up by customizingjuliapkg.json
.PySRRegressor
, I am now storing a serialized version of them. This means you can now pickle the search state and warm-start the search in another Python process. It feels much safer to do it like this.self.raw_julia_state_
will actually deserialize it automatically for youmodel.julia_options_
(generated from a serialized format for pickle safety)ncyclesperiteration => ncycles_per_iteration
loss => elementwise_loss
full_objective => loss_function
TODO:
import pysr
.pysr.install
with a warning message.jl.println
andjl.display
do not work in Jupyter notebook JuliaPy/PythonCall.jl#232Remove click dependency.(Leaving for backwards compatibility)julia_project
with development version of SymbolicRegression.jl.-O3
.seval
IPython[skipping for now...]Post: