|
53 | 53 | "## Getting Set Up\n", |
54 | 54 | "\n", |
55 | 55 | "We'll need a few dependencies to run triage in a colab notebook:\n", |
| 56 | + "- Python version 3.10\n", |
56 | 57 | "- A local postgresql server (we'll use version 11)\n", |
57 | 58 | "- A simplified dataset loaded into this database (we'll use data from DonorsChoose)\n", |
58 | 59 | "- Triage and its dependencies (we'll use the current version in pypi)" |
59 | 60 | ] |
60 | 61 | }, |
| 62 | + { |
| 63 | + "cell_type": "markdown", |
| 64 | + "metadata": {}, |
| 65 | + "source": [ |
| 66 | + "### Python version 3.10 \n", |
| 67 | + "\n", |
| 68 | + "🛑 Triage requires Python 3.10 in Colab. Colab's default Python version is 3.12+, to change the version click at the bottom right of Colab where it says **Python 3** and select the option **\"Change runtime type\"**. A window with different options will pop up, choose the option **2025.07** on the \"Runtime version\" options section.and select **Save**. " |
| 69 | + ] |
| 70 | + }, |
61 | 71 | { |
62 | 72 | "cell_type": "code", |
63 | 73 | "execution_count": null, |
64 | | - "metadata": { |
65 | | - "id": "-htIBoS7N4gK" |
66 | | - }, |
| 74 | + "metadata": {}, |
| 75 | + "outputs": [], |
| 76 | + "source": [ |
| 77 | + "# Making sure you have python 3.10 version\n", |
| 78 | + "!python --version" |
| 79 | + ] |
| 80 | + }, |
| 81 | + { |
| 82 | + "cell_type": "code", |
| 83 | + "execution_count": null, |
| 84 | + "metadata": {}, |
67 | 85 | "outputs": [], |
68 | 86 | "source": [ |
69 | 87 | "# Install and start postgresql-11 server\n", |
|
144 | 162 | }, |
145 | 163 | "outputs": [], |
146 | 164 | "source": [ |
147 | | - "from sqlalchemy.engine.url import URL\n", |
| 165 | + "from sqlalchemy.engine import URL\n", |
148 | 166 | "from triage.util.db import create_engine\n", |
149 | 167 | "import pandas as pd\n", |
150 | 168 | "\n", |
151 | | - "db_url = URL(\n", |
152 | | - " 'postgres',\n", |
| 169 | + "db_url = URL.create(\n", |
| 170 | + " 'postgresql+psycopg2',\n", |
153 | 171 | " host='localhost',\n", |
154 | 172 | " username='postgres',\n", |
155 | 173 | " database='donors_choose',\n", |
|
874 | 892 | "metadata": { |
875 | 893 | "id": "jYzBKFG3qDhQ" |
876 | 894 | }, |
877 | | - "outputs": [], |
| 895 | + "outputs": [ |
| 896 | + { |
| 897 | + "ename": "SyntaxError", |
| 898 | + "evalue": "invalid syntax (136456548.py, line 41)", |
| 899 | + "output_type": "error", |
| 900 | + "traceback": [ |
| 901 | + "\u001b[0;36m Cell \u001b[0;32mIn[1], line 41\u001b[0;36m\u001b[0m\n\u001b[0;31m cursor.execute(text\"SET ROLE {dbconfig['role']}\")\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" |
| 902 | + ] |
| 903 | + } |
| 904 | + ], |
878 | 905 | "source": [ |
879 | 906 | "import yaml\n", |
880 | 907 | "import shutil\n", |
881 | 908 | "import os\n", |
882 | 909 | "import logging\n", |
883 | 910 | "\n", |
884 | | - "from sqlalchemy.engine.url import URL\n", |
| 911 | + "from sqlalchemy.engine import URL\n", |
885 | 912 | "from sqlalchemy.event import listens_for\n", |
886 | 913 | "from sqlalchemy.pool import Pool\n", |
| 914 | + "from sqlalchemy import event\n", |
887 | 915 | "\n", |
888 | 916 | "from triage.util.db import create_engine\n", |
889 | 917 | "from triage.experiments import MultiCoreExperiment\n", |
|
910 | 938 | " # dbconfig = yaml.safe_load(dbf)\n", |
911 | 939 | "\n", |
912 | 940 | " dbconfig = yaml.safe_load(database_yaml)\n", |
913 | | - " print(dbconfig['role'])\n", |
914 | 941 | "\n", |
915 | 942 | " # assume group role to ensure shared permissions\n", |
916 | | - " @listens_for(Pool, \"connect\")\n", |
917 | | - " def assume_role(dbapi_con, connection_record):\n", |
918 | | - " logging.debug(f\"setting role {dbconfig['role']};\")\n", |
919 | | - " dbapi_con.cursor().execute(f\"set role {dbconfig['role']};\")\n", |
920 | | - " # logging.debug(f\"setting role postres;\")\n", |
921 | | - " # dbapi_con.cursor().execute(f\"set role postgres;\")\n", |
922 | | - "\n", |
923 | | - " db_url = URL(\n", |
924 | | - " 'postgres',\n", |
| 943 | + " @event.listens_for(Pool, \"connect\")\n", |
| 944 | + " def assume_role(dbapi_conn, connection_record):\n", |
| 945 | + " with dbapi_conn.cursor() as cursor:\n", |
| 946 | + " cursor.execute(\"SET ROLE %s\", (dbconfig['role'],))\n", |
| 947 | + "\n", |
| 948 | + " db_url = URL.create(\n", |
| 949 | + " 'postgresql+psycopg2',\n", |
925 | 950 | " host=dbconfig['host'],\n", |
926 | 951 | " username=dbconfig['user'],\n", |
927 | 952 | " database=dbconfig['db'],\n", |
|
1005 | 1030 | "import yaml\n", |
1006 | 1031 | "import pandas as pd\n", |
1007 | 1032 | "\n", |
1008 | | - "from sqlalchemy.engine.url import URL\n", |
| 1033 | + "from sqlalchemy.engine import URL\n", |
1009 | 1034 | "from triage.util.db import create_engine\n", |
1010 | 1035 | "from triage.component.postmodeling.experiment_summarizer import ExperimentReport\n", |
1011 | 1036 | "from matplotlib import pyplot as plt\n", |
1012 | 1037 | "%matplotlib inline\n", |
1013 | 1038 | "\n", |
1014 | 1039 | "dbconfig = yaml.safe_load(database_yaml)\n", |
1015 | | - "db_url = URL(\n", |
1016 | | - " 'postgres',\n", |
| 1040 | + "db_url = URL.create(\n", |
| 1041 | + " 'postgresql+psycopg2',\n", |
1017 | 1042 | " host=dbconfig['host'],\n", |
1018 | 1043 | " username=dbconfig['user'],\n", |
1019 | 1044 | " database=dbconfig['db'],\n", |
|
1599 | 1624 | "outputs": [], |
1600 | 1625 | "source": [ |
1601 | 1626 | "dbconfig = yaml.safe_load(database_yaml)\n", |
1602 | | - "db_url = URL(\n", |
1603 | | - " 'postgres',\n", |
| 1627 | + "db_url = URL.create(\n", |
| 1628 | + " 'postgresql+psycopg2',\n", |
1604 | 1629 | " host=dbconfig['host'],\n", |
1605 | 1630 | " username=dbconfig['user'],\n", |
1606 | 1631 | " database=dbconfig['db'],\n", |
|
2010 | 2035 | "provenance": [] |
2011 | 2036 | }, |
2012 | 2037 | "kernelspec": { |
2013 | | - "display_name": "colab_env", |
| 2038 | + "display_name": "triage_6", |
2014 | 2039 | "language": "python", |
2015 | 2040 | "name": "python3" |
2016 | 2041 | }, |
|
2024 | 2049 | "name": "python", |
2025 | 2050 | "nbconvert_exporter": "python", |
2026 | 2051 | "pygments_lexer": "ipython3", |
2027 | | - "version": "3.11.9" |
| 2052 | + "version": "3.10.6" |
2028 | 2053 | } |
2029 | 2054 | }, |
2030 | 2055 | "nbformat": 4, |
|
0 commit comments