Skip to content

Commit

Permalink
fix the computer_setup update with dict copy
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed May 19, 2023
1 parent d4de7ce commit 16197d7
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 17 deletions.
13 changes: 8 additions & 5 deletions aiidalab_widgets_base/computational_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
93 changes: 81 additions & 12 deletions notebooks/computational_resources.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
"<IPython.core.display.Javascript object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%javascript\n",
"IPython.OutputArea.prototype._should_scroll = function(lines) {\n",
Expand All @@ -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": [],
Expand All @@ -36,28 +64,54 @@
},
{
"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)"
]
},
{
"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": [],
Expand All @@ -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)"
]
Expand Down

0 comments on commit 16197d7

Please sign in to comment.