{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "tags": [ "remove-cell" ] }, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2\n", "from myst_nb import glue" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# The basics" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Before anything else, let's import the classes we need:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "try:\n", " from respace import ResultSet\n", "except ImportError:\n", " !pip install respace\n", " from respace import ResultSet" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## The ResultSet class" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Now let's build the simplest possible {class}`~respace.ResultSet`: it contains only one\n", "result `\"result\"` that depends on a single parameter `\"parameter\"`. And let's make it\n", "verbose, so we see more of what's going on:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset>\n",
"Dimensions: (parameter: 1)\n",
"Coordinates:\n",
" * parameter (parameter) int64 1\n",
"Data variables:\n",
" result (parameter) int64 -1<xarray.DataArray 'result' (parameter: 1)>\n",
"array([-1])\n",
"Coordinates:\n",
" * parameter (parameter) int64 1\n",
"Attributes:\n",
" tracking_compute_fun: <function add_one at 0x7f49fdfa3370>\n",
" computed_values: []\n",
" compute_times: []\n",
" name: result\n",
" compute_fun: <function add_one at 0x7f4a39cb13f0>\n",
" save_fun: <function save_pickle at 0x7f49fdfa1510>\n",
" load_fun: <function load_pickle at 0x7f49fdfa1630>\n",
" save_suffix: .pickle\n",
" save_path_fmt: None<xarray.DataArray 'result' (parameter: 1)>\n",
"array([0])\n",
"Coordinates:\n",
" * parameter (parameter) int64 1\n",
"Attributes:\n",
" tracking_compute_fun: <function add_one at 0x7f49fdfa3370>\n",
" computed_values: [2]\n",
" compute_times: [3.5762786865234375e-06]\n",
" name: result\n",
" compute_fun: <function add_one at 0x7f4a39cb13f0>\n",
" save_fun: <function save_pickle at 0x7f49fdfa1510>\n",
" load_fun: <function load_pickle at 0x7f49fdfa1630>\n",
" save_suffix: .pickle\n",
" save_path_fmt: None<xarray.DataArray 'result' (parameter: 4)>\n",
"array([ 0, -1, -1, -1])\n",
"Coordinates:\n",
" * parameter (parameter) int64 1 2 3 4\n",
"Attributes:\n",
" tracking_compute_fun: <function add_one at 0x7f49fdfa3370>\n",
" computed_values: [2]\n",
" compute_times: [3.5762786865234375e-06]\n",
" name: result\n",
" compute_fun: <function add_one at 0x7f4a39cb13f0>\n",
" save_fun: <function save_pickle at 0x7f49fdfa1510>\n",
" load_fun: <function load_pickle at 0x7f49fdfa1630>\n",
" save_suffix: .pickle\n",
" save_path_fmt: None<xarray.DataArray 'result' (parameter: 4)>\n",
"array([ 0, -1, -1, -1])\n",
"Coordinates:\n",
" * parameter (parameter) int64 1 2 3 4\n",
"Attributes:\n",
" tracking_compute_fun: <function add_one at 0x7f49fdfa3370>\n",
" computed_values: [2]\n",
" compute_times: [3.5762786865234375e-06]\n",
" name: result\n",
" compute_fun: <function add_one at 0x7f4a39cb13f0>\n",
" save_fun: <function save_pickle at 0x7f49fdfa1510>\n",
" load_fun: <function load_pickle at 0x7f49fdfa1630>\n",
" save_suffix: .pickle\n",
" save_path_fmt: None<xarray.DataArray 'result' (parameter: 4)>\n",
"array([ 0, -1, 1, -1])\n",
"Coordinates:\n",
" * parameter (parameter) int64 1 2 3 4\n",
"Attributes:\n",
" tracking_compute_fun: <function add_one at 0x7f49fdfa3370>\n",
" computed_values: [2, 4]\n",
" compute_times: [3.5762786865234375e-06, 2.384185791015625e-06]\n",
" name: result\n",
" compute_fun: <function add_one at 0x7f4a39cb13f0>\n",
" save_fun: <function save_pickle at 0x7f49fdfa1510>\n",
" load_fun: <function load_pickle at 0x7f49fdfa1630>\n",
" save_suffix: .pickle\n",
" save_path_fmt: None<xarray.DataArray 'result' (parameter: 2)>\n",
"array([0, 1])\n",
"Coordinates:\n",
" * parameter (parameter) int64 1 3\n",
"Attributes:\n",
" tracking_compute_fun: <function add_one at 0x7f49fdfa3370>\n",
" computed_values: [2, 4]\n",
" compute_times: [3.5762786865234375e-06, 2.384185791015625e-06]\n",
" name: result\n",
" compute_fun: <function add_one at 0x7f4a39cb13f0>\n",
" save_fun: <function save_pickle at 0x7f49fdfa1510>\n",
" load_fun: <function load_pickle at 0x7f49fdfa1630>\n",
" save_suffix: .pickle\n",
" save_path_fmt: None<xarray.DataArray 'result' (parameter: 5)>\n",
"array([ 0, -1, 1, -1, 2])\n",
"Coordinates:\n",
" * parameter (parameter) int64 1 2 3 4 5\n",
"Attributes:\n",
" tracking_compute_fun: <function add_one at 0x7f49fdfa3370>\n",
" computed_values: [2, 4, 6]\n",
" compute_times: [3.5762786865234375e-06, 2.384185791015625e-06, 2....\n",
" name: result\n",
" compute_fun: <function add_one at 0x7f4a39cb13f0>\n",
" save_fun: <function save_pickle at 0x7f49fdfa1510>\n",
" load_fun: <function load_pickle at 0x7f49fdfa1630>\n",
" save_suffix: .pickle\n",
" save_path_fmt: None<xarray.DataArray 'result' (constant: 1, date: 2, letter: 3, parameter: 5)>\n",
"array([[[[ 0, -1, 1, -1, 2],\n",
" [ 0, -1, 1, -1, 2],\n",
" [ 0, -1, 1, -1, 2]],\n",
"\n",
" [[ 0, -1, 1, -1, 2],\n",
" [ 0, -1, 1, -1, 2],\n",
" [ 0, -1, 1, -1, 2]]]])\n",
"Coordinates:\n",
" * letter (letter) object 'c' 'a' 'b'\n",
" * constant (constant) int64 4\n",
" * date (date) object 2000-01-01 2023-02-20\n",
" * parameter (parameter) int64 1 2 3 4 5\n",
"Attributes:\n",
" tracking_compute_fun: <function add_one at 0x7f49fdfa3370>\n",
" computed_values: [2, 4, 6]\n",
" compute_times: [3.5762786865234375e-06, 2.384185791015625e-06, 2....\n",
" name: result\n",
" compute_fun: <function add_one at 0x7f4a39cb13f0>\n",
" save_fun: <function save_pickle at 0x7f49fdfa1510>\n",
" load_fun: <function load_pickle at 0x7f49fdfa1630>\n",
" save_suffix: .pickle\n",
" save_path_fmt: None<xarray.Dataset>\n",
"Dimensions: (letter: 3, constant: 1, date: 2, parameter: 5)\n",
"Coordinates:\n",
" * letter (letter) object 'c' 'a' 'b'\n",
" * constant (constant) int64 4\n",
" * date (date) object 2000-01-01 2023-02-20\n",
" * parameter (parameter) int64 1 2 3 4 5\n",
"Data variables:\n",
" result (constant, date, letter, parameter) int64 0 -1 1 -1 ... 1 -1 2\n",
" other_result (letter, constant, date, parameter) int64 -1 -1 -1 ... -1 -1\n",
" c (letter, constant, date, parameter) int64 -1 -1 -1 ... -1 -1