blob: fcafa48307083d68c401c257e423ae80ac5c8a69 [file] [log] [blame]
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Execute this cell to install dependencies\n",
"%pip install sf-hamilton[visualization]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Diskcache tutorial [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/dagworks-inc/hamilton/blob/main/examples/caching_nodes/diskcache_adapter/notebook.ipynb) [![GitHub badge](https://img.shields.io/badge/github-view_source-2b3137?logo=github)](https://github.com/dagworks-inc/hamilton/blob/main/examples/caching_nodes/diskcache_adapter/notebook.ipynb)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from hamilton import driver\n",
"from hamilton.plugins import h_diskcache\n",
"\n",
"import functions"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import logging\n",
"\n",
"# get the plugin logger\n",
"logger = logging.getLogger(\"hamilton.plugins.h_diskcache\")\n",
"logger.setLevel(logging.DEBUG) # set logging.INFO for less info\n",
"logger.addHandler(logging.StreamHandler())"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"A {'external': 10}: from cache\n",
"B {'A': 4}: from cache\n",
"C {'A': 4, 'B': 1.0}: from cache\n",
"Cache size: 0.03 MB\n"
]
}
],
"source": [
"dr = (\n",
" driver.Builder()\n",
" .with_modules(functions)\n",
" .with_adapters(h_diskcache.DiskCacheAdapter())\n",
" .build()\n",
")\n",
"# if you ran `run.py`, you should see the nodes being\n",
"# read from cache\n",
"results = dr.execute([\"C\"], inputs=dict(external=10))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
}
},
"nbformat": 4,
"nbformat_minor": 2
}