From 16197d7739bf22016ebebfd1f73cca0593ae5e83 Mon Sep 17 00:00:00 2001 From: Jusong Yu Date: Fri, 19 May 2023 12:15:36 +0000 Subject: [PATCH] fix the computer_setup update with dict copy --- .../computational_resources.py | 13 ++- notebooks/computational_resources.ipynb | 93 ++++++++++++++++--- 2 files changed, 89 insertions(+), 17 deletions(-) diff --git a/aiidalab_widgets_base/computational_resources.py b/aiidalab_widgets_base/computational_resources.py index 65e5580d7..3f3ce1630 100644 --- a/aiidalab_widgets_base/computational_resources.py +++ b/aiidalab_widgets_base/computational_resources.py @@ -29,7 +29,7 @@ class QuickSetupWidget(ipw.VBox): default_calc_job_plugin = traitlets.Unicode(allow_none=True) - computer_setup = traitlets.Dict() + computer_setup = traitlets.Dict().tag(sync=True) code_setup = traitlets.Dict() def __init__(self, **kwargs): @@ -114,9 +114,10 @@ def quick_setup(self, _=None): The actual setup will be triggered from DetailedSetupWidget from ComputationalResourcesWidget. """ from jinja2 import ChainableUndefined, Environment, meta + import copy # From the remote original setup, fill the template - computer_setup = self.computer_setup + computer_setup = copy.deepcopy(self.computer_setup) # The dict is nested, so we need deepcopy for key, value in computer_setup.get("setup", {}).items(): env = Environment(undefined=ChainableUndefined) @@ -134,12 +135,12 @@ def quick_setup(self, _=None): else: computer_setup["setup"][key] = value - self.computer_setup = {**self.computer_setup} + self.computer_setup = computer_setup print(self.computer_setup) class DetailedSetupWidget(ipw.VBox): - computer_setup = traitlets.Dict() + computer_setup = traitlets.Dict().tag(sync=True) code_setup = traitlets.Dict() def __init__(self, **kargs): @@ -318,7 +319,9 @@ def __init__(self, description="Select code:", path_to_root="../", **kwargs): def _quick_setup(self, change): if change["new"] is not None: + print("HETNNNNN") self.detailed_setup.aiida_computer_setup.computer_setup = change["new"] + self.detailed_setup.aiida_computer_setup._observe_computer_setup() # self.detailed_setup.code_setup = self.comp_resources_database.code_setup def quick_setup(self, _=None): @@ -814,7 +817,7 @@ def _observe_ssh_config(self, _=None): class AiidaComputerSetup(ipw.VBox): """Inform AiiDA about a computer.""" - computer_setup = traitlets.Dict(allow_none=True) + computer_setup = traitlets.Dict(allow_none=True).tag(sync=True) message = traitlets.Unicode() def __init__(self, **kwargs): diff --git a/notebooks/computational_resources.ipynb b/notebooks/computational_resources.ipynb index 0b46bb3b6..9ff109028 100644 --- a/notebooks/computational_resources.ipynb +++ b/notebooks/computational_resources.ipynb @@ -2,10 +2,25 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "4013ce60", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/javascript": [ + "IPython.OutputArea.prototype._should_scroll = function(lines) {\n", + " return false;\n", + "}\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "%%javascript\n", "IPython.OutputArea.prototype._should_scroll = function(lines) {\n", @@ -15,17 +30,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "53f49d32", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "6ea24e36af9d4230bbde5f966901fba9", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "import aiidalab_widgets_base as awb" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "56116f88", "metadata": {}, "outputs": [], @@ -36,10 +64,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "b75b6687", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "6cad017fcce44d35904b7fe815e6bccc", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "ComputationalResourcesWidget(children=(HBox(children=(Dropdown(description='Select code:', disabled=True, opti…" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "display(resources1)\n", "# display(resources2)" @@ -47,17 +90,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "15b22b09", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{}" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "resources1.detailed_setup.aiida_computer_setup.computer_setup" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "b286d587", "metadata": {}, "outputs": [], @@ -67,10 +121,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "id": "47b3bc92", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "98b940e17ea34ee9ac31a9e5dab1b964", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "QuickSetupWidget(children=(HTML(value='Please select the computer/code from a database to pre-fill the fields …" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "display(qs)" ]