dfm / tess-atlas

MIT License
9 stars 8 forks source link

Single Transits #29

Closed avivajpeyi closed 2 years ago

avivajpeyi commented 4 years ago

There might be a way to deal with single transits now! assert np.all(periods > 0), "We haven't implemented single transits yet"

avivajpeyi commented 3 years ago

Do we know of an example TOI that I can try out?

dfm commented 3 years ago

A good place to start might be to find examples with period < 0 in the catalog. I did start implementing single transits at one point if you want to take a look there as a starting point: https://github.com/exoplanet-dev/tess.world/blob/main/src/tess_world/templates/template.py#L305

avivajpeyi commented 3 years ago

From https://exofop.ipac.caltech.edu/tess/view_toi.php, I found 66/2394 candidates have period < 0. Going to test PE with TOI 2180.

Click to expand table of Single-transit TOIs TIC ID | TOI -- | -- 298663873 | 2180.01 280865159 | 1894.01 264544388 | 1893.01 174302697 | 1896.01 219462190 | 2087.01 159400561 | 2263.01 356710041 | 2065.01 356700488 | 2098.01 307111282 | 1574.01 219466784 | 2007.01 451599528 | 1104.01 274599700 | 2317.01 267694283 | 1656.01 26547036 | 2010.01 82010657 | 1591.01 388624270 | 1026.01 124543547 | 898.01 70887357 | 2008.01 207425167 | 1812.01 122220263 | 1134.01 103633672 | 2085.01 420645189 | 1897.01 420645189 | 1897.02 201292545 | 289.01 349488688 | 2319.01 47316976 | 288.01 249945230 | 1563.01 207425167 | 1812.03 343019899 | 1386.01 251384275 | 1565.01 328933398 | 1873.02 63698669 | 1892.01 384159646 | 1895.01 172370679 | 1899.01 88840705 | 2318.01 198178505 | 2270.01 153949511 | 1277.01 207501148 | 2320.01 201233610 | 290.01 219345200 | 706.01 91987762 | 1898.01 304142124 | 1793.01 370759867 | 1581.01 259151170 | 1567.01 252490659 | 1379.01 458589703 | 693.01 52041724 | 1589.01 347332255 | 1835.02 405454160 | 563.01 47525799 | 225.01 54002556 | 1847.01 441420236 | 2221.01 58463434 | 2003.01 365938305 | 1262.01 138126035 | 2321.01 136916387 | 2011.01 158276040 | 1192.01 327017634 | 1202.01 47484268 | 226.01 243187830 | 2009.01 144138509 | 729.01 70797900 | 224.01 120269103 | 886.01 2760710 | 227.01 144440290 | 222.01
avivajpeyi commented 3 years ago

single transit --> most likely a short period single transit

Hence incorporate that into the prior --> steep power-law prior in period

avivajpeyi commented 3 years ago

Re un with above, period, duration, b, probably very correlated. We can look at corner and see whats going on (Plot log_period)

avivajpeyi commented 3 years ago

Plot divergences on top of the corner to see where and which parameters might be causing the issue. Maybe this always happens at particular parameters?

avivajpeyi commented 3 years ago

Check if this works now that I have merged in #76

avivajpeyi commented 2 years ago

Reran 2180:

failed when testing the model https://github.com/dfm/tess-atlas/blob/81db5436b8f86f9da758e6272eaffa02e7890301/src/tess_atlas/notebook_templates/toi_template.py#L330

There is an issue with the model. The model(testval) has a nan:
dur_interval__            NaN
r_log__                 -0.92
b_impact__              -1.39
t0_interval__           -1.19
p_1_lowerbound__         -inf
f0                      -3.22
u_quadlimbdark__        -2.77
jitter_log__             0.11
sigma_log__              0.11
rho_log__               -0.55
obs                -362020.84
avivajpeyi commented 2 years ago

The error is arising from the transit duration dur and the orbital period p.

{'TOI': 2180.01,
 'Period (days)': 0.0,
 'Epoch (TBJD)': 1830.7900000000373,
 'Depth (ppt)': 2.4,
 'Duration (days)': 1.3089166666666667,
 'Single Transit': True}
 def build_planet_transit_model(tic_entry):
    t = tic_entry.lightcurve.time
    y = tic_entry.lightcurve.flux
    yerr = tic_entry.lightcurve.flux_err

    n = tic_entry.planet_count
    t0s = np.array([planet.t0 for planet in tic_entry.candidates])
    depths = np.array([planet.depth for planet in tic_entry.candidates])
    periods = np.array([planet.period for planet in tic_entry.candidates])
    tmaxs = np.array([planet.tmax for planet in tic_entry.candidates])
    durations = np.array([planet.duration for planet in tic_entry.candidates])
    max_durations = np.array(
        [planet.duration_max for planet in tic_entry.candidates]
    )
    min_durations = np.array(
        [planet.duration_min for planet in tic_entry.candidates]
    )

    with pm.Model() as my_planet_transit_model:
        ## define planet parameters

        # 1) d: transit duration (duration of eclipse)
        d_priors = pm.Bound(
            pm.Lognormal, lower=min_durations, upper=max_durations
        )(
            name=DURATION,
            mu=np.log(durations),
            sigma=np.log(1.2),
            shape=n,
            testval=durations,
        )

...
        # 1) t0: the time of the first transit in data (a reference time)
        t0_norm = pm.Bound(
            pm.Normal, lower=t0s - max_durations, upper=t0s + max_durations
        )
        t0_priors = t0_norm(
            TIME_START, mu=t0s, sigma=0.5 * durations, shape=n, testval=t0s
        )

        # 2) period: the planets' orbital period
        p_params, p_priors_list, tmax_priors_list = [], [], []
        for n, planet in enumerate(tic_entry.candidates):
            # if only one transit in data we use the period
            if planet.has_data_only_for_single_transit:
                p_prior = pm.Pareto(
                    name=f"{ORBITAL_PERIOD}_{planet.index}",
                    m=planet.period_min,
                    alpha=2.0 / 3.0,
                    testval=planet.period_min,
                )
                p_param = p_prior
                tmax_prior = planet.t0
...
        p_priors = pm.Deterministic(ORBITAL_PERIOD, tt.stack(p_priors_list))
        tmax_priors = pm.Deterministic(TIME_END, tt.stack(tmax_priors_list))

...
avivajpeyi commented 2 years ago

LOL

tic_entry.candidates[0].num_periods
>>> -9223372036854775808
avivajpeyi commented 2 years ago

With the above changes, I was able to get the model to compile and run on the test val (no nans! woohoo!)

However, got the darn celerite2.backprop.LinAlgError: failed to factorize or solve matrix error again!

80

LOGS: ```python 2021-11-18 14:47:32,687 - TESS-ATLAS - INFO - Optimizing sampling starting point array: [30.25482971 19.9134664 -0.70142785] point: {'dur_interval__': array([4.59231013]), 'r_log__': array([-3.01614327]), 'b_impact__': array([-0.09347175]), 't0_interval__': array([0.]), 'p_1_lowerbound__': array(4.99338746), 'f0': array(0.), 'u_quadlimbdark__': array([4.4408921e-16, 0.0000000e+00]), 'jitter_log__': array(-0.70142785), 'sigma_log__': array(19.9134664), 'rho_log__': array(30.25482971)} Traceback (most recent call last): File "/Users/avaj0001/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/theano/compile/function/types.py", line 974, in __call__ self.fn() File "/Users/avaj0001/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/theano/graph/op.py", line 476, in rval r = p(n, [x[0] for x in i], o) File "/Users/avaj0001/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/celerite2/theano/ops.py", line 123, in perform func(*args) celerite2.backprop.LinAlgError: failed to factorize or solve matrix During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/avaj0001/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/pymc3_ext/optim.py", line 213, in __call__ res = self.func( File "/Users/avaj0001/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/theano/compile/function/types.py", line 987, in __call__ raise_with_op( File "/Users/avaj0001/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/theano/link/utils.py", line 508, in raise_with_op raise exc_value.with_traceback(exc_trace) File "/Users/avaj0001/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/theano/compile/function/types.py", line 974, in __call__ self.fn() File "/Users/avaj0001/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/theano/graph/op.py", line 476, in rval r = p(n, [x[0] for x in i], o) File "/Users/avaj0001/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/celerite2/theano/ops.py", line 123, in perform func(*args) celerite2.backprop.LinAlgError: failed to factorize or solve matrix Apply node that caused the error: _CeleriteOp{name='factor_fwd', quiet=False}(TensorConstant{[1683.3549...579482 ]}, Join.0, Elemwise{add,no_inplace}.0, Join.0, Join.0) Toposort index: 117 Inputs types: [TensorType(float64, vector), TensorType(float64, vector), TensorType(float64, vector), TensorType(float64, matrix), TensorType(float64, matrix)] Inputs shapes: [(229150,), (2,), (229150,), (229150, 2), (229150, 2)] Inputs strides: [(8,), (8,), (8,), (16, 8), (16, 8)] Inputs values: ['not shown', array([1.51898338e-13, 1.36708504e-12]), 'not shown', 'not shown', 'not shown'] Outputs clients: [[_CeleriteOp{name='factor_rev', quiet=False}(TensorConstant{[1683.3549...579482 ]}, Join.0, Elemwise{add,no_inplace}.0, Join.0, Join.0, _CeleriteOp{name='factor_fwd', quiet=False}.0, _CeleriteOp{name='factor_fwd', quiet=False}.1, _CeleriteOp{name='factor_fwd', quiet=False}.2, Elemwise{Composite{((i0 / i1) + ((i2 * i3 * i4) / sqr(i1)))}}.0, _CeleriteOp{name='solve_lower_rev', quiet=False}.3), Elemwise{true_div,no_inplace}(InplaceDimShuffle{0}.0, _CeleriteOp{name='factor_fwd', quiet=False}.0), Elemwise{Composite{((i0 / i1) + ((i2 * i3 * i4) / sqr(i1)))}}(TensorConstant{(1,) of 0.5}, _CeleriteOp{name='factor_fwd', quiet=False}.0, TensorConstant{(1,) of 0.5}, TensorConstant{(1,) of -1.0}, Elemwise{Sqr}[(0, 0)].0), Elemwise{TrueDiv}[(0, 0)](Elemwise{Sqr}[(0, 0)].0, _CeleriteOp{name='factor_fwd', quiet=False}.0), Elemwise{Log}[(0, 0)](_CeleriteOp{name='factor_fwd', quiet=False}.0)], [_CeleriteOp{name='solve_lower_fwd', quiet=False}(TensorConstant{[1683.3549...579482 ]}, Join.0, Join.0, _CeleriteOp{name='factor_fwd', quiet=False}.1, Elemwise{Composite{(i0 - ((i1 * i2) + i3))}}[(0, 2)].0), _CeleriteOp{name='solve_lower_rev', quiet=False}(TensorConstant{[1683.3549...579482 ]}, Join.0, Join.0, _CeleriteOp{name='factor_fwd', quiet=False}.1, Elemwise{Composite{(i0 - ((i1 * i2) + i3))}}[(0, 2)].0, _CeleriteOp{name='solve_lower_fwd', quiet=False}.0, _CeleriteOp{name='solve_lower_fwd', quiet=False}.1, IncSubtensor{InplaceInc;::, int64}.0), _CeleriteOp{name='factor_rev', quiet=False}(TensorConstant{[1683.3549...579482 ]}, Join.0, Elemwise{add,no_inplace}.0, Join.0, Join.0, _CeleriteOp{name='factor_fwd', quiet=False}.0, _CeleriteOp{name='factor_fwd', quiet=False}.1, _CeleriteOp{name='factor_fwd', quiet=False}.2, Elemwise{Composite{((i0 / i1) + ((i2 * i3 * i4) / sqr(i1)))}}.0, _CeleriteOp{name='solve_lower_rev', quiet=False}.3)], [_CeleriteOp{name='factor_rev', quiet=False}(TensorConstant{[1683.3549...579482 ]}, Join.0, Elemwise{add,no_inplace}.0, Join.0, Join.0, _CeleriteOp{name='factor_fwd', quiet=False}.0, _CeleriteOp{name='factor_fwd', quiet=False}.1, _CeleriteOp{name='factor_fwd', quiet=False}.2, Elemwise{Composite{((i0 / i1) + ((i2 * i3 * i4) / sqr(i1)))}}.0, _CeleriteOp{name='solve_lower_rev', quiet=False}.3)]] Backtrace when the node is created(use Theano flag traceback__limit=N to make it longer): File "/var/folders/qt/rxjvm_j566v9qn7g754s1v9hzb3p7f/T/ipykernel_68429/481931079.py", line 1, in planet_transit_model, params = build_planet_transit_model(tic_entry) File "/var/folders/qt/rxjvm_j566v9qn7g754s1v9hzb3p7f/T/ipykernel_68429/1034721686.py", line 144, in build_planet_transit_model gp = GaussianProcess( File "/Users/avaj0001/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/celerite2/core.py", line 210, in __init__ self.compute(t, **kwargs) File "/Users/avaj0001/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/celerite2/core.py", line 316, in compute self._do_compute(quiet) File "/Users/avaj0001/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/celerite2/theano/celerite2.py", line 83, in _do_compute self._d, self._W, _ = ops.factor( File "/Users/avaj0001/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/theano/graph/op.py", line 250, in __call__ node = self.make_node(*inputs, **kwargs) File "/Users/avaj0001/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/celerite2/theano/ops.py", line 83, in make_node otypes = [ File "/Users/avaj0001/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/celerite2/theano/ops.py", line 84, in tt.TensorType( HINT: Use the Theano flag 'exception_verbosity=high' for a debugprint and storage map footprint of this apply node. --------------------------------------------------------------------------- LinAlgError Traceback (most recent call last) ~/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/theano/compile/function/types.py in __call__(self, *args, **kwargs) 973 outputs = ( --> 974 self.fn() 975 if output_subset is None ~/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/theano/graph/op.py in rval(p, i, o, n) 475 def rval(p=p, i=node_input_storage, o=node_output_storage, n=node): --> 476 r = p(n, [x[0] for x in i], o) 477 for o in node.outputs: ~/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/celerite2/theano/ops.py in perform(self, node, inputs, outputs) 122 try: --> 123 func(*args) 124 except backprop.LinAlgError: LinAlgError: failed to factorize or solve matrix During handling of the above exception, another exception occurred: LinAlgError Traceback (most recent call last) /var/folders/qt/rxjvm_j566v9qn7g754s1v9hzb3p7f/T/ipykernel_68429/247479635.py in ----> 1 init_params = get_optimized_init_params(planet_transit_model, **params) /var/folders/qt/rxjvm_j566v9qn7g754s1v9hzb3p7f/T/ipykernel_68429/187439528.py in get_optimized_init_params(model, planet_params, noise_params, stellar_params, period_params) 9 theta = pmx.optimize(**kwargs, vars=[noise_params[0]]) 10 theta = pmx.optimize(**kwargs, vars=planet_params) ---> 11 theta = pmx.optimize(**kwargs, vars=noise_params) 12 theta = pmx.optimize(**kwargs, vars=stellar_params) 13 theta = pmx.optimize(**kwargs, vars=period_params) ~/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/pymc3_ext/optim.py in optimize(start, vars, return_info, verbose, progress, maxeval, model, **kwargs) 117 118 try: --> 119 info = minimize(objective, x0, **kwargs) 120 except (KeyboardInterrupt, StopIteration): 121 info = None ~/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/scipy/optimize/_minimize.py in minimize(fun, x0, args, method, jac, hess, hessp, bounds, constraints, tol, callback, options) 616 return _minimize_cg(fun, x0, args, jac, callback, **options) 617 elif meth == 'bfgs': --> 618 return _minimize_bfgs(fun, x0, args, jac, callback, **options) 619 elif meth == 'newton-cg': 620 return _minimize_newtoncg(fun, x0, args, jac, hess, hessp, callback, ~/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/scipy/optimize/optimize.py in _minimize_bfgs(fun, x0, args, jac, callback, gtol, norm, eps, maxiter, disp, return_all, finite_diff_rel_step, **unknown_options) 1233 try: 1234 alpha_k, fc, gc, old_fval, old_old_fval, gfkp1 = \ -> 1235 _line_search_wolfe12(f, myfprime, xk, pk, gfk, 1236 old_fval, old_old_fval, amin=1e-100, amax=1e100) 1237 except _LineSearchError: ~/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/scipy/optimize/optimize.py in _line_search_wolfe12(f, fprime, xk, pk, gfk, old_fval, old_old_fval, **kwargs) 1003 extra_condition = kwargs.pop('extra_condition', None) 1004 -> 1005 ret = line_search_wolfe1(f, fprime, xk, pk, gfk, 1006 old_fval, old_old_fval, 1007 **kwargs) ~/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/scipy/optimize/linesearch.py in line_search_wolfe1(f, fprime, xk, pk, gfk, old_fval, old_old_fval, args, c1, c2, amax, amin, xtol) 94 derphi0 = np.dot(gfk, pk) 95 ---> 96 stp, fval, old_fval = scalar_search_wolfe1( 97 phi, derphi, old_fval, old_old_fval, derphi0, 98 c1=c1, c2=c2, amax=amax, amin=amin, xtol=xtol) ~/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/scipy/optimize/linesearch.py in scalar_search_wolfe1(phi, derphi, phi0, old_phi0, derphi0, c1, c2, amax, amin, xtol) 170 if task[:2] == b'FG': 171 alpha1 = stp --> 172 phi1 = phi(stp) 173 derphi1 = derphi(stp) 174 else: ~/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/scipy/optimize/linesearch.py in phi(s) 82 def phi(s): 83 fc[0] += 1 ---> 84 return f(xk + s*pk, *args) 85 86 def derphi(s): ~/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/scipy/optimize/_differentiable_functions.py in fun(self, x) 247 if not np.array_equal(x, self.x): 248 self._update_x_impl(x) --> 249 self._update_fun() 250 return self.f 251 ~/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/scipy/optimize/_differentiable_functions.py in _update_fun(self) 231 def _update_fun(self): 232 if not self.f_updated: --> 233 self._update_fun_impl() 234 self.f_updated = True 235 ~/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/scipy/optimize/_differentiable_functions.py in update_fun() 135 136 def update_fun(): --> 137 self.f = fun_wrapped(self.x) 138 139 self._update_fun_impl = update_fun ~/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/scipy/optimize/_differentiable_functions.py in fun_wrapped(x) 132 # Overwriting results in undefined behaviour because 133 # fun(self.x) will change self.x, with the two no longer linked. --> 134 return fun(np.copy(x), *args) 135 136 def update_fun(): ~/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/scipy/optimize/optimize.py in __call__(self, x, *args) 72 def __call__(self, x, *args): 73 """ returns the the function value """ ---> 74 self._compute_if_needed(x, *args) 75 return self._value 76 ~/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/scipy/optimize/optimize.py in _compute_if_needed(self, x, *args) 66 if not np.all(x == self.x) or self._value is None or self.jac is None: 67 self.x = np.asarray(x).copy() ---> 68 fg = self.fun(x, *args) 69 self.jac = fg[1] 70 self._value = fg[0] ~/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/pymc3_ext/optim.py in objective(vec) 101 nonlocal neval 102 neval += 1 --> 103 nll, grad = wrapper(vec) 104 if progressbar: 105 progressbar.comment = "logp = {0:.3e}".format(-nll) ~/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/pymc3_ext/optim.py in __call__(self, vec) 211 def __call__(self, vec): 212 try: --> 213 res = self.func( 214 *get_args_for_theano_function( 215 self.bij.rmap(vec), model=self.model ~/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/theano/compile/function/types.py in __call__(self, *args, **kwargs) 985 if hasattr(self.fn, "thunks"): 986 thunk = self.fn.thunks[self.fn.position_of_error] --> 987 raise_with_op( 988 self.maker.fgraph, 989 node=self.fn.nodes[self.fn.position_of_error], ~/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/theano/link/utils.py in raise_with_op(fgraph, node, thunk, exc_info, storage_map) 506 # Some exception need extra parameter in inputs. So forget the 507 # extra long error message in that case. --> 508 raise exc_value.with_traceback(exc_trace) 509 510 ~/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/theano/compile/function/types.py in __call__(self, *args, **kwargs) 972 try: 973 outputs = ( --> 974 self.fn() 975 if output_subset is None 976 else self.fn(output_subset=output_subset) ~/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/theano/graph/op.py in rval(p, i, o, n) 474 # default arguments are stored in the closure of `rval` 475 def rval(p=p, i=node_input_storage, o=node_output_storage, n=node): --> 476 r = p(n, [x[0] for x in i], o) 477 for o in node.outputs: 478 compute_map[o][0] = True ~/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/celerite2/theano/ops.py in perform(self, node, inputs, outputs) 121 122 try: --> 123 func(*args) 124 except backprop.LinAlgError: 125 if not self.quiet: LinAlgError: failed to factorize or solve matrix Apply node that caused the error: _CeleriteOp{name='factor_fwd', quiet=False}(TensorConstant{[1683.3549...579482 ]}, Join.0, Elemwise{add,no_inplace}.0, Join.0, Join.0) Toposort index: 117 Inputs types: [TensorType(float64, vector), TensorType(float64, vector), TensorType(float64, vector), TensorType(float64, matrix), TensorType(float64, matrix)] Inputs shapes: [(229150,), (2,), (229150,), (229150, 2), (229150, 2)] Inputs strides: [(8,), (8,), (8,), (16, 8), (16, 8)] Inputs values: ['not shown', array([1.51898338e-13, 1.36708504e-12]), 'not shown', 'not shown', 'not shown'] Outputs clients: [[_CeleriteOp{name='factor_rev', quiet=False}(TensorConstant{[1683.3549...579482 ]}, Join.0, Elemwise{add,no_inplace}.0, Join.0, Join.0, _CeleriteOp{name='factor_fwd', quiet=False}.0, _CeleriteOp{name='factor_fwd', quiet=False}.1, _CeleriteOp{name='factor_fwd', quiet=False}.2, Elemwise{Composite{((i0 / i1) + ((i2 * i3 * i4) / sqr(i1)))}}.0, _CeleriteOp{name='solve_lower_rev', quiet=False}.3), Elemwise{true_div,no_inplace}(InplaceDimShuffle{0}.0, _CeleriteOp{name='factor_fwd', quiet=False}.0), Elemwise{Composite{((i0 / i1) + ((i2 * i3 * i4) / sqr(i1)))}}(TensorConstant{(1,) of 0.5}, _CeleriteOp{name='factor_fwd', quiet=False}.0, TensorConstant{(1,) of 0.5}, TensorConstant{(1,) of -1.0}, Elemwise{Sqr}[(0, 0)].0), Elemwise{TrueDiv}[(0, 0)](Elemwise{Sqr}[(0, 0)].0, _CeleriteOp{name='factor_fwd', quiet=False}.0), Elemwise{Log}[(0, 0)](_CeleriteOp{name='factor_fwd', quiet=False}.0)], [_CeleriteOp{name='solve_lower_fwd', quiet=False}(TensorConstant{[1683.3549...579482 ]}, Join.0, Join.0, _CeleriteOp{name='factor_fwd', quiet=False}.1, Elemwise{Composite{(i0 - ((i1 * i2) + i3))}}[(0, 2)].0), _CeleriteOp{name='solve_lower_rev', quiet=False}(TensorConstant{[1683.3549...579482 ]}, Join.0, Join.0, _CeleriteOp{name='factor_fwd', quiet=False}.1, Elemwise{Composite{(i0 - ((i1 * i2) + i3))}}[(0, 2)].0, _CeleriteOp{name='solve_lower_fwd', quiet=False}.0, _CeleriteOp{name='solve_lower_fwd', quiet=False}.1, IncSubtensor{InplaceInc;::, int64}.0), _CeleriteOp{name='factor_rev', quiet=False}(TensorConstant{[1683.3549...579482 ]}, Join.0, Elemwise{add,no_inplace}.0, Join.0, Join.0, _CeleriteOp{name='factor_fwd', quiet=False}.0, _CeleriteOp{name='factor_fwd', quiet=False}.1, _CeleriteOp{name='factor_fwd', quiet=False}.2, Elemwise{Composite{((i0 / i1) + ((i2 * i3 * i4) / sqr(i1)))}}.0, _CeleriteOp{name='solve_lower_rev', quiet=False}.3)], [_CeleriteOp{name='factor_rev', quiet=False}(TensorConstant{[1683.3549...579482 ]}, Join.0, Elemwise{add,no_inplace}.0, Join.0, Join.0, _CeleriteOp{name='factor_fwd', quiet=False}.0, _CeleriteOp{name='factor_fwd', quiet=False}.1, _CeleriteOp{name='factor_fwd', quiet=False}.2, Elemwise{Composite{((i0 / i1) + ((i2 * i3 * i4) / sqr(i1)))}}.0, _CeleriteOp{name='solve_lower_rev', quiet=False}.3)]] Backtrace when the node is created(use Theano flag traceback__limit=N to make it longer): File "/var/folders/qt/rxjvm_j566v9qn7g754s1v9hzb3p7f/T/ipykernel_68429/481931079.py", line 1, in planet_transit_model, params = build_planet_transit_model(tic_entry) File "/var/folders/qt/rxjvm_j566v9qn7g754s1v9hzb3p7f/T/ipykernel_68429/1034721686.py", line 144, in build_planet_transit_model gp = GaussianProcess( File "/Users/avaj0001/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/celerite2/core.py", line 210, in __init__ self.compute(t, **kwargs) File "/Users/avaj0001/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/celerite2/core.py", line 316, in compute self._do_compute(quiet) File "/Users/avaj0001/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/celerite2/theano/celerite2.py", line 83, in _do_compute self._d, self._W, _ = ops.factor( File "/Users/avaj0001/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/theano/graph/op.py", line 250, in __call__ node = self.make_node(*inputs, **kwargs) File "/Users/avaj0001/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/celerite2/theano/ops.py", line 83, in make_node otypes = [ File "/Users/avaj0001/Documents/projects/tess/tess_venv/lib/python3.9/site-packages/celerite2/theano/ops.py", line 84, in tt.TensorType( HINT: Use the Theano flag 'exception_verbosity=high' for a debugprint and storage map footprint of this apply node. ```
avivajpeyi commented 2 years ago

Hmm looking at the logs, I see that there are two 0s in the point being optimized:

{'dur_interval__': array([4.59231013]),
 'r_log__': array([-3.01614327]),
 'b_impact__': array([-0.09347175]),
 't0_interval__': array([0.]),
 'p_1_lowerbound__': array(4.99338746),
 'f0': array(0.),
 'u_quadlimbdark__': array([4.4408921e-16, 0.0000000e+00]),
 'jitter_log__': array(-0.70142785),
 'sigma_log__': array(19.9134664),
 'rho_log__': array(30.25482971)}

The error is being thrown at

theta = pmx.optimize(**kwargs, vars=noise_params)

and

noise_params = [jitter_prior, sigma_prior, rho_prior]
avivajpeyi commented 2 years ago

TOI 1847

run_toi(1847) results with an error at the start of the sampling step, because p_1_lowerbound -inf

Exofop link for TOI

 An error occurred while executing the following cell:
------------------
if tic_entry.inference_data is None:
    inference_data = run_inference(planet_transit_model)
else:
    logger.info("Using cached run")
    inference_data = tic_entry.inference_data
inference_data

------------------

---------------------------------------------------------------------------
SamplingError                             Traceback (most recent call last)
/tmp/ipykernel_176089/141900171.py in <module>
      1 if tic_entry.inference_data is None:
----> 2     inference_data = run_inference(planet_transit_model)
      3 else:
      4     logger.info("Using cached run")
      5     inference_data = tic_entry.inference_data

/tmp/ipykernel_176089/3349958539.py in run_inference(model)
      4         sampling_kwargs = dict(tune=2000, draws=2000, chains=2, cores=2)
      5         logger.info(f"Run sampler with kwargs: {sampling_kwargs}")
----> 6         inference_data = pmx.sample(
      7             **sampling_kwargs, start=init_params, return_inferencedata=True
      8         )

/fred/oz200/avajpeyi/envs/tess/lib/python3.8/site-packages/pymc3_ext/sampling/sampling.py in sample(draws, tune, model, step_kwargs, warmup_window, adapt_window, cooldown_window, initial_accept, target_accept, gamma, k, t0, parameter_groups, adapt_type, recompute_interval, regularization_steps, regularization_variance, **kwargs)
     95     )
     96
---> 97     return pm.sample(draws=draws, tune=tune, model=model, step=step, **kwargs)

/fred/oz200/avajpeyi/envs/tess/lib/python3.8/site-packages/pymc3/sampling.py in sample(draws, step, init, n_init, start, trace, chain_idx, chains, cores, tune, progressbar, model, random_seed, discard_tuned_samples, compute_convergence_checks, callback, jitter_max_retries, return_inferencedata, idata_kwargs, mp_ctx, pickle_backend, **kwargs)
    433             for chain_start_vals in start:
    434                 update_start_vals(chain_start_vals, model.test_point, model)
--> 435         check_start_vals(start, model)
    436
    437     if cores is None:

/fred/oz200/avajpeyi/envs/tess/lib/python3.8/site-packages/pymc3/util.py in check_start_vals(start, model)
    235
    236         if not np.all(np.isfinite(initial_eval)):
--> 237             raise SamplingError(
    238                 "Initial evaluation of model at starting point failed!\n"
    239                 "Starting values:\n{}\n\n"

SamplingError: Initial evaluation of model at starting point failed!
Starting values:
{'dur_interval__': array([-1.75828217,  0.66137893]), 'r_log__': array([-2.3121765, -2.9045715]), 'b_impact__': array([-0.18072936, -0.10394958]), 't0_interval__': array([0., 0.]), 'p_1_lowerbound__': array(-inf), 'tmax_2_interval__': array(0.), 'f0': array(0.), 'u_quadlimbdark__': array([4.4408921e-16, 0.0000000e+00]), 'jitter_log__': array(0.5556663), 'sigma_log__': array(0.5556663), 'rho_log__': array(0.05250777), 'dur': array([0.149375  , 0.08883333]), 'r': array([0.09904544, 0.05477226]), 'b': array([0.5, 0.5]), 't0': array([1390.70655 , 2130.150082]), 'p_1': array(750.87597302), 'tmax_2': array(2130.150082), 'p': array([750.87597302,          nan]), 'tmax': array([1390.70655 , 2130.150082]), 'u': array([0.70710678, 0.        ]), 'jitter': array(1.74310202), 'sigma': array(1.74310202), 'rho': array(1.05391075), 'rho_circ': array([128.85573981,          nan])}

Initial evaluation results:
dur_interval__           0.28
r_log__                 -1.84
b_impact__              -2.78
t0_interval__            0.47
p_1_lowerbound__         -inf
tmax_2_interval__       -0.51
f0                      -3.22
u_quadlimbdark__        -2.77
jitter_log__             0.11
sigma_log__              0.11
rho_log__               -0.55
obs                 -37873.84
Name: Log-probability of test_point, dtype: float64
SamplingError: Initial evaluation of model at starting point failed!

So the issue might be in the optimise_init_param step?

Screen Shot 2022-02-16 at 6 28 16 am Screen Shot 2022-02-16 at 6 28 06 am

From the flux vs time plot, looks like we've just missed the transit? iTerm2 WR3Q1t flux_vs_time

notebook: toi_1847.ipynb.zip

TODO

^ the test_model function should also check for infs, not just isnull

avivajpeyi commented 2 years ago

Looks like im missing the transits for several single-transit TOIs!

Here are some examples:

iTerm2 lvk4zn folded_flux_vs_time

iTerm2 WaXdxi folded_flux_vs_time

avivajpeyi commented 2 years ago

Another set of funky errors -- the transit duration seems wrong?

iTerm2 fiPjGI folded_flux_vs_time

iTerm2 KOmZWH folded_flux_vs_time

iTerm2 sBcnCS folded_flux_vs_time

avivajpeyi commented 2 years ago

The 77 analyses for single-transit systems have p_n_lowerbound = -inf

Eg from 1812:

Screen Shot 2022-02-16 at 6 46 48 am
avivajpeyi commented 2 years ago

The test-val is wrong -- currently set to prior's lower bound!

avivajpeyi commented 2 years ago

So although the periods are super long with even wider uncertainties -- the phase plots look ok?

phase_plot_1

phase_plot_2

phase_plot_3

I wonder if there is any more physics that we can use to constrain the period a bit more for these single-transit systems

avivajpeyi commented 2 years ago

Some more diagnostics:

planet_0_posteriors

planet_1_posteriors planet_2_posteriors

diagnostic_flux_vs_time

Hhmm why are my ranges going so far out I wonder... i probably samples really far away from the 1,2,3 sigma contours

avivajpeyi commented 2 years ago

Finally, the trace plot:

diagnostic_trace_plot

looks like there are a few divergences

avivajpeyi commented 2 years ago

For single transits:

avivajpeyi commented 2 years ago

period -- are we just getting back the prior?

avivajpeyi commented 2 years ago

This could be a cool system to talk about + followup + maybe highlight this in the paper