From f18b2528b6b01e7bf4d4dc056f5cdd67b51facac Mon Sep 17 00:00:00 2001
From: Robert Izzard <r.izzard@surrey.ac.uk>
Date: Mon, 21 Feb 2022 07:54:45 +0000
Subject: [PATCH] upadte log_args to handle HPC more easily

---
 binarycpython/utils/grid.py                   | 29 +++++++++++--------
 .../utils/population_extensions/HPC.py        |  2 +-
 .../utils/population_extensions/condor.py     |  2 +-
 .../utils/population_extensions/slurm.py      |  2 +-
 4 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/binarycpython/utils/grid.py b/binarycpython/utils/grid.py
index cc2a929c6..5bd145e4c 100644
--- a/binarycpython/utils/grid.py
+++ b/binarycpython/utils/grid.py
@@ -237,13 +237,17 @@ class Population(
 
     def jobID(self):
         """
-        Function to return the job ID number of this process
+        Function to return the job ID number of this process as a string.
 
         Normal processes return their process ID (PID)
         HPC processes return whatever HPC_jobID() gives.
         """
         if self.HPC_job():
             jobID = self.HPC_jobID()
+            if not jobID:
+                # fallback: use process ID but with "HPC" prepended
+                # (this should never happen!)
+                jobID = "HPC{}".format(self.process_ID)
         else:
             jobID = "{}".format(self.process_ID)
         return jobID
@@ -374,7 +378,7 @@ class Population(
 
         # get the cmd-line args in the form x=y
         cmdline_args = sys.argv[1:]
-        
+
         if cmdline_args:
             self.verbose_print(
                 "Found cmdline args. Parsing them now",
@@ -385,7 +389,7 @@ class Population(
             # Grab the input and split them up, while accepting only non-empty entries
             # cmdline_args = args
             self.grid_options["_commandline_input"] = cmdline_args
-            
+
             # Make dict and fill it
             cmdline_dict = {}
             for cmdline_arg in cmdline_args:
@@ -1614,17 +1618,18 @@ class Population(
             # that was on, we log each current system to a file (each thread has one).
             # Each new system overrides the previous
             if self.grid_options["log_args"]:
+                argfile = os.path.join(
+                    self.grid_options["log_args_dir"],
+                    "current_system",
+                    "process_{}.txt".format(self.jobID()),
+                )
                 with self.open(
-                    os.path.join(
-                        self.grid_options["log_args_dir"],
-                        "current_system",
-                        "process_{}.txt".format(self.process_ID),
-                    ),
-                    "w",
-                    encoding="utf-8",
+                        argfile,
+                        "w",
+                        encoding="utf-8",
                 ) as f:
-                    binary_cmdline_string = self._return_argline(full_system_dict)
-                    f.write(binary_cmdline_string)
+                    binary_c_cmdline_string = self._return_argline(full_system_dict)
+                    f.write(binary_c_cmdline_string)
                     f.close()
 
             ##############
diff --git a/binarycpython/utils/population_extensions/HPC.py b/binarycpython/utils/population_extensions/HPC.py
index dadfab449..5a5555a75 100644
--- a/binarycpython/utils/population_extensions/HPC.py
+++ b/binarycpython/utils/population_extensions/HPC.py
@@ -304,7 +304,7 @@ class HPC(condor, slurm):
 
     def HPC_jobID(self):
         """
-        Function to return an HPC (Slurm or Condor) job id in the form x.y. Returns None if not an HPC job.
+        Function to return an HPC (Slurm or Condor) job id in the form of a string, x.y. Returns None if not an HPC job.
         """
 
         if self.grid_options["slurm"] > 0:
diff --git a/binarycpython/utils/population_extensions/condor.py b/binarycpython/utils/population_extensions/condor.py
index 315310219..04a6f8b75 100644
--- a/binarycpython/utils/population_extensions/condor.py
+++ b/binarycpython/utils/population_extensions/condor.py
@@ -37,7 +37,7 @@ class condor:
 
     def condorID(self, ClusterID=None, Process=None):
         """
-        Function to return a Condor job ID. The ClusterID and Process passed in are used if given, otherwise we default to the condor_ClusterID and condor_Process in grid_options.
+        Function to return a Condor job ID as a string, [ClusterID].[Process]. The ClusterID and Process passed in are used if given, otherwise we default to the condor_ClusterID and condor_Process in grid_options.
         """
         if ClusterID is None:
             ClusterID = self.grid_options["condor_ClusterID"]
diff --git a/binarycpython/utils/population_extensions/slurm.py b/binarycpython/utils/population_extensions/slurm.py
index c362c0a0b..1baf701d0 100644
--- a/binarycpython/utils/population_extensions/slurm.py
+++ b/binarycpython/utils/population_extensions/slurm.py
@@ -35,7 +35,7 @@ class slurm:
 
     def slurmID(self, jobid=None, jobarrayindex=None):
         """
-        Function to return a Slurm job ID. The jobid and jobarrayindex passed in are used if given, otherwise we default to the jobid and jobarrayindex in grid_options.
+        Function to return a Slurm job ID as a string, [jobid].[jobarrayindex]. The jobid and jobarrayindex passed in are used if given, otherwise we default to the jobid and jobarrayindex in grid_options.
         """
         if jobid is None:
             jobid = self.grid_options["slurm_jobid"]
-- 
GitLab