-
-
Notifications
You must be signed in to change notification settings - Fork 150
SGE implementation #27
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4392a0b
First attempt at SGE implementation
lesteve c83c29d
Leave test_adaptive for later.
lesteve 27032ec
Need to specify loop in the Client
lesteve a7b26c8
Clean up in sge.py
lesteve 3013547
Fix flake8
lesteve cea22cc
Forgotten another self.name fixed in master
lesteve 10f7c72
Retriggering CIs
lesteve 271d78c
Clean-up
lesteve f4cf1ea
Cosmetic changes to harmonize with pbs.py
lesteve 222f157
docrep-related fixes
lesteve e9d0cb8
Make SGECluster importable from dask_jobqueue
lesteve bcf492b
Remove interface parameter from docstring
lesteve a4cd9d3
Group stdlib imports together
lesteve 2706776
Remove unused 'dirname' variable
lesteve File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,8 @@ | |
| import socket | ||
| import os | ||
| import sys | ||
| import shlex | ||
|
|
||
| import docrep | ||
|
|
||
| from distributed.utils import tmpfile, ignoring, get_ip_interface, parse_bytes | ||
|
|
@@ -153,8 +155,8 @@ def start_workers(self, n=1): | |
| workers = [] | ||
| for _ in range(n): | ||
| with self.job_file() as fn: | ||
| out = self._call([self.submit_command, fn]) | ||
| job = out.decode().split('.')[0] | ||
| out = self._call(shlex.split(self.submit_command) + [fn]) | ||
| job = out.decode().split('.')[0].strip() | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And by the way the |
||
| self.jobs[self.n] = job | ||
| workers.append(self.n) | ||
| return workers | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import logging | ||
|
|
||
| from .core import JobQueueCluster, docstrings | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| @docstrings.with_indent(4) | ||
| class SGECluster(JobQueueCluster): | ||
| """ Launch Dask on a SGE cluster | ||
|
|
||
| Parameters | ||
| ---------- | ||
| queue : str | ||
| Destination queue for each worker job. Passed to `#$ -q` option. | ||
| project : str | ||
| Accounting string associated with each worker job. Passed to | ||
| `#$ -A` option. | ||
| resource_spec : str | ||
| Request resources and specify job placement. Passed to `#$ -l` | ||
| option. | ||
| walltime : str | ||
| Walltime for each worker job. | ||
| %(JobQueueCluster.parameters)s | ||
|
|
||
| Examples | ||
| -------- | ||
| >>> from dask_jobqueue import SGECluster | ||
| >>> cluster = SGECluster(queue='regular') | ||
| >>> cluster.start_workers(10) # this may take a few seconds to launch | ||
|
|
||
| >>> from dask.distributed import Client | ||
| >>> client = Client(cluster) | ||
|
|
||
| This also works with adaptive clusters. This automatically launches and | ||
| kill workers based on load. | ||
|
|
||
| >>> cluster.adapt() | ||
| """ | ||
|
|
||
| #Override class variables | ||
| submit_command = 'qsub -terse' | ||
| cancel_command = 'qdel' | ||
|
|
||
| def __init__(self, | ||
| queue=None, | ||
| project=None, | ||
| resource_spec=None, | ||
| walltime='0:30:00', | ||
| **kwargs): | ||
|
|
||
| super(SGECluster, self).__init__(**kwargs) | ||
|
|
||
| header_lines = ['#!/bin/bash'] | ||
|
|
||
| if self.name is not None: | ||
| header_lines.append('#$ -N %(name)s') | ||
| if queue is not None: | ||
| header_lines.append('#$ -q %(queue)s') | ||
| if project is not None: | ||
| header_lines.append('#$ -P %(project)s') | ||
| if resource_spec is not None: | ||
| header_lines.append('#$ -l %(resource_spec)s') | ||
| if walltime is not None: | ||
| header_lines.append('#$ -l h_rt=%(walltime)s') | ||
| header_lines.extend(['#$ -cwd', '#$ -j y']) | ||
| header_template = '\n'.join(header_lines) | ||
|
|
||
| config = {'name': self.name, | ||
| 'queue': queue, | ||
| 'project': project, | ||
| 'processes': self.worker_processes, | ||
| 'walltime': walltime, | ||
| 'resource_spec': resource_spec,} | ||
| self.job_header = header_template % config | ||
|
|
||
| logger.debug("Job script: \n %s" % self.job_script()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,34 @@ | ||
| from time import time, sleep | ||
|
|
||
| import pytest | ||
|
|
||
| from dask.distributed import Client | ||
| from distributed.utils_test import loop # noqa: F401 | ||
|
|
||
| from dask_jobqueue import SGECluster | ||
|
|
||
| pytestmark = pytest.mark.env("sge") | ||
|
|
||
|
|
||
| def test_sge_placeholder(): | ||
| # to test that CI is working | ||
| pass | ||
| def test_basic(loop): # noqa: F811 | ||
| with SGECluster(walltime='00:02:00', threads=2, memory='7GB', | ||
| loop=loop) as cluster: | ||
| with Client(cluster, loop=loop) as client: | ||
| workers = cluster.start_workers(2) | ||
| future = client.submit(lambda x: x + 1, 10) | ||
| assert future.result(60) == 11 | ||
| assert cluster.jobs | ||
|
|
||
| info = client.scheduler_info() | ||
| w = list(info['workers'].values())[0] | ||
| assert w['memory_limit'] == 7e9 | ||
| assert w['ncores'] == 2 | ||
|
|
||
| cluster.stop_workers(workers) | ||
|
|
||
| start = time() | ||
| while len(client.scheduler_info()['workers']) > 0: | ||
| sleep(0.100) | ||
| assert time() < start + 10 | ||
|
|
||
| assert not cluster.jobs |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know shlex, is this mandatory? It serves what purpose?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In SGE, by default qsub returns quite a verbose output, e.g. something like
Your job 56 ("test.sh") has been submitted. In order for just the job id to be returned, you need to useqsub -terse. This is whysubmit_cmd = 'qsub -terse'.That means that you need to split
submit_cmd. I thinkshlex.splitis the way to do it for sh commands. We could just dosubmit_cmd.split(' ')but it may break e.g. if one of the arguments is quoted with a space inside.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok that's perfect then!