From 7a342d30e8fb3f18d27a9cfefa2c87a5e7f733db Mon Sep 17 00:00:00 2001 From: Daniel Marchand Date: Wed, 12 Apr 2023 07:55:08 +0000 Subject: [PATCH] quick draft uc3_ap3 --- start.py | 1 + uc3/steps.py | 2 +- uc3_ap2.ipynb | 3 +- uc3_ap3.ipynb | 188 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 192 insertions(+), 2 deletions(-) create mode 100644 uc3_ap3.ipynb diff --git a/start.py b/start.py index 1a98e38..9b8b337 100644 --- a/start.py +++ b/start.py @@ -10,6 +10,7 @@
  • Install application (should only be run once).
  • Run application. (App 1)
  • Run application. (App 2)
  • +
  • Run application. (App 3)
  • diff --git a/uc3/steps.py b/uc3/steps.py index fcae9f0..75a8eae 100644 --- a/uc3/steps.py +++ b/uc3/steps.py @@ -331,7 +331,7 @@ class ConfirmUserInputStep(ipw.VBox, WizardAppWidgetStep): submit = traitlets.Bool() job_uuid = str(uuid.uuid4()) job_uuidhtml = ipw.HTML( - value="

    Please email your SINTEF contact with the following UUID: {}

    ".format(job_uuid), + value="

    Please email your SINTEF contact with the following UUID: {}. Then click 'Submit calculation'.

    ".format(job_uuid), ) user_inputs = traitlets.Dict(allow_none=True) mpuc3_code = traitlets.Instance(Code, allow_none=True) diff --git a/uc3_ap2.ipynb b/uc3_ap2.ipynb index 1821944..026d2ab 100644 --- a/uc3_ap2.ipynb +++ b/uc3_ap2.ipynb @@ -107,7 +107,8 @@ ")\n", "\n", "computer_code_setup_step = ComputerCodeSetupStep(auto_advance=True)\n", - "configure_userinput_step = ConfigureUserInputStep(auto_advance=True, description_label_default=[ ['dmf', 'dmf', 0],\n", + "configure_userinput_step = ConfigureUserInputStep(auto_advance=True, description_label_default=[ \n", + " ['dmf', 'dmf', 0],\n", " ['gfr', 'gfr', 0],\n", " ['ch4mf', 'ch4mf', 0],\n", " ['h2omf', 'h2omf', 0],\n", diff --git a/uc3_ap3.ipynb b/uc3_ap3.ipynb new file mode 100644 index 0000000..c7180d7 --- /dev/null +++ b/uc3_ap3.ipynb @@ -0,0 +1,188 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "##############################################################################\n", + "#The app works around 4 major steps\n", + "# (1) Configure the user input\n", + "# (2) Confirm the user input + submit the job\n", + "# (3) Monitor the process during the run\n", + "# (4) Display the final results\n", + "#\n", + "#These steps are linked via the following \n", + "# (1) --> (2): user_inputs, a dictionary of all the user inputs\n", + "# (1) --> (2): mpuc3_code, a code for marketplace usercase 3\n", + "# (2) --> (3): process, the process (MPusercase3 CalcJob) submitted to AiiDA \n", + "# (3) --> (4): output, the ArrayData output from the CalcJob\n", + "#\n", + "#This is an early prototype that is 'stapled' from the pizza example in aiidalab_widgets_base\n", + "#as well as QE example from aiidalab_qe\n", + "#\n", + "#Specific notes/issues on the steps:\n", + "# Step 1:\n", + "# * Perhaps there should be a step 0 that allows the user to choose a model,\n", + "# then the widget can be dynamically updated\n", + "# * The code setup is rather ugly, and creating a custom code crashes\n", + "# * The user should be alerted that if they try to hit submit without \n", + "# choosing a code, that they need to choose a code first\n", + "# Step 2:\n", + "# Step 3:\n", + "# * This is taken almost directly from QE, and is the part I understand the least\n", + "# * Clicking on most outputs causes a crash\n", + "# *** I can't seem to set the 'output' propery correctly\n", + "# Step 4:\n", + "# *** Because I can't set the output property in step3 correctly, this step displays nothing\n", + "# * The current display is very ugly and taken directly from Step2, and probably be changed to\n", + "# something nicer\n", + "##############################################################################" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "import logging\n", + "\n", + "from uc3.logger import OutputWidgetHandler\n", + "\n", + "logger = logging.getLogger(\"aiidalab_mp_uc3\")\n", + "handler = OutputWidgetHandler()\n", + "handler.setFormatter(logging.Formatter('%(asctime)s - [%(levelname)s] %(message)s'))\n", + "logger.addHandler(handler)\n", + "logger.setLevel(logging.INFO)\n", + "\n", + "# Remove/Add comment of the next line to show/hide logs.\n", + "# handler.show_logs()\n", + "\n", + "handler.clear_logs()\n", + "logger.info('Starting program')" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "9f587b5d4ea34a4aad4deba0102f0c2d", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "ename": "NameError", + "evalue": "name 'DisplayAp2FinalOutput' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/tmp/ipykernel_26756/2862219995.py\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 31\u001b[0m \u001b[0mconfirm_userinput_step\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mConfirmUserInputStep\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mauto_advance\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 32\u001b[0m \u001b[0mmonitorprocess_step\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mMonitorProcessStep\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mauto_advance\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 33\u001b[0;31m \u001b[0mdisplayfinaloutput_step\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mDisplayAp2FinalOutput\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mauto_advance\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# DisplayFinalOutput(auto_advance=False)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 34\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 35\u001b[0m ipw.dlink(\n", + "\u001b[0;31mNameError\u001b[0m: name 'DisplayAp2FinalOutput' is not defined" + ] + } + ], + "source": [ + "import ipywidgets as ipw\n", + "\n", + "from aiidalab_widgets_base import WizardAppWidget\n", + "\n", + "from uc3.steps import (\n", + " ComputerCodeSetupStep,\n", + " ConfigureUserInputStep,\n", + " ConfirmUserInputStep,\n", + " MonitorProcessStep,\n", + " DisplayAp2FinalOutput,\n", + ")\n", + "\n", + "computer_code_setup_step = ComputerCodeSetupStep(auto_advance=True)\n", + "configure_userinput_step = ConfigureUserInputStep(auto_advance=True, description_label_default=[ \n", + " ['gfr', 'gfr', 0],\n", + " ['ch4mf', 'ch4mf', 0],\n", + " ['h2omf', 'h2omf', 0],\n", + " ['surfa', 'surfa', 0],\n", + " ['amf', 'amf', 0],\n", + " ['macropor', 'macropor', 0],\n", + " ['macrotor', 'macrotor', 0],\n", + " ['k1', 'k1', 0],\n", + " ['ea1', 'ea1', 0],\n", + " ['k2', 'k2', 0],\n", + " ['ea2', 'ea2', 0],\n", + " ['koeq', 'koeq', 0],\n", + " ['dhh20', 'dhh20', 0]\n", + "])\n", + "\n", + "\n", + "confirm_userinput_step = ConfirmUserInputStep(auto_advance=True)\n", + "monitorprocess_step = MonitorProcessStep(auto_advance=True)\n", + "displayfinaloutput_step = DisplayAp2FinalOutput(auto_advance=False) # DisplayFinalOutput(auto_advance=False)\n", + "\n", + "ipw.dlink(\n", + " (configure_userinput_step, \"user_inputs\"),\n", + " (confirm_userinput_step, \"user_inputs\"),\n", + ")\n", + "ipw.dlink(\n", + " (computer_code_setup_step, \"mpuc3_code\"),\n", + " (confirm_userinput_step, \"mpuc3_code\"),\n", + ")\n", + "ipw.dlink(\n", + " (confirm_userinput_step, \"process\"),\n", + " (monitorprocess_step, \"process\"),\n", + " transform=lambda x: x.uuid if x is not None else None\n", + ")\n", + "ipw.dlink(\n", + " (monitorprocess_step, \"output\"),\n", + " (displayfinaloutput_step, \"output\"),\n", + ")\n", + "\n", + "# Setup the app by adding the various steps in order.\n", + "WizardAppWidget(\n", + " steps=[\n", + " (\"Setup Computer & Code\", computer_code_setup_step),\n", + " (\"Configure User Input\", configure_userinput_step),\n", + " (\"Confirm User Input\", confirm_userinput_step),\n", + " (\"Monitor Process\", monitorprocess_step),\n", + " (\"Display Results\", displayfinaloutput_step),\n", + " ]\n", + ")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.9.13" + }, + "vscode": { + "interpreter": { + "hash": "d4d1e4263499bec80672ea0156c357c1ee493ec2b1c70f0acce89fc37c4a6abe" + } + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}