Skip to content

updating main from release #10

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 5 commits into from
Nov 25, 2024
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
93 changes: 93 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Publish Python 🐍 distribution 📦 to PyPI

on:
push:
branches:
- release

jobs:
build:
name: Build distribution 📦
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11.9"
- name: Install Poetry
run: |
python3 -m pip install poetry --user
- name: Install dependencies and build the project
run: |
poetry install --no-dev
poetry build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: Publish Python 🐍 distribution 📦 to PyPI
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/codegreen-core
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

github-release:
name: >-
Sign the Python 🐍 distribution 📦 with Sigstore
and upload them to GitHub Release
needs:
- publish-to-pypi
runs-on: ubuntu-latest

permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/gh-action-sigstore-python@v3.0.0
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--notes ""
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,7 @@ tests/data1
codegreen_core/models/files
Dockerfile
.vscode
poetry.lock
poetry.lock

codegreen_core/tools/test.py
codegreen_core/data/test.py
34 changes: 17 additions & 17 deletions codegreen_core/tools/carbon_emission.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,9 @@ def compute_ce_from_energy(server, ci_data: pd.DataFrame):
"""
date_format = "%Y%m%d%H%M" # Year, Month, Day, Hour, Minute

server_defaults = {
"power_draw_core": 15.8,
"usage_factor_core": 1,
"power_draw_mem": 0.3725,
"power_usage_efficiency": 1.6,
}
server = server_defaults | server # set defaults if not provided

server = _add_server_defaults(server) # set defaults if not provided
# print(server)
# to make sure startTimeUTC is in date format
if not pd.api.types.is_datetime64_any_dtype(ci_data["startTimeUTC"]):
ci_data["startTimeUTC"] = pd.to_datetime(ci_data["startTimeUTC"])
Expand Down Expand Up @@ -208,7 +203,7 @@ def compute_ce_from_energy(server, ci_data: pd.DataFrame):

def _compute_ce_bulk(server, jobs):
for job in jobs:
job.end_time = job["start_time"] + timedelta(minutes=job["runtime_minutes"])
job['end_time'] = job["start_time"] + timedelta(minutes=job["runtime_minutes"])

min_start_date = min(job["start_time"] for job in jobs)
max_end_date = max(job["end_time"] for job in jobs)
Expand All @@ -222,19 +217,23 @@ def _compute_ce_bulk(server, jobs):
& (energy_data["startTimeUTC"] <= job["end_time"])
]
job["emissions"], temp = compute_ce_from_energy(
filtered_energy,
server["number_core"],
server["memory_gb"],
server["power_draw_core"],
server["usage_factor_core"],
server["power_draw_mem"],
server["power_usage_efficiency"],
server,
filtered_energy
)
return energy_data, jobs, min_start_date, max_end_date

def _add_server_defaults(server):
server_defaults = {
"power_draw_core": 15.8,
"usage_factor_core": 1,
"power_draw_mem": 0.3725,
"power_usage_efficiency": 1.6,
}
server = server_defaults | server # set defaults if not provided
return server

def plot_ce_jobs(server, jobs):
energy_data, jobs, min_start_date, max_end_date = _compute_ce_bulk(server, jobs)
energy_data, jobs, min_start_date, max_end_date = _compute_ce_bulk(_add_server_defaults(server), jobs)
Color = {
"red": "#D6A99A",
"green": "#99D19C",
Expand Down Expand Up @@ -294,4 +293,5 @@ def plot_ce_jobs(server, jobs):
# Add legend and show the plot
fig.tight_layout()
# plt.legend(loc='lower right')
plt.show()
plt.show(block=True)
# plt.pyplot.show()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "codegreen_core"
version = "0.5.0"
version = "0.0.2"
description = "This package helps you become aware of the carbon footprint of your computation"
authors = ["Anne Hartebrodt <anne.hartebrodt@fau.de>","Shubh Vardhan Jain <shubh.v.jain@fau.de>"]
readme = "README.md"
Expand Down
Loading