Skip to content

Instantly share code, notes, and snippets.

@minrk
Last active October 18, 2021 18:30
Show Gist options
  • Save minrk/381f0eb13ab0445efc05b3ec010c2dd4 to your computer and use it in GitHub Desktop.
Save minrk/381f0eb13ab0445efc05b3ec010c2dd4 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "41853895-e5d7-4139-970b-34fdc2edb310",
"metadata": {},
"outputs": [],
"source": [
"import ipyparallel as ipp"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "748dca8f-25e3-473e-8dd3-1f09e0c12c76",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Using existing profile dir: '/data/profile'\n",
"Starting 2 engines with <class 'ipyparallel.cluster.launcher.SlurmEngineSetLauncher'>\n",
"Job submitted with job id: '14'\n",
"100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:08<00:00, 4.36s/engine]\n"
]
}
],
"source": [
"cluster = ipp.Cluster(engine_launcher_class=\"slurm\", controller_ip=\"0.0.0.0\", profile_dir=\"/data/profile\")\n",
"cluster.config.SlurmEngineSetLauncher.batch_template = \"\"\"\\\n",
"#!/bin/sh\n",
"#SBATCH --ntasks={n}\n",
"#SBATCH --export=ALL\n",
"#SBATCH --job-name=ipengine-{cluster_id}\n",
"#SBATCH --mem=1gb\n",
"#SBATCH --time=00:05:00\n",
"#SBATCH --ntasks-per-node=1\n",
"env | sort\n",
"\n",
"srun {program_and_args}\n",
"\"\"\"\n",
"\n",
"cluster.start_cluster_sync(n=2)\n",
"rc = cluster.connect_client_sync()\n",
"rc.wait_for_engines(2)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "e6ffeba7-a5f3-4fef-878e-3ff9d3c7f734",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)\n",
" 14 normal ipengine root R 0:06 2 c[1-2]\n"
]
}
],
"source": [
"!squeue"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "11ea5231-bca2-47a0-aff6-0aea26d1ceea",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{0: 'c1', 1: 'c2'}"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import socket\n",
"rc[:].apply_async(socket.gethostname).get_dict()"
]
},
{
"cell_type": "markdown",
"id": "fea4d80b-2953-4ad5-b599-5707698c6639",
"metadata": {},
"source": [
"The rendered template:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "a0877530-f510-4c3b-b49a-7dce836b1c34",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"#!/bin/sh\n",
"#SBATCH --ntasks=2\n",
"#SBATCH --export=ALL\n",
"#SBATCH --job-name=ipengine-1634581693-wslm\n",
"#SBATCH --mem=1gb\n",
"#SBATCH --time=00:05:00\n",
"#SBATCH --ntasks-per-node=1\n",
"env | sort\n",
"\n",
"srun /usr/bin/python3 -m ipyparallel.engine\n"
]
}
],
"source": [
"!cat slurm_engine.sbatch"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment