Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
nb_slurm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Viacheslav Ostroukh
nb_slurm
Commits
f26c8f84
Commit
f26c8f84
authored
7 years ago
by
Viacheslav Ostroukh
Browse files
Options
Downloads
Patches
Plain Diff
documentation
parent
69b7bce4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
nb_slurm/kernelmanager.py
+27
-2
27 additions, 2 deletions
nb_slurm/kernelmanager.py
nb_slurm/kernelspecmanager.py
+14
-0
14 additions, 0 deletions
nb_slurm/kernelspecmanager.py
with
41 additions
and
2 deletions
nb_slurm/kernelmanager.py
+
27
−
2
View file @
f26c8f84
...
...
@@ -97,6 +97,17 @@ class SlurmKernelManager(IOLoopKernelManager):
self
.
slurm_jobid
=
None
def
start_kernel
(
self
,
**
kw
):
"""
Starts a kernel on a remote host, using
'
salloc
'
and
'
srun
'
to
allocate an interactive shell on a remote node and launching a kernel
there with
'
exec
'
.
Parameters
----------
`**kw` : optional
keyword arguments that are passed down to build the kernel_cmd
and launching the kernel. Only
'
env
'
and
'
extra_arguments
'
have
an impact, but others are stored to be on the safe side.
"""
# Prepare the environment for kernel
env
=
kw
.
pop
(
'
env
'
,
os
.
environ
).
copy
()
# Don't allow PYTHONEXECUTABLE to be passed to kernel process.
...
...
@@ -149,7 +160,7 @@ class SlurmKernelManager(IOLoopKernelManager):
In all cases the kernel is restarted, the only difference is whether
it is given a chance to perform a clean shutdown or not.
newports : igored
newports : i
n
gored
, always True effectively
Left for the compatibility with Jupyter
'
s reference
implementation. We can
'
t guarantee, that node of the new kernel
will be the same, so ports are always cleaned and assigned freshly.
...
...
@@ -171,6 +182,15 @@ class SlurmKernelManager(IOLoopKernelManager):
self
.
start_kernel
(
**
self
.
_launch_args
)
def
_launch_slurm_shell
(
self
,
env
):
"""
Launches an interactive SLURM shell with
'
salloc
'
and
'
srun
'
and
returns information about it.
Parameters
----------
`env` : dict or None
A dictionary of environment variables, passed to the process. If
None, shell inherits parent process
'
environment.
"""
metadata
=
self
.
kernel_spec
.
metadata
.
get
(
self
.
_metadata_namespace
,
None
)
if
metadata
is
None
:
raise
SlurmAllocationError
(
"
SLURM metadata for the kernel
"
...
...
@@ -213,6 +233,9 @@ class SlurmKernelManager(IOLoopKernelManager):
raise_from
(
SlurmAllocationError
(
e
),
tb
)
def
write_connection_file
(
self
):
"""
Write connection info to JSON dict and assign
self.connection_file.
"""
if
(
self
.
_connection_file_written
and
os
.
path
.
exists
(
self
.
connection_file
)):
return
...
...
@@ -286,6 +309,7 @@ class SlurmKernelManager(IOLoopKernelManager):
return
True
def
_kill_kernel
(
self
):
"""
Kill the running kernel.
"""
if
self
.
has_kernel
:
self
.
kernel
.
kill
(
1
)
self
.
kernel
.
wait
()
...
...
@@ -295,13 +319,14 @@ class SlurmKernelManager(IOLoopKernelManager):
raise
RuntimeError
(
"
Cannot kill kernel. No kernel is running!
"
)
def
signal_kernel
(
self
,
signum
):
"""
Sends a signal to the shell, where the kernel is being executed.
"""
if
self
.
has_kernel
:
self
.
kernel
.
kill
(
signum
)
else
:
raise
RuntimeError
(
"
Cannot signal kernel. No kernel is running!
"
)
def
is_alive
(
self
):
"""
Kernel is
treat
ed as alive, if its job exists and its state is
"""
Kernel is
consider
ed as alive, if its job exists and its state is
RUNNING
"""
out
=
PopenSpawn
([
self
.
scontrol_command
,
...
...
This diff is collapsed.
Click to expand it.
nb_slurm/kernelspecmanager.py
+
14
−
0
View file @
f26c8f84
...
...
@@ -11,6 +11,12 @@ except ImportError:
# noinspection PyClassHasNoInit
class
SlurmKernelSpecManager
(
KernelSpecManager
):
"""
For each Jupyter kernel profile its parent finds this class generates
a set of child profiles, that are used to execute these kernels with
different SLURM parameters. Parameters are configurable via Jupyter
config and passed to the Kernel Manager via KernelSpec metadata.
"""
profiles
=
Dict
(
default_value
=
{
'
default
'
:
[]},
help
=
(
...
...
@@ -32,6 +38,10 @@ class SlurmKernelSpecManager(KernelSpecManager):
metadata_salloc_args
=
'
salloc_args
'
def
find_kernel_specs
(
self
):
"""
Gets kernel spec from `nb_conda_kernels.CondaKernelSpecManager` or
`jupyter_client.kernelspec.KernelSpecManager` and generates SLURM
profiles for each of them.
"""
kspecs
=
super
(
SlurmKernelSpecManager
,
self
).
find_kernel_specs
()
return
{
self
.
_kn_separator
.
join
((
kernel_name
,
profile_name
)):
profile_loc
...
...
@@ -40,6 +50,10 @@ class SlurmKernelSpecManager(KernelSpecManager):
}
def
get_kernel_spec
(
self
,
kernel_name
):
"""
Returns a :class:`KernelSpec` instance for the given kernel_name.
Raises KeyError if the given kernel name is not found.
"""
splitted
=
kernel_name
.
split
(
self
.
_kn_separator
)
orig_name
=
self
.
_kn_separator
.
join
(
splitted
[:
-
1
])
profile_name
=
splitted
[
-
1
]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment