Quib dependency network
In Quibbler, each quib is connected to quibs that it depends on (upstream quibs) and quibs that depend on it (downstream). Quibbler provides simple tools to transverse this relationship network, revealing the parameters affecting for a focal downstream result, or understanding what downstream results are affected by a given parameter or source data.
# Quibbler import:
import pyquibbler as qb
from pyquibbler import iquib
qb.initialize_quibbler()
Parents and children
For each quib, we can get the quibs immediately upstream to it (parents)
or immediately downstream to it (children) using the
get_parents
, get_children
methods.
a = iquib(1)
b = iquib(2)
c = a + b
c.get_parents()
{a = iquib(1), b = iquib(2)}
a.get_children()
{c = a + b}
When we consider the children or parents of a quib, we might get unnamed quibs, typically representing intermediate results. For example:
a = iquib(1)
c = (a + 10) * 2
c.get_parents()
{a + 10}
To byass these intermediate quibs and get the more relevant, named
quibs, we can use the bypass_intermediate_quibs
option:
c.get_parents(bypass_intermediate_quibs=True)
{a = iquib(1)}
Ancestors and descendants
To recursively find all the quibs that affect a focal quib (ancestors)
or all the quibs that are affected by a focal quib, we use the
get_ancestors
, get_descendants
:
import numpy as np
a = iquib(1)
b = a + 10
c = (b * 2) + a
d = np.log(c)
d.get_ancestors()
{a = iquib(1), b = a + 10, b * 2, c = b*2 + a}
Again, we can limit to named quibs:
d.get_ancestors(bypass_intermediate_quibs=True)
{a = iquib(1), b = a + 10, c = b*2 + a}
For example, to find all the inputs affecting a focal quib, we can use:
{ancestor for ancestor in d.get_ancestors() if ancestor.is_iquib}
{a = iquib(1)}
Displaying the dependency graph
When working within Jupyter lab (either with or without the
pyquibbler-labextension), we can graphically display the relationship
graph of connected quibs, using the dependency_graph()
function.
from pyquibbler.quib_network import dependency_graph
dependency_graph(c)
The dependency graph allows multiple options for restricting the network
to quibs affecting or affected by a focal quib. See the function
documentation for more detail (dependency_graph()
)