Skip to content

Commit

Permalink
Merge branch 'main' into add-release-pr-trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
bennibbelink authored Feb 14, 2024
2 parents 4faffe9 + 4b7796c commit a73d754
Show file tree
Hide file tree
Showing 18 changed files with 1,905 additions and 1,857 deletions.
47 changes: 35 additions & 12 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ jobs:
permissions:
contents: read
packages: write
pull-requests: write

strategy:
fail-fast: false
Expand Down Expand Up @@ -59,21 +58,45 @@ jobs:
continue-on-error: true
uses: docker/build-push-action@v5
with:
cache-from: type=registry,ref=ghcr.io/cyclus/cymetric_${{ matrix.ubuntu_versions }}_${{ matrix.pkg_mgr }}/cymetric:ci-layer-cache
cache-to: type=registry,ref=ghcr.io/cyclus/cymetric_${{ matrix.ubuntu_versions }}_${{ matrix.pkg_mgr }}/cymetric:ci-layer-cache,mode=max
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/cymetric_${{ matrix.ubuntu_versions }}_${{ matrix.pkg_mgr }}/cymetric:ci-layer-cache
cache-to: type=registry,ref=ghcr.io/${{ github.repository_owner }}/cymetric_${{ matrix.ubuntu_versions }}_${{ matrix.pkg_mgr }}/cymetric:ci-layer-cache,mode=max
file: docker/Dockerfile
build-args: |
pkg_mgr=${{ matrix.pkg_mgr }}
ubuntu_version=${{ matrix.ubuntu_versions }}
cycamore_tag=${{ matrix.cycamore_tag }}
- name: PR Comment
if: ${{ github.event_name == 'pull_request' }}
uses: thollander/actions-comment-pull-request@v2
- name: Export Environment Variables
if: github.event_name == 'pull_request'
run: |
echo "BUILD_STATUS=${{steps.build-cymetric.outcome == 'success' && '**Success** :white_check_mark:' ||
steps.build-cymetric.outcome == 'failure' && '**Failure** :x:' ||
'**Skipped due to upstream failure** :warning:'}}" >> "$GITHUB_ENV"
echo "ARTIFACT_NAME=${{ matrix.ubuntu_versions }}_${{ matrix.pkg_mgr }}_${{ matrix.cycamore_tag }}" >> "$GITHUB_ENV"
- name: Construct Artifact
if: github.event_name == 'pull_request'
run: |
echo "Build \`FROM cycamore_${{ matrix.ubuntu_versions }}_${{ matrix.pkg_mgr }}/cycamore:${{ matrix.cycamore_tag }}\` - ${{ env.BUILD_STATUS }}" > ${{ env.ARTIFACT_NAME }}.txt
- name: Upload Artifact
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.ARTIFACT_NAME }}.txt

upload-pr-number:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Save PR number to file
run: |
echo "${{ github.event.number }}" > pr_number
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
comment_tag: ${{ matrix.ubuntu_versions }}_${{ matrix.pkg_mgr }}_${{ matrix.cycamore_tag }}
message: |
## Build statuses using cycamore_${{ matrix.ubuntu_versions }}_${{ matrix.pkg_mgr }}:${{ matrix.cycamore_tag }}
- Cymetric: ${{steps.build-cymetric.outcome == 'success' && '*Success* :white_check_mark:' ||
steps.build-cymetric.outcome == 'failure' && '**Failure** :x:' ||
'**Skipped due to upstream failure** :warning:'}}
name: pr_number
path: pr_number
33 changes: 33 additions & 0 deletions .github/workflows/pr_comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Comment on PR

on:
workflow_run:
workflows: ["Build/Test for PR and collaborator push"]
types:
- completed

jobs:
pr-comment:
runs-on: ubuntu-latest
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
merge-multiple: true

- name: Merge artifacts and get PR number
run: |
echo "### Build Status Report" > artifacts_merged.md
cat ./*.txt >> artifacts_merged.md
echo "PR_NUMBER=$(cat pr_number)" >> "$GITHUB_ENV"
- name: PR Comment
uses: thollander/actions-comment-pull-request@v2
with:
pr_number: ${{ env.PR_NUMBER }}
comment_tag: build_status_report
filePath: artifacts_merged.md

11 changes: 7 additions & 4 deletions .github/workflows/publish_latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ on:
jobs:
build-cymetric-and-push:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

strategy:
matrix:
ubuntu_versions : [
Expand Down Expand Up @@ -52,11 +55,11 @@ jobs:
- name: Build and Test Cymetric
uses: docker/build-push-action@v5
with:
cache-from: type=registry,ref=ghcr.io/cyclus/cymetric_${{ matrix.ubuntu_versions }}_${{ matrix.pkg_mgr }}/cymetric:ci-layer-cache
cache-to: type=registry,ref=ghcr.io/cyclus/cymetric_${{ matrix.ubuntu_versions }}_${{ matrix.pkg_mgr }}/cymetric:ci-layer-cache,mode=max
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/cymetric_${{ matrix.ubuntu_versions }}_${{ matrix.pkg_mgr }}/cymetric:ci-layer-cache
cache-to: type=registry,ref=ghcr.io/${{ github.repository_owner }}/cymetric_${{ matrix.ubuntu_versions }}_${{ matrix.pkg_mgr }}/cymetric:ci-layer-cache,mode=max
file: docker/Dockerfile
push: true
tags: ghcr.io/cyclus/cymetric_${{ matrix.ubuntu_versions }}_${{ matrix.pkg_mgr }}/cymetric:${{ env.tag }}
tags: ghcr.io/${{ github.repository_owner }}/cymetric_${{ matrix.ubuntu_versions }}_${{ matrix.pkg_mgr }}/cymetric:${{ env.tag }}
build-args: |
pkg_mgr=${{ matrix.pkg_mgr }}
ubuntu_version=${{ matrix.ubuntu_versions }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/publish_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ jobs:
- name: Build and Test Cymetric
uses: docker/build-push-action@v5
with:
cache-from: type=registry,ref=ghcr.io/cyclus/cymetric_${{ matrix.ubuntu_versions }}_${{ matrix.pkg_mgr }}/cymetric:ci-layer-cache
cache-to: type=registry,ref=ghcr.io/cyclus/cymetric_${{ matrix.ubuntu_versions }}_${{ matrix.pkg_mgr }}/cymetric:ci-layer-cache,mode=max
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/cymetric_${{ matrix.ubuntu_versions }}_${{ matrix.pkg_mgr }}/cymetric:ci-layer-cache
cache-to: type=registry,ref=ghcr.io/${{ github.repository_owner }}/cymetric_${{ matrix.ubuntu_versions }}_${{ matrix.pkg_mgr }}/cymetric:ci-layer-cache,mode=max
file: docker/Dockerfile
push: true
tags: |
ghcr.io/cyclus/cymetric_${{ matrix.ubuntu_versions }}_${{ matrix.pkg_mgr }}/cymetric:${{ env.version_tag }}
ghcr.io/cyclus/cymetric_${{ matrix.ubuntu_versions }}_${{ matrix.pkg_mgr }}/cymetric:${{ env.stable_tag }}
ghcr.io/${{ github.repository_owner }}/cymetric_${{ matrix.ubuntu_versions }}_${{ matrix.pkg_mgr }}/cymetric:${{ env.version_tag }}
ghcr.io/${{ github.repository_owner }}/cymetric_${{ matrix.ubuntu_versions }}_${{ matrix.pkg_mgr }}/cymetric:${{ env.stable_tag }}
build-args: |
pkg_mgr=${{ matrix.pkg_mgr }}
ubuntu_version=${{ matrix.ubuntu_versions }}
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ cymetric Change Log

.. current developments
**Added:**
* GitHub workflows for CI (#188, #190, #191, #192)
* GitHub workflows for CI (#188, #190, #191, #192, #193)

**Changed**
* Converted test suite from nose to pytest (#188)
* Removed some unused imports, mainly pyne (#184)

v1.5.5
====================
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Dependencies
First, please check to make sure you have all of the dependencies.

Required dependencies:

* Cyclus and its dependencies
* `Jinja2 <http://jinja.pocoo.org/docs/dev/>`_
* `pandas <http://pandas.pydata.org/>`_
Expand Down
1 change: 1 addition & 0 deletions cymetric/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import numpy as np
import pandas as pd


from cymetric.evaluator import Evaluator, METRIC_REGISTRY


Expand Down
14 changes: 11 additions & 3 deletions cymetric/fco_metrics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""FCO metrics"""
import pandas as pd


try:
from pyne import data
import pyne.enrichment as enr
Expand Down Expand Up @@ -167,9 +169,15 @@ def fco_fuel_loading(mats, trans):
mass = mass.groupby(mass.index)['Mass'].sum()
mass = mass.reset_index()
# sum by years (12 time steps)
mass = pd.DataFrame(data={'Year': mass.TimeCreated.apply(lambda x: x // 12),
'FuelLoading': mass.Mass.apply(lambda x: x / 1000)},
columns=['Year', 'FuelLoading'])
mass = pd.DataFrame(
data={
'Year': mass.TimeCreated.apply(
lambda x: x // 12),
'FuelLoading': mass.Mass.apply(
lambda x: x / 1000)},
columns=[
'Year',
'FuelLoading'])
mass = mass.groupby('Year').sum()
rtn = mass.reset_index()
return rtn
Expand Down
4 changes: 0 additions & 4 deletions cymetric/filters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import warnings
import pandas as pd
import numpy as np

try:
from graphviz import Digraph
Expand All @@ -10,8 +8,6 @@

try:
from pyne import data
import pyne.enrichment as enr
from pyne import nucname
HAVE_PYNE = True
except ImportError:
HAVE_PYNE = False
Expand Down
10 changes: 0 additions & 10 deletions cymetric/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,13 @@
"""
import warnings

import pandas as pd
import numpy as np

try:
from graphviz import Digraph
HAVE_GRAPHVIZ = True
except ImportError:
HAVE_GRAPHVIZ = False

try:
from pyne import data
import pyne.enrichment as enr
from pyne import nucname
HAVE_PYNE = True
except ImportError:
HAVE_PYNE = False

from cymetric import tools
from cymetric.filters import transactions_nuc

Expand Down
4 changes: 2 additions & 2 deletions cymetric/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import numpy as np
import pandas as pd


try:
from pyne import data
import pyne.enrichment as enr
HAVE_PYNE = True
except ImportError:
HAVE_PYNE = False
Expand Down Expand Up @@ -284,7 +284,7 @@ def agents(entry, exit, decom, info):
mergeon = ['SimId', 'AgentId']
df = entry[['SimId', 'AgentId', 'Kind', 'Spec', 'Prototype', 'ParentId',
'Lifetime', 'EnterTime']]
df['ExitTime'] = [np.nan]*len(entry)
df['ExitTime'] = [np.nan] * len(entry)
if exit is not None:
exit.columns = ['SimId', 'AgentId', 'Exits']
df = tools.merge_and_fillna_col(df, exit[['SimId', 'AgentId',
Expand Down
6 changes: 3 additions & 3 deletions cymetric/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
else:
str_types = (str, unicode)

from cyclus import typesystem as ts
from cyclus.typesystem import NAMES, RANKS, IDS


Expand Down Expand Up @@ -40,8 +39,9 @@ def canon_shape(shape, dbtype):
s.append(i)
rank = RANKS[dbtype]
if len(s) != rank:
msg = ('the shape rank for the {0} type must be {1}, got {2} for a '
'shape of {3}.')
msg = (
'the shape rank for the {0} type must be {1}, got {2} for a '
'shape of {3}.')
raise ValueError(msg.format(NAMES[dbtype], rank, len(s), s))
rtn = tuple(s)
elif isinstance(shape, int):
Expand Down
22 changes: 8 additions & 14 deletions cymetric/timeseries.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
import warnings

import pandas as pd
import numpy as np

try:
from pyne import data
import pyne.enrichment as enr
from pyne import nucname
HAVE_PYNE = True
except ImportError:
HAVE_PYNE = False

from cymetric import tools
from cymetric import filters

Expand Down Expand Up @@ -42,7 +31,12 @@ def transactions(evaler, senders=(), receivers=(), commodities=(), nucs=()):
return df


def transactions_activity(evaler, senders=(), receivers=(), commodities=(), nucs=()):
def transactions_activity(
evaler,
senders=(),
receivers=(),
commodities=(),
nucs=()):
"""
Shape the reduced transation Data Frame into a simple time serie. Applying nuclides selection when required.
Expand Down Expand Up @@ -86,8 +80,8 @@ def transactions_decayheat(
if len(nucs) != 0:
nucs = tools.format_nucs(nucs)

df = filters.transactions_decayheat(evaler, senders, receivers, commodities,
nucs)
df = filters.transactions_decayheat(
evaler, senders, receivers, commodities, nucs)

df = df[['Time', 'DecayHeat']].groupby(['Time']).sum()
df.reset_index(inplace=True)
Expand Down
9 changes: 4 additions & 5 deletions cymetric/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
import sys
import warnings

import numpy as np
import pandas as pd


try:
from pyne import data
import pyne.enrichment as enr
from pyne import nucname
HAVE_PYNE = True
except ImportError:
Expand All @@ -26,8 +24,9 @@ def dbopen(fname):
"""Opens a Cyclus database."""
_, ext = os.path.splitext(fname)
if ext not in EXT_BACKENDS:
msg = ('The backend database type of {0!r} could not be determined from '
'extension {1!r}.')
msg = (
'The backend database type of {0!r} could not be determined from '
'extension {1!r}.')
raise ValueError(msg.format(fname, ext))
db = EXT_BACKENDS[ext](fname)
return db
Expand Down
Loading

0 comments on commit a73d754

Please sign in to comment.