{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Main Calculation Restart" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `crystal17.main.base` workflow builds on the `crystal.main` calculation, by automating restarts of the calculation for known failure modes:\n", "\n", "- **No SCF convergence within maximum cycles**: the FMIXING value is lowered, and the calculation is restarted from the last known geometry and wave-function (using GUESSP)\n", "- **No geometric convergence within maximum iterations**: the calculation is restarted from the last known geometry and wave-function (using GUESSP)\n", "- **Reaches scheduler wall-time**: the calculation is restarted from the last known geometry.\n", "\n", "Additionally, new SHRINK terms can be computed, to adhere to a minimum desired k-point spacing, given the input structure." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[32m ✓ \u001b[0mprofile: On profile test_profile\u001b[0m\r\n", "\u001b[32m ✓ \u001b[0mrepository: /var/folders/dm/b2qnkb_n3r72slmpxlfmcjvm00lbnd/T/tmpe58nwedg/test_repo\u001b[0m\r\n", "\u001b[32m ✓ \u001b[0mpostgres: Connected as aiida@localhost:64032\u001b[0m\r\n", "\u001b[32m ✓ \u001b[0mrabbitmq: Connected to amqp://127.0.0.1?heartbeat=600\u001b[0m\r\n", "\u001b[32m ✓ \u001b[0mdaemon: Daemon is running as PID 52302 since 2019-08-12 12:10:21\u001b[0m\r\n" ] } ], "source": [ "!verdi status" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-\b/\b|\b\\\b-\b/\b|\b\\\b-\b/\b\u001b[31m\u001b[1mInputs\u001b[0m\r\n", "\u001b[1m cry: required \u001b[0m\r\n", " basis_family: optional Str An alternative to specifying the basis sets manually: one can specify the n ...\u001b[0m\r\n", " clean_workdir: optional Bool If `True`, work directories of all called calculation will be cleaned at th ...\u001b[0m\r\n", " kpoints_distance: optional Float The minimum desired distance in 1/Å between k-points in reciprocal space. T ...\u001b[0m\r\n", " kpoints_force_parity: optional Bool Optional input when constructing the k-points based on a desired `kpoints_d ...\u001b[0m\r\n", " max_iterations: optional Int Maximum number of iterations the work chain will restart the calculation to ...\u001b[0m\r\n", " metadata: optional \u001b[0m\r\n", "\u001b[31m\u001b[1mOutputs\u001b[0m\r\n", "\u001b[1m remote_folder: required RemoteData Input files necessary to run the process will be stored in this folder node ...\u001b[0m\r\n", "\u001b[1m results: required Dict the data extracted from the main output file\u001b[0m\r\n", " structure: optional StructureData the structure output from the calculation\u001b[0m\r\n", " symmetry: optional SymmetryData the symmetry data from the calculation\u001b[0m\r\n", "\u001b[31m\u001b[1mExit codes\u001b[0m\r\n", " 1: The process has failed with an unspecified error.\u001b[0m\r\n", " 2: The process failed with legacy failure mode.\u001b[0m\r\n", " 10: The process returned an invalid output.\u001b[0m\r\n", " 11: The process did not register a required output.\u001b[0m\r\n", " 101: The maximum number of iterations was exceeded.\u001b[0m\r\n", " 102: The calculation failed for an unknown reason, twice in a row.\u001b[0m\r\n", " 201: The parameters could not be validated against the jsonschema.\u001b[0m\r\n", " 202: The explicit `basis_sets` or `basis_family` could not be used to get the necessary basis sets.\u001b[0m\r\n", " 204: The `metadata.options` did not specify both `resources.num_machines` and `max_wallclock_seconds`.\u001b[0m\r\n", " 300: The calculation failed with an unrecoverable error.\u001b[0m\r\n", " 320: The initialization calculation failed.\u001b[0m\r\n" ] } ], "source": [ "!verdi plugin list aiida.workflows crystal17.main.base" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "from aiida.engine import run_get_node\n", "from aiida.plugins import (\n", " DataFactory, WorkflowFactory, CalculationFactory)\n", "from aiida.tools.visualization import Graph\n", "\n", "from aiida_crystal17.tests import resource_context, get_test_structure_and_symm\n", "from aiida_crystal17.tests.utils import get_default_metadata\n", "from aiida_crystal17.tests.utils import get_or_create_local_computer, get_or_create_code" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'test_profile'" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from aiida import load_profile\n", "profile = load_profile()\n", "profile.name" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "aiida_crystal17.data.basis_set.BasisSetData" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "DataFactory('crystal17.basisset')" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "computer = get_or_create_local_computer('work_directory', 'localhost')\n", "code = get_or_create_code('crystal17.main', computer, 'mock_crystal17')\n", "\n", "params = {\n", " \"title\": \"NiO Bulk with AFM spin\",\n", " \"scf.single\": \"UHF\",\n", " \"scf.k_points\": (8, 8),\n", " \"scf.spinlock.SPINLOCK\": (0, 15),\n", " \"scf.numerical.FMIXING\": 50,\n", " \"scf.numerical.MAXCYCLE\": 10,\n", " \"scf.post_scf\": [\"PPAN\"]\n", " }\n", "\n", "instruct, symmetry = get_test_structure_and_symm(\"NiO_afm\")\n", "\n", "kind_data = DataFactory('crystal17.kinds')(data={\n", " \"kind_names\": [\"Ni1\", \"Ni2\", \"O\"],\n", " \"spin_alpha\": [True, False, False], \"spin_beta\": [False, True, False]})\n", "\n", "with resource_context('basis_sets', 'sto3g') as path:\n", " DataFactory('crystal17.basisset').upload_basisset_family(\n", " path,\n", " \"sto3g\",\n", " \"minimal basis sets\",\n", " stop_if_existing=False,\n", " extension=\".basis\")\n", "\n", "# set up calculation\n", "process_class = code.get_builder().process_class\n", "calc_builder = process_class.create_builder(\n", " params, instruct, \"sto3g\",\n", " symmetry=symmetry,\n", " kinds=kind_data,\n", " code=code,\n", " metadata=get_default_metadata(),\n", " unflatten=True)\n", "\n", "wc_builder = WorkflowFactory('crystal17.main.base').get_builder()\n", "wc_builder.cry = dict(calc_builder)\n", "wc_builder.clean_workdir = True" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "outputs, wc_node = run_get_node(wc_builder)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "True\n", "ProcessState.FINISHED\n", "0\n" ] } ], "source": [ "print(wc_node.is_finished_ok)\n", "print(wc_node.process_state)\n", "print(wc_node.exit_status)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-\b/\b|\b\\\b-\b/\b|\b\\\b\u001b[22mCryMainBaseWorkChain<16> Finished [5:results]\r\n", " ├── CryMainCalculation<18> Finished [411]\r\n", " └── CryMainCalculation<23> Finished [0]\u001b[0m\r\n" ] } ], "source": [ "!verdi process status {wc_node.pk}" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-\b/\b|\b\\\b-\b/\b|\b\\\b-\b/\b\u001b[22m2019-08-12 11:10:35 [1 | REPORT]: [16|CryMainBaseWorkChain|run_calculation]: launching CryMainCalculation<18> iteration #1\r\n", "2019-08-12 11:10:49 [4 | REPORT]: [16|CryMainBaseWorkChain|report_error_handled]: CryMainCalculation<18> failed with exit status 411: SCF convergence did not finalise (usually due to reaching step limit)\r\n", "2019-08-12 11:10:49 [5 | REPORT]: [16|CryMainBaseWorkChain|report_error_handled]: Action taken: reduced fmixing from 50 to 40 and restarting from last calculation\r\n", "2019-08-12 11:10:49 [6 | REPORT]: [16|CryMainBaseWorkChain|run_calculation]: launching CryMainCalculation<23> iteration #2\r\n", "2019-08-12 11:10:59 [7 | REPORT]: [16|CryMainBaseWorkChain|inspect_calculation]: CryMainCalculation<23> completed successfully\r\n", "2019-08-12 11:10:59 [8 | REPORT]: [16|CryMainBaseWorkChain|results]: work chain completed after 2 iterations\r\n", "2019-08-12 11:10:59 [9 | REPORT]: [16|CryMainBaseWorkChain|on_terminated]: cleaned remote folders of calculations: 23 18\u001b[0m\r\n" ] } ], "source": [ "!verdi process report {wc_node.pk}" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "%3\n", "\n", "\n", "\n", "N16\n", "\n", "CryMainBaseWorkChain (16)\n", "State: finished\n", "Exit Code: 0\n", "\n", "\n", "\n", "N26\n", "\n", "Dict (26)\n", "\n", "\n", "\n", "N16->N26\n", "\n", "\n", "RETURN\n", "results\n", "\n", "\n", "\n", "N24\n", "\n", "RemoteData (24)\n", "@localhost\n", "\n", "\n", "\n", "N16->N24\n", "\n", "\n", "RETURN\n", "remote_folder\n", "\n", "\n", "\n", "N23\n", "\n", "CryMainCalculation (23)\n", "State: finished\n", "Exit Code: 0\n", "\n", "\n", "\n", "N16->N23\n", "\n", "\n", "CALL_CALC\n", "iteration_02\n", "\n", "\n", "\n", "N18\n", "\n", "CryMainCalculation (18)\n", "State: finished\n", "Exit Code: 411\n", "\n", "\n", "\n", "N16->N18\n", "\n", "\n", "CALL_CALC\n", "iteration_01\n", "\n", "\n", "\n", "N23->N26\n", "\n", "\n", "CREATE\n", "results\n", "\n", "\n", "\n", "N23->N24\n", "\n", "\n", "CREATE\n", "remote_folder\n", "\n", "\n", "\n", "N25\n", "\n", "FolderData (25)\n", "\n", "\n", "\n", "N23->N25\n", "\n", "\n", "CREATE\n", "retrieved\n", "\n", "\n", "\n", "N19\n", "\n", "RemoteData (19)\n", "@localhost\n", "\n", "\n", "\n", "N18->N19\n", "\n", "\n", "CREATE\n", "remote_folder\n", "\n", "\n", "\n", "N21\n", "\n", "Dict (21)\n", "\n", "\n", "\n", "N18->N21\n", "\n", "\n", "CREATE\n", "results\n", "\n", "\n", "\n", "N20\n", "\n", "FolderData (20)\n", "\n", "\n", "\n", "N18->N20\n", "\n", "\n", "CREATE\n", "retrieved\n", "\n", "\n", "\n", "N15\n", "\n", "Int (15)\n", "value: 5\n", "\n", "\n", "\n", "N15->N16\n", "\n", "\n", "INPUT_WORK\n", "max_iterations\n", "\n", "\n", "\n", "N14\n", "\n", "Bool (14)\n", "True\n", "\n", "\n", "\n", "N14->N16\n", "\n", "\n", "INPUT_WORK\n", "clean_workdir\n", "\n", "\n", "\n", "N1\n", "\n", "Code (1)\n", "mock_crystal17@localhost\n", "\n", "\n", "\n", "N1->N16\n", "\n", "\n", "INPUT_WORK\n", "cry__code\n", "\n", "\n", "\n", "N1->N23\n", "\n", "\n", "INPUT_CALC\n", "code\n", "\n", "\n", "\n", "N1->N18\n", "\n", "\n", "INPUT_CALC\n", "code\n", "\n", "\n", "\n", "N13\n", "\n", "KindData (13)\n", "\n", "\n", "\n", "N13->N16\n", "\n", "\n", "INPUT_WORK\n", "cry__kinds\n", "\n", "\n", "\n", "N13->N23\n", "\n", "\n", "INPUT_CALC\n", "kinds\n", "\n", "\n", "\n", "N13->N18\n", "\n", "\n", "INPUT_CALC\n", "kinds\n", "\n", "\n", "\n", "N8\n", "\n", "SymmetryData (8)\n", "hall_number: 400\n", "symmops: 16\n", "\n", "\n", "\n", "N8->N16\n", "\n", "\n", "INPUT_WORK\n", "cry__symmetry\n", "\n", "\n", "\n", "N8->N23\n", "\n", "\n", "INPUT_CALC\n", "symmetry\n", "\n", "\n", "\n", "N8->N18\n", "\n", "\n", "INPUT_CALC\n", "symmetry\n", "\n", "\n", "\n", "N6\n", "\n", "StructureData (6)\n", "Ni2O2\n", "\n", "\n", "\n", "N6->N16\n", "\n", "\n", "INPUT_WORK\n", "cry__structure\n", "\n", "\n", "\n", "N6->N23\n", "\n", "\n", "INPUT_CALC\n", "structure\n", "\n", "\n", "\n", "N6->N18\n", "\n", "\n", "INPUT_CALC\n", "structure\n", "\n", "\n", "\n", "N12\n", "\n", "CryInputParamsData (12)\n", "\n", "\n", "\n", "N12->N16\n", "\n", "\n", "INPUT_WORK\n", "cry__parameters\n", "\n", "\n", "\n", "N11\n", "\n", "BasisSetData (11)\n", "\n", "\n", "\n", "N11->N16\n", "\n", "\n", "INPUT_WORK\n", "cry__basissets__O\n", "\n", "\n", "\n", "N11->N23\n", "\n", "\n", "INPUT_CALC\n", "basissets__O\n", "\n", "\n", "\n", "N11->N18\n", "\n", "\n", "INPUT_CALC\n", "basissets__O\n", "\n", "\n", "\n", "N10\n", "\n", "BasisSetData (10)\n", "\n", "\n", "\n", "N10->N16\n", "\n", "\n", "INPUT_WORK\n", "cry__basissets__Ni\n", "\n", "\n", "\n", "N10->N23\n", "\n", "\n", "INPUT_CALC\n", "basissets__Ni\n", "\n", "\n", "\n", "N10->N18\n", "\n", "\n", "INPUT_CALC\n", "basissets__Ni\n", "\n", "\n", "\n", "N19->N23\n", "\n", "\n", "INPUT_CALC\n", "wf_folder\n", "\n", "\n", "\n", "N22\n", "\n", "CryInputParamsData (22)\n", "\n", "\n", "\n", "N22->N23\n", "\n", "\n", "INPUT_CALC\n", "parameters\n", "\n", "\n", "\n", "N17\n", "\n", "CryInputParamsData (17)\n", "\n", "\n", "\n", "N17->N18\n", "\n", "\n", "INPUT_CALC\n", "parameters\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "graph = Graph(graph_attr={'size': \"8,8!\", \"rankdir\": \"LR\"})\n", "graph.recurse_descendants(\n", " wc_node, annotate_links=\"both\",\n", " include_process_inputs=True\n", ")\n", "graph.graphviz" ] } ], "metadata": { "celltoolbar": "Tags", "hide_input": false, "jupytext": { "formats": "ipynb,md:myst" }, "kernelspec": { "display_name": "Python 3", "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.6.7" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 2 }