diff --git a/projects/flow.hoomd.lj/src/project_2.ipynb b/projects/flow.hoomd.lj/src/project_2.ipynb new file mode 100644 index 0000000..c9c1b54 --- /dev/null +++ b/projects/flow.hoomd.lj/src/project_2.ipynb @@ -0,0 +1,304 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/ychihmei/opt/anaconda3/envs/RS/lib/python3.10/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", + " from .autonotebook import tqdm as notebook_tqdm\n" + ] + } + ], + "source": [ + "import flow\n", + "import hoomd\n", + "import numpy as np\n", + "import signac\n", + "\n", + "cpu = hoomd.device.CPU()\n", + "# Initialize the HOOMD-blue execution context\n", + "# hoomd.context.initialize(\"\")\n", + "\n", + "project_root = \"projects/tutorial-signac-flow-hoomd\"\n", + "\n", + "\n", + "class MyProject(flow.FlowProject):\n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "from math import ceil\n", + "\n", + "\n", + "def init(N):\n", + " with hoomd.Simulation(device=cpu, seed=job.statepoint.seed):\n", + " n = ceil(pow(N, 1 / 3))\n", + " assert n**3 == N\n", + " hoomd.init.create_lattice(unitcell=hoomd.lattice.sc(a=1.0), n=n)\n", + " hoomd.dump.gsd(\"init.gsd\", period=None, group=hoomd.group.all())\n", + "\n", + "\n", + "def sample_lj(N, sigma, seed, kT, tau, p, tauP, steps, r_cut):\n", + " from hoomd import md\n", + "\n", + " hoomd.init.read_gsd(\"init.gsd\", restart=\"restart.gsd\")\n", + " group = hoomd.group.all()\n", + " hoomd.dump.gsd(\"restart.gsd\", truncate=True, period=100, phase=0, group=group)\n", + " lj = md.pair.lj(r_cut=r_cut, nlist=md.nlist.cell())\n", + " lj.pair_coeff.set(\"A\", \"A\", epsilon=1.0, sigma=sigma)\n", + " md.integrate.mode_standard(dt=0.005)\n", + " md.integrate.npt(group=group, kT=kT, tau=tau, P=p, tauP=tauP)\n", + " hoomd.analyze.log(\"dump.log\", [\"V\"], 100, phase=0)\n", + " hoomd.run_upto(steps)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "@MyProject.label\n", + "def estimated(job):\n", + " return \"V\" in job.document\n", + "\n", + "\n", + "@MyProject.label\n", + "def sampled(job):\n", + " return job.document.get(\"sample_step\", 0) >= 5000\n", + "\n", + "\n", + "@MyProject.operation\n", + "@MyProject.post(estimated)\n", + "def estimate(job):\n", + " job.document[\"V\"] = job.sp.N * job.sp.kT / job.sp.p\n", + " # sp = job.statepoint()\n", + " # job.document[\"V\"] = sp[\"N\"] * sp[\"kT\"] / sp[\"p\"]\n", + "\n", + "\n", + "@MyProject.operation\n", + "@MyProject.post(sampled)\n", + "def sample(job):\n", + " import hoomd\n", + "\n", + " with job:\n", + " with hoomd.Simulation(device=cpu, seed=job.statepoint.seed):\n", + " try:\n", + " sample_lj(steps=5000, **job.statepoint())\n", + " finally:\n", + " job.document[\"sample_step\"] = hoomd.get_step()" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/ychihmei/opt/anaconda3/envs/RS/lib/python3.10/site-packages/signac/synced_collections/numpy_utils.py:46: NumpyConversionWarning: Any numpy types provided will be transparently converted to the closest base Python equivalents.\n", + " warnings.warn(NUMPY_CONVERSION_WARNING, NumpyConversionWarning)\n" + ] + } + ], + "source": [ + "project = MyProject.init_project(name=\"FlowTutorialHOOMDProject\", root=project_root)\n", + "\n", + "# Uncomment the following two lines if you want to start over!\n", + "# for job in project:\n", + "# job.remove()\n", + "\n", + "for p in np.linspace(0.5, 5.0, 10):\n", + " sp = dict(N=512, sigma=1.0, seed=42, kT=1.0, p=p, tau=1.0, tauP=1.0, r_cut=2.5)\n", + " job = project.open_job(sp).init()\n", + " with job:\n", + " hoomd.Simulation(device=sp[\"N\"], seed=None)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Fetching status: 100%|██████████| 20/20 [00:00<00:00, 7722.18it/s]\n", + "Fetching labels: 100%|██████████| 10/10 [00:00<00:00, 39568.91it/s]" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Overview: 10 jobs/aggregates, 10 jobs/aggregates with eligible operations.\n", + "\n", + "label ratio\n", + "--------- --------------------------------------------------------\n", + "estimated |████ | 1/10 (10.00%)\n", + "\n", + "operation number of eligible jobs submission status\n", + "----------- ------------------------- -------------------\n", + "sample 10 [U]: 10\n", + "estimate 9 [U]: 10\n", + "\n", + "Detailed View:\n", + "\n", + "job id operation p V labels\n", + "-------------------------------- ------------ --- ---- ---------\n", + "18c063206c37ab03d06de130c6ae2b70 estimate [U] 1 None\n", + " sample [U] 1 None\n", + "2a05a487f254db90b08f576d199a83b7 sample [U] 5 None estimated\n", + "4ef567c185064a4b27b73f62124991c0 estimate [U] 3 None\n", + " sample [U] 3 None\n", + "5b3c8f0fbd9458a304222d83bb82bc30 estimate [U] 3.5 None\n", + " sample [U] 3.5 None\n", + "6681f083e2b03f5b9816f35502e411f7 estimate [U] 1.5 None\n", + " sample [U] 1.5 None\n", + "6ff6b952b42f0ad3e1315e137cf67cdb estimate [U] 4 None\n", + " sample [U] 4 None\n", + "99f5397cf2f6250afe34927606aa2f37 estimate [U] 4.5 None\n", + " sample [U] 4.5 None\n", + "a5d4427e8d285c78239005f740a2625b estimate [U] 2 None\n", + " sample [U] 2 None\n", + "a89bc9f5cceaf268f18efed936a70333 estimate [U] 0.5 None\n", + " sample [U] 0.5 None\n", + "c342fff540bfa0a2128efac700fc5aef estimate [U] 2.5 None\n", + " sample [U] 2.5 None\n", + "\n", + "[U]:unknown [R]:registered [I]:inactive [S]:submitted [H]:held [Q]:queued [A]:active [E]:error\n", + "\n", + "\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "project.print_status(detailed=True, parameters=[\"p\", \"V\"])" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'V' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m/Users/ychihmei/Code/signac-examples/projects/flow.hoomd.lj/src/project_2.ipynb Cell 6\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[39mprint\u001b[39m(V)\n", + "\u001b[0;31mNameError\u001b[0m: name 'V' is not defined" + ] + } + ], + "source": [ + "print(V)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "ename": "UserOperationError", + "evalue": "An exception was raised during operation sample for job or aggregate with id 2a05a487f254db90b08f576d199a83b7.", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", + "File \u001b[0;32m~/opt/anaconda3/envs/RS/lib/python3.10/site-packages/flow/project.py:3190\u001b[0m, in \u001b[0;36mFlowProject._execute_operation\u001b[0;34m(self, operation, timeout, pretend)\u001b[0m\n\u001b[1;32m 3189\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m-> 3190\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_operations[operation\u001b[39m.\u001b[39;49mname](\u001b[39m*\u001b[39;49moperation\u001b[39m.\u001b[39;49m_jobs)\n\u001b[1;32m 3191\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mException\u001b[39;00m \u001b[39mas\u001b[39;00m error:\n", + "File \u001b[0;32m~/opt/anaconda3/envs/RS/lib/python3.10/site-packages/flow/project.py:622\u001b[0m, in \u001b[0;36mFlowOperation.__call__\u001b[0;34m(self, *jobs)\u001b[0m\n\u001b[1;32m 609\u001b[0m \u001b[39mr\u001b[39m\u001b[39m\"\"\"Call the operation on the provided jobs.\u001b[39;00m\n\u001b[1;32m 610\u001b[0m \n\u001b[1;32m 611\u001b[0m \u001b[39mParameters\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 620\u001b[0m \n\u001b[1;32m 621\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[0;32m--> 622\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_op_func(\u001b[39m*\u001b[39;49mjobs)\n", + "\u001b[1;32m/Users/ychihmei/Code/signac-examples/projects/flow.hoomd.lj/src/project_2.ipynb Cell 6\u001b[0m in \u001b[0;36msample\u001b[0;34m(job)\u001b[0m\n\u001b[1;32m 23\u001b[0m \u001b[39mwith\u001b[39;00m job:\n\u001b[0;32m---> 24\u001b[0m \u001b[39mwith\u001b[39;00m hoomd\u001b[39m.\u001b[39mSimulation(device\u001b[39m=\u001b[39mcpu, seed\u001b[39m=\u001b[39mjob\u001b[39m.\u001b[39mstatepoint\u001b[39m.\u001b[39mseed):\n\u001b[1;32m 25\u001b[0m \u001b[39mtry\u001b[39;00m:\n", + "\u001b[0;31mAttributeError\u001b[0m: __enter__", + "\nThe above exception was the direct cause of the following exception:\n", + "\u001b[0;31mUserOperationError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m/Users/ychihmei/Code/signac-examples/projects/flow.hoomd.lj/src/project_2.ipynb Cell 6\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m project\u001b[39m.\u001b[39;49mrun()\n", + "File \u001b[0;32m~/opt/anaconda3/envs/RS/lib/python3.10/site-packages/flow/project.py:3438\u001b[0m, in \u001b[0;36mFlowProject.run\u001b[0;34m(self, jobs, names, pretend, np, timeout, num, num_passes, progress, order, ignore_conditions)\u001b[0m\n\u001b[1;32m 3428\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\n\u001b[1;32m 3429\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mInvalid value for the \u001b[39m\u001b[39m'\u001b[39m\u001b[39morder\u001b[39m\u001b[39m'\u001b[39m\u001b[39m argument, valid arguments are \u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m 3430\u001b[0m \u001b[39m\"\u001b[39m\u001b[39m'\u001b[39m\u001b[39mnone\u001b[39m\u001b[39m'\u001b[39m\u001b[39m, \u001b[39m\u001b[39m'\u001b[39m\u001b[39mby-job\u001b[39m\u001b[39m'\u001b[39m\u001b[39m, \u001b[39m\u001b[39m'\u001b[39m\u001b[39mcyclic\u001b[39m\u001b[39m'\u001b[39m\u001b[39m, \u001b[39m\u001b[39m'\u001b[39m\u001b[39mrandom\u001b[39m\u001b[39m'\u001b[39m\u001b[39m, None, or a callable.\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m 3431\u001b[0m )\n\u001b[1;32m 3433\u001b[0m logger\u001b[39m.\u001b[39minfo(\n\u001b[1;32m 3434\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mExecuting \u001b[39m\u001b[39m%i\u001b[39;00m\u001b[39m operation(s) (Pass #\u001b[39m\u001b[39m%02d\u001b[39;00m\u001b[39m)...\u001b[39m\u001b[39m\"\u001b[39m,\n\u001b[1;32m 3435\u001b[0m \u001b[39mlen\u001b[39m(operations),\n\u001b[1;32m 3436\u001b[0m i_pass,\n\u001b[1;32m 3437\u001b[0m )\n\u001b[0;32m-> 3438\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_run_operations(\n\u001b[1;32m 3439\u001b[0m operations, pretend\u001b[39m=\u001b[39;49mpretend, np\u001b[39m=\u001b[39;49mnp, timeout\u001b[39m=\u001b[39;49mtimeout, progress\u001b[39m=\u001b[39;49mprogress\n\u001b[1;32m 3440\u001b[0m )\n", + "File \u001b[0;32m~/opt/anaconda3/envs/RS/lib/python3.10/site-packages/flow/project.py:3058\u001b[0m, in \u001b[0;36mFlowProject._run_operations\u001b[0;34m(self, operations, pretend, np, timeout, progress)\u001b[0m\n\u001b[1;32m 3056\u001b[0m operations \u001b[39m=\u001b[39m tqdm(operations)\n\u001b[1;32m 3057\u001b[0m \u001b[39mfor\u001b[39;00m operation \u001b[39min\u001b[39;00m operations:\n\u001b[0;32m-> 3058\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_execute_operation(operation, timeout, pretend)\n\u001b[1;32m 3059\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m 3060\u001b[0m logger\u001b[39m.\u001b[39mdebug(\u001b[39m\"\u001b[39m\u001b[39mParallelized execution of \u001b[39m\u001b[39m%i\u001b[39;00m\u001b[39m operation(s).\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39mlen\u001b[39m(operations))\n", + "File \u001b[0;32m~/opt/anaconda3/envs/RS/lib/python3.10/site-packages/flow/project.py:3192\u001b[0m, in \u001b[0;36mFlowProject._execute_operation\u001b[0;34m(self, operation, timeout, pretend)\u001b[0m\n\u001b[1;32m 3190\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_operations[operation\u001b[39m.\u001b[39mname](\u001b[39m*\u001b[39moperation\u001b[39m.\u001b[39m_jobs)\n\u001b[1;32m 3191\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mException\u001b[39;00m \u001b[39mas\u001b[39;00m error:\n\u001b[0;32m-> 3192\u001b[0m \u001b[39mraise\u001b[39;00m UserOperationError(\n\u001b[1;32m 3193\u001b[0m \u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mAn exception was raised during operation \u001b[39m\u001b[39m{\u001b[39;00moperation\u001b[39m.\u001b[39mname\u001b[39m}\u001b[39;00m\u001b[39m \u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m 3194\u001b[0m \u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mfor job or aggregate with id \u001b[39m\u001b[39m{\u001b[39;00mget_aggregate_id(operation\u001b[39m.\u001b[39m_jobs)\u001b[39m}\u001b[39;00m\u001b[39m.\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m 3195\u001b[0m ) \u001b[39mfrom\u001b[39;00m \u001b[39merror\u001b[39;00m\n", + "\u001b[0;31mUserOperationError\u001b[0m: An exception was raised during operation sample for job or aggregate with id 2a05a487f254db90b08f576d199a83b7." + ] + } + ], + "source": [ + "project.run()" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'V' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m/Users/ychihmei/Code/signac-examples/projects/flow.hoomd.lj/src/project_2.ipynb Cell 8\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[39mprint\u001b[39m(V)\n", + "\u001b[0;31mNameError\u001b[0m: name 'V' is not defined" + ] + } + ], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3.10.4 ('RS')", + "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.10.4" + }, + "vscode": { + "interpreter": { + "hash": "d0f6f30aa31cd7031202ef1611dc07a0ec742865e629d88081a44390ddef9294" + } + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}