File size: 28,447 Bytes
072f65e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Prepare input structures\n",
    "\n",
    "We first start by preparing the input ASE database. In the subfolder `structures` there are 9 example MOF structures. `save_to_db` is an convenient function to conver CIF files into one db."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[32m2024-12-22 11:40:02.836\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mmlip_arena.tasks.mof\u001b[0m:\u001b[36m<module>\u001b[0m:\u001b[36m6\u001b[0m - \u001b[1m\n",
      "The module 'mlip_arena.tasks.mof' is adapted from the repository: https://github.com/hspark1212/DAC-SIM. \n",
      "By using this module, you agree to the terms and conditions specified in the following license: \n",
      "\n",
      "https://github.com/hspark1212/DAC-SIM/blob/main/LICENSE\n",
      "\n",
      "Additionally, please ensure proper attribution by citing the reference: \n",
      "\n",
      "Lim, Y., Park, H., Walsh, A., & Kim, J. (2024). Accelerating CO₂ Direct Air Capture Screening for Metal-Organic Frameworks with a Transferable Machine Learning Force Field.\n",
      "\n",
      "A local copy of the LICENSE file can be found at: /pscratch/sd/c/cyrusyc/mlip-arena/mlip_arena/tasks/mof/LICENSE.\n",
      "\u001b[0m\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "No module named 'deepmd'\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/pscratch/sd/c/cyrusyc/.conda/mlip-arena/lib/python3.11/site-packages/ase/io/cif.py:408: UserWarning: crystal system 'triclinic' is not interpreted for space group Spacegroup(1, setting=1). This may result in wrong setting!\n",
      "  warnings.warn(\n",
      "\u001b[32m2024-12-22 11:40:22.686\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mmlip_arena.tasks.mof.input\u001b[0m:\u001b[36msave_to_db\u001b[0m:\u001b[36m45\u001b[0m - \u001b[1mmofs.db uploaded to atomind/mlip-arena/mof\u001b[0m\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "PosixPath('mofs.db')"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from dotenv import load_dotenv\n",
    "load_dotenv()\n",
    "\n",
    "import glob\n",
    "from ase.io import read\n",
    "from mlip_arena.tasks.mof.input import save_to_db\n",
    "\n",
    "files = glob.glob('structures/*.cif')\n",
    "\n",
    "atoms_list = []\n",
    "\n",
    "for file in files:\n",
    "    atoms = read(file)\n",
    "    atoms_list.append(atoms)\n",
    "\n",
    "save_to_db(\n",
    "    atoms_list=atoms_list,\n",
    "    db_path='mofs.db'\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "tags": []
   },
   "source": [
    "## Demo: MOF benchmark workflow"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "from ase.build import molecule\n",
    "from mlip_arena.models import MLIPEnum\n",
    "from mlip_arena.tasks.mof.input import get_atoms_from_db\n",
    "from mlip_arena.tasks.mof.flow import widom_insertion\n",
    "from prefect import flow\n",
    "from tqdm.auto import tqdm\n",
    "\n",
    "@flow\n",
    "def benchmark_one():\n",
    "    results = []\n",
    "    for model in MLIPEnum:\n",
    "        if model.name != \"MACE-MP(M)\":\n",
    "            continue # skip all models other than MACE-MP\n",
    "        for atoms in tqdm(get_atoms_from_db('mofs.db')):\n",
    "            result = widom_insertion(\n",
    "                atoms, \n",
    "                molecule('CO2'),\n",
    "                calculator_name=model.name,\n",
    "            )\n",
    "            results.append(result)\n",
    "            break # only test on first MOF\n",
    "    return [r for r in results]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">15:46:06.786 | <span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>    | Flow run<span style=\"color: #800080; text-decoration-color: #800080\"> 'amigurumi-beagle'</span> - Beginning flow run<span style=\"color: #800080; text-decoration-color: #800080\"> 'amigurumi-beagle'</span> for flow<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\"> 'benchmark-one'</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "15:46:06.786 | \u001b[36mINFO\u001b[0m    | Flow run\u001b[35m 'amigurumi-beagle'\u001b[0m - Beginning flow run\u001b[35m 'amigurumi-beagle'\u001b[0m for flow\u001b[1;35m 'benchmark-one'\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "2a1bc33089b44a308a44cd14979533f7",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "0it [00:00, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "6c5c9eda59644f528f76c5b2b18b272d",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "mof/mofs.db:   0%|          | 0.00/168k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">15:46:07.619 | <span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>    | Task run 'Widom Insertion: C28H16O10V2 + CO2 - MACE-MP(M)' - Optimizing structure\n",
       "</pre>\n"
      ],
      "text/plain": [
       "15:46:07.619 | \u001b[36mINFO\u001b[0m    | Task run 'Widom Insertion: C28H16O10V2 + CO2 - MACE-MP(M)' - Optimizing structure\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Selected GPU cuda:0 with 40339.31 MB free memory from 1 GPUs\n",
      "Using device: cuda:0\n",
      "Selected GPU cuda:0 with 40339.31 MB free memory from 1 GPUs\n",
      "Default dtype float32 does not match model dtype float64, converting models to float32.\n",
      "Using calculator: <mlip_arena.models.externals.mace-mp.MACE_MP_Medium object at 0x7f8395425890>\n",
      "Using filter: <ase.filters.FrechetCellFilter object at 0x7f839420ba50>\n",
      "Using optimizer: <ase.optimize.fire2.FIRE2 object at 0x7f839662e4d0>\n",
      "       Step     Time          Energy          fmax\n",
      "FIRE2:    0 15:46:10     -398.611542        0.341164\n",
      "FIRE2:    1 15:46:10     -398.627014        0.185914\n",
      "FIRE2:    2 15:46:12     -398.632233        0.157950\n",
      "FIRE2:    3 15:46:12     -398.636993        0.163124\n",
      "FIRE2:    4 15:46:12     -398.633881        0.158292\n",
      "FIRE2:    5 15:46:13     -398.642792        0.152467\n",
      "FIRE2:    6 15:46:13     -398.643768        0.142569\n",
      "FIRE2:    7 15:46:13     -398.637024        0.131079\n",
      "FIRE2:    8 15:46:13     -398.648560        0.115860\n",
      "FIRE2:    9 15:46:13     -398.648590        0.099157\n",
      "FIRE2:   10 15:46:13     -398.654022        0.081072\n",
      "FIRE2:   11 15:46:14     -398.651306        0.062052\n",
      "FIRE2:   12 15:46:14     -398.661194        0.044053\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">15:46:14.836 | <span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>    | Task run 'OPT: C28H16O10V2 - MACE-MP(M)' - Finished in state <span style=\"color: #008000; text-decoration-color: #008000\">Completed</span>()\n",
       "</pre>\n"
      ],
      "text/plain": [
       "15:46:14.836 | \u001b[36mINFO\u001b[0m    | Task run 'OPT: C28H16O10V2 - MACE-MP(M)' - Finished in state \u001b[32mCompleted\u001b[0m()\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">15:46:14.840 | <span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>    | Task run 'Widom Insertion: C28H16O10V2 + CO2 - MACE-MP(M)' - Optimizing gas molecule\n",
       "</pre>\n"
      ],
      "text/plain": [
       "15:46:14.840 | \u001b[36mINFO\u001b[0m    | Task run 'Widom Insertion: C28H16O10V2 + CO2 - MACE-MP(M)' - Optimizing gas molecule\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Selected GPU cuda:0 with 40301.98 MB free memory from 1 GPUs\n",
      "Using device: cuda:0\n",
      "Selected GPU cuda:0 with 40301.98 MB free memory from 1 GPUs\n",
      "Default dtype float32 does not match model dtype float64, converting models to float32.\n",
      "Using calculator: <mlip_arena.models.externals.mace-mp.MACE_MP_Medium object at 0x7f83942934d0>\n",
      "Using optimizer: <ase.optimize.fire2.FIRE2 object at 0x7f8394175990>\n",
      "       Step     Time          Energy          fmax\n",
      "FIRE2:    0 15:46:15      -22.777348        0.437851\n",
      "FIRE2:    1 15:46:17      -22.778408        0.014392\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">15:46:17.127 | <span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>    | Task run 'OPT: CO2 - MACE-MP(M)' - Finished in state <span style=\"color: #008000; text-decoration-color: #008000\">Completed</span>()\n",
       "</pre>\n"
      ],
      "text/plain": [
       "15:46:17.127 | \u001b[36mINFO\u001b[0m    | Task run 'OPT: CO2 - MACE-MP(M)' - Finished in state \u001b[32mCompleted\u001b[0m()\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of accessible positions: 357364 out of total 498623\n",
      "Selected GPU cuda:0 with 40280.80 MB free memory from 1 GPUs\n",
      "Using device: cuda:0\n",
      "Selected GPU cuda:0 with 40280.80 MB free memory from 1 GPUs\n",
      "Default dtype float32 does not match model dtype float64, converting models to float32.\n",
      "Using calculator: <mlip_arena.models.externals.mace-mp.MACE_MP_Medium object at 0x7f838c597e50>\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "986f472b9f3f41f08f9b0f4f63a3e115",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Fold 1/3:   0%|          | 0/5000 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "fdc869472a884749984fbf9d79523b00",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Fold 2/3:   0%|          | 0/5000 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "104602f6026249ff8cd0d0d302b84a46",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Fold 3/3:   0%|          | 0/5000 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/pscratch/sd/c/cyrusyc/mlip-arena-dev/mlip_arena/tasks/mof/flow.py:291: RuntimeWarning: overflow encountered in exp\n",
      "  boltzmann_factor = np.exp(\n",
      "/pscratch/sd/c/cyrusyc/mlip-arena-dev/mlip_arena/tasks/mof/flow.py:311: RuntimeWarning: overflow encountered in exp\n",
      "  boltzmann_factor = np.exp(\n",
      "/pscratch/sd/c/cyrusyc/mlip-arena-dev/mlip_arena/tasks/mof/flow.py:326: RuntimeWarning: invalid value encountered in scalar divide\n",
      "  u = (interaction_energies * boltzmann_factor).sum() / boltzmann_factor.sum()\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">15:52:13.884 | <span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>    | Task run 'Widom Insertion: C28H16O10V2 + CO2 - MACE-MP(M)' - Finished in state <span style=\"color: #008000; text-decoration-color: #008000\">Completed</span>()\n",
       "</pre>\n"
      ],
      "text/plain": [
       "15:52:13.884 | \u001b[36mINFO\u001b[0m    | Task run 'Widom Insertion: C28H16O10V2 + CO2 - MACE-MP(M)' - Finished in state \u001b[32mCompleted\u001b[0m()\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">15:52:14.235 | <span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>    | Flow run<span style=\"color: #800080; text-decoration-color: #800080\"> 'amigurumi-beagle'</span> - Finished in state <span style=\"color: #008000; text-decoration-color: #008000\">Completed</span>()\n",
       "</pre>\n"
      ],
      "text/plain": [
       "15:52:14.235 | \u001b[36mINFO\u001b[0m    | Flow run\u001b[35m 'amigurumi-beagle'\u001b[0m - Finished in state \u001b[32mCompleted\u001b[0m()\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "[2.3816888372250245e-06, 2.5323794093995965e-06, inf]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result = benchmark_one()\n",
    "result[0]['henry_coefficient']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Run workflow"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">11:40:36.644 | <span style=\"color: #d7d700; text-decoration-color: #d7d700\">WARNING</span> | MDAnalysis.coordinates.AMBER - netCDF4 is not available. Writing AMBER ncdf files will be slow.\n",
       "</pre>\n"
      ],
      "text/plain": [
       "11:40:36.644 | \u001b[38;5;184mWARNING\u001b[0m | MDAnalysis.coordinates.AMBER - netCDF4 is not available. Writing AMBER ncdf files will be slow.\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">11:40:44.431 | <span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>    | distributed.http.proxy - To route to workers diagnostics web server please install jupyter-server-proxy: python -m pip install jupyter-server-proxy\n",
       "</pre>\n"
      ],
      "text/plain": [
       "11:40:44.431 | \u001b[36mINFO\u001b[0m    | distributed.http.proxy - To route to workers diagnostics web server please install jupyter-server-proxy: python -m pip install jupyter-server-proxy\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">11:40:44.445 | <span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>    | distributed.scheduler - State start\n",
       "</pre>\n"
      ],
      "text/plain": [
       "11:40:44.445 | \u001b[36mINFO\u001b[0m    | distributed.scheduler - State start\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">11:40:44.503 | <span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>    | distributed.scheduler -   Scheduler at:  tcp://128.55.64.42:36351\n",
       "</pre>\n"
      ],
      "text/plain": [
       "11:40:44.503 | \u001b[36mINFO\u001b[0m    | distributed.scheduler -   Scheduler at:  tcp://128.55.64.42:36351\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">11:40:44.505 | <span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>    | distributed.scheduler -   dashboard at:  <span style=\"color: #0000ff; text-decoration-color: #0000ff\">http://128.55.64.42:8787/status</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "11:40:44.505 | \u001b[36mINFO\u001b[0m    | distributed.scheduler -   dashboard at:  \u001b[94mhttp://128.55.64.42:8787/status\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">11:40:44.506 | <span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>    | distributed.scheduler - Registering Worker plugin shuffle\n",
       "</pre>\n"
      ],
      "text/plain": [
       "11:40:44.506 | \u001b[36mINFO\u001b[0m    | distributed.scheduler - Registering Worker plugin shuffle\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#!/bin/bash\n",
      "\n",
      "#SBATCH -A matgen\n",
      "#SBATCH --mem=0\n",
      "#SBATCH -t 00:30:00\n",
      "#SBATCH -J mof\n",
      "#SBATCH -q regular\n",
      "#SBATCH -N 1\n",
      "#SBATCH -C gpu\n",
      "#SBATCH -G 4\n",
      "source ~/.bashrc\n",
      "module load python\n",
      "source activate /pscratch/sd/c/cyrusyc/.conda/mlip-arena\n",
      "/pscratch/sd/c/cyrusyc/.conda/mlip-arena/bin/python -m distributed.cli.dask_worker tcp://128.55.64.42:36351 --name dummy-name --nthreads 1 --memory-limit 59.60GiB --nanny --death-timeout 60\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">11:40:44.514 | <span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>    | distributed.deploy.adaptive - Adaptive scaling started: minimum=10 maximum=20\n",
       "</pre>\n"
      ],
      "text/plain": [
       "11:40:44.514 | \u001b[36mINFO\u001b[0m    | distributed.deploy.adaptive - Adaptive scaling started: minimum=10 maximum=20\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">11:40:44.522 | <span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>    | distributed.scheduler - Receive client connection: Client-a27a9a6e-c09c-11ef-8318-c77ccf4f19b4\n",
       "</pre>\n"
      ],
      "text/plain": [
       "11:40:44.522 | \u001b[36mINFO\u001b[0m    | distributed.scheduler - Receive client connection: Client-a27a9a6e-c09c-11ef-8318-c77ccf4f19b4\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">11:40:44.523 | <span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>    | distributed.core - Starting established connection to tcp://128.55.64.42:48148\n",
       "</pre>\n"
      ],
      "text/plain": [
       "11:40:44.523 | \u001b[36mINFO\u001b[0m    | distributed.core - Starting established connection to tcp://128.55.64.42:48148\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">11:40:45.046 | <span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>    | prefect.engine - Created flow run<span style=\"color: #800080; text-decoration-color: #800080\"> 'enormous-hog'</span> for flow<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\"> 'run'</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "11:40:45.046 | \u001b[36mINFO\u001b[0m    | prefect.engine - Created flow run\u001b[35m 'enormous-hog'\u001b[0m for flow\u001b[1;35m 'run'\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">11:40:45.048 | <span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>    | prefect.engine - View at <span style=\"color: #0000ff; text-decoration-color: #0000ff\">https://app.prefect.cloud/account/f7d40474-9362-4bfa-8950-ee6a43ec00f3/workspace/d4bb0913-5f5e-49f7-bfc5-06509088baeb/runs/flow-run/c0c7a3f2-d8d0-4f17-9789-4e070f17bf3b</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "11:40:45.048 | \u001b[36mINFO\u001b[0m    | prefect.engine - View at \u001b[94mhttps://app.prefect.cloud/account/f7d40474-9362-4bfa-8950-ee6a43ec00f3/workspace/d4bb0913-5f5e-49f7-bfc5-06509088baeb/runs/flow-run/c0c7a3f2-d8d0-4f17-9789-4e070f17bf3b\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">11:40:45.366 | <span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>    | prefect.task_runner.dask - Connecting to existing Dask cluster SLURMCluster(00ac1d39, 'tcp://128.55.64.42:36351', workers=0, threads=0, memory=0 B)\n",
       "</pre>\n"
      ],
      "text/plain": [
       "11:40:45.366 | \u001b[36mINFO\u001b[0m    | prefect.task_runner.dask - Connecting to existing Dask cluster SLURMCluster(00ac1d39, 'tcp://128.55.64.42:36351', workers=0, threads=0, memory=0 B)\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">11:40:45.395 | <span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>    | distributed.scheduler - Receive client connection: PrefectDaskClient-a2fe06b3-c09c-11ef-8318-c77ccf4f19b4\n",
       "</pre>\n"
      ],
      "text/plain": [
       "11:40:45.395 | \u001b[36mINFO\u001b[0m    | distributed.scheduler - Receive client connection: PrefectDaskClient-a2fe06b3-c09c-11ef-8318-c77ccf4f19b4\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">11:40:45.401 | <span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>    | distributed.core - Starting established connection to tcp://128.55.64.42:48168\n",
       "</pre>\n"
      ],
      "text/plain": [
       "11:40:45.401 | \u001b[36mINFO\u001b[0m    | distributed.core - Starting established connection to tcp://128.55.64.42:48168\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "c88bb75bf9b84285bfd6d524e7d73650",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "0it [00:00, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">11:40:45.501 | <span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>    | Task run 'get_atoms_from_db-6be' - Created task run 'get_atoms_from_db-6be' for task 'get_atoms_from_db'\n",
       "</pre>\n"
      ],
      "text/plain": [
       "11:40:45.501 | \u001b[36mINFO\u001b[0m    | Task run 'get_atoms_from_db-6be' - Created task run 'get_atoms_from_db-6be' for task 'get_atoms_from_db'\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from dask.distributed import Client\n",
    "from dask_jobqueue import SLURMCluster\n",
    "from prefect_dask import DaskTaskRunner\n",
    "from mlip_arena.tasks.mof.flow import run as MOF\n",
    "\n",
    "# Orchestrate your awesome dask workflow runner\n",
    "\n",
    "nodes_per_alloc = 1\n",
    "gpus_per_alloc = 4\n",
    "ntasks = 1\n",
    "\n",
    "cluster_kwargs = dict(\n",
    "    cores=1,\n",
    "    memory=\"64 GB\",\n",
    "    shebang=\"#!/bin/bash\",\n",
    "    account=\"matgen\",\n",
    "    walltime=\"00:30:00\",\n",
    "    job_mem=\"0\",\n",
    "    job_script_prologue=[\n",
    "        \"source ~/.bashrc\",\n",
    "        \"module load python\",\n",
    "        \"source activate /pscratch/sd/c/cyrusyc/.conda/mlip-arena\",\n",
    "    ],\n",
    "    job_directives_skip=[\"-n\", \"--cpus-per-task\", \"-J\"],\n",
    "    job_extra_directives=[\n",
    "        \"-J mof\",\n",
    "        \"-q regular\",\n",
    "        f\"-N {nodes_per_alloc}\",\n",
    "        \"-C gpu\",\n",
    "        f\"-G {gpus_per_alloc}\",\n",
    "    ],\n",
    ")\n",
    "\n",
    "cluster = SLURMCluster(**cluster_kwargs)\n",
    "print(cluster.job_script())\n",
    "cluster.adapt(minimum_jobs=10, maximum_jobs=20)\n",
    "client = Client(cluster)\n",
    "\n",
    "# Run the workflow on HPC cluster in parallel\n",
    "\n",
    "results = MOF.with_options(\n",
    "    task_runner=DaskTaskRunner(address=client.scheduler.address),\n",
    "    # log_prints=True,\n",
    ")()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "mlip-arena",
   "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.11.8"
  },
  "widgets": {
   "application/vnd.jupyter.widget-state+json": {
    "state": {},
    "version_major": 2,
    "version_minor": 0
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}