Skip to content

Commit

Permalink
Use shlex.quote to convert the arguments into unix format (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
dachengx authored Sep 9, 2024
1 parent 09f35f5 commit 461fa19
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
23 changes: 11 additions & 12 deletions alea/submitters/htcondor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import getpass
import tarfile
import shlex
import json
import tempfile
import time
import threading
Expand All @@ -25,6 +24,7 @@
TransformationCatalog,
ReplicaCatalog,
)
from alea.runner import Runner
from alea.submitter import Submitter
from alea.utils import load_yaml, dump_yaml

Expand Down Expand Up @@ -449,13 +449,14 @@ def _initialize_job(
"""
job = Job(name)
job.add_profiles(Namespace.CONDOR, "request_cpus", f"{cores}")

if run_on_submit_node:
job.add_selector_profile(execution_site="local")
# no other attributes on a local job
return job

job.add_profiles(Namespace.CONDOR, "request_cpus", f"{cores}")

# Set memory and disk requirements
# If the job fails, retry with more memory and disk
# Somehow we need to write memory in MB and disk in kB
Expand Down Expand Up @@ -497,13 +498,7 @@ def _add_separate_job(self, combine_i):
"""Add a separate job to the workflow."""
logger.info(f"Adding separate job {combine_i} to the workflow")
separate_name = "separate"
separate_job = self._initialize_job(
name=separate_name,
cores=1,
memory=self.request_memory * 2,
disk=self.combine_disk,
run_on_submit_node=True,
)
separate_job = self._initialize_job(name=separate_name, run_on_submit_node=True)

# Separate job configuration: all toymc results and files will be combined into one tarball
separate_job.add_inputs(File(f"{self.workflow_id}-{combine_i}-combined_output.tar.gz"))
Expand Down Expand Up @@ -565,6 +560,9 @@ def _generate_workflow(self, name="run_toymc_wrapper"):
combine_i = 0
new_to_combine = True

# Prepare for argument conversion
_, _, annotations = Runner.runner_arguments()

# Generate jobstring and output names from tickets generator
for job_id, (script, _) in enumerate(self.combined_tickets_generator()):
# If the number of jobs to combine is reached, add a new combine job
Expand Down Expand Up @@ -638,10 +636,11 @@ def _generate_workflow(self, name="run_toymc_wrapper"):

# Add the arguments into the job
# Using escaped argument to avoid the shell syntax error
def _extract_all_to_tuple(d):
def _extract_all_to_tuple(kwargs) -> tuple:
"""Generate the submission script from the runner arguments."""
return tuple(
f"{json.dumps(str(d[key])).replace(' ', '')}".replace("'", '\\"')
for key in d.keys()
shlex.quote(Submitter.arg_to_str(kwargs[arg], annotation))
for arg, annotation in annotations.items()
)

# Correct the paths in the arguments
Expand Down
6 changes: 6 additions & 0 deletions alea/submitters/run_toymc_wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

set -e

# Check if number of arguments passed is correct
if [ $# -ne 21 ]; then
echo "Error: You need to provide required number of arguments."
exit 1
fi

# Extract the arguments
statistical_model=$1
poi=$2
Expand Down

0 comments on commit 461fa19

Please sign in to comment.