You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Problem: We do not have good examples for replicating
flux job info in Python
Solution: Add an interactive demo
Signed-off-by: vsoch <[email protected]>
"Here we instantiate a flux handle. This will connect to the running flux instance.\nIf you were running this on a cluster with Flux, you'd likely already be able to\nconnect. If you are testing out on your own, you might need to do flux start --test-size=4\n\n"
26
+
]
27
+
},
28
+
{
29
+
"cell_type": "code",
30
+
"execution_count": null,
31
+
"metadata": {
32
+
"collapsed": false
33
+
},
34
+
"outputs": [],
35
+
"source": [
36
+
"handle = flux.Flux()"
37
+
]
38
+
},
39
+
{
40
+
"cell_type": "markdown",
41
+
"metadata": {},
42
+
"source": [
43
+
"This is a new jobspec, or a recipe for a flux job. You'll notice we are providing a command\ndirectly, along with tasks, nodes, and cores per task. You could also provide a script here.\nIf we were doing this on the command line, it would be equivalent to what is generated by:\nflux submit --ntasks=4 --nodes=2 --cores-per-task=2 sleep 10\n\n"
"Now let's say we store that jobid somewhere how do we get info later?\nWe know that if we ran flux jobs -a on the command line, we'd see the job\n\n"
116
+
]
117
+
},
118
+
{
119
+
"cell_type": "code",
120
+
"execution_count": null,
121
+
"metadata": {
122
+
"collapsed": false
123
+
},
124
+
"outputs": [],
125
+
"source": [
126
+
"res = subprocess.getoutput('flux jobs -a')\nprint(res)"
127
+
]
128
+
},
129
+
{
130
+
"cell_type": "markdown",
131
+
"metadata": {},
132
+
"source": [
133
+
"And if you are an expert user, you know that you can see metadata for a job\nThis command, without a key, will show the keys available to you\n\n"
134
+
]
135
+
},
136
+
{
137
+
"cell_type": "code",
138
+
"execution_count": null,
139
+
"metadata": {
140
+
"collapsed": false
141
+
},
142
+
"outputs": [],
143
+
"source": [
144
+
"res = subprocess.getoutput(f'flux job info {jobid} | true')\nprint(res)"
145
+
]
146
+
},
147
+
{
148
+
"cell_type": "markdown",
149
+
"metadata": {},
150
+
"source": [
151
+
"And since the underlying logic here is pinging the flux KVS or key value store,\nwe can select one of those keys to view. For example, here is the jobspec\n\n"
152
+
]
153
+
},
154
+
{
155
+
"cell_type": "code",
156
+
"execution_count": null,
157
+
"metadata": {
158
+
"collapsed": false
159
+
},
160
+
"outputs": [],
161
+
"source": [
162
+
"res = subprocess.getoutput(f'flux job info {jobid} jobspec')\nprint(res)"
163
+
]
164
+
},
165
+
{
166
+
"cell_type": "markdown",
167
+
"metadata": {},
168
+
"source": [
169
+
"This is great, but ideally we can get this metadata directly from Python.\nFirst, here is a way to get basic jobinfo. Given we start with a string jobid,\nwe will first want to parse it back into a Flux JobID, and then prepare\na payload to the Job List RPC to say \"give me all the attributes back\"\n\n"
"You can get less commonly used (and thus exposed) metadata like this\nsuch as the emoji state!\n\n"
188
+
]
189
+
},
190
+
{
191
+
"cell_type": "code",
192
+
"execution_count": null,
193
+
"metadata": {
194
+
"collapsed": false
195
+
},
196
+
"outputs": [],
197
+
"source": [
198
+
"info = rpc.get_jobinfo()\nprint(info.__dict__)"
199
+
]
200
+
},
201
+
{
202
+
"cell_type": "markdown",
203
+
"metadata": {},
204
+
"source": [
205
+
"But for either of the above approaches, we aren't getting anything back about our\noriginal jobspec! That's because we need to query the KVS for that. Notice here we\nhave metadata like the current working directory (cwd)\n\n"
"Finally, to watch (or stream) output, you can do the following.\nEach line here is a json structure that you can further parse.\nAs an example, if \"data\" is present as a key, this usually is output\n\n"
224
+
]
225
+
},
226
+
{
227
+
"cell_type": "code",
228
+
"execution_count": null,
229
+
"metadata": {
230
+
"collapsed": false
231
+
},
232
+
"outputs": [],
233
+
"source": [
234
+
"for line in flux.job.event_watch(handle, jobid, \"guest.output\"):\n print(line)"
0 commit comments