Skip to content

Commit

Permalink
fix: issues encountered while running notebooks (#236)
Browse files Browse the repository at this point in the history
* Switch from computer.name to computer.label
* Remove obsolete multi-structure notebook
  • Loading branch information
ltalirz committed Sep 15, 2021
1 parent eddeb9a commit 2df148f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 60 deletions.
12 changes: 6 additions & 6 deletions aiidalab_widgets_base/codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def _get_codes(self):

@staticmethod
def _full_code_label(code):
return f"{code.label}@{code.computer.name}"
return f"{code.label}@{code.computer.label}"

def refresh(self, _=None):
"""Refresh available codes.
Expand All @@ -123,7 +123,7 @@ def refresh(self, _=None):

@validate("selected_code")
def _validate_selected_code(self, change):
"""If code is provided, set it as it is. If code's name is provided,
"""If code is provided, set it as it is. If code's label is provided,
select the code and set it."""
code = change["value"]
self.output.value = ""
Expand All @@ -132,7 +132,7 @@ def _validate_selected_code(self, change):
if code is None:
return None

# Check code by name.
# Check code by label.
if isinstance(code, str):
if code in self.codes:
return self.codes[code]
Expand Down Expand Up @@ -254,7 +254,7 @@ def _setup_code(self, _=None):
print("You did not specify absolute path to the executable")
return
if self.exists():
print(f"Code {self.label}@{self.computer.name} already exists")
print(f"Code {self.label}@{self.computer.label} already exists")
return
code = Code(remote_computer_exec=(self.computer, self.remote_abs_path))
code.label = self.label
Expand All @@ -264,15 +264,15 @@ def _setup_code(self, _=None):
code.set_append_text(self.append_text)
code.store()
code.reveal()
full_string = f"{self.label}@{self.computer.name}"
full_string = f"{self.label}@{self.computer.label}"
print(check_output(["verdi", "code", "show", full_string]).decode("utf-8"))

def exists(self):
"""Returns True if the code exists, returns False otherwise."""
from aiida.common import MultipleObjectsError, NotExistent

try:
Code.get_from_string(f"{self.label}@{self.computer.name}")
Code.get_from_string(f"{self.label}@{self.computer.label}")
return True
except MultipleObjectsError:
return True
Expand Down
12 changes: 6 additions & 6 deletions aiidalab_widgets_base/computers.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ def _configure_computer(self):
from aiida.orm import AuthInfo

authinfo = AuthInfo(
computer=Computer.objects.get(name=self.label), user=aiidauser
computer=Computer.objects.get(label=self.label), user=aiidauser
)
authinfo.set_auth_params(authparams)
authinfo.store()
Expand All @@ -764,15 +764,15 @@ def _on_setup_computer(self, _=None):
print("Please specify the computer name (for AiiDA)")
return
try:
computer = Computer.objects.get(name=self.label)
computer = Computer.objects.get(label=self.label)
print(f"A computer called {self.label} already exists.")
return
except NotExistent:
pass

print(f"Creating new computer with name '{self.label}'")
computer = Computer(
name=self.label, hostname=self.hostname, description=self.description
label=self.label, hostname=self.hostname, description=self.description
)
computer.set_transport_type(self.transport)
computer.set_scheduler_type(self.scheduler)
Expand Down Expand Up @@ -869,7 +869,7 @@ def _get_computers(self):
user = User.objects.get_default()

return {
c[0].name: c[0]
c[0].label: c[0]
for c in QueryBuilder().append(Computer).all()
if c[0].is_user_configured(user)
and (self.allow_select_disabled or c[0].is_user_enabled(user))
Expand All @@ -890,7 +890,7 @@ def refresh(self, _=None):

@validate("selected_computer")
def _validate_selected_computer(self, change):
"""Select computer either by name or by class instance."""
"""Select computer either by label or by class instance."""
computer = change["value"]
self.output.value = ""
if not computer:
Expand All @@ -902,7 +902,7 @@ def _validate_selected_computer(self, change):
was found in your AiiDA database."""

if isinstance(computer, Computer):
if computer.name in self.computers:
if computer.label in self.computers:
return computer
self.output.value = f"""The computer instance '<span style="color:red">{computer}</span>'
supplied was not found in your AiiDA database."""
Expand Down
1 change: 1 addition & 0 deletions docs/source/widget-list/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
notebooks
1 change: 0 additions & 1 deletion docs/source/widget-list/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ See also the `corresponding git repository <https://github.com/aiidalab/aiidalab
notebooks/process
notebooks/process_list
notebooks/structures
notebooks/structures_multi
notebooks/wizard_apps
notebooks/eln_configure
notebooks/eln_import
47 changes: 0 additions & 47 deletions notebooks/structures_multi.ipynb

This file was deleted.

0 comments on commit 2df148f

Please sign in to comment.