fix: better init of spergel HLR and tabulate xValue#258
Conversation
Merging this PR will improve performance by ×2.6
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | WallTime | test_benchmark_spergel_init[run] |
7.4 µs | 40.3 µs | -81.77% |
| ❌ | Simulation | test_benchmark_spergel_init[run] |
104.1 µs | 267.2 µs | -61.02% |
| ❌ | Simulation | test_benchmarks_lanczos_interp[xval-no_conserve_dc-run] |
828.5 µs | 1,248.5 µs | -33.64% |
| ⚡ | Simulation | test_benchmark_spergel_xvalue[run] |
34,862.4 ms | 310 ms | ×110 |
| ⚡ | WallTime | test_benchmark_spergel_xvalue[run] |
1,819.6 ms | 37.6 ms | ×48 |
| ⚡ | WallTime | test_benchmark_spergel_calcfluxrad[run] |
225.7 µs | 121.6 µs | +85.6% |
| ⚡ | Simulation | test_benchmark_spergel_calcfluxrad[run] |
1,090.6 µs | 626.3 µs | +74.13% |
| 🆕 | Simulation | test_benchmark_spergel_init_float[run] |
N/A | 104.2 µs | N/A |
| 🆕 | WallTime | test_benchmark_spergel_init_float[run] |
N/A | 7.5 µs | N/A |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing test-spergel (ef1603d) with main (9b25b7d)1
Footnotes
|
hello - i started looking into what you requested in slack. Regarding the image artifacts with
but using
I used the same code that's here to test. I don't understand why the residual changes so much in this PR after doubling the |
|
re the regression when nu is not constant - I could not find any. Perhaps I misunderstood but here is the code I was using to test this in my laptop. import numpy as np
import jax_galsim as jgs
def _draw_spergel_jgs(
params: dict, nu: float | Array, *, psf: jgs.GSObject, fft_size: int, slen: int
):
gsparams = jgs.GSParams(minimum_fft_size=fft_size, maximum_fft_size=fft_size)
prof = jgs.Spergel(nu=nu, flux=params["flux"], half_light_radius=params["hlr"])
prof = prof.shear(q=params["q"], beta=params["beta"] * jgs.degrees)
gal = jgs.Convolve([prof, psf]).withGSParams(gsparams)
return gal.drawImage(nx=slen, ny=slen, scale=0.2, dtype=jnp.float64).array
# let's average the time over 1000 runs each while varying the parameters
# but fixing the PSF
times1 = []
times2 = []
xpsf = jgs.Gaussian(half_light_radius=0.7, flux=1.0)
draw_jax_nu_float = jit(
partial(_draw_spergel_jgs, nu=-0.6, psf=xpsf, fft_size=256, slen=201)
)
draw_jax_nu_array = jit(partial(_draw_spergel_jgs, psf=xpsf, fft_size=256, slen=201))
for ii in range(1000):
params = {
"flux": np.random.uniform(1, 3, size=()).item(),
"hlr": np.random.uniform(0.4, 0.5, size=()).item(),
"q": 1.0,
"beta": 0.0,
}
_nu = np.random.uniform(-0.55, -0.65, size=()).item()
_nu = device_put(jnp.array(_nu))
params_jax = device_put(params)
# compilation
if ii == 0:
draw_jax_nu_float(params_jax)
draw_jax_nu_array(params_jax, _nu)
# timing
t1 = time.time()
with transfer_guard("disallow"):
_ = block_until_ready(draw_jax_nu_float(params_jax))
t2 = time.time()
times1.append(t2 - t1)
t1 = time.time()
with transfer_guard("disallow"):
_ = block_until_ready(draw_jax_nu_array(params_jax, _nu))
t2 = time.time()
times2.append(t2 - t1)
t_nu_float = np.mean(times1)
t_nu_array = np.mean(times2)
print(f"Average time nu float: {t_nu_float:.4f}")
print(f"Average time nu array: {t_nu_array:.4f}")Did I miss something? |




This PR has a new way to initialize the spergel HLR and a better way to compute autodiff using implicit differentiation.