{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "958f64d1",
   "metadata": {},
   "outputs": [],
   "source": [
    "# This is an example of how we see \n",
    "# the package work. The functions listed here\n",
    "# are probably the only ones that should be exposed, ie documented.\n",
    "# others should br prepended with a double underscore\n",
    "#  \n",
    "# The cognet directory has the following \"modules\"\n",
    "# which are seprate .py files containing clases and functions\n",
    "# The modules are cognet.py, dataFormatter.py, model.py, util.py, viz.py\n",
    "# we will write the viz.py later.\n",
    "import sys\n",
    "\n",
    "from quasinet.qnet import qdistance\n",
    "from cognet.cognet import cognet as cg\n",
    "from cognet.dataFormatter import dataFormatter\n",
    "from cognet.model import model \n",
    "#import cognet.util\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "yr = '2018'\n",
    "POLEFILE='examples_data/polar_vectors.csv'\n",
    "QPATH='examples_data/gss_'+yr+'.joblib'\n",
    "IMMUTABLE_FILE='examples_data/immutable.csv'\n",
    "GSSDATA = '../../creed2_/GSS/data/processed_data/gss_'+yr+'.csv'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "fe5c3fed",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "updating\n"
     ]
    }
   ],
   "source": [
    "## read in data, configure to Qnet specifications and fit Qnet model\n",
    "fit = False\n",
    "data_obj=dataFormatter(GSSDATA)\n",
    "model_obj = model()\n",
    "if fit:\n",
    "    model_obj.fit(data_obj=data_obj)\n",
    "    model_obj.save(\"../../mpi_tmp/GSS_cognet_test.joblib\")\n",
    "else:\n",
    "    model_obj.load(\"../../creed2_/GSS/Qnets/gss_2018.joblib\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "f01e89e7",
   "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 th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>wrkstat</th>\n",
       "      <th>HRS1</th>\n",
       "      <th>HRS2</th>\n",
       "      <th>evwork</th>\n",
       "      <th>wrkslf</th>\n",
       "      <th>wrkgovt</th>\n",
       "      <th>OCC10</th>\n",
       "      <th>PRESTG10</th>\n",
       "      <th>PRESTG105PLUS</th>\n",
       "      <th>INDUS10</th>\n",
       "      <th>...</th>\n",
       "      <th>neisafe</th>\n",
       "      <th>rlooks</th>\n",
       "      <th>rgroomed</th>\n",
       "      <th>rweight</th>\n",
       "      <th>rhlthend</th>\n",
       "      <th>wtss</th>\n",
       "      <th>wtssnr</th>\n",
       "      <th>wtssall</th>\n",
       "      <th>vstrat</th>\n",
       "      <th>vpsu</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>temp not working</td>\n",
       "      <td>e</td>\n",
       "      <td>c</td>\n",
       "      <td>nan</td>\n",
       "      <td>someone else</td>\n",
       "      <td>private</td>\n",
       "      <td>b</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>...</td>\n",
       "      <td>very safe</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>e</td>\n",
       "      <td>e</td>\n",
       "      <td>e</td>\n",
       "      <td>3301</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>working fulltime</td>\n",
       "      <td>c</td>\n",
       "      <td>e</td>\n",
       "      <td>nan</td>\n",
       "      <td>someone else</td>\n",
       "      <td>private</td>\n",
       "      <td>b</td>\n",
       "      <td>d</td>\n",
       "      <td>d</td>\n",
       "      <td>c</td>\n",
       "      <td>...</td>\n",
       "      <td>very safe</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>3301</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>working fulltime</td>\n",
       "      <td>c</td>\n",
       "      <td>e</td>\n",
       "      <td>nan</td>\n",
       "      <td>someone else</td>\n",
       "      <td>private</td>\n",
       "      <td>c</td>\n",
       "      <td>d</td>\n",
       "      <td>d</td>\n",
       "      <td>c</td>\n",
       "      <td>...</td>\n",
       "      <td>very safe</td>\n",
       "      <td>attractive</td>\n",
       "      <td>about average</td>\n",
       "      <td>about the right weight</td>\n",
       "      <td>nan</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>3301</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>working fulltime</td>\n",
       "      <td>e</td>\n",
       "      <td>e</td>\n",
       "      <td>nan</td>\n",
       "      <td>someone else</td>\n",
       "      <td>private</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>...</td>\n",
       "      <td>somewhat safe</td>\n",
       "      <td>about average</td>\n",
       "      <td>about average</td>\n",
       "      <td>slightly underweight</td>\n",
       "      <td>excellent</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>3301</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>working fulltime</td>\n",
       "      <td>c</td>\n",
       "      <td>e</td>\n",
       "      <td>nan</td>\n",
       "      <td>self-employed</td>\n",
       "      <td>private</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>...</td>\n",
       "      <td>very unsafe</td>\n",
       "      <td>very unattractive</td>\n",
       "      <td>very poorly groomed</td>\n",
       "      <td>very overweight</td>\n",
       "      <td>poor</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>3301</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1779</th>\n",
       "      <td>retired</td>\n",
       "      <td>e</td>\n",
       "      <td>e</td>\n",
       "      <td>yes</td>\n",
       "      <td>someone else</td>\n",
       "      <td>private</td>\n",
       "      <td>d</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>...</td>\n",
       "      <td>very safe</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>3378</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1780</th>\n",
       "      <td>school</td>\n",
       "      <td>e</td>\n",
       "      <td>e</td>\n",
       "      <td>no</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>e</td>\n",
       "      <td>e</td>\n",
       "      <td>e</td>\n",
       "      <td>e</td>\n",
       "      <td>...</td>\n",
       "      <td>somewhat safe</td>\n",
       "      <td>about average</td>\n",
       "      <td>about average</td>\n",
       "      <td>slightly underweight</td>\n",
       "      <td>excellent</td>\n",
       "      <td>d</td>\n",
       "      <td>d</td>\n",
       "      <td>d</td>\n",
       "      <td>3378</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1781</th>\n",
       "      <td>working fulltime</td>\n",
       "      <td>c</td>\n",
       "      <td>e</td>\n",
       "      <td>nan</td>\n",
       "      <td>someone else</td>\n",
       "      <td>government</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>...</td>\n",
       "      <td>very safe</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>3378</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1782</th>\n",
       "      <td>working parttime</td>\n",
       "      <td>c</td>\n",
       "      <td>e</td>\n",
       "      <td>nan</td>\n",
       "      <td>someone else</td>\n",
       "      <td>private</td>\n",
       "      <td>c</td>\n",
       "      <td>b</td>\n",
       "      <td>b</td>\n",
       "      <td>c</td>\n",
       "      <td>...</td>\n",
       "      <td>very safe</td>\n",
       "      <td>about average</td>\n",
       "      <td>about average</td>\n",
       "      <td>slightly overweight</td>\n",
       "      <td>excellent</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>3378</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1783</th>\n",
       "      <td>retired</td>\n",
       "      <td>e</td>\n",
       "      <td>e</td>\n",
       "      <td>yes</td>\n",
       "      <td>someone else</td>\n",
       "      <td>private</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>...</td>\n",
       "      <td>very safe</td>\n",
       "      <td>attractive</td>\n",
       "      <td>well groomed</td>\n",
       "      <td>about the right weight</td>\n",
       "      <td>nan</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>c</td>\n",
       "      <td>3378</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1784 rows × 1034 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "               wrkstat HRS1 HRS2 evwork         wrkslf     wrkgovt OCC10  \\\n",
       "0     temp not working    e    c    nan   someone else     private     b   \n",
       "1     working fulltime    c    e    nan   someone else     private     b   \n",
       "2     working fulltime    c    e    nan   someone else     private     c   \n",
       "3     working fulltime    e    e    nan   someone else     private     c   \n",
       "4     working fulltime    c    e    nan  self-employed     private     c   \n",
       "...                ...  ...  ...    ...            ...         ...   ...   \n",
       "1779           retired    e    e    yes   someone else     private     d   \n",
       "1780            school    e    e     no            nan         nan     e   \n",
       "1781  working fulltime    c    e    nan   someone else  government     c   \n",
       "1782  working parttime    c    e    nan   someone else     private     c   \n",
       "1783           retired    e    e    yes   someone else     private     c   \n",
       "\n",
       "     PRESTG10 PRESTG105PLUS INDUS10  ...        neisafe             rlooks  \\\n",
       "0           c             c       c  ...      very safe                nan   \n",
       "1           d             d       c  ...      very safe                nan   \n",
       "2           d             d       c  ...      very safe         attractive   \n",
       "3           c             c       c  ...  somewhat safe      about average   \n",
       "4           c             c       c  ...    very unsafe  very unattractive   \n",
       "...       ...           ...     ...  ...            ...                ...   \n",
       "1779        c             c       c  ...      very safe                nan   \n",
       "1780        e             e       e  ...  somewhat safe      about average   \n",
       "1781        c             c       c  ...      very safe                nan   \n",
       "1782        b             b       c  ...      very safe      about average   \n",
       "1783        c             c       c  ...      very safe         attractive   \n",
       "\n",
       "                 rgroomed                 rweight   rhlthend wtss wtssnr  \\\n",
       "0                     nan                     nan        nan    e      e   \n",
       "1                     nan                     nan        nan    c      c   \n",
       "2           about average  about the right weight        nan    c      c   \n",
       "3           about average    slightly underweight  excellent    c      c   \n",
       "4     very poorly groomed         very overweight       poor    c      c   \n",
       "...                   ...                     ...        ...  ...    ...   \n",
       "1779                  nan                     nan        nan    c      c   \n",
       "1780        about average    slightly underweight  excellent    d      d   \n",
       "1781                  nan                     nan        nan    c      c   \n",
       "1782        about average     slightly overweight  excellent    c      c   \n",
       "1783         well groomed  about the right weight        nan    c      c   \n",
       "\n",
       "     wtssall vstrat vpsu  \n",
       "0          e   3301    1  \n",
       "1          c   3301    1  \n",
       "2          c   3301    1  \n",
       "3          c   3301    1  \n",
       "4          c   3301    1  \n",
       "...      ...    ...  ...  \n",
       "1779       c   3378    2  \n",
       "1780       d   3378    2  \n",
       "1781       c   3378    2  \n",
       "1782       c   3378    2  \n",
       "1783       c   3378    2  \n",
       "\n",
       "[1784 rows x 1034 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cognet_obj = cg()\n",
    "cognet_obj.load_from_model(model_obj, data_obj, 'all')\n",
    "cognet_obj.dmat_filewriter(\"GSS_cognet.py\", \"../../creed2_/GSS/Qnets/gss_2018.joblib\",\n",
    "                           MPI_SETUP_FILE=\"GSS_mpi_setup.sh\",\n",
    "                           MPI_RUN_FILE=\"GSS_mpi_run.sh\",\n",
    "                           MPI_LAUNCHER_FILE=\"GSS_mpi_launcher.sh\",\n",
    "                           YEARS='2018',NODES=4,T=14)\n",
    "cognet_obj.samples"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
