{ "cells": [ { "cell_type": "markdown", "id": "50415948", "metadata": {}, "source": [ "# Improving Pastas performance with caching\n", "\n", "This notebook shows how pastas performance can be improved by caching computation results. " ] }, { "cell_type": "code", "execution_count": null, "id": "6c5afe91", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "\n", "import pastas as ps\n", "\n", "ps.set_log_level(\"WARNING\")" ] }, { "cell_type": "markdown", "id": "56c395ae", "metadata": {}, "source": [ "Load some test data for the examples." ] }, { "cell_type": "code", "execution_count": null, "id": "fb231873", "metadata": {}, "outputs": [], "source": [ "head = pd.read_csv(\"data/heby_head.csv\", index_col=0, parse_dates=True).squeeze(\n", " \"columns\"\n", ")\n", "evap = pd.read_csv(\"data/heby_evap.csv\", index_col=0, parse_dates=True).squeeze(\n", " \"columns\"\n", ")\n", "prec = pd.read_csv(\"data/heby_prec.csv\", index_col=0, parse_dates=True).squeeze(\n", " \"columns\"\n", ")\n", "temp = pd.read_csv(\"data/heby_temp.csv\", index_col=0, parse_dates=True).squeeze(\n", " \"columns\"\n", ")" ] }, { "cell_type": "markdown", "id": "4c5ffdfd", "metadata": {}, "source": [ "If the `cachetools` module is installed, Pastas can cache intermediate results for certain stressmodels. The cache essentially works as a dictionary that checks if the input arguments to a function, e.g. `StressModel.simulate()` are already stored in the cache. If so, it returns the stored solution, otherwise it computes the solution and adds it to the cache.\n", "\n", "
cachetools is not available the ._cache attribute will be None.\n",
"stressmodel._cache.clear(), or rebuild the stress model.\n",
"