core

Fill in a module description here
# collapse_hide
df_run = pd.DataFrame()
for xp in r_xp.json():
    
    experiment_id = xp["experiment_id"]
    url=URL + "/runs/experiment/" + experiment_id
    print(xp["name"], url)
    r = requests.get(url, timeout=2)
    assert r.status_code == 200
    # We keep only the N last run
    for run in r.json()[-2:]:
        run_id = run["id"]
        page = 1
        #while True:
        while page<3:
            url = URL + "/emissions/run/" + run_id + "?size=1000&page=" + str(page)
            r = requests.get(url=url, timeout=30)
            assert r.status_code == 200
            if r.json()["items"] == []:
                break
            df_last_run = pd.DataFrame(r.json()["items"])
            print(f"Il y a {len(df_last_run)} émissions dans {url}")
            df_last_run["datacenter"] = xp["name"]
            df_run = pd.concat([df_run, df_last_run])
            page += 1

df_run.head(1)
df_run.tail(1)
DC5 https://api.codecarbon.io/runs/experiment/0bfa2432-efda-4656-bdb4-f72d15866b0b
Il y a 102 émissions dans https://api.codecarbon.io/emissions/run/09762fc4-08e5-4f9f-b796-bddd90e7fdad?size=1000&page=1
Il y a 1000 émissions dans https://api.codecarbon.io/emissions/run/8d2890eb-8e64-4271-9bc9-61b6860b0345?size=1000&page=1
Il y a 1000 émissions dans https://api.codecarbon.io/emissions/run/8d2890eb-8e64-4271-9bc9-61b6860b0345?size=1000&page=2
DC2 https://api.codecarbon.io/runs/experiment/ea060644-5303-4a68-8fb2-d0902b269022
Il y a 1000 émissions dans https://api.codecarbon.io/emissions/run/63ec8a01-e03b-4130-b101-9a4c084f0ddd?size=1000&page=1
Il y a 1000 émissions dans https://api.codecarbon.io/emissions/run/63ec8a01-e03b-4130-b101-9a4c084f0ddd?size=1000&page=2
Il y a 1000 émissions dans https://api.codecarbon.io/emissions/run/00d90dd0-6b6c-4ceb-9a8d-78c34cfe48b1?size=1000&page=1
Il y a 1000 émissions dans https://api.codecarbon.io/emissions/run/00d90dd0-6b6c-4ceb-9a8d-78c34cfe48b1?size=1000&page=2
timestamp run_id duration emissions_sum emissions_rate energy_consumed cpu_power gpu_power ram_power cpu_energy gpu_energy ram_energy id datacenter
999 2022-12-10T20:04:15.174623 00d90dd0-6b6c-4ceb-9a8d-78c34cfe48b1 303 0.000113 0.000373 0.002061 23.761942 0.0 0.09375 0.002053 0.0 0.000008 19288d97-e24d-44fb-85a3-895182984ff2 DC2
print(f"Nombre d'émissions : {len(df_run):,}")
Nombre d'émissions : 6,102
fig = px.line(df_run, x="timestamp", y=["cpu_power"], color="datacenter")
fig.show()