Skip to content

Lazy Julia loading via juliacall: import time 215s -> 6.4s#28

Open
mesonepigreco wants to merge 3 commits into
mainfrom
fast_julia_startup
Open

Lazy Julia loading via juliacall: import time 215s -> 6.4s#28
mesonepigreco wants to merge 3 commits into
mainfrom
fast_julia_startup

Conversation

@mesonepigreco

Copy link
Copy Markdown
Collaborator

Replace the eager PyJulia/PyCall initialization at import time with a lazy bridge (Modules/JuliaExt.py). The Julia runtime now boots at the first actual use of MODE_FAST_JULIA instead of at "import tdscha", and the backend is juliacall (PythonCall.jl), which has no libpython coupling: no python-jl, no PyCall rebuilds, and Julia is installed automatically on fresh machines through the shipped juliapkg.json.

  • Remove the triplicated eager init blocks in DynamicalLanczos.py and the one in QSpaceLanczos.py; route all julia.Main call sites through the JuliaExt proxy (numpy <-> Julia Array conversions preserve PyJulia call semantics with the strictly-typed kernel signatures).
  • is_julia_enabled() / JULIA_EXT keep their meaning (backend availability) without booting the runtime.
  • Default to a single Julia thread (as PyJulia did): the Threads.@threads kernels in tdscha_core.jl race on shared buffers with >1 thread (see julia_design.md section 7).
  • New optional extra: pip install tdscha[julia] -> juliacall.
  • SSCHA_JULIA_BACKEND env var: juliacall | pyjulia (legacy) | none.
  • Design and measurements documented in julia_design.md; docs updated.

A companion patch with the same bridge is needed in python-sscha (sscha.Ensemble had the same eager pattern, worth 194s of the total).

Replace the eager PyJulia/PyCall initialization at import time with a lazy
bridge (Modules/JuliaExt.py). The Julia runtime now boots at the first
actual use of MODE_FAST_JULIA instead of at "import tdscha", and the
backend is juliacall (PythonCall.jl), which has no libpython coupling:
no python-jl, no PyCall rebuilds, and Julia is installed automatically on
fresh machines through the shipped juliapkg.json.

- Remove the triplicated eager init blocks in DynamicalLanczos.py and the
  one in QSpaceLanczos.py; route all julia.Main call sites through the
  JuliaExt proxy (numpy <-> Julia Array conversions preserve PyJulia call
  semantics with the strictly-typed kernel signatures).
- is_julia_enabled() / __JULIA_EXT__ keep their meaning (backend
  availability) without booting the runtime.
- Default to a single Julia thread (as PyJulia did): the Threads.@threads
  kernels in tdscha_core.jl race on shared buffers with >1 thread (see
  julia_design.md section 7).
- New optional extra: pip install tdscha[julia] -> juliacall.
- SSCHA_JULIA_BACKEND env var: juliacall | pyjulia (legacy) | none.
- Design and measurements documented in julia_design.md; docs updated.

A companion patch with the same bridge is needed in python-sscha
(sscha.Ensemble had the same eager pattern, worth 194s of the total).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@mesonepigreco mesonepigreco added this to the 1.7 milestone Jun 12, 2026
@mesonepigreco mesonepigreco added the enhancement New feature or request label Jun 12, 2026
- Bump version in pyproject.toml and meson.build from 1.6.3 to 1.7.0
- Add Examples/ensemble_gold/ (50-config converged SSCHA ensemble,
  3x3x3 gold supercell) for non-TRI q-point testing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant