quickstart.ipynb 2.99 KB
Newer Older
1 2 3 4 5 6
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
Wout De Nolf's avatar
Wout De Nolf committed
7 8
    "# Quick start\n",
    "\n",
Wout De Nolf's avatar
Wout De Nolf committed
9
    "## Submit\n",
Wout De Nolf's avatar
Wout De Nolf committed
10
    "\n",
Wout De Nolf's avatar
Wout De Nolf committed
11
    "Run an OAR job that prints \"Hello world\" (only \"command\" is a required argument):"
12 13 14 15
   ]
  },
  {
   "cell_type": "code",
Wout De Nolf's avatar
Wout De Nolf committed
16
   "execution_count": 8,
Wout De Nolf's avatar
Wout De Nolf committed
17 18 19
   "metadata": {
    "scrolled": true
   },
Wout De Nolf's avatar
Wout De Nolf committed
20 21 22 23 24
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
Wout De Nolf's avatar
Wout De Nolf committed
25
      "Job(1131384)\n",
Wout De Nolf's avatar
Wout De Nolf committed
26 27 28 29 30
      " name = quickstart\n",
      " project = oarpy\n",
      " state = Waiting\n",
      " owner = denolf\n",
      " runtime = 0:00:00\n",
Wout De Nolf's avatar
Wout De Nolf committed
31
      "..............\n",
Wout De Nolf's avatar
Wout De Nolf committed
32 33 34
      "Succes:\n",
      "Hello word\n",
      "\n"
Wout De Nolf's avatar
Wout De Nolf committed
35 36 37
     ]
    }
   ],
38
   "source": [
Wout De Nolf's avatar
Wout De Nolf committed
39
    "from oarpy.oarjob import submit\n",
40
    "\n",
Wout De Nolf's avatar
Wout De Nolf committed
41
    "job = submit(command='echo \"Hello word\"', name='quickstart',\n",
Wout De Nolf's avatar
Wout De Nolf committed
42
    "             project='oarpy', core=1, gpu=False, walltime={'hours':2})\n",
Wout De Nolf's avatar
Wout De Nolf committed
43
    "print(job)\n",
44
    "job.wait()\n",
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
    "\n",
    "if job.exit_code:\n",
    "    print('Failed:\\n{}'.format(job.stderr))\n",
    "elif job.exit_code is None:\n",
    "    print('Interrupted:\\n{}'.format(job.stdout))\n",
    "else:\n",
    "    print('Succes:\\n{}'.format(job.stdout))\n",
    "\n",
    "job.remove_logs()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
Wout De Nolf's avatar
Wout De Nolf committed
60
    "## Search\n",
Wout De Nolf's avatar
Wout De Nolf committed
61
    "\n",
Wout De Nolf's avatar
Wout De Nolf committed
62 63 64 65 66
    "Find the job started above in case you know the job ID:"
   ]
  },
  {
   "cell_type": "code",
Wout De Nolf's avatar
Wout De Nolf committed
67
   "execution_count": 9,
Wout De Nolf's avatar
Wout De Nolf committed
68 69 70 71 72 73
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
Wout De Nolf's avatar
Wout De Nolf committed
74
      "Job(1131384)\n",
Wout De Nolf's avatar
Wout De Nolf committed
75 76 77 78
      " name = quickstart\n",
      " project = oarpy\n",
      " state = Terminated\n",
      " owner = denolf\n",
Wout De Nolf's avatar
Wout De Nolf committed
79
      " runtime = 0:00:07\n"
Wout De Nolf's avatar
Wout De Nolf committed
80 81 82 83 84
     ]
    }
   ],
   "source": [
    "from oarpy.oarjob import Job\n",
Wout De Nolf's avatar
Wout De Nolf committed
85
    "job = Job(1131384)\n",
Wout De Nolf's avatar
Wout De Nolf committed
86 87 88 89 90 91 92 93
    "print(job)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Find the job started above in case you do not know the job ID (not all arguments are necessary):"
94 95 96 97
   ]
  },
  {
   "cell_type": "code",
Wout De Nolf's avatar
Wout De Nolf committed
98
   "execution_count": 10,
99
   "metadata": {},
Wout De Nolf's avatar
Wout De Nolf committed
100 101 102 103 104
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
Wout De Nolf's avatar
Wout De Nolf committed
105
      "[Job(1131384)]\n"
Wout De Nolf's avatar
Wout De Nolf committed
106 107 108
     ]
    }
   ],
109
   "source": [
Wout De Nolf's avatar
Wout De Nolf committed
110
    "from oarpy.oarjob import search\n",
111
    "from oarpy import timeutils\n",
Wout De Nolf's avatar
Wout De Nolf committed
112
    "import os\n",
113
    "\n",
Wout De Nolf's avatar
Wout De Nolf committed
114
    "owner = os.getlogin()\n",
Wout De Nolf's avatar
Wout De Nolf committed
115
    "start = timeutils.add(timeutils.now(), minutes=-3)\n",
Wout De Nolf's avatar
Wout De Nolf committed
116 117 118
    "jobs = search(owner=owner, start=start, name='quickstart',\n",
    "              project='oarpy', state='Terminated')\n",
    "print(jobs)"
119 120 121 122 123 124 125 126 127 128 129 130
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
Wout De Nolf's avatar
Wout De Nolf committed
131
    "version": 2
132 133 134 135 136
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
Wout De Nolf's avatar
Wout De Nolf committed
137 138
   "pygments_lexer": "ipython2",
   "version": "2.7.9"
139 140 141 142 143
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}