Pre-compiled Mandel & Agol routine?
See original GitHub issueHey,
I’m upgrading my planet search into a proper pip-installable package and doing improvements along the way. One part of that is looking to use starry for Mandel & Agol light curve models instead of batman like I’ve been using because of the improved numerical stability stuff. The problem I’m running into is that it seems to require a “flux” routine to be compiled at the very least every time the package is imported. That’s a 10+ second operation, and if that’s required to be run every time I search a star, that’s going to add up and may not be worth it.
Here’s how my code is currently set up:
import warnings
import numpy as np
import starry
starry.config.lazy = False
star = starry.Map(udeg=2)
# don't bother with the theano warnings
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=FutureWarning)
# compile the flux routine once on loading the package instead
# of every call to mandel_agol
star.flux(xo=0, yo=0, zo=1, ro=0.1)
def mandel_agol(bs: np.ndarray, u1: float, u2: float, r2r1: float):
star[1:3] = [u1, u2]
# don't bother with the theano warnings
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=FutureWarning)
return star.flux(xo=0, yo=bs, zo=1, ro=r2r1)
I originally was creating a new Map() object in every call to mandel_agol, but that forced a compilation every function call. So I moved a single object outside the function definition, and that top bit calls star.flux for no reason except to compile the code when I import the file so that future calls in the python session can call mandel_agol without the compilation delay. But if I send off 100 processes to search 100 stars, and each one has to pause for 10 seconds as I import the package to wait for that function to compile, that adds up quickly.
So I guess my question is:
-
Am I missing anything in starry that already exists to avoid this?
-
Is it possible to create a “Mandel & Agol” class that is compiled only once when the package is installed (or the function is first called after installation), but never again? starry is an amazing package with lots of bells and whistles, but a simple quadratic limb darkened Mandel & Agol routine is never going to go out of style. Is there any other python version of Mandel & Agol besides batman that people use? As far as I know, starry is the only robust one without all the numerical issues, so exposing a simple pre-compiled mandel_agol function for people like me to get quick values would be valuable.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (3 by maintainers)
@ethankruse I also just pushed a commit to that exoplanet branch that might make what you need easier. Here’s how you would use it:
I’ve tested that this pickles properly too.
Interesting. I’m not sure why the pickle takes so long to load. @dfm any ideas? You must run into similar issues with exoplanet.
I certainly didn’t design starry with this in mind – it should really only be imported once, and maps should only be instantiated a single time, then re-used as often as you need them. That said, the code that computes the Mandel and Agol routine is (relatively) simple. If Dan doesn’t have a better solution, I could spend a couple hours next week to carve out the relevant sections and compile it into a shared library with negligible overhead.