Skip to content

Conversation

@mezzeddinee
Copy link
Collaborator

The current repository for Green DIRAC still contains the initial impl of the GreenSiteDirector (e.g., CIM token is not dynamic), This PR shall correct the issue and contains the latest updates...

mezzeddinee and others added 6 commits October 11, 2025 14:38
# Conflicts:
#	src/GreenDIRAC/WorkloadManagementSystem/Agent/GreenReportingAgent.py
#	src/GreenDIRAC/__init__.py
- Introduced SiteDirectorGreen for green-aware pilot scheduling
- Integrates with GD-CI and CIM APIs to fetch live PUE and carbon intensity (CI)
- Caches metrics and computes combined green efficiency score (30% PUE / 70% CI)
- Sorts queues by green efficiency before submitting pilots
- Maintains full compatibility with standard DIRAC SiteDirector logic
- Initial implementation does not yet use class inheritance;
  will be refactored in a future PR to extend the base SiteDirector cleanly
…robust JobDB storage

- Added direct CIM API integration for fetching PUE and CI via GOCDB site mapping.
- Implemented automatic JWT token retrieval and caching for CIM API authentication.
- Computed energy (kWh) and CO₂ emissions (gCO₂) per job using TDP, PUE, and CI.
- Enhanced logging: added site-level summaries and detailed per-job reporting.
self.maxJobsAtOnce = self.am_getOption("MaxJobsAtOnce", self.maxJobsAtOnce)
self.login = self.am_getOption("CIM_EMAIL", self.login)
self.password = self.am_getOption("CIM_PASSWORD", self.password)
self.cim_api_base = self.am_getOption("cim_api_base", self.cim_api_base)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put it into the configuration

def initialize(self):
"""Sets defaults"""
# CIM API settings
self.login = "atsareg@in2p3.fr"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this and the next line

pue, ci, gocdb = siteRes["Value"]

cpu_s = float(rec.get("TotalCPUTime(s)", 0))
energy_kwh = cpu_s * tdp / cores / 1000.0 / 3600.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this a separate function. Later we can have several models/functions to compare

emissions = energy_kwh * pue * ci / 1000.0 # gCO2

rec.update({
"Energy(kwh)": energy_kwh,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the record field values against the common "Catalin's" document

age = (time.time() - float(self.token_ts)) / 3600
if age < self.token_max_age_hours:
return self.token
url = f"{self.cim_api_base.rstrip('/')}/../gd-cim-api/get-token"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplify,correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants