Skip to content

Commit bad6541

Browse files
committed
doc update
1 parent 457ca26 commit bad6541

File tree

7 files changed

+28
-20
lines changed

7 files changed

+28
-20
lines changed

codegreen_core/tools/carbon_emission.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from .carbon_intensity import compute_ci
88

9-
109
def compute_ce(
1110
server: dict,
1211
start_time: datetime,
@@ -46,7 +45,6 @@ def compute_ce(
4645
ce_total, ce_df = compute_ce_from_energy(server, ci_ts)
4746
return ce_total, ce_df
4847

49-
5048
def _compute_energy_used(
5149
runtime_minutes,
5250
number_core,

codegreen_core/tools/carbon_intensity.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,24 @@ def _calculate_ci_from_energy_mix(energy_mix):
118118

119119
def compute_ci(country: str, start_time: datetime, end_time: datetime) -> pd.DataFrame:
120120
"""
121-
Computes carbon intensity data for a given country and time period.
121+
Computes the carbon intensity (CI) for a given country and time period.
122122
123-
If energy data is available, the carbon intensity is calculated from actual energy data for the specified time range.
124-
If energy data is not available for the country, a default carbon intensity value is used instead.
125-
The default CI values for all countries are stored in utilities/ci_default_values.csv.
123+
This function determines the energy data source for the country.
124+
- If energy data is available (e.g., from ENTSOE), it calculates CI using actual energy data.
125+
- If energy data is unavailable, it uses default CI values from `ci_default_values.csv` for the country.
126+
127+
:param country: The 2 letter country code.
128+
:type country: str
129+
:param start_time: The start of the time range for which CI is computed.
130+
:type start_time: datetime
131+
:param end_time: The end of the time range for which CI is computed.
132+
:type end_time: datetime
133+
134+
:returns: A pandas DataFrame containing timestamps (`startTimeUTC`) and corresponding carbon intensity values.
135+
:rtype: pd.DataFrame
126136
127137
"""
138+
128139
if not isinstance(country, str):
129140
raise ValueError("Invalid country")
130141

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

134145
if not isinstance(end_time, datetime):
135146
raise ValueError("Invalid end_time")
147+
148+
if start_time >= end_time:
149+
raise ValueError("start_time must be before end_time")
150+
136151

137152
e_source = get_country_energy_source(country)
138153
if e_source == "ENTSOE":
@@ -190,6 +205,7 @@ def compute_ci_from_energy(
190205
- `Nuclear` (float): Base carbon intensity value for nuclear energy.
191206
- `Solar` (float): Base carbon intensity value for solar energy.
192207
- `Wind` (float): Base carbon intensity value for wind energy.
208+
193209
"""
194210

195211
if not isinstance(energy_data, pd.DataFrame):

codegreen_core/tools/loadshift_location.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ def predict_optimal_location_now(
1111
percent_renewable: int,
1212
hard_finish_date: datetime,
1313
) -> tuple:
14-
"""
15-
Given a list of countries, returns the best location where a computation can be run based on the input criteria
16-
"""
17-
print()
14+
# Given a list of countries, returns the best location where a computation can be run based on the input criteria
1815
# first get data
1916
start_time = datetime.now()
2017
forecast_data = (
@@ -45,9 +42,8 @@ def predict_optimal_location(
4542
hard_finish_date,
4643
request_date=None,
4744
):
48-
"""
49-
Determines the optimal location and time to run a computation using energy data of the selected locations
50-
"""
45+
46+
#Determines the optimal location and time to run a computation using energy data of the selected locations
5147
## obtain the optimal start time for each country
5248
best_values = {}
5349
current_best = -1

codegreen_core/tools/loadshift_time.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
# ========= the main methods ============
1818

19-
2019
def _get_energy_data(country, start, end):
2120
"""
2221
Get energy data and check if it must be cached based on the options set
@@ -129,7 +128,7 @@ def predict_optimal_time(
129128
request_time: datetime = None,
130129
) -> tuple:
131130
"""
132-
Predicts the optimal time window to run a task based in energy data, run time estimates and renewable energy target.
131+
Predicts the optimal time window to run a task within the given energy data time frame the run time estimate .
133132
134133
:param energy_data: A DataFrame containing the energy data including startTimeUTC, totalRenewable,total,percent_renewable,posix_timestamp
135134
:param estimated_runtime_hours: The estimated runtime in hours

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Welcome to codegreen_core's documentation!
1414
features
1515
installation
1616
setup
17+
Tutorial <https://github.com/codegreen-framework/codegreen-core/blob/main/docs/Tutorials.ipynb>
1718
api
1819
status
1920
methodology

docs/methodology.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ One challenge with the carbon intensity calculation is that the values can vary
3636
When energy generation data is not available for a country, the average values of Carbon Intensity is used. The source of this data is Carbon Footprint Ltd [8]
3737

3838

39-
4039
Carbon emission of a job
4140
-------------------------
4241

43-
**The Methodology for calculating carbon emissions** (Based on [7])
42+
The Methodology for calculating carbon emissions is based on [7]
4443

4544
Carbon emission of a job depends on 2 factors : Energy consumed by the hardware to run the computation and the emissions generated to produce this energy. The unit used is CO2e or Carbon dioxide equivalent.
4645

@@ -57,4 +56,3 @@ Carbon emission of a job depends on 2 factors : Energy consumed by the hardware
5756

5857
- Emissions related to the production of the energy : represented by the Carbon Intensity of the energy mix during that period. Already implemented above
5958
- The result is Carbon emission in CO2e
60-

docs/references.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ References
44
This page lists out all the references to external sources used in the documentation.
55

66

7-
- [1] J. Malmodin, N. Lövehagen, P. Bergmark, and D. Lundén, ICT sector electricity consumption and greenhouse gas emissions 2020 outcome, Telecommunications Policy, vol. 48, no. 3, p. 102701, Apr. 2024, doi: 10.1016/j.telpol.2023.102701.
8-
- [2] E. Strubell, A. Ganesh, and A. McCallum, Energy and Policy Considerations for Deep Learning in NLP, Jun. 05, 2019, arXiv: arXiv:1906.02243. Accessed: Oct. 11, 2024. [Online]. Available: http://arxiv.org/abs/1906.02243
7+
- [1] J. Malmodin, N. Lövehagen, P. Bergmark, and D. Lundén, 'ICT sector electricity consumption and greenhouse gas emissions - 2020 outcome', Telecommunications Policy, vol. 48, no. 3, p. 102701, Apr. 2024, doi: 10.1016/j.telpol.2023.102701.
8+
- [2] E. Strubell, A. Ganesh, and A. McCallum, 'Energy and Policy Considerations for Deep Learning in NLP', Jun. 05, 2019, arXiv: arXiv:1906.02243. Accessed: Oct. 11, 2024. [Online]. Available: http://arxiv.org/abs/1906.02243
99
- [3] Carbon intensity of electricity generation https://ourworldindata.org/grapher/carbon-intensity-electricity (Accessed 11-10-24)
1010
- [4] N. Scarlat, M. Prussi, and M. Padella, “Quantification of the carbon intensity of electricity produced and used in Europe,” Applied Energy, vol. 305. Elsevier BV, p. 117901, Jan. 2022. doi: 10.1016/j.apenergy.2021.117901.
1111
- [5] Schlömer S., T. Bruckner, L. Fulton, E. Hertwich, A. McKinnon, D. Perczyk, J. Roy, R. Schaeffer, R. Sims, P. Smith, and R. Wiser, 2014: Annex III: Technology-specific cost and performance parameters. In: Climate Change 2014: Mitigation of Climate Change. Contribution of Working Group III to the Fifth Assessment Report of the Intergovernmental Panel on Climate Change [Edenhofer, O., R. Pichs-Madruga, Y. Sokona, E. Farahani, S. Kadner, K. Seyboth, A. Adler, I. Baum, S. Brunner, P. Eickemeier, B. Kriemann, J. Savolainen, S. Schlömer, C. von Stechow, T. Zwickel and J.C. Minx (eds.)]. Cambridge University Press, Cambridge, United Kingdom and New York, NY, USA. (https://www.ipcc.ch/site/assets/uploads/2018/02/ipcc_wg3_ar5_annex-iii.pdf#page=7) (Accessed 11-10-24)

0 commit comments

Comments
 (0)