Skip to content
Closed
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
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ repos:
types: [python]
require_serial: true

- id: run_files
Comment thread
Matt-Carre marked this conversation as resolved.
name: run yaml-making files
language: system
entry: bash runthefiles
types: [python]
pass_filenames: true
require_serial: true

- id: ruff-format
name: format with ruff
language: system
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ description = " Python alternative to creating and running argo workflows in the
dependencies = [
"gql",
"aiohttp",
"hera",
"requests",
] # Add project dependencies here, e.g. ["click", "numpy"]
dynamic = ["version"]
license.file = "LICENSE"
Expand Down
8 changes: 8 additions & 0 deletions runthefiles
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
cd src/python_interface_to_workflows/workflow_definitions
for file in *
do
uv run "$file"
done
mv *.yaml ../templates/
Comment thread
Matt-Carre marked this conversation as resolved.
git add -u
Comment thread
Matt-Carre marked this conversation as resolved.
10 changes: 5 additions & 5 deletions src/python_interface_to_workflows/submit_to_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ def submit_to_graphql():
mutation = gql("""
mutation SubmitDivision {
submitWorkflowTemplate(
name: "division"
name: "divisionyaml.yaml"
visit: {
proposalCode: "ks",
proposalNumber: 10000,
number: 3
}
parameters: {
numinput: "19",
numdivisor: "10"
}
parameters: {
Comment thread
Matt-Carre marked this conversation as resolved.
x: "19",
y: "10"
}
){
name
}
Expand Down
68 changes: 68 additions & 0 deletions src/python_interface_to_workflows/templates/divisionyaml.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
apiVersion: argoproj.io/v1alpha1
kind: ClusterWorkflowTemplate
metadata:
name: hera-division
generateName: hera-division-
namespace: ks10000-3
annotations:
workflows.argoproj.io/description: |-
Takes a numerical input and returns the
remainder, output float, and output string to a json file
workflows.argoproj.io/title: Division via hera test
workflows.diamond.ac.uk/repository: https://github.com/DiamondLightSource/python-interface-to-workflows
labels:
workflows.diamond.ac.uk/science-group-examples: 'true'
spec:
entrypoint: divide
templates:
- name: divide
steps:
- - name: first
template: do-devision
arguments:
parameters:
- name: x
value: '2'
- name: y
value: '5'
- name: do-devision
inputs:
parameters:
- name: x
- name: y
outputs:
artifacts:
- name: json-output
path: /output-dir/output.json
script:
image: python:3.10
source: |-
import os
import sys
sys.path.append(os.getcwd())
import json
try: x = json.loads(r'''{{inputs.parameters.x}}''')
except: x = r'''{{inputs.parameters.x}}'''
try: y = json.loads(r'''{{inputs.parameters.y}}''')
except: y = r'''{{inputs.parameters.y}}'''

div = x / y
intdiv = x // y
remain = x % y
dictionary_of_results = {'divide': div, 'integer divisor': intdiv, 'remainder': remain}
with open('/output-dir/output.json', 'w') as otpt:
json.dump(dictionary_of_results, otpt)
command:
- python
volumeMounts:
- name: output-dir
mountPath: /output-dir/
volumeClaimTemplates:
- metadata:
name: output-dir
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Mi
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import json

from hera.shared import global_config
from hera.workflows import (
Artifact,
Steps,
Volume,
Workflow,
script, # pyright: ignore[reportUnknownVariableType]
)
from hera.workflows import models as m

global_config.host = "https://argo-workflows.staging.workflows.diamond.ac.uk/"
Comment thread
Matt-Carre marked this conversation as resolved.
global_config.image = "python:3.10"
global_config.token = "Token"


@script(
volume_mounts=[m.VolumeMount(name="output-dir", mount_path="/output-dir/")],
outputs=Artifact(name="json-output", path="/output-dir/output.json"),
)
def do_devision(x: int, y: int):
div = x / y
intdiv = x // y
remain = x % y
dictionary_of_results = {
"divide": div,
"integer divisor": intdiv,
"remainder": remain,
}
with open("/output-dir/output.json", "w") as otpt:
json.dump(dictionary_of_results, otpt)


with Workflow(
generate_name="hera-division-",
entrypoint="divide",
namespace="ks10000-3",
name="hera-division",
api_version="argoproj.io/v1alpha1",
kind="ClusterWorkflowTemplate",
labels={"workflows.diamond.ac.uk/science-group-examples": "true"},
annotations={
"workflows.argoproj.io/title": "Division via hera test",
"workflows.argoproj.io/description": """Takes a numerical input and returns the
remainder, output float, and output string to a json file""",
"workflows.diamond.ac.uk/repository": "https://github.com/DiamondLightSource/python-interface-to-workflows",
},
volumes=Volume(name="output-dir", mount_path="/output-dir", size="1Mi"),
) as w:
with Steps(name="divide"):
do_devision(name="first", arguments={"x": 2, "y": 5})


with open("divisionyaml.yaml", "w") as div:
div.write(w.to_yaml()) # pyright: ignore[reportUnknownMemberType]

# w.create()
Loading
Loading