holoviz / datashader

Quickly and accurately render even the largest data.
http://datashader.org
BSD 3-Clause "New" or "Revised" License
3.24k stars 363 forks source link

Add debug logging to compiler module #1280

Closed ianthomas23 closed 9 months ago

ianthomas23 commented 9 months ago

Fixes #1266.

This adds some debug logging to the compiler.py module to show the dynamically-generated Python code that is subsequently compiled by numba. By default logging is disabled, and when it is enabled an example of the logged output for an antialiased ds.where(ds.min("value"), "other") reduction is

def aa_stage_2_accumulate(aggs_and_copies, first_pass):
    if first_pass:
        for a in literal_unroll(aggs_and_copies):
            a[1][:] = a[0][:]
    else:
        combine0(aggs_and_copies[1][::-1], aggs_and_copies[0][::-1])
def aa_stage_2_clear(aggs_and_copies):
    aggs_and_copies[0][0].fill(nan)
    aggs_and_copies[1][0].fill(nan)
global_cuda_mutex False
any_uses_cuda_mutex False
arg_lk _0 <datashader.reductions.min object at 0x17461f350> value
arg_lk _1 <datashader.reductions.where object at 0x17461f390> other
arg_lk _2 <datashader.reductions.extract object at 0x174634990> value
arg_lk _3 <datashader.reductions.extract object at 0x1746349d0> other
func _4 CPUDispatcher(<function min._append_antialias at 0x17285b560>)
func _5 CPUDispatcher(<function where._append_antialias at 0x174119300>)
def append(i0, x, y, aa_factor, _0, _1, _2, _3):
    _6 = _4(x, y, _0, _2[i0], aa_factor)
    if _6 >= 0:
        _5(x, y, _1, _3[i0], aa_factor, _6)

To enable logging in a user script use

import logging
logger = logging.getLogger("datashader.compiler")
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())

This is the standard approach and is a bit verbose but suffices for the moment. In future we could consider adding a new setup_logging function that does all of this in a one-liner.

codecov[bot] commented 9 months ago

Codecov Report

Merging #1280 (cb41f58) into main (3dab9df) will decrease coverage by 0.03%. The diff coverage is 63.63%.

@@            Coverage Diff             @@
##             main    #1280      +/-   ##
==========================================
- Coverage   83.54%   83.52%   -0.03%     
==========================================
  Files          35       35              
  Lines        9134     9145      +11     
==========================================
+ Hits         7631     7638       +7     
- Misses       1503     1507       +4     
Files Changed Coverage Δ
datashader/compiler.py 88.85% <63.63%> (-0.95%) :arrow_down:

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more