Skip to content

Portfolio Optimization Notebook Runner #51

Portfolio Optimization Notebook Runner

Portfolio Optimization Notebook Runner #51

Workflow file for this run

name: Portfolio Optimization Notebook Runner
on:
push:
branches:
- main
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
run-notebooks:
runs-on: arc-runners-org-nvidia-ai-bp-1-gpu
env:
PYTHON_VERSION: 3.12
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install Git LFS
run: |
echo "===================== Install Git LFS ====================="
sudo apt-get update
sudo apt-get install -y git-lfs
git lfs install
- name: Pull Git LFS files
run: |
echo "===================== Pull LFS files ====================="
git lfs pull
- name: Check System Info
run: |
echo "===================== System Info ====================="
more /etc/os-release
uname -a
docker version
- name: Run container and execute notebooks
run: |
docker run --gpus all --rm \
-v "$(pwd):/workspace" \
-w /workspace \
nvcr.io/nvidia/pytorch:25.08-py3 \
bash -c '
set -e
echo "===================== Python and GPU Info ====================="
python --version
nvidia-smi
echo "===================== Install uv ====================="
curl -LsSf https://astral.sh/uv/install.sh | sh
export PATH="/root/.cargo/bin:$PATH"
source $HOME/.local/bin/env
echo "===================== Install Dependencies with uv ====================="
uv sync --extra cuda13
uv sync --extra cuda13 --extra dev
echo "===================== Install Jupyter and other packages ====================="
pip install jupyter jupyterlab ipykernel papermill nbconvert
echo "===================== Create Jupyter Kernel ====================="
uv run python -m ipykernel install --user --name=portfolio-opt --display-name "Portfolio Optimization"
echo "===================== List Jupyter Kernel ====================="
jupyter kernelspec list
echo "===================== Change to notebooks directory ====================="
cd notebooks
echo "===================== Run cvar_basic notebook ====================="
papermill cvar_basic.ipynb cvar_basic_result.ipynb --kernel portfolio-opt --log-output --log-level DEBUG
echo "===================== Run efficient_frontier notebook ====================="
papermill efficient_frontier.ipynb efficient_frontier_result.ipynb --kernel portfolio-opt --log-output --log-level DEBUG
echo "===================== Run rebalancing_strategies notebook ====================="
papermill rebalancing_strategies.ipynb rebalancing_strategies_result.ipynb --kernel portfolio-opt --log-output --log-level DEBUG
echo "===================== Run launchable notebook ====================="
papermill launchable.ipynb launchable_brev_result.ipynb --kernel portfolio-opt --log-output --log-level DEBUG
echo "===================== Convert notebooks to HTML ====================="
jupyter nbconvert --to html cvar_basic_result.ipynb
jupyter nbconvert --to html efficient_frontier_result.ipynb
jupyter nbconvert --to html rebalancing_strategies_result.ipynb
jupyter nbconvert --to html launchable_brev_result.ipynb
'
- name: Verify results
if: always()
env:
TEST_DOCKER_PULL_KEY: ${{ secrets.TEST_DOCKER_PULL_KEY }}
run: |
echo "Checking for generated files...."
ls -lh notebooks/*result*
cd notebooks
echo "$TEST_DOCKER_PULL_KEY" |docker login nvcr.io --username '$oauthtoken' --password-stdin
docker run --rm \
-v ./cvar_basic_result.html:/app/input/quantitative_portfolio_optimization/cvar_basic.html \
-v ./efficient_frontier_result.html:/app/input/quantitative_portfolio_optimization/efficient_frontier.html \
-v ./rebalancing_strategies_result.html:/app/input/quantitative_portfolio_optimization/rebalancing_strategies.html \
-v ./launchable_brev_result.html:/app/input/quantitative_portfolio_optimization/launchable_brev_result.html \
-v "$(pwd):/workspace" \
nvcr.io/rw983xdqtcdp/auto_test_team/blueprint-github-test-image:latest \
pytest -m quantitative_portfolio_optimization --disable-warnings --html=/workspace/quantitative_portfolio_optimization.html --self-contained-html
- name: Upload notebook results as artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: notebook-results
path: |
notebooks/cvar_basic_result.html
notebooks/efficient_frontier_result.html
notebooks/rebalancing_strategies_result.html
notebooks/launchable_brev_result.html
notebooks/quantitative_portfolio_optimization.html
retention-days: 30
- name: Set result output
id: set_result
if: always()
run: |
echo "RESULT=$(if [ ${{ job.status }} == 'success' ]; then echo 'PASS'; else echo 'FAIL'; fi)" >> $GITHUB_OUTPUT
- name: Send mail
uses: dawidd6/action-send-mail@6e71c855c9a091d80a519621b9fd3e8d252ca40c
if: always()
with:
server_address: smtp.gmail.com
server_port: 587
username: ${{ secrets.SMTP_USERNAME }}
password: ${{ secrets.SMTP_PASSWORD }}
# Email details
subject: "QA Test Workflow Result for ${{ github.repository }}"
to: Github-Action-Blueprint-QA@nvidia.com
from: github-workflow-notification@gmail.com
html_body: |
<p>Hello,</p>
<p>The workflow for repository: <strong>${{ github.repository }}</strong> has completed.<br>
<strong>Result:</strong> ${{ steps.set_result.outputs.RESULT }}</p>
<p>You can review the details on GitHub:<br>
<a href="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}">${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}</a></p>
<p>Thanks!</p>