From d57620e59817c9f4eab853cc4441d6105fd9ec40 Mon Sep 17 00:00:00 2001 From: Selina Ziegler <63650208+zieglerSe@users.noreply.github.com> Date: Wed, 25 Oct 2023 13:22:39 +0200 Subject: [PATCH] #1 Fix submission fail due to values of time or cpu being 0. --- src/Slurmi/Environment.fs | 12 -- src/Slurmi/HelperFunctions.fs | 71 ------------ src/Slurmi/Job.fs | 33 +++--- src/Slurmi/Slurmi.fsproj | 2 - src/Slurmi/Workflow.fs | 201 +--------------------------------- 5 files changed, 21 insertions(+), 298 deletions(-) delete mode 100644 src/Slurmi/Environment.fs delete mode 100644 src/Slurmi/HelperFunctions.fs diff --git a/src/Slurmi/Environment.fs b/src/Slurmi/Environment.fs deleted file mode 100644 index 94901ad..0000000 --- a/src/Slurmi/Environment.fs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Slurmi - - - -//type EnvironmentSLURM() = -// let mutable environment : (string * string) list = [] - -// member this.AddCommandAndArgument (command: string) (argument: string) = -// environment <- (command, argument) :: environment - -// member this.GetEnvironment() = -// environment \ No newline at end of file diff --git a/src/Slurmi/HelperFunctions.fs b/src/Slurmi/HelperFunctions.fs deleted file mode 100644 index 4f3899a..0000000 --- a/src/Slurmi/HelperFunctions.fs +++ /dev/null @@ -1,71 +0,0 @@ -namespace Slurmi - -open DynamicObj -open System.Runtime.InteropServices -open Fli - -// change to get right paths to github -//module helperFunctions = - -// let findDependencyName (name:string) (jobArray:Job array )= -// let id = -// jobArray -// |> Array.findIndex (fun x -> x.Name = name) -// let name = $"$Job{id}" -// name - - -// let getDependency (job:Job)= -// (match (job |> Job.LongCommand.tryGetDependency) with -// | (Some value) -> "--dependency="+(DependencyType.concat (fst (value:?>(TypeOfDep*DependencyType[]))) (snd (value:?>(TypeOfDep*DependencyType[])))) -// | (None) -> "") - -// let createNamesForWF (jobs:Job array)= -// jobs -// |> Array.mapi (fun i x -> ($"Job{i}",x)) - -// let formatWF (wfJob:(string*Job)) = -// let jId = fst wfJob -// let job = snd wfJob -// let parsable = -// (match (job |> Job.tryGetParsable) with -// | (Some value) -> (sprintf "--parsable") -// | (None) -> "") -// let dep: string = -// getDependency job -// let fullString = -// $"{jId}=$(sbatch {parsable} {dep} {job.Name})" -// fullString - -// let createWorkflowFromJobArray (jobs:Job array) = -// let jobNames = createNamesForWF jobs - -// let parsableJobs = jobNames |> Array.map (fun x -> fst x,x |> snd |> Job.SetParsable true ) - -// let jobString = parsableJobs |> Array.map (fun x -> formatWF x) -// jobString - -// let createWorkflowFromWFType (wf:Workflow) = -// let jobs = wf.Jobs -// let jobNames = createNamesForWF jobs - -// let parsableJobs = jobNames |> Array.map (fun x -> fst x,x |> snd |> Job.SetParsable true ) - -// let jobString = parsableJobs |> Array.map (fun x -> formatWF x) - -// let textToDisplay = -// [| -// "#!/bin/bash" -// ; -// (match (wf |> Workflow.tryGetTime) with -// | (Some value) -> (sprintf "#SBATCH --time=%s" (Job.formatTime (value:?>(int*int*int*int)))) -// | (None) -> "") -// ; -// (match (wf |> Workflow.tryGetPartition) with -// | (Some value) -> (sprintf "#SBATCH -p %s" (value:?>string)) -// | (None) -> "") - -// |] -// |> Array.filter (fun x -> x <> "" || x <> " ") - -// jobString |> Array.append textToDisplay diff --git a/src/Slurmi/Job.fs b/src/Slurmi/Job.fs index e95de15..8d0f805 100644 --- a/src/Slurmi/Job.fs +++ b/src/Slurmi/Job.fs @@ -1,9 +1,5 @@ namespace Slurmi -//#r "nuget: DynamicObj, 2.0.0" -//#r "nuget: Fli, 1.10.0" -// #r "nuget: Slurmi" - ////// .Split "\n") // Replace("\r","\n")) open DynamicObj open System.Runtime.InteropServices open Fli @@ -26,14 +22,22 @@ type TimeClock = } with override this.ToString() = - let hourString = sprintf "%02d" this.hour - let minuteString = sprintf "%02d" this.minute - let secondString = - match this.second with - | Some(s) -> sprintf ":%02d" s - | None -> "" - sprintf "%s:%s%s" hourString minuteString secondString - + if this = {hour = 0; minute = 0; second = Some 0} then + let hourString = sprintf "%02d" this.hour + let minuteString = sprintf "01" + let secondString = + match this.second with + | Some(s) -> sprintf ":%02d" s + | None -> "" + sprintf "%s:%s%s" hourString minuteString secondString + else + let hourString = sprintf "%02d" this.hour + let minuteString = sprintf "%02d" this.minute + let secondString = + match this.second with + | Some(s) -> sprintf ":%02d" s + | None -> "" + sprintf "%s:%s%s" hourString minuteString secondString type TimeFormat1 = { @@ -1711,7 +1715,10 @@ type LongCommand (jobName: string) = static member SetCPUsPerTask ([]?CPUsPerTask:int) = (fun (job: LongCommand) -> - CPUsPerTask |> DynObj.setValueOpt job "cpus-per-task" + if CPUsPerTask = (Some 0) then + Some 1 |> DynObj.setValueOpt job "cpus-per-task" + else + CPUsPerTask |> DynObj.setValueOpt job "cpus-per-task" job ) static member tryGetCPUsPerTask (job: LongCommand) = diff --git a/src/Slurmi/Slurmi.fsproj b/src/Slurmi/Slurmi.fsproj index ee6be48..69b6042 100644 --- a/src/Slurmi/Slurmi.fsproj +++ b/src/Slurmi/Slurmi.fsproj @@ -34,11 +34,9 @@ - - diff --git a/src/Slurmi/Workflow.fs b/src/Slurmi/Workflow.fs index f8e59ff..a7773ca 100644 --- a/src/Slurmi/Workflow.fs +++ b/src/Slurmi/Workflow.fs @@ -1,7 +1,5 @@ namespace Slurmi -open DynamicObj -open System.Runtime.InteropServices open Fli open Graphoscope open System.Collections.Generic @@ -103,14 +101,13 @@ module Workflow = () member this.checkAllForWorked (graph:FGraph) (jobs:string ) (workedOn:List) = - printfn "working on %A rn " jobs this.checkForWorkedBash graph jobs workedOn if (this.hasSuccessors graph jobs) then let successors = this.getSuccessors graph jobs successors |> Seq.iter (fun x -> this.checkAllForWorked graph (fst x) workedOn) else - printfn "no successors" + () member this.submitAll (graph:FGraph) (workedOn:List)= @@ -188,199 +185,3 @@ module Workflow = Graph = WFGraph.createGraphFromJobList jobList } } - -//namespace Slurmi - -//open DynamicObj -//open System.Runtime.InteropServices -//open Fli -//open Graphoscope -//open System.Collections.Generic - -//module Workflow = - -// let callToTerminalCMD (command:string) = -// let processResponse = -// cli { -// Shell CMD -// Command command -// } -// |> Command.execute -// // processResponse.Text -// processResponse -// let callToTerminalBash (command:string) = -// let processResponse = -// cli { -// Shell BASH -// Command command -// } -// |> Command.execute -// // processResponse.Text -// processResponse - -// let matchOutput x = -// match x with -// | Some value -> value -// | None -> failwith "No output" - -// let getResultFromCall (command:string) = -// (callToTerminalCMD (command)).Text -// |> matchOutput - -// let getResultFromCallBASH (command:string) = -// (callToTerminalBash (command)).Text -// |> matchOutput - - -// type JobWithDep = - -// { -// JobInfo : Job -// AllOrAny : TypeOfDep -// DependingOn : (Job*KindOfDependency) list - -// } - - -// let createGraphFromJobList (input: JobWithDep list)= -// let g = FGraph.empty -// input -// |> List.iter ( -// fun jobWithDep -> -// //FGraph.addElement jobWithDep.JobInfo.Name jobWithDep.DependingOn jobWithDep.DependingOn |> ignore -// jobWithDep.JobInfo.OnlyKey |> OnlyKey.SetParsable true |> ignore -// jobWithDep.DependingOn -// |> List.iter (fun (job,dep) -> FGraph.addElement job.Name (input|> List.find (fun x -> x.JobInfo.Name = job.Name)) jobWithDep.JobInfo.Name jobWithDep dep g |> ignore)) - -// g - -// let sendToTerminalAndReceiveJobID (job:JobWithDep)= -// // job -// // set parsable -// job.JobInfo.OnlyKey |> OnlyKey.SetParsable true |> ignore - -// let res = getResultFromCallBASH (job.JobInfo.formatProcess) -// // submit -// // get return -// job.JobInfo |> Job.SetJobID res |> ignore -// // set as Job ID - - -// let sendToTerminalAndReceiveJobIDCMD (job:JobWithDep)= -// // job -// // set parsable -// job.JobInfo.OnlyKey |> OnlyKey.SetParsable true |> ignore - -// let res = getResultFromCall (job.JobInfo.formatProcess) -// // submit -// // get return -// job.JobInfo |> Job.SetJobID res |> ignore -// // set as Job ID - - -// let getNodesWithoutDependencies (graph:FGraph) = -// graph.Keys -// |> Seq.map (fun x -> ((graph.Item x) |> fun (a,b,c) -> b), graph.Item x |> (FContext.predecessors) |> Seq.length) -// |> Seq.filter (fun x -> (snd x = 0 ) ) -// |> Seq.map fst - -// let getPredecessors (graph:FGraph) (jobToSearch:string) = -// (graph.Item (jobToSearch)) |> FContext.predecessors - - - -// let hasPredecessors (graph:FGraph) (jobToSearch:string) = -// if (getPredecessors graph jobToSearch |> Seq.length > 0) then true else false - - -// let getSuccessors (graph:FGraph) (jobToSearch:string) = -// (graph.Item (jobToSearch)) |> FContext.successors -// let hasSuccessors (graph:FGraph) (jobToSearch:string) = -// if (getSuccessors graph jobToSearch |> Seq.length > 0) then true else false - - -// let arePredecessorsWorkedAlready (graph:FGraph)(jobToLook:string) (workedOn:List) = -// let predecessors = getPredecessors graph jobToLook -// let predecessorsWorked = predecessors |> Seq.toArray |> Array.forall (fun x -> workedOn.Contains (fst x)) -// predecessorsWorked - -// let getJob (graph:FGraph) (job:string )= -// let name,job,kind = graph.[job] -// job - -// let getKind (graph:FGraph) (job:string )= -// let name,job,kind = graph.[job] -// kind - -// let getDependencies (graph:FGraph) (job:string )= -// let name,job,kind = graph.[job] -// name - -// let getIdFromJobWithDep (jwd:JobWithDep) = -// jwd.JobInfo |> Job.tryGetJobID - -// let getJobId (graph:FGraph) (job:string)= -// let job = getJob graph job -// let jid = job.JobInfo |> Job.tryGetJobID -// jid.Value |> string - - -// let formatDep (graph:FGraph) (job:string) = -// let deps = (getDependencies graph job) |> Seq.map (fun x ->(KindOfDependency.toString x.Value)+(getJobId graph x.Key)) |> Seq.toArray -// let jobInfo = getJob graph job -// let command = deps |> String.concat (jobInfo.AllOrAny |> TypeOfDep.toString) -// printfn "%A" command -// jobInfo.JobInfo.TwoDashes |> LongCommand.SetDependency command |> ignore - -// let checkForWorked (graph:FGraph)(jobToLook:string) (workedOn:List)= -// if (arePredecessorsWorkedAlready graph jobToLook workedOn) then - -// if workedOn.Contains jobToLook -// then printfn "already worked on %A "jobToLook -// else -// printfn "added %A" jobToLook -// let jtwo = getJob graph jobToLook - -// formatDep graph jobToLook -// jtwo.JobInfo |> Job.SetJobID (getResultFromCallBASH (jtwo.JobInfo.produceCall)) |> ignore - -// workedOn.Add jobToLook -// else -// printfn "false" - -// let rec checkAllForWorked (graph:FGraph) (jobs:string ) (workedOn:List) = -// printfn "working on %A rn " jobs -// checkForWorked graph jobs workedOn -// if (hasSuccessors graph jobs) then -// let successors = getSuccessors graph jobs - -// successors |> Seq.iter (fun x -> checkAllForWorked graph (fst x) workedOn) -// else -// printfn "no successors" - - - - - - -// let formatCallWithDep (job:JobWithDep)= -// let jobInfo = job.JobInfo -// let localStr = new System.Text.StringBuilder() -// localStr.Append ("#!/bin/bash \n") |> ignore -// localStr.Append ("#SBATCH ") |> ignore -// localStr.AppendFormat (sprintf "-J %s " jobInfo.Name) |> ignore -// localStr.Append (jobInfo.formatOneDash) |> ignore -// localStr.Append (jobInfo.formatTwoDashes) |> ignore -// localStr.Append (jobInfo.formatOnlyKey) |> ignore -// localStr.Append ("\n") |> ignore -// if jobInfo |> Job.tryGetEnvironment |> Option.isSome then -// localStr.Append (jobInfo.formatEnv) |> ignore -// localStr.Append jobInfo.formatProcess |> ignore -// localStr.ToString() - - -// let submitAll (graph:FGraph) (workedOn:List)= -// let firstNodes = -// getNodesWithoutDependencies graph -// |> Seq.toArray -// firstNodes |> Array.map (fun x -> checkAllForWorked graph x.JobInfo.Name workedOn) |> ignore