Skip to content

Commit

Permalink
Merge pull request #52 from fasrc/User_Doc-Python
Browse files Browse the repository at this point in the history
User doc python
  • Loading branch information
swinney authored Oct 23, 2024
2 parents 856794f + 71c1e20 commit eaccaac
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 311 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/Languages-Python-Example1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: CI Test for Languages-Python-Example1/mc_pi.py

on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch: # This enables manual triggering of the workflow

jobs:
Languages-Python-Example1:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x' # Specify the required Python version

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt # If you have a requirements.txt file in the repo
- name: Run mc_pi.py
run: |
python Languages/Python/Example1/mc_pi.py
slurm:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Pull SLURM Simulator Docker Image
run: |
docker pull hpcnow/slurm_simulator:24.05.1
- name: List Files in Mounted Directory
run: |
docker run --rm -v ${{ github.workspace }}:/workspace -w /workspace hpcnow/slurm_simulator:24.05.1 ls -la /workspace/Languages/Python/Example1
- name: Check File Permissions
run: |
docker run --rm -v ${{ github.workspace }}:/workspace -w /workspace hpcnow/slurm_simulator:24.05.1 stat /workspace/Languages/Python/Example1/run.sbatch
- name: Run SLURM job in Docker
run: |
docker run --rm --detach \
--name "${USER}_simulator" \
-h "slurm-simulator" \
--security-opt seccomp:unconfined \
--privileged -e container=docker \
-v /run -v /sys/fs/cgroup:/sys/fs/cgroup \
-v ${{ github.workspace }}:/workspace \
-w /workspace \
--cgroupns=host \
hpcnow/slurm_simulator:24.05.1 /usr/sbin/init
sbatch /workspace/Languages/Python/Example1/run.sbatch
35 changes: 35 additions & 0 deletions Languages/Python/Example1/test_mc_pi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# test_mc_pi.py
import unittest
import mc_pi
import random

class TestMCPi(unittest.TestCase):
def test_pi_estimate(self):
# Set a seed for reproducibility
random.seed(0)
N = 100000
count = 0
for i in range(N):
x = random.random()
y = random.random()
z = x*x + y*y
if z <= 1.0:
count += 1
PI = 4.0 * count / N
self.assertAlmostEqual(PI, 3.1415926535897932, places=2)

def test_count_inside_circle(self):
# Set a seed for reproducibility
random.seed(0)
N = 100000
count = 0
for i in range(N):
x = random.random()
y = random.random()
z = x*x + y*y
if z <= 1.0:
count += 1
self.assertEqual(count, 78539) # This value is based on the seed

if __name__ == '__main__':
unittest.main()
197 changes: 0 additions & 197 deletions Languages/Python/Mamba.md

This file was deleted.

Loading

0 comments on commit eaccaac

Please sign in to comment.