inducer / pytato

Lazily evaluated arrays in Python
Other
8 stars 16 forks source link

Get precise traceback of array creation #480

Closed majosm closed 3 months ago

majosm commented 5 months ago

Removes the

pytato/array.py:2049, in concatenate(): non_equality_tags=frozenset({_get_created_at_tag()}),
pytato/array.py:1887, in _get_created_at_tag(): for s in traceback.extract_stack()))})

and any other internal pytato stuff from the end of the stack trace stored in the CreatedAt tag.

majosm commented 5 months ago

@matthiasdiener What do you think?

matthiasdiener commented 5 months ago

LGTM, thanks. Out of curiosity - is the heuristic in _PytatoStackSummary.short_str useful here? Should it be adjusted?

majosm commented 5 months ago

LGTM, thanks. Out of curiosity - is the heuristic in _PytatoStackSummary.short_str useful here? Should it be adjusted?

TIL. 🙂

I think the heuristic there still works (though it's possibly redundant after this change). I'm personally finding the full stack printout to be the most useful, because sometimes there is still extra junk on the stack (from outside of pytato) after the point where the array is "created". Mainly it's array container stuff, e.g.:

expr.non_equality_tags=frozenset({CreatedAt(
  <frozen runpy>:198, in _run_module_as_main(): 
  <frozen runpy>:88, in _run_code(): 
  lib/python3.11/site-packages/mpi4py/__main__.py:7, in <module>(): main()
  lib/python3.11/site-packages/mpi4py/run.py:218, in main(): run_command_line(args)
  lib/python3.11/site-packages/mpi4py/run.py:46, in run_command_line(): run_path(sys.argv[0], run_name='__main__')
  <frozen runpy>:291, in run_path(): 
  <frozen runpy>:98, in _run_module_code(): 
  <frozen runpy>:88, in _run_code(): 
  driver.py:76, in <module>(): main(actx_class, restart_filename=restart_filename,
  emirge/mirgecom/mirgecom/mpi.py:245, in wrapped_func(): func(*args, **kwargs)
  y3prediction/prediction.py:4567, in main(): advance_state(rhs=my_rhs, timestepper=timestepper,
  emirge/mirgecom/mirgecom/steppers.py:439, in advance_state(): _advance_state_stepper_func(
  emirge/mirgecom/mirgecom/steppers.py:164, in _advance_state_stepper_func(): state = timestepper(state=state, t=t, dt=dt, rhs=maybe_compiled_rhs)
  emirge/mirgecom/mirgecom/integrators/lsrk.py:67, in euler_step(): return lsrk_step(EulerCoefs, state, t, dt, rhs)
  emirge/mirgecom/mirgecom/integrators/lsrk.py:53, in lsrk_step(): k = coefs.A[i]*k + dt*rhs(t + coefs.C[i]*dt, state)
  y3prediction/prediction.py:4543, in my_rhs(): rhs_state = unfiltered_rhs_compiled(t, state)
  emirge/arraycontext/arraycontext/impl/pytato/compile.py:314, in __call__(): output_template = self.f(
  y3prediction/prediction.py:4351, in unfiltered_rhs(): fluid_rhs = ns_operator(
  emirge/mirgecom/mirgecom/navierstokes.py:553, in ns_operator(): bnd_term = bnd_term - inviscid_flux_on_element_boundary(
  emirge/mirgecom/mirgecom/inviscid.py:321, in inviscid_flux_on_element_boundary(): sum(_interior_flux(state_pair) for state_pair in interior_state_pairs)
  emirge/mirgecom/mirgecom/inviscid.py:321, in <genexpr>(): sum(_interior_flux(state_pair) for state_pair in interior_state_pairs)
  emirge/mirgecom/mirgecom/inviscid.py:307, in _interior_flux(): outlined_num_flux(state_pair, normal))
  emirge/arraycontext/arraycontext/impl/pytato/outline.py:128, in __call__(): output = self.f(*pl_args, **pl_kwargs)
  emirge/mirgecom/mirgecom/inviscid.py:301, in outlined_num_flux(): return numerical_flux_func(state_pair, gas_model, normal)
  emirge/mirgecom/mirgecom/inviscid.py:149, in inviscid_facial_flux_rusanov(): f_plus_normal=inviscid_flux(state_pair.ext)@normal,
  emirge/mirgecom/mirgecom/inviscid.py:95, in inviscid_flux(): + np.eye(state.dim)*state.pressure
  <container arithmetic for DOFArray>:203, in _dofarray_rmul(): 
  <container arithmetic for DOFArray>:208, in _dofarray_rmul(): 
  <container arithmetic for DOFArray>:208, in <listcomp>(): )})

vs.

next(iter(expr.non_equality_tags)).traceback.short_str()='<container arithmetic for DOFArray>:208, in <listcomp>():\n'