MCPcopy Create free account
hub / github.com/mlco2/codecarbon / _create_run

Method _create_run

codecarbon/core/api_client.py:249–298  ·  view source on GitHub ↗

Create the experiment for project_id

(self, experiment_id: str)

Source from the content-addressed store, hash-verified

247 return True
248
249 def _create_run(self, experiment_id: str):
250 """
251 Create the experiment for project_id
252 """
253 if self.experiment_id is None:
254 # TODO : raise an Exception ?
255 logger.error(
256 "ApiClient FATAL The ApiClient._create_run() needs an experiment_id !"
257 )
258 return None
259 try:
260 run = RunCreate(
261 timestamp=get_datetime_with_timezone(),
262 experiment_id=experiment_id,
263 os=self.conf.get("os"),
264 python_version=self.conf.get("python_version"),
265 codecarbon_version=self.conf.get("codecarbon_version"),
266 cpu_count=self.conf.get("cpu_count"),
267 cpu_model=self.conf.get("cpu_model"),
268 gpu_count=self.conf.get("gpu_count"),
269 gpu_model=self.conf.get("gpu_model"),
270 # Reduce precision for Privacy
271 longitude=round(self.conf.get("longitude", 0), 1),
272 latitude=round(self.conf.get("latitude", 0), 1),
273 region=self.conf.get("region"),
274 provider=self.conf.get("provider"),
275 ram_total_size=self.conf.get("ram_total_size"),
276 tracking_mode=self.conf.get("tracking_mode"),
277 )
278 payload = dataclasses.asdict(run)
279 url = self.url + "/runs"
280 headers = self._get_headers()
281 r = requests.post(url=url, json=payload, timeout=2, headers=headers)
282 if r.status_code != 201:
283 self._log_error(url, payload, r)
284 return None
285 self.run_id = r.json()["id"]
286 logger.info(
287 "ApiClient Successfully registered your run on the API.\n\n"
288 + f"Run ID: {self.run_id}\n"
289 + f"Experiment ID: {self.experiment_id}\n"
290 )
291 return self.run_id
292 except requests.exceptions.ConnectionError as e:
293 logger.error(
294 f"Failed to connect to API, please check the configuration. {e}",
295 exc_info=False,
296 )
297 except Exception as e:
298 logger.error(e, exc_info=True)
299
300 def list_experiments_from_project(self, project_id: str):
301 """

Callers 3

__init__Method · 0.95
add_emissionMethod · 0.95

Calls 5

_get_headersMethod · 0.95
_log_errorMethod · 0.95
RunCreateClass · 0.90
jsonMethod · 0.80