qtoolkit.manager module#

class qtoolkit.manager.QueueManager(scheduler_io: BaseSchedulerIO, host: BaseHost = None)[source]#

Bases: QTKObject

Main interface to interact with a job queue on a given host.

scheduler_io#

The scheduler IO implementation (e.g., SlurmIO).

Type:

BaseSchedulerIO

host#

The host where commands are executed (e.g., LocalHost, RemoteHost).

Type:

BaseHost

cancel(job: QJob | int | str) CancelResult[source]#

Cancel a job from the queue.

Parameters:

job – The job to cancel.

Returns:

The result of the cancellation.

Return type:

CancelResult

execute_cmd(cmd: str, workdir: str | Path | None = None) tuple[str, str, int][source]#

Execute a command.

Parameters:
  • cmd – Command to be executed.

  • workdir – Path where the command will be executed.

Returns:

  • stdout (str) – Standard output of the command.

  • stderr (str) – Standard error of the command.

  • exit_code (int) – Exit code of the command.

get_change_dir(dir_path: str | Path | None) str[source]#

Generate the command to change to the working directory.

Parameters:

dir_path – The directory path.

Returns:

The ‘cd’ command string.

Return type:

str

get_environment_setup(env_config: dict | None) str | None[source]#

Generate bash commands to set up the execution environment.

Parameters:

env_config – Environment configuration dictionary.

Returns:

The environment setup commands, or None if no config provided.

Return type:

str or None

get_job(job: QJob | int | str) QJob | None[source]#

Get job from job id or QJob object.

Parameters:

job – Identifier of the job to get.

Returns:

Qjob object corresponding to the job id provided or None if no job was found with that id.

Return type:

qtoolkit.QJob object or None

get_jobs_list(jobs: list[QJob | int | str] | None = None, user: str | None = None) list[QJob][source]#

Get a list of jobs from the queue.

Parameters:
  • jobs – List of job identifiers to retrieve.

  • user – Filter jobs by username.

Returns:

The list of retrieved jobs.

Return type:

list of QJob

get_post_run(post_run: str | list[str] | None) str | None[source]#

Process the post-run commands.

Parameters:

post_run – The post-run commands.

Returns:

The processed post-run commands string.

Return type:

str or None

get_pre_run(pre_run: str | list[str] | None) str | None[source]#

Process the pre-run commands.

Parameters:

pre_run – The pre-run commands.

Returns:

The processed pre-run commands string.

Return type:

str or None

get_run_commands(commands: str | list[str] | None) str | None[source]#

Process the main run commands.

Parameters:

commands – The main commands.

Returns:

The processed run commands string.

Return type:

str or None

get_submission_script(commands: str | list[str] | None, options: dict | QResources | None = None, work_dir: str | Path | None = None, pre_run: str | list[str] | None = None, post_run: str | list[str] | None = None, environment: dict | None = None) str[source]#

Generate the full submission script.

Parameters:
  • commands – The main commands to execute in the job.

  • options – Scheduler options.

  • work_dir – Working directory for the job.

  • pre_run – Commands to run before the main commands.

  • post_run – Commands to run after the main commands.

  • environment – Configuration for the execution environment (modules, conda, env vars).

Returns:

The generated submission script content.

Return type:

str

submit(commands: str | list[str] | None, options: dict | QResources | None = None, work_dir: str | Path | None = None, environment: dict | None = None, script_fname: str = 'submit.script', create_submit_dir: bool = False) SubmissionResult[source]#

Submit a job to the queue.

Parameters:
  • commands – The commands to run in the job.

  • options – Scheduler options.

  • work_dir – Working directory for the job.

  • environment – Environment setup configuration.

  • script_fname – Filename for the submission script.

  • create_submit_dir – Whether to create the working directory if it doesn’t exist.

Returns:

The result of the submission.

Return type:

SubmissionResult