Skip to content

Commit

Permalink
quick draft uc3_ap3
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sintef committed Apr 12, 2023
1 parent 98f2673 commit 7a342d3
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 2 deletions.
1 change: 1 addition & 0 deletions start.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<li><a href="{appbase}/install_uc3.ipynb" target="_blank">Install application (should only be run once).</a></li>
<li><a href="{appbase}/uc3.ipynb" target="_blank">Run application. (App 1)</a></li>
<li><a href="{appbase}/uc3_ap2.ipynb" target="_blank">Run application. (App 2)</a></li>
<li><a href="{appbase}/uc3_ap3.ipynb" target="_blank">Run application. (App 3)</a></li>
</ul></td>
</tr>
</table>
Expand Down
2 changes: 1 addition & 1 deletion uc3/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ class ConfirmUserInputStep(ipw.VBox, WizardAppWidgetStep):
submit = traitlets.Bool()
job_uuid = str(uuid.uuid4())
job_uuidhtml = ipw.HTML(
value="<h4>Please email your SINTEF contact with the following UUID: {}</h4>".format(job_uuid),
value="<h4>Please email your SINTEF contact with the following UUID: {}. Then click 'Submit calculation'.</h4>".format(job_uuid),
)
user_inputs = traitlets.Dict(allow_none=True)
mpuc3_code = traitlets.Instance(Code, allow_none=True)
Expand Down
3 changes: 2 additions & 1 deletion uc3_ap2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
188 changes: 188 additions & 0 deletions uc3_ap3.ipynb
Original file line number Diff line number Diff line change
@@ -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<cell line: 33>\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
}

0 comments on commit 7a342d3

Please sign in to comment.