Spaces:
Running
Running
File size: 5,545 Bytes
79edee4 |
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 |
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"\n",
"from ase import units\n",
"from dask.distributed import Client\n",
"from dask_jobqueue import SLURMCluster\n",
"from dotenv import load_dotenv\n",
"from prefect import flow, task\n",
"from prefect_dask import DaskTaskRunner\n",
"\n",
"from mlip_arena.models import REGISTRY, MLIPEnum\n",
"from mlip_arena.tasks.md import run as MD\n",
"from mlip_arena.tasks.stability.input import get_atoms_from_db\n",
"\n",
"load_dotenv()\n",
"\n",
"HF_TOKEN = os.environ.get(\"HF_TOKEN\", None)\n",
"MP_API_KEY = os.environ.get(\"MP_API_KEY\", None)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"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",
" processes=1,\n",
" shebang=\"#!/bin/bash\",\n",
" account=\"matgen\",\n",
" walltime=\"03:00:00\",\n",
" # job_cpu=128,\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 stability-npt\",\n",
" \"-q preempt\",\n",
" \"--time-min=00:30:00\",\n",
" \"--comment=12:00:00\",\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=5, maximum_jobs=10)\n",
"client = Client(cluster)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from mlip_arena.tasks.utils import get_calculator\n",
"\n",
"selected_models = [\n",
" \"MACE-MP(M)\",\n",
" \"CHGNet\",\n",
" \"M3GNet\",\n",
" \"MatterSim\",\n",
" \"eqV2(OMat)\",\n",
" \"MACE-MPA\",\n",
" \"ORBv2\",\n",
" \"SevenNet\",\n",
" \"ALIGNN\",\n",
"]\n",
"\n",
"\n",
"@task\n",
"def run_one(\n",
" atoms,\n",
" model,\n",
"):\n",
" result = MD.with_options(\n",
" timeout_seconds=600,\n",
" retries=2,\n",
" refresh_cache=True\n",
" )(\n",
" atoms=atoms,\n",
" calculator=get_calculator(\n",
" model.name,\n",
" calculator_kwargs=None,\n",
" ),\n",
" ensemble=\"npt\",\n",
" dynamics=\"nose-hoover\",\n",
" time_step=None,\n",
" dynamics_kwargs=dict(\n",
" ttime=25 * units.fs, pfactor=((75 * units.fs) ** 2) * 1e2 * units.GPa\n",
" ),\n",
" total_time=1e4, # 5e4, # fs\n",
" temperature=[300, 3000],\n",
" pressure=[0, 5e2 * units.GPa], # 500 GPa / 10 ps = 50 GPa / 1 ps\n",
" traj_file=f\"{REGISTRY[model.name]['family']}/{model.name}_{atoms.info.get('material_id', 'random')}_{atoms.get_chemical_formula()}_npt.traj\",\n",
" traj_interval=10,\n",
" )\n",
"\n",
" return result\n",
"\n",
"\n",
"@flow\n",
"def compress():\n",
" futures = []\n",
" # To download the database automatically, `huggingface_hub login` or provide HF_TOKEN\n",
" for atoms in get_atoms_from_db(\"random-mixture.db\", force_download=False):\n",
" for model in MLIPEnum:\n",
" if model.name not in selected_models:\n",
" continue\n",
"\n",
" if \"stability\" not in REGISTRY[model.name][\"gpu-tasks\"]:\n",
" continue\n",
"\n",
" try:\n",
" future = run_one.with_options(\n",
" timeout_seconds=600, retries=2, refresh_cache=False\n",
" ).submit(atoms.copy(), model)\n",
" futures.append(future)\n",
" except:\n",
" continue\n",
"\n",
" return [future.result(raise_on_failure=False) for future in futures]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"compress.with_options(\n",
" task_runner=DaskTaskRunner(address=client.scheduler.address), log_prints=True\n",
")()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "NERSC Python",
"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.7"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 4
}
|