diff --git a/dev/run_time_test_databases.ipynb b/dev/run_time_test_databases.ipynb new file mode 100644 index 0000000..dbb1a31 --- /dev/null +++ b/dev/run_time_test_databases.ipynb @@ -0,0 +1,1630 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Standardized test cases" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "For benchmarking, we need a standardized set of case studies, ranging form simple to very large. This helps us to test and track the performance of improvements of bw_timex with the same set of test cases.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 0) set up variables & functions" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "import bw2data as bd\n", + "\n", + "from bw_temporalis import TemporalDistribution\n", + "from datetime import datetime\n", + "\n", + "from cProfile import Profile\n", + "from pstats import SortKey, Stats" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [], + "source": [ + "assert 'bw25_premise_background_v2' in bd.projects\n", + "if 'bw25_premise_background_v2' not in bd.projects:\n", + " import bw2io as bi\n", + " bi.backup.restore_project_directory(fp= 'your/path/to/file/brightway2-project-bw25_premise_background_v2-backup.26-March-2024-01-40PM.tar.gz',\n", + " overwrite_existing=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['test_medium']\n", + "Databases dictionary with 5 object(s):\n", + "\tbiosphere3\n", + "\tcutoff39\n", + "\tdb_2020\n", + "\tdb_2030\n", + "\tdb_2040\n" + ] + } + ], + "source": [ + "bd.projects.set_current('bw25_premise_background_v2')\n", + "\n", + "to_delete = []\n", + "for db in bd.databases: #deleting all test_systems\n", + " if \"test\" in db:\n", + " to_delete.append(db)\n", + "print(to_delete)\n", + "\n", + "for db in to_delete:\n", + " del bd.databases[db] \n", + "\n", + "print(bd.databases)" + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "metadata": {}, + "outputs": [], + "source": [ + "def create_standardized_test_system(db_name, number_tiers, number_processes_per_tier, td_timesteps, td_dtype, background_process, loop = False):\n", + " \"\"\"\n", + " Create a foreground database with a standardized structure for testing purposes. It contains number_tiers supply chain levels, with each containing \n", + " number_processes_per_tier processes. Each process consumes from all processes in the tier below. \n", + " Each process has a temporal distribution with td_timesteps steps, e.g. 3, in td_dtype resolution, e.g. years, starting at a unit of time later than the consuming process\n", + " The last tier consumes a process from the background system, with the same temporal distribution as above.\n", + " If loop = True, a loop is included: the last process in last tier consumes from the last process in first tier, no TDs at this node.\n", + " No additional TDs at biosphere flows.\n", + "\n", + " Parameters:\n", + " db_name: str, name of the database\n", + " number_tiers: int, number of tiers in the supply chain\n", + " number_processes_per_tier: int, number of processes per tier\n", + " td_timesteps: int, number of timesteps in the temporal distribution\n", + " td_dtype: str, dtype of the temporal distribution, e.g. \"timedelta64[Y]\" or \"timedelta64[M]\"\n", + " background_process: node, bw2data object, background process to be consumed by the last tier in the foreground system\n", + " loop: bool, whether to include a loop in the foreground system\n", + "\n", + " returns: None\n", + "\n", + " \n", + " \"\"\"\n", + " \n", + " # create a new database\n", + " if db_name in bd.databases:\n", + " del bd.databases[db_name]\n", + " print(f\"Database {db_name} already exists, overwriting.\")\n", + " foreground = bd.Database(db_name)\n", + " foreground.register()\n", + "\n", + " # save FU node\n", + " FU_node = foreground.new_node(\n", + " code=\"FU\",\n", + " name=\"functional unit\",\n", + " unit = \"unit\"\n", + " )\n", + " FU_node.save()\n", + " FU_node.new_edge(input=FU_node , amount=1, unit = \"unit\", type=\"production\").save()\n", + "\n", + " #create nodes\n", + " for tier in range(1, number_tiers+1):\n", + " for process in range(1, number_processes_per_tier+1):\n", + " process_name = f'tier{tier}_act{process}'\n", + " process_code = f't{tier}_a{process}'\n", + " process_node = foreground.new_node(\n", + " code=process_code,\n", + " name=process_name,\n", + " unit = \"unit\"\n", + " )\n", + " process_node.save()\n", + " process_node.new_edge(input=process_node , amount=1, unit = \"unit\", type=\"production\").save()\n", + "\n", + " #relink nodes\n", + " for tier in range(1, number_tiers+1):\n", + " for process in range(1, number_processes_per_tier+1):\n", + " process_name = f'tier{tier}_act{process}'\n", + " process_code = f't{tier}_a{process}'\n", + " process_node = foreground.get(process_code)\n", + " if tier == 1: #tier 1 = FU\n", + " consuming_node = FU_node\n", + " new_edge = consuming_node.new_edge(input=process_node , amount=1, unit = \"unit\", type=\"technosphere\")\n", + " new_edge.save()\n", + " else: # lower tiers: all nodes at the tier above consume from all nodes at the tier below, with a temporal distribution specified by the inputs\n", + " for process in range(1, number_processes_per_tier+1):\n", + " consuming_node = foreground.get(f't{tier-1}_a{process}')\n", + " new_edge = consuming_node.new_edge(input=process_node , amount=1, unit = \"unit\", type=\"technosphere\")\n", + " temporal_distribution = TemporalDistribution(date = np.array(np.arange(1, td_timesteps+1), dtype = td_dtype), \n", + " amount = np.full(td_timesteps, 1 / td_timesteps)) #linear distribution between 1 and td_timesteps in years\n", + " new_edge[\"temporal_distribution\"] = temporal_distribution\n", + " new_edge.save()\n", + "\n", + " # add background process to nodes on last tier\n", + " for process in range(1, number_processes_per_tier+1):\n", + " last_foreground_node = foreground.get(f't{number_tiers}_a{process}')\n", + " new_edge = last_foreground_node.new_edge(input=background_process, amount=4, type=\"technosphere\")\n", + " temporal_distribution = TemporalDistribution(date = np.array(np.arange(1, td_timesteps+1), dtype = td_dtype),\n", + " amount = np.full(td_timesteps, 1 / td_timesteps)) #linear distribution between 1 and td_timesteps in years\n", + " new_edge[\"temporal_distribution\"] = temporal_distribution\n", + " new_edge.save()\n", + "\n", + " if loop:\n", + " # add loop to foreground: last process in last tier consumes from last process in first tier, no TDs\n", + " loop_consumer = foreground.get(f't{number_tiers}_a{number_processes_per_tier}')\n", + " loop_producer = foreground.get(f't{1}_a{number_processes_per_tier}')\n", + " new_edge = loop_consumer.new_edge(input=loop_producer, amount=0.3, type=\"technosphere\")\n", + " new_edge.save()\n", + "\n", + " count_exc = 0\n", + " for act in foreground:\n", + " for exc in act.technosphere():\n", + " count_exc += 1\n", + " \n", + " print(f\"Database {db_name} created with {len(foreground)} processes and {count_exc} exchanges\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 1) small system" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Database test_small created with 5 processes and 8 exchanges\n" + ] + } + ], + "source": [ + "background_process = bd.get_node(database=\"db_2020\", name=\"market for transport, passenger car, electric\", location=\"GLO\")\n", + "db_name = \"test_small\"\n", + "create_standardized_test_system(db_name = db_name, number_tiers = 2 , number_processes_per_tier=2,\n", + " td_timesteps= 2, td_dtype = \"timedelta64[Y]\", background_process=background_process,\n", + " loop = False)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [], + "source": [ + "# # check db entries:\n", + "# foreground = bd.Database(db_name)\n", + "# for act in foreground:\n", + "# print(act)\n", + "# for exc in act.exchanges():\n", + "# td = exc.get(\"temporal_distribution\", None)\n", + "# print(\"--\", exc[\"type\"],\"|\", exc,\"|\", td) \n", + "# print (\"\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [], + "source": [ + "database_date_dict = {\n", + " \"db_2020\": datetime.strptime(\"2020\", \"%Y\"),\n", + " \"db_2030\": datetime.strptime(\"2030\", \"%Y\"),\n", + " \"db_2040\": datetime.strptime(\"2040\", \"%Y\"),\n", + " db_name: \"dynamic\",\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 2766164 function calls (2762178 primitive calls) in 5.789 seconds\n", + "\n", + " Ordered by: cumulative time\n", + " List reduced from 995 to 10 due to restriction <10>\n", + "\n", + " ncalls tottime percall cumtime percall filename:lineno(function)\n", + " 1 0.000 0.000 5.736 5.736 C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timex_lca.py:91(__init__)\n", + " 1 0.000 0.000 2.816 2.816 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2calc\\lca.py:384(lci)\n", + " 1 0.000 0.000 2.425 2.425 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2calc\\lca.py:411(lci_calculation)\n", + " 1 0.000 0.000 2.356 2.356 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2calc\\lca.py:366(solve_linear_system)\n", + " 1 0.000 0.000 2.356 2.356 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\pypardiso\\scipy_aliases.py:12(spsolve)\n", + " 2 2.347 1.174 2.348 1.174 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\pypardiso\\pardiso_wrapper.py:266(_call_pardiso)\n", + " 1 0.001 0.001 2.335 2.335 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\pypardiso\\pardiso_wrapper.py:145(factorize)\n", + " 1 0.020 0.020 2.292 2.292 C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timex_lca.py:986(create_node_id_collection_dict)\n", + " 24112 0.084 0.000 2.230 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2data\\backends\\base.py:316(__iter__)\n", + " 101216 0.057 0.000 1.856 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:4664(next)\n", + "\n", + "\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from bw_timex import TimexLCA\n", + "FU_node = bd.Database(db_name).get(\"FU\")\n", + "\n", + "with Profile() as profile:\n", + " tlca = TimexLCA(\n", + " demand={FU_node: 1},\n", + " method=(\"EF v3.1\", \"climate change\", \"global warming potential (GWP100)\"),\n", + " database_date_dict=database_date_dict,\n", + " )\n", + "Stats(profile).sort_stats(SortKey.CUMULATIVE).print_stats(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timex_lca.py:208: UserWarning: No edge filter function provided. Skipping all edges in background databases.\n", + " warnings.warn(\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Starting graph traversal\n", + "Calculation count: 10\n", + " 6242762 function calls (6017710 primitive calls) in 36.908 seconds\n", + "\n", + " Ordered by: cumulative time\n", + " List reduced from 1473 to 10 due to restriction <10>\n", + "\n", + " ncalls tottime percall cumtime percall filename:lineno(function)\n", + " 18 0.441 0.025 29.908 1.662 {built-in method select.select}\n", + " 72339 29.076 0.000 29.093 0.000 C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\helper_classes.py:109(add)\n", + " 72592 0.059 0.000 4.486 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:4664(next)\n", + " 72572 0.086 0.000 4.427 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:4578(iterate)\n", + " 72441 0.200 0.000 3.339 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:7894(process_row)\n", + " 72441 0.231 0.000 1.803 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:7852(process_row)\n", + " 133/131 0.000 0.000 1.346 0.010 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:2012(inner)\n", + " 131 0.000 0.000 1.345 0.010 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:2087(execute)\n", + " 110 0.000 0.000 1.329 0.012 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:7254(__iter__)\n", + " 72441 0.423 0.000 1.319 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:6631(__init__)\n", + "\n", + "\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "with Profile() as profile:\n", + " tlca.build_timeline()\n", + "Stats(profile).sort_stats(SortKey.CUMULATIVE).print_stats(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 3799096 function calls (3714640 primitive calls) in 9.979 seconds\n", + "\n", + " Ordered by: cumulative time\n", + " List reduced from 1414 to 10 due to restriction <10>\n", + "\n", + " ncalls tottime percall cumtime percall filename:lineno(function)\n", + " 74 0.002 0.000 4.709 0.064 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2data\\utils.py:362(get_node)\n", + " 166/121 0.000 0.000 4.263 0.035 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:2012(inner)\n", + " 121 0.000 0.000 4.261 0.035 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:2087(execute)\n", + " 121 0.001 0.000 4.261 0.035 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:2260(_execute)\n", + " 121 0.000 0.000 4.259 0.035 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:3307(execute)\n", + " 104 0.000 0.000 4.246 0.041 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:7254(__iter__)\n", + " 121 0.001 0.000 4.194 0.035 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:3298(execute_sql)\n", + " 121 4.193 0.035 4.193 0.035 {method 'execute' of 'sqlite3.Cursor' objects}\n", + " 10 0.000 0.000 2.995 0.300 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2calc\\lca.py:384(lci)\n", + " 10 0.006 0.001 2.563 0.256 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2calc\\lca.py:411(lci_calculation)\n", + "\n", + "\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "with Profile() as profile:\n", + " tlca.lci()\n", + " \n", + "Stats(profile).sort_stats(SortKey.CUMULATIVE).print_stats(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 2489 function calls (2481 primitive calls) in 0.005 seconds\n", + "\n", + " Ordered by: cumulative time\n", + " List reduced from 248 to 10 due to restriction <10>\n", + "\n", + " ncalls tottime percall cumtime percall filename:lineno(function)\n", + " 1 0.000 0.000 0.002 0.002 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\matrix_utils\\mapped_matrix.py:15(__init__)\n", + " 1 0.000 0.000 0.001 0.001 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\matrix_utils\\mapped_matrix.py:167(map_indices)\n", + " 1 0.000 0.000 0.001 0.001 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\matrix_utils\\resource_group.py:166(map_indices)\n", + " 1 0.000 0.000 0.001 0.001 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\ipykernel\\iostream.py:276()\n", + " 8 0.000 0.000 0.001 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\matrix_utils\\indexers.py:24(__init__)\n", + " 8 0.000 0.000 0.001 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\matrix_utils\\indexers.py:32(reset)\n", + " 5 0.000 0.000 0.001 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\scipy\\sparse\\_coo.py:27(__init__)\n", + " 2 0.000 0.000 0.001 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\matrix_utils\\aggregation.py:5(aggregate_with_sparse)\n", + " 1 0.000 0.000 0.001 0.001 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2calc\\lca.py:446(lcia_calculation)\n", + " 1 0.000 0.000 0.001 0.001 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\scipy\\sparse\\_matrix.py:43(__mul__)\n", + "\n", + "\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "with Profile() as profile:\n", + " tlca.static_lcia()\n", + "\n", + "Stats(profile).sort_stats(SortKey.CUMULATIVE).print_stats(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2.058617754929586" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tlca.static_score" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 2) medium system" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['test_medium']\n", + "Databases dictionary with 5 object(s):\n", + "\tbiosphere3\n", + "\tcutoff39\n", + "\tdb_2020\n", + "\tdb_2030\n", + "\tdb_2040\n" + ] + } + ], + "source": [ + "# needed to avoid multiple results error https://github.com/brightway-lca/bw_timex/issues/101\n", + "to_delete = []\n", + "for db in bd.databases: #deleting all test_systems\n", + " if \"test\" in db:\n", + " to_delete.append(db)\n", + "print(to_delete)\n", + "\n", + "for db in to_delete:\n", + " del bd.databases[db] \n", + "\n", + "print(bd.databases)" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Database test_medium created with 17 processes and 56 exchanges\n" + ] + } + ], + "source": [ + "background_process = bd.get_node(database=\"db_2020\", name=\"market for transport, passenger car, electric\", location=\"GLO\")\n", + "db_name = \"test_medium\"\n", + "create_standardized_test_system(db_name = db_name, number_tiers = 4, number_processes_per_tier=4,\n", + " td_timesteps= 2, td_dtype = \"timedelta64[Y]\", background_process=background_process,\n", + " loop = False)" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "'tier4_act1' (unit, GLO, None)\n", + "-- production | Exchange: 1 unit 'tier4_act1' (unit, GLO, None) to 'tier4_act1' (unit, GLO, None)> | None\n", + "-- technosphere | Exchange: 4 kilometer 'market for transport, passenger car, electric' (kilometer, GLO, None) to 'tier4_act1' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "\n", + "\n", + "'tier2_act4' (unit, GLO, None)\n", + "-- production | Exchange: 1 unit 'tier2_act4' (unit, GLO, None) to 'tier2_act4' (unit, GLO, None)> | None\n", + "-- technosphere | Exchange: 1 unit 'tier3_act1' (unit, GLO, None) to 'tier2_act4' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier3_act2' (unit, GLO, None) to 'tier2_act4' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier3_act3' (unit, GLO, None) to 'tier2_act4' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier3_act4' (unit, GLO, None) to 'tier2_act4' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "\n", + "\n", + "'tier1_act4' (unit, GLO, None)\n", + "-- production | Exchange: 1 unit 'tier1_act4' (unit, GLO, None) to 'tier1_act4' (unit, GLO, None)> | None\n", + "-- technosphere | Exchange: 1 unit 'tier2_act1' (unit, GLO, None) to 'tier1_act4' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier2_act2' (unit, GLO, None) to 'tier1_act4' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier2_act3' (unit, GLO, None) to 'tier1_act4' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier2_act4' (unit, GLO, None) to 'tier1_act4' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "\n", + "\n", + "'tier4_act3' (unit, GLO, None)\n", + "-- production | Exchange: 1 unit 'tier4_act3' (unit, GLO, None) to 'tier4_act3' (unit, GLO, None)> | None\n", + "-- technosphere | Exchange: 4 kilometer 'market for transport, passenger car, electric' (kilometer, GLO, None) to 'tier4_act3' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "\n", + "\n", + "'tier1_act1' (unit, GLO, None)\n", + "-- production | Exchange: 1 unit 'tier1_act1' (unit, GLO, None) to 'tier1_act1' (unit, GLO, None)> | None\n", + "-- technosphere | Exchange: 1 unit 'tier2_act1' (unit, GLO, None) to 'tier1_act1' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier2_act2' (unit, GLO, None) to 'tier1_act1' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier2_act3' (unit, GLO, None) to 'tier1_act1' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier2_act4' (unit, GLO, None) to 'tier1_act1' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "\n", + "\n", + "'tier2_act1' (unit, GLO, None)\n", + "-- production | Exchange: 1 unit 'tier2_act1' (unit, GLO, None) to 'tier2_act1' (unit, GLO, None)> | None\n", + "-- technosphere | Exchange: 1 unit 'tier3_act1' (unit, GLO, None) to 'tier2_act1' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier3_act2' (unit, GLO, None) to 'tier2_act1' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier3_act3' (unit, GLO, None) to 'tier2_act1' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier3_act4' (unit, GLO, None) to 'tier2_act1' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "\n", + "\n", + "'tier4_act4' (unit, GLO, None)\n", + "-- production | Exchange: 1 unit 'tier4_act4' (unit, GLO, None) to 'tier4_act4' (unit, GLO, None)> | None\n", + "-- technosphere | Exchange: 4 kilometer 'market for transport, passenger car, electric' (kilometer, GLO, None) to 'tier4_act4' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "\n", + "\n", + "'tier2_act3' (unit, GLO, None)\n", + "-- production | Exchange: 1 unit 'tier2_act3' (unit, GLO, None) to 'tier2_act3' (unit, GLO, None)> | None\n", + "-- technosphere | Exchange: 1 unit 'tier3_act1' (unit, GLO, None) to 'tier2_act3' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier3_act2' (unit, GLO, None) to 'tier2_act3' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier3_act3' (unit, GLO, None) to 'tier2_act3' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier3_act4' (unit, GLO, None) to 'tier2_act3' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "\n", + "\n", + "'functional unit' (unit, GLO, None)\n", + "-- production | Exchange: 1 unit 'functional unit' (unit, GLO, None) to 'functional unit' (unit, GLO, None)> | None\n", + "-- technosphere | Exchange: 1 unit 'tier1_act1' (unit, GLO, None) to 'functional unit' (unit, GLO, None)> | None\n", + "-- technosphere | Exchange: 1 unit 'tier1_act2' (unit, GLO, None) to 'functional unit' (unit, GLO, None)> | None\n", + "-- technosphere | Exchange: 1 unit 'tier1_act3' (unit, GLO, None) to 'functional unit' (unit, GLO, None)> | None\n", + "-- technosphere | Exchange: 1 unit 'tier1_act4' (unit, GLO, None) to 'functional unit' (unit, GLO, None)> | None\n", + "\n", + "\n", + "'tier4_act2' (unit, GLO, None)\n", + "-- production | Exchange: 1 unit 'tier4_act2' (unit, GLO, None) to 'tier4_act2' (unit, GLO, None)> | None\n", + "-- technosphere | Exchange: 4 kilometer 'market for transport, passenger car, electric' (kilometer, GLO, None) to 'tier4_act2' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "\n", + "\n", + "'tier3_act1' (unit, GLO, None)\n", + "-- production | Exchange: 1 unit 'tier3_act1' (unit, GLO, None) to 'tier3_act1' (unit, GLO, None)> | None\n", + "-- technosphere | Exchange: 1 unit 'tier4_act1' (unit, GLO, None) to 'tier3_act1' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier4_act2' (unit, GLO, None) to 'tier3_act1' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier4_act3' (unit, GLO, None) to 'tier3_act1' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier4_act4' (unit, GLO, None) to 'tier3_act1' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "\n", + "\n", + "'tier1_act2' (unit, GLO, None)\n", + "-- production | Exchange: 1 unit 'tier1_act2' (unit, GLO, None) to 'tier1_act2' (unit, GLO, None)> | None\n", + "-- technosphere | Exchange: 1 unit 'tier2_act1' (unit, GLO, None) to 'tier1_act2' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier2_act2' (unit, GLO, None) to 'tier1_act2' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier2_act3' (unit, GLO, None) to 'tier1_act2' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier2_act4' (unit, GLO, None) to 'tier1_act2' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "\n", + "\n", + "'tier3_act3' (unit, GLO, None)\n", + "-- production | Exchange: 1 unit 'tier3_act3' (unit, GLO, None) to 'tier3_act3' (unit, GLO, None)> | None\n", + "-- technosphere | Exchange: 1 unit 'tier4_act1' (unit, GLO, None) to 'tier3_act3' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier4_act2' (unit, GLO, None) to 'tier3_act3' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier4_act3' (unit, GLO, None) to 'tier3_act3' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier4_act4' (unit, GLO, None) to 'tier3_act3' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "\n", + "\n", + "'tier2_act2' (unit, GLO, None)\n", + "-- production | Exchange: 1 unit 'tier2_act2' (unit, GLO, None) to 'tier2_act2' (unit, GLO, None)> | None\n", + "-- technosphere | Exchange: 1 unit 'tier3_act1' (unit, GLO, None) to 'tier2_act2' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier3_act2' (unit, GLO, None) to 'tier2_act2' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier3_act3' (unit, GLO, None) to 'tier2_act2' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier3_act4' (unit, GLO, None) to 'tier2_act2' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "\n", + "\n", + "'tier1_act3' (unit, GLO, None)\n", + "-- production | Exchange: 1 unit 'tier1_act3' (unit, GLO, None) to 'tier1_act3' (unit, GLO, None)> | None\n", + "-- technosphere | Exchange: 1 unit 'tier2_act1' (unit, GLO, None) to 'tier1_act3' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier2_act2' (unit, GLO, None) to 'tier1_act3' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier2_act3' (unit, GLO, None) to 'tier1_act3' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier2_act4' (unit, GLO, None) to 'tier1_act3' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "\n", + "\n", + "'tier3_act4' (unit, GLO, None)\n", + "-- production | Exchange: 1 unit 'tier3_act4' (unit, GLO, None) to 'tier3_act4' (unit, GLO, None)> | None\n", + "-- technosphere | Exchange: 1 unit 'tier4_act1' (unit, GLO, None) to 'tier3_act4' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier4_act2' (unit, GLO, None) to 'tier3_act4' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier4_act3' (unit, GLO, None) to 'tier3_act4' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier4_act4' (unit, GLO, None) to 'tier3_act4' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "\n", + "\n", + "'tier3_act2' (unit, GLO, None)\n", + "-- production | Exchange: 1 unit 'tier3_act2' (unit, GLO, None) to 'tier3_act2' (unit, GLO, None)> | None\n", + "-- technosphere | Exchange: 1 unit 'tier4_act1' (unit, GLO, None) to 'tier3_act2' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier4_act2' (unit, GLO, None) to 'tier3_act2' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier4_act3' (unit, GLO, None) to 'tier3_act2' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "-- technosphere | Exchange: 1 unit 'tier4_act4' (unit, GLO, None) to 'tier3_act2' (unit, GLO, None)> | TemporalDistribution instance with 2 values and total: 1\n", + "\n", + "\n" + ] + } + ], + "source": [ + "# check db entries:\n", + "foreground = bd.Database(db_name)\n", + "for act in foreground:\n", + " print(act)\n", + " for exc in act.exchanges():\n", + " td = exc.get(\"temporal_distribution\", None)\n", + " print(\"--\", exc[\"type\"],\"|\", exc,\"|\", td) \n", + " print (\"\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": {}, + "outputs": [], + "source": [ + "database_date_dict = {\n", + " \"db_2020\": datetime.strptime(\"2020\", \"%Y\"),\n", + " \"db_2030\": datetime.strptime(\"2030\", \"%Y\"),\n", + " \"db_2040\": datetime.strptime(\"2040\", \"%Y\"),\n", + " db_name: \"dynamic\",\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 2890863 function calls (2856774 primitive calls) in 6.837 seconds\n", + "\n", + " Ordered by: cumulative time\n", + " List reduced from 1017 to 10 due to restriction <10>\n", + "\n", + " ncalls tottime percall cumtime percall filename:lineno(function)\n", + " 1 0.000 0.000 3.575 3.575 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2calc\\lca.py:384(lci)\n", + " 1 0.000 0.000 3.141 3.141 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2calc\\lca.py:411(lci_calculation)\n", + " 1 0.000 0.000 2.223 2.223 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2calc\\lca.py:366(solve_linear_system)\n", + " 1 0.000 0.000 2.223 2.223 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\pypardiso\\scipy_aliases.py:12(spsolve)\n", + " 2 2.218 1.109 2.218 1.109 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\pypardiso\\pardiso_wrapper.py:266(_call_pardiso)\n", + " 1 0.000 0.000 2.190 2.190 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\pypardiso\\pardiso_wrapper.py:145(factorize)\n", + " 101516 0.068 0.000 2.158 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:4664(next)\n", + " 101516 0.111 0.000 2.091 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:4578(iterate)\n", + " 24252 0.086 0.000 1.241 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:7894(process_row)\n", + " 3 0.000 0.000 0.866 0.289 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\asyncio\\base_events.py:1910(_run_once)\n", + "\n", + "\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from bw_timex import TimexLCA\n", + "FU_node = bd.Database(db_name).get(\"FU\")\n", + "\n", + "with Profile() as profile:\n", + " tlca = TimexLCA(\n", + " demand={FU_node: 1},\n", + " method=(\"EF v3.1\", \"climate change\", \"global warming potential (GWP100)\"),\n", + " database_date_dict=database_date_dict,\n", + " )\n", + "Stats(profile).sort_stats(SortKey.CUMULATIVE).print_stats(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timex_lca.py:208: UserWarning: No edge filter function provided. Skipping all edges in background databases.\n", + " warnings.warn(\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Starting graph traversal\n", + "Calculation count: 596\n", + " 10787689 function calls (10462928 primitive calls) in 47.443 seconds\n", + "\n", + " Ordered by: cumulative time\n", + " List reduced from 1475 to 10 due to restriction <10>\n", + "\n", + " ncalls tottime percall cumtime percall filename:lineno(function)\n", + " 16 0.046 0.003 38.013 2.376 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\selectors.py:313(_select)\n", + " 72561 31.020 0.000 31.037 0.000 C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\helper_classes.py:109(add)\n", + " 16 0.427 0.027 29.149 1.822 {built-in method select.select}\n", + " 1 0.001 0.001 9.666 9.666 C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timex_lca.py:151(build_timeline)\n", + " 72318 0.310 0.000 8.752 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2data\\backends\\base.py:316(__iter__)\n", + "2942/2940 0.003 0.000 5.441 0.002 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:2012(inner)\n", + " 2940 0.002 0.000 5.436 0.002 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:2087(execute)\n", + " 2940 0.009 0.000 5.240 0.002 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:2260(_execute)\n", + " 2940 0.007 0.000 5.209 0.002 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:3307(execute)\n", + " 79382 0.072 0.000 5.135 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:4664(next)\n", + "\n", + "\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 61, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "with Profile() as profile:\n", + " tlca.build_timeline()\n", + " \n", + "Stats(profile).sort_stats(SortKey.CUMULATIVE).print_stats(10) #1 min" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 12974572 function calls (12803202 primitive calls) in 83.762 seconds\n", + "\n", + " Ordered by: cumulative time\n", + " List reduced from 1424 to 10 due to restriction <10>\n", + "\n", + " ncalls tottime percall cumtime percall filename:lineno(function)\n", + " 766 0.021 0.000 70.982 0.093 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2data\\utils.py:362(get_node)\n", + "2008/1405 0.003 0.000 69.643 0.050 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:2012(inner)\n", + " 1405 0.001 0.000 69.628 0.050 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:2087(execute)\n", + " 1202 0.002 0.000 69.504 0.058 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:7254(__iter__)\n", + " 1405 0.008 0.000 68.888 0.049 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:2260(_execute)\n", + " 1405 0.004 0.000 68.862 0.049 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:3307(execute)\n", + " 1405 0.008 0.000 68.052 0.048 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:3298(execute_sql)\n", + " 1405 68.036 0.048 68.036 0.048 {method 'execute' of 'sqlite3.Cursor' objects}\n", + " 1 0.000 0.000 6.048 6.048 C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timex_lca.py:537(build_datapackage)\n", + " 1 0.000 0.000 6.048 6.048 C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\matrix_modifier.py:51(create_datapackage)\n", + "\n", + "\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 62, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "with Profile() as profile:\n", + " tlca.lci()\n", + " \n", + "Stats(profile).sort_stats(SortKey.CUMULATIVE).print_stats(10) #37 secs" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 2852 function calls (2850 primitive calls) in 0.006 seconds\n", + "\n", + " Ordered by: cumulative time\n", + " List reduced from 229 to 10 due to restriction <10>\n", + "\n", + " ncalls tottime percall cumtime percall filename:lineno(function)\n", + " 1 0.000 0.000 0.005 0.005 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\asyncio\\base_events.py:1910(_run_once)\n", + " 1 0.000 0.000 0.005 0.005 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\selectors.py:319(select)\n", + " 1 0.000 0.000 0.005 0.005 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\selectors.py:313(_select)\n", + " 1 0.000 0.000 0.005 0.005 {built-in method select.select}\n", + " 1 0.000 0.000 0.005 0.005 C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timex_lca.py:360(static_lcia)\n", + " 1 0.000 0.000 0.005 0.005 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2calc\\lca.py:424(lcia)\n", + " 1 0.000 0.000 0.003 0.003 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2calc\\lca.py:283(load_lcia_data)\n", + " 1 0.000 0.000 0.001 0.001 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2calc\\lca.py:446(lcia_calculation)\n", + " 1 0.000 0.000 0.001 0.001 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\scipy\\sparse\\_matrix.py:43(__mul__)\n", + " 1 0.000 0.000 0.001 0.001 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\scipy\\sparse\\_base.py:568(_matmul_dispatch)\n", + "\n", + "\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 53, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "with Profile() as profile:\n", + " tlca.static_lcia()\n", + "\n", + "Stats(profile).sort_stats(SortKey.CUMULATIVE).print_stats(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "11.95350274003336" + ] + }, + "execution_count": 56, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tlca.static_score" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 3) large system\n" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['test_medium']\n", + "Databases dictionary with 5 object(s):\n", + "\tbiosphere3\n", + "\tcutoff39\n", + "\tdb_2020\n", + "\tdb_2030\n", + "\tdb_2040\n" + ] + } + ], + "source": [ + "# needed to avoid multiple results error https://github.com/brightway-lca/bw_timex/issues/101\n", + "to_delete = []\n", + "for db in bd.databases: #deleting all test_systems\n", + " if \"test\" in db:\n", + " to_delete.append(db)\n", + "print(to_delete)\n", + "\n", + "for db in to_delete:\n", + " del bd.databases[db] \n", + "\n", + "print(bd.databases)" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Database test_large already exists, overwriting.\n", + "Database test_large created with 21 processes and 72 exchanges\n" + ] + } + ], + "source": [ + "background_process = bd.get_node(database=\"db_2020\", name=\"market for transport, passenger car, electric\", location=\"GLO\")\n", + "db_name = \"test_large\"\n", + "create_standardized_test_system(db_name = db_name, number_tiers = 5, number_processes_per_tier=4,\n", + " td_timesteps= 2, td_dtype = \"timedelta64[Y]\", background_process=background_process,\n", + " loop = False)" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "metadata": {}, + "outputs": [], + "source": [ + "# # check db entries:\n", + "# foreground = bd.Database(db_name)\n", + "# for act in foreground:\n", + "# print(act)\n", + "# for exc in act.exchanges():\n", + "# td = exc.get(\"temporal_distribution\", None)\n", + "# print(\"--\", exc[\"type\"],\"|\", exc,\"|\", td) \n", + "# print (\"\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": 72, + "metadata": {}, + "outputs": [], + "source": [ + "database_date_dict = {\n", + " \"db_2020\": datetime.strptime(\"2020\", \"%Y\"),\n", + " \"db_2030\": datetime.strptime(\"2030\", \"%Y\"),\n", + " \"db_2040\": datetime.strptime(\"2040\", \"%Y\"),\n", + " db_name: \"dynamic\"}" + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 2932530 function calls (2896291 primitive calls) in 6.285 seconds\n", + "\n", + " Ordered by: cumulative time\n", + " List reduced from 1043 to 10 due to restriction <10>\n", + "\n", + " ncalls tottime percall cumtime percall filename:lineno(function)\n", + " 1 0.000 0.000 2.683 2.683 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2calc\\lca.py:384(lci)\n", + " 1 0.000 0.000 2.253 2.253 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2calc\\lca.py:411(lci_calculation)\n", + " 1 0.000 0.000 2.210 2.210 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2calc\\lca.py:366(solve_linear_system)\n", + " 1 0.000 0.000 2.210 2.210 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\pypardiso\\scipy_aliases.py:12(spsolve)\n", + " 2 2.203 1.101 2.203 1.101 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\pypardiso\\pardiso_wrapper.py:266(_call_pardiso)\n", + " 1 0.001 0.001 2.189 2.189 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\pypardiso\\pardiso_wrapper.py:145(factorize)\n", + " 101616 0.062 0.000 2.081 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:4664(next)\n", + " 101616 0.101 0.000 2.019 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:4578(iterate)\n", + " 24292 0.078 0.000 1.243 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:7894(process_row)\n", + " 24406 0.085 0.000 0.860 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:7852(process_row)\n", + "\n", + "\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 73, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from bw_timex import TimexLCA\n", + "FU_node = bd.Database(db_name).get(\"FU\")\n", + "\n", + "with Profile() as profile:\n", + " tlca = TimexLCA(\n", + " demand={FU_node: 1},\n", + " method=(\"EF v3.1\", \"climate change\", \"global warming potential (GWP100)\"),\n", + " database_date_dict=database_date_dict,\n", + " )\n", + "Stats(profile).sort_stats(SortKey.CUMULATIVE).print_stats(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timex_lca.py:208: UserWarning: No edge filter function provided. Skipping all edges in background databases.\n", + " warnings.warn(\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Starting graph traversal\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw_graph_tools\\graph_traversal.py:473: UserWarning: Stopping traversal due to calculation count.\n", + " warnings.warn(\"Stopping traversal due to calculation count.\")\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Calculation count: 2001\n", + " 19319170 function calls (18681003 primitive calls) in 56.084 seconds\n", + "\n", + " Ordered by: cumulative time\n", + " List reduced from 1477 to 10 due to restriction <10>\n", + "\n", + " ncalls tottime percall cumtime percall filename:lineno(function)\n", + " 20 0.039 0.002 43.982 2.199 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\selectors.py:313(_select)\n", + " 20 0.462 0.023 37.743 1.887 {built-in method select.select}\n", + " 72701 31.270 0.000 31.287 0.000 C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\helper_classes.py:109(add)\n", + " 1 0.001 0.001 11.424 11.424 C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timex_lca.py:151(build_timeline)\n", + " 1 0.001 0.001 9.706 9.706 C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timeline_builder.py:29(__init__)\n", + " 1 0.070 0.070 9.705 9.705 C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\edge_extractor.py:70(build_edge_timeline)\n", + "7837/7835 0.011 0.000 6.496 0.001 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:2012(inner)\n", + " 7835 0.006 0.000 6.484 0.001 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:2087(execute)\n", + " 7835 0.031 0.000 6.283 0.001 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:2260(_execute)\n", + " 7835 0.023 0.000 6.174 0.001 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:3307(execute)\n", + "\n", + "\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 74, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "with Profile() as profile:\n", + " tlca.build_timeline()\n", + " \n", + "Stats(profile).sort_stats(SortKey.CUMULATIVE).print_stats(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 75, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 17210206 function calls (16980999 primitive calls) in 124.671 seconds\n", + "\n", + " Ordered by: cumulative time\n", + " List reduced from 1378 to 10 due to restriction <10>\n", + "\n", + " ncalls tottime percall cumtime percall filename:lineno(function)\n", + " 1 0.000 0.000 124.670 124.670 C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timex_lca.py:268(lci)\n", + " 26 0.001 0.000 112.243 4.317 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\asyncio\\base_events.py:1910(_run_once)\n", + " 26 0.606 0.023 112.216 4.316 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\selectors.py:319(select)\n", + " 1219 0.034 0.000 109.487 0.090 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2data\\utils.py:362(get_node)\n", + "3249/2262 0.004 0.000 107.953 0.048 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:2012(inner)\n", + " 2262 0.002 0.000 107.927 0.048 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:2087(execute)\n", + " 1931 0.003 0.000 107.723 0.056 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:7254(__iter__)\n", + " 2262 0.014 0.000 106.887 0.047 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:2260(_execute)\n", + " 2262 0.007 0.000 106.842 0.047 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:3307(execute)\n", + " 2262 0.013 0.000 105.561 0.047 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:3298(execute_sql)\n", + "\n", + "\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 75, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "with Profile() as profile:\n", + " tlca.lci()\n", + " \n", + "Stats(profile).sort_stats(SortKey.CUMULATIVE).print_stats(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 76, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 5358 function calls (5354 primitive calls) in 0.008 seconds\n", + "\n", + " Ordered by: cumulative time\n", + " List reduced from 241 to 10 due to restriction <10>\n", + "\n", + " ncalls tottime percall cumtime percall filename:lineno(function)\n", + " 25 0.002 0.000 0.003 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw_processing\\datapackage.py:180(filter_by_attribute)\n", + " 1 0.000 0.000 0.002 0.002 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\matrix_utils\\mapped_matrix.py:15(__init__)\n", + " 1 0.000 0.000 0.002 0.002 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2calc\\utils.py:19(consistent_global_index)\n", + " 1 0.000 0.000 0.001 0.001 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\matrix_utils\\utils.py:6(filter_groups_for_packages)\n", + " 2 0.000 0.000 0.001 0.001 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\matrix_utils\\aggregation.py:5(aggregate_with_sparse)\n", + " 1 0.000 0.000 0.001 0.001 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\matrix_utils\\mapped_matrix.py:167(map_indices)\n", + " 1 0.000 0.000 0.001 0.001 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\matrix_utils\\resource_group.py:166(map_indices)\n", + " 1 0.000 0.000 0.001 0.001 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2calc\\lca.py:446(lcia_calculation)\n", + " 1 0.000 0.000 0.001 0.001 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\scipy\\sparse\\_matrix.py:43(__mul__)\n", + " 1 0.000 0.000 0.001 0.001 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\scipy\\sparse\\_base.py:568(_matmul_dispatch)\n", + "\n", + "\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 76, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "with Profile() as profile:\n", + " tlca.static_lcia()\n", + "\n", + "Stats(profile).sort_stats(SortKey.CUMULATIVE).print_stats(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "379.79756051343105" + ] + }, + "execution_count": 77, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tlca.static_score" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 4) small system with loop" + ] + }, + { + "cell_type": "code", + "execution_count": 78, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['test_large']\n", + "Databases dictionary with 5 object(s):\n", + "\tbiosphere3\n", + "\tcutoff39\n", + "\tdb_2020\n", + "\tdb_2030\n", + "\tdb_2040\n" + ] + } + ], + "source": [ + "# needed to avoid multiple results error https://github.com/brightway-lca/bw_timex/issues/101\n", + "to_delete = []\n", + "for db in bd.databases: #deleting all test_systems\n", + " if \"test\" in db:\n", + " to_delete.append(db)\n", + "print(to_delete)\n", + "\n", + "for db in to_delete:\n", + " del bd.databases[db] \n", + "\n", + "print(bd.databases)" + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Database test_loop created with 7 processes and 16 exchanges\n" + ] + } + ], + "source": [ + "background_process = bd.get_node(database=\"db_2020\", name=\"market for transport, passenger car, electric\", location=\"GLO\")\n", + "db_name = \"test_loop\"\n", + "create_standardized_test_system(db_name = db_name, number_tiers = 2, number_processes_per_tier=3,\n", + " td_timesteps= 2, td_dtype = \"timedelta64[Y]\", background_process=background_process,\n", + " loop = True)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# # check db entries:\n", + "# foreground = bd.Database(db_name)\n", + "# for act in foreground:\n", + "# print(act)\n", + "# for exc in act.exchanges():\n", + "# td = exc.get(\"temporal_distribution\", None)\n", + "# print(\"--\", exc[\"type\"],\"|\", exc,\"|\", td) \n", + "# print (\"\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "metadata": {}, + "outputs": [], + "source": [ + "database_date_dict = {\n", + " \"db_2020\": datetime.strptime(\"2020\", \"%Y\"),\n", + " \"db_2030\": datetime.strptime(\"2030\", \"%Y\"),\n", + " \"db_2040\": datetime.strptime(\"2040\", \"%Y\"),\n", + " db_name: \"dynamic\"}" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 2787235 function calls (2758095 primitive calls) in 5.767 seconds\n", + "\n", + " Ordered by: cumulative time\n", + " List reduced from 1024 to 10 due to restriction <10>\n", + "\n", + " ncalls tottime percall cumtime percall filename:lineno(function)\n", + " 1 0.000 0.000 2.949 2.949 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2calc\\lca.py:384(lci)\n", + " 1 0.000 0.000 2.543 2.543 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2calc\\lca.py:411(lci_calculation)\n", + " 1 0.000 0.000 2.492 2.492 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2calc\\lca.py:366(solve_linear_system)\n", + " 1 0.000 0.000 2.492 2.492 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\pypardiso\\scipy_aliases.py:12(spsolve)\n", + " 2 2.485 1.242 2.485 1.243 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\pypardiso\\pardiso_wrapper.py:266(_call_pardiso)\n", + " 1 0.001 0.001 2.471 2.471 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\pypardiso\\pardiso_wrapper.py:145(factorize)\n", + " 101266 0.056 0.000 1.880 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:4664(next)\n", + " 101266 0.094 0.000 1.824 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:4578(iterate)\n", + " 24152 0.070 0.000 1.100 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:7894(process_row)\n", + " 24182 0.077 0.000 0.769 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:7852(process_row)\n", + "\n", + "\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 82, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from bw_timex import TimexLCA\n", + "FU_node = bd.Database(db_name).get(\"FU\")\n", + "\n", + "with Profile() as profile:\n", + " tlca = TimexLCA(\n", + " demand={FU_node: 1},\n", + " method=(\"EF v3.1\", \"climate change\", \"global warming potential (GWP100)\"),\n", + " database_date_dict=database_date_dict,\n", + " )\n", + "Stats(profile).sort_stats(SortKey.CUMULATIVE).print_stats(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 83, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timex_lca.py:208: UserWarning: No edge filter function provided. Skipping all edges in background databases.\n", + " warnings.warn(\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Starting graph traversal\n", + "Calculation count: 339\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timeline_builder.py:537: Warning: Reference date 2041-01-01 00:00:00 is higher than all provided dates. Data will be taken from the closest lower year.\n", + " warnings.warn(\n", + "C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timeline_builder.py:537: Warning: Reference date 2042-01-01 00:00:00 is higher than all provided dates. Data will be taken from the closest lower year.\n", + " warnings.warn(\n", + "C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timeline_builder.py:537: Warning: Reference date 2043-01-01 00:00:00 is higher than all provided dates. Data will be taken from the closest lower year.\n", + " warnings.warn(\n", + "C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timeline_builder.py:537: Warning: Reference date 2044-01-01 00:00:00 is higher than all provided dates. Data will be taken from the closest lower year.\n", + " warnings.warn(\n", + "C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timeline_builder.py:537: Warning: Reference date 2045-01-01 00:00:00 is higher than all provided dates. Data will be taken from the closest lower year.\n", + " warnings.warn(\n", + "C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timeline_builder.py:537: Warning: Reference date 2046-01-01 00:00:00 is higher than all provided dates. Data will be taken from the closest lower year.\n", + " warnings.warn(\n", + "C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timeline_builder.py:537: Warning: Reference date 2047-01-01 00:00:00 is higher than all provided dates. Data will be taken from the closest lower year.\n", + " warnings.warn(\n", + "C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timeline_builder.py:537: Warning: Reference date 2048-01-01 00:00:00 is higher than all provided dates. Data will be taken from the closest lower year.\n", + " warnings.warn(\n", + "C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timeline_builder.py:537: Warning: Reference date 2049-01-01 00:00:00 is higher than all provided dates. Data will be taken from the closest lower year.\n", + " warnings.warn(\n", + "C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timeline_builder.py:537: Warning: Reference date 2050-01-01 00:00:00 is higher than all provided dates. Data will be taken from the closest lower year.\n", + " warnings.warn(\n", + "C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timeline_builder.py:537: Warning: Reference date 2051-01-01 00:00:00 is higher than all provided dates. Data will be taken from the closest lower year.\n", + " warnings.warn(\n", + "C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timeline_builder.py:537: Warning: Reference date 2052-01-01 00:00:00 is higher than all provided dates. Data will be taken from the closest lower year.\n", + " warnings.warn(\n", + "C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timeline_builder.py:537: Warning: Reference date 2053-01-01 00:00:00 is higher than all provided dates. Data will be taken from the closest lower year.\n", + " warnings.warn(\n", + "C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timeline_builder.py:537: Warning: Reference date 2054-01-01 00:00:00 is higher than all provided dates. Data will be taken from the closest lower year.\n", + " warnings.warn(\n", + "C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timeline_builder.py:537: Warning: Reference date 2055-01-01 00:00:00 is higher than all provided dates. Data will be taken from the closest lower year.\n", + " warnings.warn(\n", + "C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timeline_builder.py:537: Warning: Reference date 2056-01-01 00:00:00 is higher than all provided dates. Data will be taken from the closest lower year.\n", + " warnings.warn(\n", + "C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timeline_builder.py:537: Warning: Reference date 2057-01-01 00:00:00 is higher than all provided dates. Data will be taken from the closest lower year.\n", + " warnings.warn(\n", + "C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timeline_builder.py:537: Warning: Reference date 2058-01-01 00:00:00 is higher than all provided dates. Data will be taken from the closest lower year.\n", + " warnings.warn(\n", + "C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timeline_builder.py:537: Warning: Reference date 2059-01-01 00:00:00 is higher than all provided dates. Data will be taken from the closest lower year.\n", + " warnings.warn(\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 10579214 function calls (10252086 primitive calls) in 54.938 seconds\n", + "\n", + " Ordered by: cumulative time\n", + " List reduced from 1475 to 10 due to restriction <10>\n", + "\n", + " ncalls tottime percall cumtime percall filename:lineno(function)\n", + " 21 1.269 0.060 38.676 1.842 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\selectors.py:313(_select)\n", + " 72748 34.009 0.000 34.028 0.000 C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\helper_classes.py:109(add)\n", + " 21 0.414 0.020 20.773 0.989 {built-in method select.select}\n", + " 1 0.002 0.002 17.646 17.646 C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timex_lca.py:151(build_timeline)\n", + " 1 0.009 0.009 7.540 7.540 C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timeline_builder.py:108(build_timeline)\n", + " 72318 0.279 0.000 6.642 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2data\\backends\\base.py:316(__iter__)\n", + " 79296 0.089 0.000 5.146 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:4664(next)\n", + " 1 0.052 0.052 5.061 5.061 C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timex_lca.py:1200(add_static_activities_to_time_mapping_dict)\n", + " 78618 0.107 0.000 5.057 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:4578(iterate)\n", + " 1 0.206 0.206 4.733 4.733 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\pandas\\core\\frame.py:9735(explode)\n", + "\n", + "\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 83, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "with Profile() as profile:\n", + " tlca.build_timeline()\n", + " \n", + "Stats(profile).sort_stats(SortKey.CUMULATIVE).print_stats(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 84, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 62205535 function calls (61973453 primitive calls) in 157.458 seconds\n", + "\n", + " Ordered by: cumulative time\n", + " List reduced from 1378 to 10 due to restriction <10>\n", + "\n", + " ncalls tottime percall cumtime percall filename:lineno(function)\n", + " 1 0.000 0.000 157.449 157.449 C:\\Users\\MULLERA\\OneDrive - VITO\\Documents\\04_Coding\\tictac_lca\\bw_timex\\timex_lca.py:268(lci)\n", + " 32 0.001 0.000 112.742 3.523 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\asyncio\\base_events.py:1910(_run_once)\n", + " 32 3.478 0.109 112.536 3.517 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\selectors.py:319(select)\n", + " 1452 0.050 0.000 104.599 0.072 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2data\\utils.py:362(get_node)\n", + "3007/2293 0.005 0.000 96.948 0.042 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:2012(inner)\n", + " 2293 0.002 0.000 96.925 0.042 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:2087(execute)\n", + " 2053 0.004 0.000 96.766 0.047 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:7254(__iter__)\n", + " 2293 0.017 0.000 95.181 0.042 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:2260(_execute)\n", + " 2293 0.008 0.000 95.125 0.041 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:3307(execute)\n", + " 2293 0.016 0.000 93.716 0.041 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\peewee.py:3298(execute_sql)\n", + "\n", + "\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 84, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "with Profile() as profile:\n", + " tlca.lci()\n", + " \n", + "Stats(profile).sort_stats(SortKey.CUMULATIVE).print_stats(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 85, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 7571 function calls (7567 primitive calls) in 0.008 seconds\n", + "\n", + " Ordered by: cumulative time\n", + " List reduced from 241 to 10 due to restriction <10>\n", + "\n", + " ncalls tottime percall cumtime percall filename:lineno(function)\n", + " 25 0.002 0.000 0.003 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw_processing\\datapackage.py:180(filter_by_attribute)\n", + " 1 0.000 0.000 0.002 0.002 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2calc\\utils.py:19(consistent_global_index)\n", + " 1 0.000 0.000 0.002 0.002 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\bw2calc\\lca.py:446(lcia_calculation)\n", + " 1 0.000 0.000 0.002 0.002 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\scipy\\sparse\\_matrix.py:43(__mul__)\n", + " 1 0.000 0.000 0.002 0.002 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\scipy\\sparse\\_base.py:568(_matmul_dispatch)\n", + " 1 0.000 0.000 0.002 0.002 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\scipy\\sparse\\_compressed.py:509(_matmul_sparse)\n", + " 1 0.000 0.000 0.001 0.001 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\matrix_utils\\utils.py:6(filter_groups_for_packages)\n", + " 1 0.001 0.001 0.001 0.001 {built-in method scipy.sparse._sparsetools.csr_matmat}\n", + " 5 0.000 0.000 0.001 0.000 c:\\Users\\MULLERA\\AppData\\Local\\anaconda3\\envs\\timex_temporalis_local\\Lib\\site-packages\\scipy\\sparse\\_coo.py:27(__init__)\n", + " 5390 0.001 0.000 0.001 0.000 {method 'get' of 'dict' objects}\n", + "\n", + "\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 85, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "with Profile() as profile:\n", + " tlca.static_lcia()\n", + "\n", + "Stats(profile).sort_stats(SortKey.CUMULATIVE).print_stats(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 86, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "6.2748978774385025" + ] + }, + "execution_count": 86, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tlca.static_score" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "timex_temporalis_local", + "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.12.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}