Skip to content

Support changing batch script shell in BatchSettings #33

Open
@Spartee

Description

@Spartee

Description

Not every system/user uses bash for job submission to a scheduler. SmartSim should be able to change the shebang line at the top of the script thats written for batch steps.

Implementation Strategy

The base BatchSettings class should have a private variable (e.g. _shell) that defaults to #!/bin/bash. The BatchSettings class should also have a method set_shell that takes in a string and does some checking on the user input before setting the private variable. Each Step class created as a result of BatchSettings should use that private variable (optionally set by the user) to write the beginning of the batch file that is written prior to job submission.

Since the base class is being used to introduce the private variable and the method, SbatchSettings, QsubBatchSettings, CobaltBatchSettings, and any future batch settings classes will all inherit the field and method.

The following Step classes will need to be edited

  • SbatchStep
  • QsubBatchStep
  • CobaltBatchStep

for example, for SbatchStep, the SbatchStep._write_script method looks like:

    def _write_script(self):
        """Write the batch script

        :return: batch script path after writing
        :rtype: str
        """
        batch_script = self.get_step_file(ending=".sh")
        output, error = self.get_output_files()
        with open(batch_script, "w") as f:
            f.write("#!/bin/bash\n\n")                 # this is the line that should be replaced with the private variable accessor
            f.write(f"#SBATCH --output={output}\n")
            f.write(f"#SBATCH --error={error}\n")
            f.write(f"#SBATCH --job-name={self.name}\n")

            # add additional sbatch options
            for opt in self.batch_settings.format_batch_args():
                f.write(f"#SBATCH {opt}\n")

            for i, cmd in enumerate(self.step_cmds):
                f.write("\n")
                f.write(f"{' '.join((cmd))} &\n")
                if i == len(self.step_cmds) - 1:
                    f.write("\n")
                    f.write("wait\n")
        return batch_script

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: settingsIssues related to Batch or Run settingsgood first issueIssue that is ideal for first-time contributorstype: featureIssues that include feature request or feature idea

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions