Skip to content

Commit

Permalink
Added jupyter notebook runner
Browse files Browse the repository at this point in the history
Added new packages to dockerfile
  • Loading branch information
DanPorter committed Feb 13, 2025
1 parent f5c48b6 commit d7e29e2
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM docker.io/continuumio/miniconda3:24.5.0-0
RUN conda install numpy matplotlib h5py
RUN python -m pip install hdfmap
RUN conda install -c conda-forge numpy matplotlib h5py hdf5plugin imageio jupyter nbconvert nbformat papermill
RUN python -m pip install hdfmap nexus2srs
46 changes: 46 additions & 0 deletions jupyter_notebook_script.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
apiVersion: argoproj.io/v1alpha1
kind: ClusterWorkflowTemplate
metadata:
name: mmg-test-python
spec:
entrypoint: mmg-test-python
templates:
- name: notebook
script:
image: ghcr.io/diamondlightsource/magnetic-materials-workflows:0.1.0-rc4
command:
- jupyter-nbconvert
- --execute
- --stdin
- --to
- html
- --output
- notebook
- --output-dir
- /outputs
source: |
{{ .Files.Get "notebooks/notebook.ipynb" | fromJson | toPrettyJson | nindent 10 }}
volumeMounts:
- name: outputs
mountPath: /outputs
volumeClaimTemplates:
- metadata:
name: tmpdir
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
storageClassName: local-path
arguments:
parameters:
- name: visitdir
valueFrom:
configMapKeyRef:
name: sessionspaces
key: data_directory
volumes:
- name: session
hostPath:
path: "{{ workflow.parameters.visitdir }}"
type: Directory
175 changes: 175 additions & 0 deletions notebooks/mmg_test_processor.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "0552e358",
"metadata": {},
"outputs": [],
"source": [
"# Processor requirements\n",
"# The first two cells must be code cells, inpath and outpath define the scan file location and output location\n",
"inpath = \"\""
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "e6a617f0",
"metadata": {},
"outputs": [],
"source": [
"outpath = \"\""
]
},
{
"cell_type": "markdown",
"id": "4d8b6081",
"metadata": {},
"source": [
"# Test Processor\n",
"\n",
"Load some modules and see what is available"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b06a18c7-499d-4536-8e36-fbf4cedd28d3",
"metadata": {},
"outputs": [],
"source": [
"print(inpath)\n",
"print(outpath)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "92330199",
"metadata": {},
"outputs": [],
"source": [
"def module_info():\n",
" import sys\n",
" out = 'Python version %s' % sys.version\n",
" out += '\\n at: %s' % sys.executable\n",
" # Modules\n",
" import numpy\n",
" out += '\\n numpy version: %s' % numpy.__version__\n",
" import h5py\n",
" out += '\\n h5py version: %s' % h5py.__version__\n",
" try:\n",
" import imageio\n",
" out += '\\n imageio version: %s' % imageio.__version__\n",
" except ImportError:\n",
" out += '\\n imageio version: None'\n",
" try:\n",
" import hdf5plugin\n",
" out += '\\nhdf5plugin version: %s' % hdf5plugin.version\n",
" except ImportError:\n",
" out += '\\nhdf5plugin version: None'\n",
" try:\n",
" import matplotlib\n",
" out += '\\nmatplotlib version: %s' % matplotlib.__version__\n",
" except ImportError:\n",
" out += '\\nmatplotlib version: None'\n",
" try:\n",
" import lmfit\n",
" out += '\\n lmfit version: %s' % lmfit.__version__\n",
" except ImportError:\n",
" out += '\\n lmfit version: None'\n",
" try:\n",
" import hdfmap\n",
" out += '\\n hdfmap version: %s' % hdfmap.__version__\n",
" except ImportError:\n",
" out += '\\n hdfmap version: None'\n",
" try:\n",
" import nexus2srs\n",
" out += '\\n nexus2srs version: %s' % nexus2srs.__version__\n",
" except ImportError:\n",
" out += '\\n nexus2srs version: None'\n",
" \n",
" import os\n",
" out += '\\nRunning in directory: %s\\n' % os.path.abspath('.')\n",
" return out"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "ac437f62",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Python version 3.11.3 | packaged by conda-forge | (main, Apr 6 2023, 08:57:19) [GCC 11.3.0]\n",
" at: /dls_sw/apps/python/miniforge/4.10.0-0/envs/python3.11/bin/python3.11\n",
" numpy version: 1.24.3\n",
" h5py version: 3.8.0\n",
" imageio version: 2.28.1\n",
"hdf5plugin version: 4.1.2\n",
"matplotlib version: 3.7.1\n",
" lmfit version: 1.2.1\n",
" hdfmap version: 0.7.0\n",
" nexus2srs version: None\n",
"Running in directory: /dls_sw/i06/scripts/gda-zocalo/notebooks\n",
"\n"
]
}
],
"source": [
"print(module_info())"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "496f9973",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['In', 'Out', '_', '_11', '__', '___', '__builtin__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', '_dh', '_i', '_i1', '_i10', '_i11', '_i12', '_i13', '_i14', '_i15', '_i16', '_i17', '_i18', '_i19', '_i2', '_i20', '_i21', '_i3', '_i4', '_i5', '_i6', '_i7', '_i8', '_i9', '_ih', '_ii', '_iii', '_oh', 'exit', 'get_ipython', 'inpath', 'module_info', 'open', 'outpath', 'quit']\n"
]
}
],
"source": [
"print(dir())"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "88d9c494",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
6 changes: 5 additions & 1 deletion python_script.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ spec:
value: |
print(f"Scan command: {cmd}")
script:
image: ghcr.io/diamondlightsource/magnetic-materials-workflows:0.1.0-rc2
image: ghcr.io/diamondlightsource/magnetic-materials-workflows:0.1.0-rc3
volumeMounts:
- name: session
mountPath: "{{ workflow.parameters.visitdir }}"
Expand All @@ -42,3 +42,7 @@ spec:
cmd = scan('scan_command')

{{inputs.parameters.python-code}}
outputs:
artifacts:
- name: 'some data'
path: '/tmp/data.json'

0 comments on commit d7e29e2

Please sign in to comment.