Skip to content

Commit

Permalink
removed CPU TDP setup as it doesnt really work, added a check to remo…
Browse files Browse the repository at this point in the history
…ve codecarbon.lock file during init to prevent multiple instance issues
  • Loading branch information
jzvolensky committed Jan 16, 2025
1 parent 0c28380 commit 40e9166
Show file tree
Hide file tree
Showing 2 changed files with 243 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -76,14 +76,14 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"[codecarbon INFO @ 09:19:47] offline tracker init\n"
"[codecarbon INFO @ 11:20:05] offline tracker init\n"
]
}
],
Expand All @@ -93,7 +93,6 @@
" log_level=\"error\",\n",
" save_to_file=True,\n",
" output_dir=\"./\",\n",
" default_cpu_power=21 # TODO: Set the correct value\n",
")"
]
},
Expand All @@ -112,7 +111,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -177,19 +176,19 @@
" <!-- LED Bulb Runtime Metric -->\n",
" <div class=\"item\">\n",
" <img src=\"../assets/lightbulb.svg\" alt=\"LED Bulb\">\n",
" <p><strong>LED Bulb Runtime:</strong><br>0.38 seconds </p>\n",
" <p><strong>LED Bulb Runtime:</strong><br>0.15 seconds </p>\n",
" <span class=\"tooltip\">\n",
" This energy is equivalent to powering a standard 10W LED bulb for 0.38 seconds .\n",
" This energy is equivalent to powering a standard 10W LED bulb for 0.15 seconds .\n",
" </span>\n",
" </div>\n",
" \n",
" <!-- Smartwatch Runtime Metric -->\n",
" <div class=\"item\">\n",
" <img src=\"../assets/smartwatch.svg\" alt=\"Smartwatch\">\n",
" <p><strong>Smartwatch Runtime idle use:</strong><br>1.06 minutes </p>\n",
" <p><strong>Smartwatch Runtime normal use:</strong><br>7.66 seconds </p>\n",
" <p><strong>Smartwatch Runtime idle use:</strong><br>24.50 seconds </p>\n",
" <p><strong>Smartwatch Runtime normal use:</strong><br>2.94 seconds </p>\n",
" <span class=\"tooltip\">\n",
" The amount of energy used to run the code could power a smartwatch for 1.06 minutes in idle mode and for 7.66 seconds in regular use mode .\n",
" The amount of energy used to run the code could power a smartwatch for 24.50 seconds in idle mode and for 2.94 seconds in regular use mode .\n",
" </span>\n",
" </div>\n",
" </div>\n",
Expand All @@ -206,7 +205,7 @@
" text-align: center;\n",
" box-sizing: border-box;\n",
" position: relative;\n",
" border: 2px solid transparent; /* Initial border */\n",
" border: 2px solid transparent;\n",
" transition: border-color 0.3s;\n",
" }\n",
" .item img {\n",
Expand Down Expand Up @@ -253,9 +252,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Starting experiment: 2\n",
"Stopped experiment: 2\n"
]
}
],
"source": [
"tracker.start_experiment(experiment_id=2)\n",
"\n",
Expand Down Expand Up @@ -290,9 +298,103 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/html": [
"<!DOCTYPE html>\n",
"<html lang=\"en\">\n",
" <head>\n",
" <meta charset=\"UTF-8\" />\n",
" <title>Emission Equivalents for Latest Run</title>\n",
" </head>\n",
" <body>\n",
" <h2>Emission Equivalents for Latest Run</h2>\n",
" <div class=\"container\">\n",
" <!-- Mars Rover Perseverance Metric -->\n",
" <div class=\"item\">\n",
" <img src=\"../assets/marsrover.svg\" alt=\"Mars Rover\">\n",
" <p><strong>Mars Rover Perseverance distance:</strong><br>0.18 Meters</p>\n",
" <span class=\"tooltip\">\n",
" This is equivalent to the amount of energy required to move the Perseverance rover 0.18 meters.\n",
" </span>\n",
" </div>\n",
" \n",
" <!-- LED Bulb Runtime Metric -->\n",
" <div class=\"item\">\n",
" <img src=\"../assets/lightbulb.svg\" alt=\"LED Bulb\">\n",
" <p><strong>LED Bulb Runtime:</strong><br>1.29 minutes </p>\n",
" <span class=\"tooltip\">\n",
" This energy is equivalent to powering a standard 10W LED bulb for 1.29 minutes .\n",
" </span>\n",
" </div>\n",
" \n",
" <!-- Smartwatch Runtime Metric -->\n",
" <div class=\"item\">\n",
" <img src=\"../assets/smartwatch.svg\" alt=\"Smartwatch\">\n",
" <p><strong>Smartwatch Runtime idle use:</strong><br>3.57 hours </p>\n",
" <p><strong>Smartwatch Runtime normal use:</strong><br>25.72 minutes </p>\n",
" <span class=\"tooltip\">\n",
" The amount of energy used to run the code could power a smartwatch for 3.57 hours in idle mode and for 25.72 minutes in regular use mode .\n",
" </span>\n",
" </div>\n",
" </div>\n",
" </body>\n",
" <style>\n",
" .container {\n",
" display: flex;\n",
" flex-wrap: wrap;\n",
" min-height: 300px;\n",
" }\n",
" .item {\n",
" flex: 1;\n",
" padding: 10px;\n",
" text-align: center;\n",
" box-sizing: border-box;\n",
" position: relative;\n",
" border: 2px solid transparent;\n",
" transition: border-color 0.3s;\n",
" }\n",
" .item img {\n",
" width: 100px;\n",
" height: 100px;\n",
" transition: transform 0.3s;\n",
" }\n",
" .item:hover {\n",
" border-color: #838383; \n",
" }\n",
" .item:hover img {\n",
" transform: scale(1.2);\n",
" }\n",
" .tooltip {\n",
" display: none; \n",
" color: #000000;\n",
" text-align: center;\n",
" margin-top: 10px;\n",
" border-radius: 5px;\n",
" padding: 5px;\n",
" background-color: #ffffff;\n",
" }\n",
" .item:hover .tooltip {\n",
" display: block; \n",
" }\n",
" body {\n",
" background-color: #121212;\n",
" color: #ffffff;\n",
" }\n",
"</style>\n",
"</html>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"calculate_emission_equivalents(experiment_id=2)"
]
Expand All @@ -319,9 +421,32 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Starting experiment: 3\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/jzvolensky/miniconda3/envs/cubes-and-clouds/lib/python3.11/site-packages/xarray/core/groupby.py:508: FutureWarning: 'M' is deprecated and will be removed in a future version, please use 'ME' instead.\n",
" index_grouper = pd.Grouper(\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Stopped experiment: 3\n"
]
}
],
"source": [
"tracker.start_experiment(experiment_id=3)\n",
"\n",
Expand Down Expand Up @@ -351,9 +476,103 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/html": [
"<!DOCTYPE html>\n",
"<html lang=\"en\">\n",
" <head>\n",
" <meta charset=\"UTF-8\" />\n",
" <title>Emission Equivalents for Latest Run</title>\n",
" </head>\n",
" <body>\n",
" <h2>Emission Equivalents for Latest Run</h2>\n",
" <div class=\"container\">\n",
" <!-- Mars Rover Perseverance Metric -->\n",
" <div class=\"item\">\n",
" <img src=\"../assets/marsrover.svg\" alt=\"Mars Rover\">\n",
" <p><strong>Mars Rover Perseverance distance:</strong><br>1.67 Meters</p>\n",
" <span class=\"tooltip\">\n",
" This is equivalent to the amount of energy required to move the Perseverance rover 1.67 meters.\n",
" </span>\n",
" </div>\n",
" \n",
" <!-- LED Bulb Runtime Metric -->\n",
" <div class=\"item\">\n",
" <img src=\"../assets/lightbulb.svg\" alt=\"LED Bulb\">\n",
" <p><strong>LED Bulb Runtime:</strong><br>11.63 minutes </p>\n",
" <span class=\"tooltip\">\n",
" This energy is equivalent to powering a standard 10W LED bulb for 11.63 minutes .\n",
" </span>\n",
" </div>\n",
" \n",
" <!-- Smartwatch Runtime Metric -->\n",
" <div class=\"item\">\n",
" <img src=\"../assets/smartwatch.svg\" alt=\"Smartwatch\">\n",
" <p><strong>Smartwatch Runtime idle use:</strong><br>32.29 hours </p>\n",
" <p><strong>Smartwatch Runtime normal use:</strong><br>3.88 hours </p>\n",
" <span class=\"tooltip\">\n",
" The amount of energy used to run the code could power a smartwatch for 32.29 hours in idle mode and for 3.88 hours in regular use mode .\n",
" </span>\n",
" </div>\n",
" </div>\n",
" </body>\n",
" <style>\n",
" .container {\n",
" display: flex;\n",
" flex-wrap: wrap;\n",
" min-height: 300px;\n",
" }\n",
" .item {\n",
" flex: 1;\n",
" padding: 10px;\n",
" text-align: center;\n",
" box-sizing: border-box;\n",
" position: relative;\n",
" border: 2px solid transparent;\n",
" transition: border-color 0.3s;\n",
" }\n",
" .item img {\n",
" width: 100px;\n",
" height: 100px;\n",
" transition: transform 0.3s;\n",
" }\n",
" .item:hover {\n",
" border-color: #838383; \n",
" }\n",
" .item:hover img {\n",
" transform: scale(1.2);\n",
" }\n",
" .tooltip {\n",
" display: none; \n",
" color: #000000;\n",
" text-align: center;\n",
" margin-top: 10px;\n",
" border-radius: 5px;\n",
" padding: 5px;\n",
" background-color: #ffffff;\n",
" }\n",
" .item:hover .tooltip {\n",
" display: block; \n",
" }\n",
" body {\n",
" background-color: #121212;\n",
" color: #ffffff;\n",
" }\n",
"</style>\n",
"</html>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"calculate_emission_equivalents(experiment_id=3)"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class CustomEmissionsTracker(OfflineEmissionsTracker):
"""

def __init__(self, *args, **kwargs):

lock_file="/tmp/.codecarbon.lock"
if os.path.exists(lock_file):
os.remove(lock_file)
carbon_logger.debug("Removed lock file to prevent double tracker instances.")
super().__init__(*args, **kwargs)
self.current_experiment_id = None
self.emissions_file = os.path.join(
Expand Down

0 comments on commit 40e9166

Please sign in to comment.