Skip to content

Commit

Permalink
Merge branch 'main' into docker-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhollas committed May 21, 2024
2 parents d8b979c + a915571 commit 8f4e7cb
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 78 deletions.
Binary file modified docs/source/_static/cheatsheet_h.pdf
Binary file not shown.
Binary file modified docs/source/intro/_cheatsheet/cheatsheet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 59 additions & 56 deletions docs/source/intro/_cheatsheet/cheatsheet.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/source/intro/_cheatsheet/cheatsheet_v.pdf
Binary file not shown.
8 changes: 2 additions & 6 deletions src/aiida/cmdline/groups/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import functools
import re
import typing as t
import warnings

import click

Expand Down Expand Up @@ -179,11 +178,8 @@ def list_options(self, entry_point: str) -> list:
# we simply remove all ``NoneType`` and the remaining type should be the type of the option.
if hasattr(field_info.annotation, '__args__'):
args = list(filter(lambda e: e != type(None), field_info.annotation.__args__))
if len(args) > 1:
warnings.warn(
f'field `{key}` defines multiple types, but can take only one, taking the first: `{args[0]}`',
UserWarning,
)
# Click parameters only support specifying a single type, so we default to the first one even if the
# pydantic model defines multiple.
field_type = args[0]
else:
field_type = field_info.annotation
Expand Down
10 changes: 7 additions & 3 deletions src/aiida/orm/nodes/data/code/installed.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
from __future__ import annotations

import pathlib
import typing as t

from pydantic import field_validator, model_validator
from pydantic import ConfigDict, field_validator, model_validator

from aiida.common import exceptions
from aiida.common.lang import type_check
Expand All @@ -36,12 +37,15 @@
class InstalledCode(Code):
"""Data plugin representing an executable code on a remote computer."""

_EMIT_CODE_DEPRECATION_WARNING: bool = False
_KEY_ATTRIBUTE_FILEPATH_EXECUTABLE: str = 'filepath_executable'

class Model(AbstractCode.Model):
"""Model describing required information to create an instance."""

computer: str = MetadataField(
model_config = ConfigDict(arbitrary_types_allowed=True)

computer: t.Union[str, Computer] = MetadataField(
...,
title='Computer',
description='The remote computer on which the executable resides.',
Expand Down Expand Up @@ -78,7 +82,7 @@ def validate_full_label_uniqueness(self) -> AbstractCode.Model:
"""Validate that the full label does not already exist."""
from aiida.orm import load_code

full_label = f'{self.label}@{self.computer.label}' # type: ignore[attr-defined]
full_label = f'{self.label}@{self.computer.label}' # type: ignore[union-attr]

try:
load_code(full_label)
Expand Down
18 changes: 11 additions & 7 deletions src/aiida/orm/nodes/data/code/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,17 @@ class Code(AbstractCode):
def __init__(self, remote_computer_exec=None, local_executable=None, input_plugin_name=None, files=None, **kwargs):
super().__init__(**kwargs)

warn_deprecation(
'The `Code` class is deprecated. To create an instance, use the '
'`aiida.orm.nodes.data.code.installed.InstalledCode` or `aiida.orm.nodes.data.code.portable.PortableCode` '
'for a "remote" or "local" code, respectively. If you are using this class to compare type, e.g. in '
'`isinstance`, use `aiida.orm.nodes.data.code.abstract.AbstractCode`.',
version=3,
)
# The ``_EMIT_CODE_DEPRECATION_WARNING`` attribute is set in subclasses to avoid the deprecation message below
# is also shown when they are instantiated, since they are not deprecated.
if getattr(self, '_EMIT_CODE_DEPRECATION_WARNING', True):
warn_deprecation(
'The `Code` class is deprecated. To create an instance, use the '
'`aiida.orm.nodes.data.code.installed.InstalledCode` or '
'`aiida.orm.nodes.data.code.portable.PortableCode` for a "remote" or "local" code, respectively. If '
'you are using this class to compare type, e.g. in '
'`isinstance`, use `aiida.orm.nodes.data.code.abstract.AbstractCode`.',
version=3,
)

if remote_computer_exec and local_executable:
raise ValueError('cannot set `remote_computer_exec` and `local_executable` at the same time')
Expand Down
4 changes: 3 additions & 1 deletion src/aiida/orm/nodes/data/code/portable.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from __future__ import annotations

import pathlib
import typing as t

from pydantic import field_validator

Expand All @@ -38,12 +39,13 @@
class PortableCode(Code):
"""Data plugin representing an executable code stored in AiiDA's storage."""

_EMIT_CODE_DEPRECATION_WARNING: bool = False
_KEY_ATTRIBUTE_FILEPATH_EXECUTABLE: str = 'filepath_executable'

class Model(AbstractCode.Model):
"""Model describing required information to create an instance."""

filepath_files: str = MetadataField(
filepath_files: t.Union[str, pathlib.Path] = MetadataField(
...,
title='Code directory',
description='Filepath to directory containing code files.',
Expand Down
15 changes: 10 additions & 5 deletions src/aiida/tools/archive/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,12 +460,17 @@ def _import_nodes(

# get matching uuids from the backend
backend_uuid_id: Dict[str, int] = {}
input_id_uuid_uuids = list(input_id_uuid.values())

if input_id_uuid:
backend_uuid_id = dict(
orm.QueryBuilder(backend=backend_to)
.append(orm.Node, filters={'uuid': {'in': list(input_id_uuid.values())}}, project=['uuid', 'id'])
.all(batch_size=query_params.batch_size)
)
for _, batch in batch_iter(input_id_uuid_uuids, query_params.filter_size):
backend_uuid_id.update(
dict(
orm.QueryBuilder(backend=backend_to)
.append(orm.Node, filters={'uuid': {'in': batch}}, project=['uuid', 'id'])
.all(batch_size=query_params.batch_size)
)
)

new_nodes = len(input_id_uuid) - len(backend_uuid_id)

Expand Down

0 comments on commit 8f4e7cb

Please sign in to comment.