{ "cells": [ { "cell_type": "markdown", "metadata": { "toc": true }, "source": [ "

Table of Contents

\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# restarting a notebook from a checkpoint" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Import the functions and classes you'll need from the build_2D_matrix module\n", "\n", "* see [vanderPlas section 13](https://jakevdp.github.io/WhirlwindTourOfPython/13-modules-and-packages.html) and\n", " this [stack overflow entry on the dir function](https://stackoverflow.com/questions/1842414/why-is-dir-named-dir-in-python)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['Boundary_Def', 'Problem_Def', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'avg', 'build_2D_matrix', 'index_to_row_col']\n" ] } ], "source": [ "import numpy as np\n", "import build_2D_matrix\n", "print(dir(build_2D_matrix))" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from build_2D_matrix import Boundary_Def, Problem_Def, build_2D_matrix, index_to_row_col" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Import the state from the original notebook" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['n_x', 'n_y', 'poro', 'width_x', 'width_y', 'Qsource', 'c0', 'c_init', 'Diff', 'save_date', 'case_name', 'comment', 'history', 'units']\n" ] } ], "source": [ "import numpy as np\n", "in_file = 'savestate.npz'\n", "values = np.load(in_file)\n", "print(list(values.keys()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Turn the npz object into a dictionary\n", "\n", "* This is a good time to review list, dictionary and set comprehensions:\n", "[Vanderplas section 11](https://jakevdp.github.io/WhirlwindTourOfPython/11-list-comprehensions.html)\n", "\n", "* Essentially we're doing this so we can get a nicely formatted printout of the values" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'n_x': array(51),\n", " 'n_y': array(1),\n", " 'poro': array(0.4),\n", " 'width_x': array(10),\n", " 'width_y': array(0),\n", " 'Qsource': array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n", " 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n", " 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]),\n", " 'c0': array(1),\n", " 'c_init': array([1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n", " 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n", " 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]),\n", " 'Diff': array(0.01728),\n", " 'save_date': array('March 3, 2019', dtype='