Spaces:
Sleeping
Sleeping
| """ | |
| warmup_bridge.py | |
| Pre-warms the juliacall Python<->Julia bridge at build time. | |
| Non-fatal: always exits 0 so Docker build never fails here. | |
| """ | |
| import os, sys | |
| # Tell juliapkg to use the pre-installed Julia and NEVER download anything | |
| os.environ["JULIA_DEPOT_PATH"] = "/app/.julia" | |
| os.environ["JULIA_BINDIR"] = "/usr/local/julia/bin" | |
| os.environ["PYTHON_JULIAPKG_OFFLINE"] = "yes" # critical: no downloads | |
| print("Pre-warming juliacall bridge...") | |
| try: | |
| from juliacall import Main as jl | |
| jl.seval('push!(LOAD_PATH, "/app/src")') | |
| jl.seval('include("/app/src/QuantEngine.jl")') | |
| jl.seval("using .QuantEngine") | |
| # Sanity check via the bridge | |
| import numpy as np | |
| c = (100.0 * np.exp(np.cumsum(np.random.randn(100) * 0.005))).tolist() | |
| result = jl.QuantEngine.sma(jl.convert(jl.Vector[jl.Float64], c), 20) | |
| assert len(list(result)) == 100 | |
| print("juliacall bridge warmed up ✓") | |
| except Exception as e: | |
| print(f"WARNING: juliacall warmup skipped: {e}") | |
| print("Julia will initialise on first user request instead.") | |
| sys.exit(0) # always succeed — this is optional warmup | |