{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a4dbec07",
   "metadata": {},
   "source": [
    "# Isard to Chenery-Moses\n",
    "\n",
    "This notebook converts the packaged SUT test table to the Chenery-Moses format.\n",
    "\n",
    "\n",
    "## Core method\n",
    "\n",
    "The relevant entry point is `Database.to_chenery_moses`.\n",
    "\n",
    "\n",
    "## What changes\n",
    "\n",
    "This transformation changes the international trade modelling assumption underlying the database\n",
    "\n",
    "* Isard model: goods are differentiated by place of origin (R1 or R2). Each demand flow (intermediate or final) is explicitly allocated across distinct regional or foreign suppliers. The SUT therefore records who supplies whom, keeping trade flows separated by origin. This yields a detailed representation of trade without assuming perfect substitutability between sources.\n",
    "\n",
    "* Chenery-Moses model: In the Chenery–Moses approach, goods are treated as homogeneous regardless of origin. Total supply (domestic + imports) is pooled and then allocated to uses (intermediate and final demand) using average import shares. The supplying origin is no longer tracked for each use; instead, a common domestic/import proportion is applied across all demand, simplifying the trade structure.\n",
    "\n",
    "Updates the relevant SUT matrices for the selected scenarios and then resets those scenarios to flow matrices so coefficient-side matrices can be rebuilt consistently on demand.\n",
    "\n",
    "![chenery-moses](../../_static/images/Chenery-Moses.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "12908e64",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-05-01T07:14:12.087411Z",
     "iopub.status.busy": "2026-05-01T07:14:12.087301Z",
     "iopub.status.idle": "2026-05-01T07:14:14.554742Z",
     "shell.execute_reply": "2026-05-01T07:14:14.554360Z"
    }
   },
   "outputs": [],
   "source": [
    "import mario"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "dcca20a1",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-05-01T07:14:14.557570Z",
     "iopub.status.busy": "2026-05-01T07:14:14.557077Z",
     "iopub.status.idle": "2026-05-01T07:14:14.691789Z",
     "shell.execute_reply": "2026-05-01T07:14:14.691411Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO Parser: excel reading SUT flows from /Users/lorenzorinaldi/Documents/GitHub/MARIO/mario/test/tables/test_SUT_standard.xlsx.\n",
      "INFO Parser: state payload ready with 10 canonical blocks.\n",
      "INFO Parser: excel state ready for SUT.\n",
      "INFO Metadata: initialized.\n"
     ]
    }
   ],
   "source": [
    "isard_sut = mario.load_test(\"SUT\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7f4e4a93",
   "metadata": {},
   "source": [
    "## Inspect the starting table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "eabf92e7",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-05-01T07:14:14.693687Z",
     "iopub.status.busy": "2026-05-01T07:14:14.693588Z",
     "iopub.status.idle": "2026-05-01T07:14:14.696858Z",
     "shell.execute_reply": "2026-05-01T07:14:14.696632Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'SUT'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "isard_sut.table_type"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "3b710f25",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-05-01T07:14:14.698289Z",
     "iopub.status.busy": "2026-05-01T07:14:14.698204Z",
     "iopub.status.idle": "2026-05-01T07:14:14.733038Z",
     "shell.execute_reply": "2026-05-01T07:14:14.732663Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Region</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Region 1</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Region 2</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Level</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Activity</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Activity</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Item</th>\n",
       "      <th>Manufacturing</th>\n",
       "      <th>Services</th>\n",
       "      <th>Manufacturing</th>\n",
       "      <th>Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Region</th>\n",
       "      <th>Level</th>\n",
       "      <th>Item</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">Region 1</th>\n",
       "      <th rowspan=\"2\" valign=\"top\">Commodity</th>\n",
       "      <th>Goods</th>\n",
       "      <td>3.334903e+11</td>\n",
       "      <td>1.657755e+11</td>\n",
       "      <td>1.487965e+11</td>\n",
       "      <td>6.895332e+10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Services</th>\n",
       "      <td>3.261811e+11</td>\n",
       "      <td>7.254021e+11</td>\n",
       "      <td>1.176727e+10</td>\n",
       "      <td>3.588505e+10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">Region 2</th>\n",
       "      <th rowspan=\"2\" valign=\"top\">Commodity</th>\n",
       "      <th>Goods</th>\n",
       "      <td>1.922623e+11</td>\n",
       "      <td>4.099986e+10</td>\n",
       "      <td>3.038628e+13</td>\n",
       "      <td>1.157115e+13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Services</th>\n",
       "      <td>2.614852e+10</td>\n",
       "      <td>5.823465e+10</td>\n",
       "      <td>1.154871e+13</td>\n",
       "      <td>3.075294e+13</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Region                           Region 1                    Region 2  \\\n",
       "Level                            Activity                    Activity   \n",
       "Item                        Manufacturing      Services Manufacturing   \n",
       "Region   Level     Item                                                 \n",
       "Region 1 Commodity Goods     3.334903e+11  1.657755e+11  1.487965e+11   \n",
       "                   Services  3.261811e+11  7.254021e+11  1.176727e+10   \n",
       "Region 2 Commodity Goods     1.922623e+11  4.099986e+10  3.038628e+13   \n",
       "                   Services  2.614852e+10  5.823465e+10  1.154871e+13   \n",
       "\n",
       "Region                                     \n",
       "Level                                      \n",
       "Item                             Services  \n",
       "Region   Level     Item                    \n",
       "Region 1 Commodity Goods     6.895332e+10  \n",
       "                   Services  3.588505e+10  \n",
       "Region 2 Commodity Goods     1.157115e+13  \n",
       "                   Services  3.075294e+13  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "isard_sut.U"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "1c76b8c7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Region</th>\n",
       "      <th>Region 1</th>\n",
       "      <th>Region 2</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Level</th>\n",
       "      <th>Consumption category</th>\n",
       "      <th>Consumption category</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Item</th>\n",
       "      <th>Final demand</th>\n",
       "      <th>Final demand</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Region</th>\n",
       "      <th>Level</th>\n",
       "      <th>Item</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">Region 1</th>\n",
       "      <th rowspan=\"2\" valign=\"top\">Commodity</th>\n",
       "      <th>Goods</th>\n",
       "      <td>3.452438e+11</td>\n",
       "      <td>2.491705e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Services</th>\n",
       "      <td>1.239017e+12</td>\n",
       "      <td>4.451280e+10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">Region 2</th>\n",
       "      <th rowspan=\"2\" valign=\"top\">Commodity</th>\n",
       "      <th>Goods</th>\n",
       "      <td>1.358686e+11</td>\n",
       "      <td>2.070121e+13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Services</th>\n",
       "      <td>5.020717e+10</td>\n",
       "      <td>6.211882e+13</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Region                                  Region 1             Region 2\n",
       "Level                       Consumption category Consumption category\n",
       "Item                                Final demand         Final demand\n",
       "Region   Level     Item                                              \n",
       "Region 1 Commodity Goods            3.452438e+11         2.491705e+11\n",
       "                   Services         1.239017e+12         4.451280e+10\n",
       "Region 2 Commodity Goods            1.358686e+11         2.070121e+13\n",
       "                   Services         5.020717e+10         6.211882e+13"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "isard_sut.Yc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "875c5c48",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-05-01T07:14:14.734864Z",
     "iopub.status.busy": "2026-05-01T07:14:14.734725Z",
     "iopub.status.idle": "2026-05-01T07:14:14.765985Z",
     "shell.execute_reply": "2026-05-01T07:14:14.765612Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Region</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Region 1</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Region 2</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Level</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Commodity</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Commodity</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Item</th>\n",
       "      <th>Goods</th>\n",
       "      <th>Services</th>\n",
       "      <th>Goods</th>\n",
       "      <th>Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Region</th>\n",
       "      <th>Level</th>\n",
       "      <th>Item</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">Region 1</th>\n",
       "      <th rowspan=\"2\" valign=\"top\">Activity</th>\n",
       "      <th>Manufacturing</th>\n",
       "      <td>1.240653e+12</td>\n",
       "      <td>3.487923e+10</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Services</th>\n",
       "      <td>7.077650e+10</td>\n",
       "      <td>2.347886e+12</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">Region 2</th>\n",
       "      <th rowspan=\"2\" valign=\"top\">Activity</th>\n",
       "      <th>Manufacturing</th>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>6.243698e+13</td>\n",
       "      <td>6.506942e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Services</th>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>5.907938e+11</td>\n",
       "      <td>1.039044e+14</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Region                               Region 1                    Region 2  \\\n",
       "Level                               Commodity                   Commodity   \n",
       "Item                                    Goods      Services         Goods   \n",
       "Region   Level    Item                                                      \n",
       "Region 1 Activity Manufacturing  1.240653e+12  3.487923e+10  0.000000e+00   \n",
       "                  Services       7.077650e+10  2.347886e+12  0.000000e+00   \n",
       "Region 2 Activity Manufacturing  0.000000e+00  0.000000e+00  6.243698e+13   \n",
       "                  Services       0.000000e+00  0.000000e+00  5.907938e+11   \n",
       "\n",
       "Region                                         \n",
       "Level                                          \n",
       "Item                                 Services  \n",
       "Region   Level    Item                         \n",
       "Region 1 Activity Manufacturing  0.000000e+00  \n",
       "                  Services       0.000000e+00  \n",
       "Region 2 Activity Manufacturing  6.506942e+11  \n",
       "                  Services       1.039044e+14  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "isard_sut.S"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "a2689008",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-05-01T07:14:14.767989Z",
     "iopub.status.busy": "2026-05-01T07:14:14.767752Z",
     "iopub.status.idle": "2026-05-01T07:14:14.802854Z",
     "shell.execute_reply": "2026-05-01T07:14:14.802568Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO Resolver: resolving Z for baseline.\n",
      "INFO Resolver: trying Z via concat.\n",
      "INFO Resolver: resolved Z via concat.\n",
      "INFO Test: table is in Isard format\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "isard_sut.is_isard()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0ab773c1",
   "metadata": {},
   "source": [
    "## Convert the SUT"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "7cbfb620",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-05-01T07:14:14.804584Z",
     "iopub.status.busy": "2026-05-01T07:14:14.804481Z",
     "iopub.status.idle": "2026-05-01T07:14:15.164067Z",
     "shell.execute_reply": "2026-05-01T07:14:15.163789Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO Test: table is not in Chenery-Moses format\n",
      "INFO Database: Transforming the database into Chenery-Moses\n",
      "INFO Resolver: resolving Y for baseline.\n",
      "INFO Resolver: trying Y via concat.\n",
      "INFO Resolver: resolved Y via concat.\n",
      "INFO Resolver: resolving s for baseline.\n",
      "INFO Resolver: trying s via extract.\n",
      "INFO Resolver: trying s via formula build_sut_s_from_S_Xc.\n",
      "INFO Resolver: resolved s via formula build_sut_s_from_S_Xc.\n",
      "INFO Resolver: resolving U for baseline.\n",
      "INFO Resolver: trying U via extract.\n",
      "INFO Resolver: resolved U via extract.\n",
      "INFO Resolver: resolving S for baseline.\n",
      "INFO Resolver: trying S via extract.\n",
      "INFO Resolver: resolved S via extract.\n",
      "INFO Resolver: resolving Ya for baseline.\n",
      "INFO Resolver: trying Ya via extract.\n",
      "INFO Resolver: resolved Ya via extract.\n",
      "INFO Resolver: resolving Yc for baseline.\n",
      "INFO Resolver: trying Yc via extract.\n",
      "INFO Resolver: resolved Yc via extract.\n",
      "INFO Databases: reset to flows.\n",
      "INFO Transformation of the database from into Chenery-Moses\n"
     ]
    }
   ],
   "source": [
    "chenery_moses_sut = isard_sut.to_chenery_moses(inplace=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "7e4f7c0e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-05-01T07:14:15.165610Z",
     "iopub.status.busy": "2026-05-01T07:14:15.165519Z",
     "iopub.status.idle": "2026-05-01T07:14:15.197539Z",
     "shell.execute_reply": "2026-05-01T07:14:15.197258Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Region</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Region 1</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Region 2</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Level</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Activity</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Activity</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Item</th>\n",
       "      <th>Manufacturing</th>\n",
       "      <th>Services</th>\n",
       "      <th>Manufacturing</th>\n",
       "      <th>Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Region</th>\n",
       "      <th>Level</th>\n",
       "      <th>Item</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">Region 1</th>\n",
       "      <th rowspan=\"2\" valign=\"top\">Commodity</th>\n",
       "      <th>Goods</th>\n",
       "      <td>5.257525e+11</td>\n",
       "      <td>2.067754e+11</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Services</th>\n",
       "      <td>3.523296e+11</td>\n",
       "      <td>7.836367e+11</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">Region 2</th>\n",
       "      <th rowspan=\"2\" valign=\"top\">Commodity</th>\n",
       "      <th>Goods</th>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>3.053508e+13</td>\n",
       "      <td>1.164010e+13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Services</th>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>1.156048e+13</td>\n",
       "      <td>3.078883e+13</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Region                           Region 1                    Region 2  \\\n",
       "Level                            Activity                    Activity   \n",
       "Item                        Manufacturing      Services Manufacturing   \n",
       "Region   Level     Item                                                 \n",
       "Region 1 Commodity Goods     5.257525e+11  2.067754e+11  0.000000e+00   \n",
       "                   Services  3.523296e+11  7.836367e+11  0.000000e+00   \n",
       "Region 2 Commodity Goods     0.000000e+00  0.000000e+00  3.053508e+13   \n",
       "                   Services  0.000000e+00  0.000000e+00  1.156048e+13   \n",
       "\n",
       "Region                                     \n",
       "Level                                      \n",
       "Item                             Services  \n",
       "Region   Level     Item                    \n",
       "Region 1 Commodity Goods     0.000000e+00  \n",
       "                   Services  0.000000e+00  \n",
       "Region 2 Commodity Goods     1.164010e+13  \n",
       "                   Services  3.078883e+13  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chenery_moses_sut.U"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "7c6cd18a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Region</th>\n",
       "      <th>Region 1</th>\n",
       "      <th>Region 2</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Level</th>\n",
       "      <th>Consumption category</th>\n",
       "      <th>Consumption category</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Item</th>\n",
       "      <th>Final demand</th>\n",
       "      <th>Final demand</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Region</th>\n",
       "      <th>Level</th>\n",
       "      <th>Item</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">Region 1</th>\n",
       "      <th rowspan=\"2\" valign=\"top\">Commodity</th>\n",
       "      <th>Goods</th>\n",
       "      <td>4.811124e+11</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Services</th>\n",
       "      <td>1.289224e+12</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">Region 2</th>\n",
       "      <th rowspan=\"2\" valign=\"top\">Commodity</th>\n",
       "      <th>Goods</th>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>2.095038e+13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Services</th>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>6.216333e+13</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Region                                  Region 1             Region 2\n",
       "Level                       Consumption category Consumption category\n",
       "Item                                Final demand         Final demand\n",
       "Region   Level     Item                                              \n",
       "Region 1 Commodity Goods            4.811124e+11         0.000000e+00\n",
       "                   Services         1.289224e+12         0.000000e+00\n",
       "Region 2 Commodity Goods            0.000000e+00         2.095038e+13\n",
       "                   Services         0.000000e+00         6.216333e+13"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chenery_moses_sut.Yc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "5897c367",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-05-01T07:14:15.199295Z",
     "iopub.status.busy": "2026-05-01T07:14:15.199140Z",
     "iopub.status.idle": "2026-05-01T07:14:15.231122Z",
     "shell.execute_reply": "2026-05-01T07:14:15.230826Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Region</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Region 1</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Region 2</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Level</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Commodity</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Commodity</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Item</th>\n",
       "      <th>Goods</th>\n",
       "      <th>Services</th>\n",
       "      <th>Goods</th>\n",
       "      <th>Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Region</th>\n",
       "      <th>Level</th>\n",
       "      <th>Item</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">Region 1</th>\n",
       "      <th rowspan=\"2\" valign=\"top\">Activity</th>\n",
       "      <th>Manufacturing</th>\n",
       "      <td>7.989323e+11</td>\n",
       "      <td>3.353010e+10</td>\n",
       "      <td>4.417211e+11</td>\n",
       "      <td>1.349125e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Services</th>\n",
       "      <td>4.557730e+10</td>\n",
       "      <td>2.257070e+12</td>\n",
       "      <td>2.519920e+10</td>\n",
       "      <td>9.081599e+10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">Region 2</th>\n",
       "      <th rowspan=\"2\" valign=\"top\">Activity</th>\n",
       "      <th>Manufacturing</th>\n",
       "      <td>3.656706e+11</td>\n",
       "      <td>8.376176e+08</td>\n",
       "      <td>6.207131e+13</td>\n",
       "      <td>6.498566e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Services</th>\n",
       "      <td>3.460064e+09</td>\n",
       "      <td>1.337527e+11</td>\n",
       "      <td>5.873338e+11</td>\n",
       "      <td>1.037706e+14</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Region                               Region 1                    Region 2  \\\n",
       "Level                               Commodity                   Commodity   \n",
       "Item                                    Goods      Services         Goods   \n",
       "Region   Level    Item                                                      \n",
       "Region 1 Activity Manufacturing  7.989323e+11  3.353010e+10  4.417211e+11   \n",
       "                  Services       4.557730e+10  2.257070e+12  2.519920e+10   \n",
       "Region 2 Activity Manufacturing  3.656706e+11  8.376176e+08  6.207131e+13   \n",
       "                  Services       3.460064e+09  1.337527e+11  5.873338e+11   \n",
       "\n",
       "Region                                         \n",
       "Level                                          \n",
       "Item                                 Services  \n",
       "Region   Level    Item                         \n",
       "Region 1 Activity Manufacturing  1.349125e+09  \n",
       "                  Services       9.081599e+10  \n",
       "Region 2 Activity Manufacturing  6.498566e+11  \n",
       "                  Services       1.037706e+14  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chenery_moses_sut.S"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "342a7e9e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO Resolver: resolving Z for baseline.\n",
      "INFO Resolver: trying Z via concat.\n",
      "INFO Resolver: resolved Z via concat.\n",
      "INFO Test: table is not in Isard format\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chenery_moses_sut.is_isard()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "mario",
   "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.13.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
