akernel icon indicating copy to clipboard operation
akernel copied to clipboard

How to access reactive dependencies for display and navigation?

Open stefaneidelloth opened this issue 2 years ago • 2 comments

How can I access the information about dependencies of akernel to use it for JupyterLab extensions? What would be the right entry point for that?

Lets say I have a JupyterLab extension that is able to access a notebook cell model:

let notebook = __tryToGetNotebook(app);
    if(notebook){       
        let cellModels = notebook.model.cells   
        for(let cellIndex=0; cellIndex < cellModels.length; cellIndex++){
            let cellModel = cellModels.get(cellIndex);          
            let dependencies = __getDependencies(cellModel, notebook); //<= how to implement this?
        }
}

=> Is it possible to ask the cell for its dependencies? Or would I have to somehow directly communicate with akernel or ipyx?

Related:

  • https://github.com/davidbrochart/akernel/issues/24
  • https://stackoverflow.com/questions/69539309/how-to-monitor-state-of-observales-in-reactive-calculations

Some possible use cases:

A. Show neighboring cell dependencies in a dependency view when focusing a distinct cell. The corresponding terms in obsservablehq are "Visual Dataflow" and "Minimap": https://observablehq.com/@observablehq/introducing-visual-dataflow

image

B. Generate a full dependency graph

Could look similar to

image

https://observablehq.com/@observablehq/notebook-visualizer

https://observablehq.com/@observablehq/notebook-visualizer-elk-edition

C. Generate editable flow chart from akernel notebook cells

Maybe combine akernel with a view of ipyspaghetti or node-red, so that a user gets an alternative GUI to edit the notebook cells in some sort of flow chart.

https://github.com/cphyc/ipyspaghetti

image

https://nodered.org

image

D. Navigate between dependent cells.

Similar to the navigation features in a code IDE, the dependency information could be used to

  • Jump to a cell where some input comes from
  • Show usages of some output and jump to it

https://www.jetbrains.com/help/pycharm/navigating-through-the-source-code.html#go_to_declaration

stefaneidelloth avatar Oct 27 '21 07:10 stefaneidelloth

Is it possible to ask the cell for its dependencies? Or would I have to somehow directly communicate with akernel or ipyx?

In akernel, dependencies are not cell based but variable based. When you assign to a variable, it keeps track of the variables that are used on the right hand side. So indeed I think you would have to communicate with the variable, which is an ipyx.X object. I think some of the use cases you mentioned could become possible by implementing the functionality in ipyx as a widget. In particular, the dependency graph could be interesting.

davidbrochart avatar Oct 27 '21 09:10 davidbrochart

#28 adds support for DAG visualization.

davidbrochart avatar Oct 29 '21 16:10 davidbrochart