Skip to content

Commit

Permalink
Merge pull request #763 from Project-MONAI/samrooke/AC-2026-update-ar…
Browse files Browse the repository at this point in the history
…go-workflow-validation-logic

Samrooke/ac 2026 update argo workflow validation logic
  • Loading branch information
samrooke authored Apr 24, 2023
2 parents 6ce8360 + ca6a254 commit 864bfd0
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 7 deletions.
15 changes: 15 additions & 0 deletions src/Shared/Shared/ValidationConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ public static class ValidationConstants
/// </summary>
public static readonly string Notifications = "notifications";

/// <summary>
/// Key for the CPU.
/// </summary>
public static readonly string Cpu = "cpu";

/// <summary>
/// Key for the memory.
/// </summary>
public static readonly string Memory = "memory_gb";

/// <summary>
/// Key for the GPU.
/// </summary>
public static readonly string Gpu = "gpu";

public enum ModeValues
{
QA,
Expand Down
15 changes: 15 additions & 0 deletions src/TaskManager/Plug-ins/Argo/StaticValues/Keys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@ internal static class Keys
/// </summary>
public static readonly string TaskPriorityClassName = "priority";

/// <summary>
/// Key for CPU
/// </summary>
public static readonly string Cpu = "cpu";

/// <summary>
/// Key for memory allocation
/// </summary>
public static readonly string Memory = "memory_gb";

/// <summary>
/// Key for GPU
/// </summary>
public static readonly string Gpu = "number_gpu";

/// <summary>
/// Required arguments to run the Argo workflow.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ private void ValidateTasks(Workflow workflow, string firstTaskId)
{
// duplicate destinations
var duplicates = destinations
.GroupBy(i => i)
.Where(g => g.Count() > 1)
.Select(g => g.Key);
.GroupBy(i => i)
.Where(g => g.Count() > 1)
.Select(g => g.Key);

foreach (var dupe in duplicates)
{
Expand Down Expand Up @@ -348,6 +348,27 @@ private void ValidateArgoTask(TaskObject currentTask)
break;
}
}

new List<string> { Cpu, Memory }.ForEach(key =>
{
if (
currentTask.Args.TryGetValue(key, out var val) &&
!string.IsNullOrEmpty(val) &&
double.TryParse(val, out double parsedVal) &&
(parsedVal < 1 || Math.Truncate(parsedVal) != parsedVal))
{
Errors.Add($"Task: '{currentTask.Id}' value '{val}' provided for argument '{key}' is not valid. The value needs to be a whole number greater than 0.");
}
});

if (
currentTask.Args.TryGetValue(Gpu, out var gpu) &&
!string.IsNullOrEmpty(gpu) &&
double.TryParse(gpu, out double parsedGpu) &&
(parsedGpu != 0 || parsedGpu != 1))
{
Errors.Add($"Task: '{currentTask.Id}' value '{gpu}' provided for argument '{Gpu}' is not valid. The value needs to be 0 or 1.");
}
}

private void ValidateClinicalReviewTask(TaskObject[] tasks, TaskObject currentTask)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
*/

using System;
using System.Security.Cryptography.Xml;
using System.Threading.Tasks;
using Amazon.Runtime.Internal.Transform;
using Microsoft.Extensions.Logging;
using Monai.Deploy.WorkflowManager.Common.Interfaces;
using Monai.Deploy.WorkflowManager.Contracts.Models;
Expand Down Expand Up @@ -206,7 +204,10 @@ public async Task ValidateWorkflow_ValidatesAWorkflow_ReturnsErrorsAndHasCorrect
Type = "argo",
Description = "Test Argo Task",
Args = {
{ "example", "value" }
{ "example", "value" },
{ "cpu", "0.1" },
{ "memory_gb", "0.1" },
{ "gpu", "2" }
},
TaskDestinations = new TaskDestination[]
{
Expand Down Expand Up @@ -347,7 +348,7 @@ public async Task ValidateWorkflow_ValidatesAWorkflow_ReturnsErrorsAndHasCorrect

Assert.True(errors.Count > 0);

Assert.Equal(40, errors.Count);
Assert.Equal(43, errors.Count);

var convergingTasksDestinations = "Converging Tasks Destinations in tasks: (test-clinical-review-2, example-task) on task: example-task";
Assert.Contains(convergingTasksDestinations, errors);
Expand Down Expand Up @@ -385,6 +386,15 @@ public async Task ValidateWorkflow_ValidatesAWorkflow_ReturnsErrorsAndHasCorrect
var missingArgoArgs = "Task: 'test-argo-task' workflow_template_name must be specified, this corresponds to an Argo template name.";
Assert.Contains(missingArgoArgs, errors);

var invalidArgoArg1 = "Task: 'test-argo-task' value '0.1' provided for argument 'cpu' is not valid. The value needs to be a whole number greater than 0.";
Assert.Contains(invalidArgoArg1, errors);

var invalidArgoArg2 = "Task: 'test-argo-task' value '0.1' provided for argument 'memory_gb' is not valid. The value needs to be a whole number greater than 0.";
Assert.Contains(invalidArgoArg2, errors);

var invalidArgoArg3 = "Task: 'test-argo-task' value '2' provided for argument 'gpu' is not valid. The value needs to be 0 or 1.";
Assert.Contains(invalidArgoArg3, errors);

var incorrectClinicalReviewValueFormat = $"Invalid Value property on input artifact 'Invalid Value Format' in task: 'test-clinical-review'. Incorrect format.";
Assert.Contains(incorrectClinicalReviewValueFormat, errors);

Expand Down

0 comments on commit 864bfd0

Please sign in to comment.