From b0e0de29d54137a9396f5eba785077f10933e426 Mon Sep 17 00:00:00 2001
From: Christian Schiffer <c.schiffer@fz-juelich.de>
Date: Fri, 31 Mar 2023 14:58:14 +0200
Subject: [PATCH] Implemented train+predict

---
 atlas_server/src/app.py       |  4 +++-
 atlas_server/src/scheduler.py |  9 +++++++--
 microdraw/src/atlas_ui.js     | 13 ++++++++++---
 microdraw/src/microdraw.html  |  2 ++
 4 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/atlas_server/src/app.py b/atlas_server/src/app.py
index 6c77bdc..a4501cc 100644
--- a/atlas_server/src/app.py
+++ b/atlas_server/src/app.py
@@ -267,12 +267,14 @@ class TaskJobList(Resource):
                 annotations = task.annotations
                 # noinspection PyUnresolvedReferences
                 job_type = job_configuration.job_type
-                if job_type.lower() in ("training", "train"):
+                if job_type.lower() in ("training", "train", "training_prediction", "train_predict", "train+predict"):
+                    with_prediction = "predict" in job_type.lower()
                     job_id = submit_training_job(brain=brain,
                                                  annotations=annotations,
                                                  job_configuration=job_configuration,
                                                  project_id=project_id,
                                                  task_id=task_id,
+                                                 with_prediction=with_prediction,
                                                  **kwargs)
                 elif job_type in ("prediction", "predict"):
                     job_id = submit_prediction_job(brain=brain,
diff --git a/atlas_server/src/scheduler.py b/atlas_server/src/scheduler.py
index 950c93c..bb71bf7 100644
--- a/atlas_server/src/scheduler.py
+++ b/atlas_server/src/scheduler.py
@@ -56,7 +56,7 @@ def _setup_training_config_file(config_file, brain, annotations, **kwargs):
     return config_content
 
 
-def submit_training_job(brain, annotations, job_configuration, project_id, task_id, **kwargs):
+def submit_training_job(brain, annotations, job_configuration, project_id, task_id, with_prediction=False, **kwargs):
     additional_files = []
 
     # Create the working directory path by combining project and task id
@@ -101,7 +101,12 @@ def submit_training_job(brain, annotations, job_configuration, project_id, task_
     labels = sorted(list(labels))
 
     # Read the job script end encode its content
-    script_path = os.path.join(STATIC_DIR, "training/train.job.sh")
+    if with_prediction:
+        fname = "training/train_predict.job.sh"
+    else:
+        fname = "training/train.job.sh"
+
+    script_path = os.path.join(STATIC_DIR, fname)
     with open(script_path, "r") as f:
         # Replace labels in job file
         content = f.read()
diff --git a/microdraw/src/atlas_ui.js b/microdraw/src/atlas_ui.js
index ff36034..397710f 100644
--- a/microdraw/src/atlas_ui.js
+++ b/microdraw/src/atlas_ui.js
@@ -509,15 +509,22 @@ var app = new Vue({
 				}
 			});
 		},
-		submitTrainingJob(project, task) {
+		submitTrainingPredictionJob(project, task) {
+			this.submitTrainingJob(project, task, true);
+		},
+		submitTrainingJob(project, task, with_prediction=false) {
+			let job_type = "training";
+			if (with_prediction) {
+				job_type = "train+predict";
+			}
 			let job_configuration = new JobConfiguration(
 				// account
 				"jinm16",
 				// "jinm16",
 				// time
-				"01:00:00",
+				"03:00:00",
 				// job_type
-				"training",
+				job_type,
 				// gres
 				// "",
 				"gpu:4",
diff --git a/microdraw/src/microdraw.html b/microdraw/src/microdraw.html
index 8a75df0..fdb69ae 100755
--- a/microdraw/src/microdraw.html
+++ b/microdraw/src/microdraw.html
@@ -300,6 +300,7 @@
 							<div class="btn-group" role="group">
 								<button type="button" class="btn btn-info" v-on:click="submitAllJobsForProject(selected_project, submitTrainingJob)">Train all</button>
 								<button type="button" class="btn btn-info" v-on:click="submitAllJobsForProject(selected_project, submitPredictionJob)">Predict all</button>
+								<button type="button" class="btn btn-info" v-on:click="submitAllJobsForProject(selected_project, submitTrainingPredictionJob)">Train+Predict all</button>
 								<button type="button" class="btn btn-danger" v-on:click="cancelAllJobsForProject(selected_project)">Cancel all</button>
 							</div>
 						</div>
@@ -651,6 +652,7 @@
 							<div class="btn-group" role="group">
 								<button type="button" class="btn btn-primary" v-on:click="submitTrainingJob(selected_project, selected_task)">Start training</button>
 								<button type="button" class="btn btn-primary" v-on:click="submitPredictionJob(selected_project, selected_task)">Start prediction</button>
+								<button type="button" class="btn btn-primary" v-on:click="submitTrainingPredictionJob(selected_project, selected_task)">Start training & prediction</button>
 								<button type="button" class="btn btn-secondary" v-on:click="getJobStatusForAll(selected_project, selected_task)">Update all</button>
 								<!-- <button type="button" class="btn btn-danger"
 									v-on:click="cancelAllJobs(selected_project, selected_task)">Cancel all</button> -->
-- 
GitLab