Skip to content

doc updated. no change in verison #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions codegreen_core/tools/carbon_emission.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from .carbon_intensity import compute_ci


def compute_ce(
server: dict,
start_time: datetime,
Expand Down Expand Up @@ -46,7 +45,6 @@ def compute_ce(
ce_total, ce_df = compute_ce_from_energy(server, ci_ts)
return ce_total, ce_df


def _compute_energy_used(
runtime_minutes,
number_core,
Expand Down
24 changes: 20 additions & 4 deletions codegreen_core/tools/carbon_intensity.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,24 @@ def _calculate_ci_from_energy_mix(energy_mix):

def compute_ci(country: str, start_time: datetime, end_time: datetime) -> pd.DataFrame:
"""
Computes carbon intensity data for a given country and time period.
Computes the carbon intensity (CI) for a given country and time period.

If energy data is available, the carbon intensity is calculated from actual energy data for the specified time range.
If energy data is not available for the country, a default carbon intensity value is used instead.
The default CI values for all countries are stored in utilities/ci_default_values.csv.
This function determines the energy data source for the country.
- If energy data is available (e.g., from ENTSOE), it calculates CI using actual energy data.
- If energy data is unavailable, it uses default CI values from `ci_default_values.csv` for the country.

:param country: The 2 letter country code.
:type country: str
:param start_time: The start of the time range for which CI is computed.
:type start_time: datetime
:param end_time: The end of the time range for which CI is computed.
:type end_time: datetime

:returns: A pandas DataFrame containing timestamps (`startTimeUTC`) and corresponding carbon intensity values.
:rtype: pd.DataFrame

"""

if not isinstance(country, str):
raise ValueError("Invalid country")

Expand All @@ -133,6 +144,10 @@ def compute_ci(country: str, start_time: datetime, end_time: datetime) -> pd.Dat

if not isinstance(end_time, datetime):
raise ValueError("Invalid end_time")

if start_time >= end_time:
raise ValueError("start_time must be before end_time")


e_source = get_country_energy_source(country)
if e_source == "ENTSOE":
Expand Down Expand Up @@ -190,6 +205,7 @@ def compute_ci_from_energy(
- `Nuclear` (float): Base carbon intensity value for nuclear energy.
- `Solar` (float): Base carbon intensity value for solar energy.
- `Wind` (float): Base carbon intensity value for wind energy.

"""

if not isinstance(energy_data, pd.DataFrame):
Expand Down
10 changes: 3 additions & 7 deletions codegreen_core/tools/loadshift_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ def predict_optimal_location_now(
percent_renewable: int,
hard_finish_date: datetime,
) -> tuple:
"""
Given a list of countries, returns the best location where a computation can be run based on the input criteria
"""
print()
# Given a list of countries, returns the best location where a computation can be run based on the input criteria
# first get data
start_time = datetime.now()
forecast_data = (
Expand Down Expand Up @@ -45,9 +42,8 @@ def predict_optimal_location(
hard_finish_date,
request_date=None,
):
"""
Determines the optimal location and time to run a computation using energy data of the selected locations
"""

#Determines the optimal location and time to run a computation using energy data of the selected locations
## obtain the optimal start time for each country
best_values = {}
current_best = -1
Expand Down
3 changes: 1 addition & 2 deletions codegreen_core/tools/loadshift_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

# ========= the main methods ============


def _get_energy_data(country, start, end):
"""
Get energy data and check if it must be cached based on the options set
Expand Down Expand Up @@ -129,7 +128,7 @@ def predict_optimal_time(
request_time: datetime = None,
) -> tuple:
"""
Predicts the optimal time window to run a task based in energy data, run time estimates and renewable energy target.
Predicts the optimal time window to run a task within the given energy data time frame the run time estimate .

:param energy_data: A DataFrame containing the energy data including startTimeUTC, totalRenewable,total,percent_renewable,posix_timestamp
:param estimated_runtime_hours: The estimated runtime in hours
Expand Down
Loading