Skip to content

Commit

Permalink
Adding support for orm.Containerized codes (#617)
Browse files Browse the repository at this point in the history
This is obtained using the `AiidaCodeSetup().code_setup` attribute.

I am not sure is the better way, as we should also provide the possibility to change the image_name and the engine_command via the GUI. However, I think that for now this is acceptable, as the containerized codes are mainly
set up by using the information on the aiida-resource-registry repo. Actually, it is a really new thing and for now only the phonopy@merlin-cpu is defined.
  • Loading branch information
mikibonacci authored Jul 5, 2024
1 parent d8b7e71 commit 6075e7c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions aiidalab_widgets_base/computational_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1196,16 +1196,26 @@ def on_setup_code(self, _=None):
"append_text",
]

containerized_code_additional_items = [
"image_name",
"engine_command",
]

kwargs = {key: getattr(self, key).value for key in items_to_configure}

# Check for additional keys needed for orm.ContainerizedCode
for container_key in containerized_code_additional_items:
if container_key in self.code_setup.keys():
kwargs[container_key] = self.code_setup[container_key]

# set computer from its widget value the UUID of the computer.
computer = orm.load_computer(self.computer.value)

# Checking if the code with this name already exists
qb = orm.QueryBuilder()
qb.append(orm.Computer, filters={"uuid": computer.uuid}, tag="computer")
qb.append(
orm.InstalledCode,
orm.AbstractCode,
with_computer="computer",
filters={"label": kwargs["label"]},
)
Expand All @@ -1223,7 +1233,10 @@ def on_setup_code(self, _=None):
return False

try:
code = orm.InstalledCode(computer=computer, **kwargs)
if "image_name" in kwargs.keys():
code = orm.ContainerizedCode(computer=computer, **kwargs)
else:
code = orm.InstalledCode(computer=computer, **kwargs)
except (common.exceptions.InputValidationError, KeyError) as exception:
self.message = wrap_message(
f"Invalid input for code creation: <code>{exception}</code>",
Expand Down

0 comments on commit 6075e7c

Please sign in to comment.