from hamilton import driverfrom hamilton.plugins import h_diskcacheimport src.workflow as workflow# check if we are runnign in ipython console# or during rendering via the jupyter kernel# in which case we don't want to open files# while renderingfrom IPython.core.getipython import get_ipythonip = get_ipython()interactive =Falseif ip isnotNoneand'interactiveshell.TerminalInteractiveShell'instr(ip): interactive =Truecache = h_diskcache.DiskCacheAdapter()dr = ( driver.Builder() .with_modules(workflow) .with_adapter(cache) .build())
cache.cache.clear()
g = dr.display_all_functions()if interactive: g.render(view=True)g
dr.execute(final_vars=["plot"])
{'plot': (<Figure size 672x480 with 1 Axes>, <Axes: >)}
Source Code
---title: Hamilton Eample---# Setup```bashpython-m venv .venvsource .venv/bin/activatepip install -r requirements.txt```# Hamilton Example```{python}from hamilton import driverfrom hamilton.plugins import h_diskcacheimport src.workflow as workflow# check if we are runnign in ipython console# or during rendering via the jupyter kernel# in which case we don't want to open files# while renderingfrom IPython.core.getipython import get_ipythonip = get_ipython()interactive =Falseif ip isnotNoneand'interactiveshell.TerminalInteractiveShell'instr(ip): interactive =Truecache = h_diskcache.DiskCacheAdapter()dr = ( driver.Builder() .with_modules(workflow) .with_adapter(cache) .build())``````{python}#| eval: falsecache.cache.clear()``````{python}g = dr.display_all_functions()if interactive: g.render(view=True)g``````{python}dr.execute(final_vars=["plot"])```