Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use shlex.quote to convert the arguments into unix format #209

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

request_cpus can not be assigned to a local job.


# 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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For separation jobs, these arguments are not really used.


# 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))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to

def script_from_runner_kwargs(annotations, kwargs) -> str:

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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the number of arguments.

echo "Error: You need to provide required number of arguments."
exit 1
fi

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