Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 25, 2024
1 parent a0f4e49 commit 38f3e91
Show file tree
Hide file tree
Showing 15 changed files with 105 additions and 214 deletions.
6 changes: 2 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ requires-python = '>=3.9'
'core.structure' = 'aiida.orm.nodes.data.structure:StructureData'
'core.upf' = 'aiida.orm.nodes.data.upf:UpfData'

[project.entry-points.'aiida.exporters']

[project.entry-points.'aiida.groups']
'core' = 'aiida.orm.groups:Group'
'core.auto' = 'aiida.orm.groups:AutoGroup'
Expand Down Expand Up @@ -180,10 +182,6 @@ requires-python = '>=3.9'
'core.arithmetic.add_multiply' = 'aiida.workflows.arithmetic.add_multiply:add_multiply'
'core.arithmetic.multiply_add' = 'aiida.workflows.arithmetic.multiply_add:MultiplyAddWorkChain'

[project.entry-points.'aiida.exporters']
# 'core.arithmetic.add_multiply' = 'aiida.workflows.arithmetic.add_multiply:add_multiply'
# 'core.arithmetic.multiply_add' = 'aiida.workflows.arithmetic.multiply_add:MultiplyAddWorkChain'

[project.optional-dependencies]
atomic_tools = [
'PyCifRW~=4.4',
Expand Down
16 changes: 6 additions & 10 deletions src/aiida/cmdline/commands/cmd_data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
"""The `verdi data` command line interface."""

from aiida.cmdline.commands.cmd_verdi import verdi
from aiida.cmdline.utils.pluginable import Pluginable
from aiida.cmdline.params import arguments, options, types
from aiida.cmdline.utils.pluginable import Pluginable


@verdi.group('data', entry_point_group='aiida.cmdline.data', cls=Pluginable)
def verdi_data():
"""Inspect, create and manage data nodes."""


@verdi_data.command('dump')
@arguments.DATA()
@options.PATH()
Expand All @@ -27,22 +28,17 @@ def data_dump(
path,
overwrite,
) -> None:

"""Dump an arbitrary `Data` node entity to disk.
"""
"""Dump an arbitrary `Data` node entity to disk."""
from aiida.tools.dumping.data import DataDumper

data_dumper = DataDumper(
overwrite=overwrite
)
data_dumper = DataDumper(overwrite=overwrite)

print(type(data), data)
# `data` comes as a tuple
if len(data) > 1:
raise NotImplementedError("Dumping of multiple data nodes not yet supported.")
raise NotImplementedError('Dumping of multiple data nodes not yet supported.')

# Probs shouldn't do that. Quick hack.
data=data[0]
data = data[0]

data_dumper.dump(data_node=data, output_path=path)
3 changes: 1 addition & 2 deletions src/aiida/cmdline/commands/cmd_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ def group_path_ls(path, type_string, recursive, as_table, no_virtual, with_descr
continue
echo.echo(child.path, bold=not child.is_virtual)


@verdi_group.command('dump')
@arguments.GROUP()
# @with_dbenv()
Expand All @@ -659,10 +660,8 @@ def group_path_ls(path, type_string, recursive, as_table, no_virtual, with_descr
# help='Add a filter to show only groups for which the label contains STRING.',
# )
def group_dump(group):

print(group)
from aiida.tools.dumping.group import GroupDumper

group_dumper = GroupDumper()
group_dumper.dump(group)

5 changes: 1 addition & 4 deletions src/aiida/cmdline/commands/cmd_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,10 +682,7 @@ def process_dump(

try:
dump_path = process_dumper.dump(
process_node=process,
output_path=path,
include_attributes=include_attributes,
include_extras=include_extras
process_node=process, output_path=path, include_attributes=include_attributes, include_extras=include_extras
)
except FileExistsError:
echo.echo_critical(
Expand Down
1 change: 1 addition & 0 deletions src/aiida/cmdline/commands/cmd_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ def profile_delete(force, delete_data, profiles):
get_config().delete_profile(profile.name, delete_storage=delete_data)
echo.echo_success(f'Profile `{profile.name}` was deleted.')


@verdi_profile.command('dump')
@options.PATH()
@arguments.PROFILE(default=defaults.get_default_profile)
Expand Down
5 changes: 2 additions & 3 deletions src/aiida/tools/dumping/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
# Could add saveguard file with filename based on class name or sthg like that
#

class AbstractDumper():

class AbstractDumper:
def __init__(self, overwrite, incremental):
self.overwrite = overwrite
self.incremental = incremental


15 changes: 7 additions & 8 deletions src/aiida/tools/dumping/backup-code.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Could also be a more general CollectionDumper class, actually

import contextlib
from aiida.common import timezone
from aiida.orm import CalculationNode, Code, Computer, Group, QueryBuilder, StructureData, User, WorkflowNode
from typing import List
from aiida.tools.dumping.utils import _validate_make_dump_path, get_nodes_from_db
from pathlib import Path
from typing import List

from aiida.common import timezone
from aiida.orm import CalculationNode, WorkflowNode
from aiida.tools.dumping.processes import ProcessDumper
from aiida.tools.dumping.utils import get_nodes_from_db

# DEFAULT_ENTITIES_TO_DUMP = [WorkflowNode, StructureData, User, Code, Computer]
DEFAULT_ENTITIES_TO_DUMP = [CalculationNode, WorkflowNode] # , StructureData, User, Code, Computer]
Expand Down Expand Up @@ -45,19 +46,18 @@ def dump(self, group):
print(type(entity), entity, len(group_nodes))

# print("ABC", aiida_entity==CalculationNode)
if entity==CalculationNode:
if entity == CalculationNode:
print('SELF._DUMP_CALCULATIONS_HIDDEN', len(group_nodes))
self._dump_calculations_hidden(calculations=group_nodes)

if entity==WorkflowNode:
if entity == WorkflowNode:
print('SELF._DUMP_WORKFLOWS_HIDDEN', len(group_nodes))
self._dump_workflows_hidden(workflows=group_nodes)

def _dump_calculations_hidden(self, calculations):
# ? Dump only top-level workchains, as that includes sub-workchains already

for calculation in calculations:

# ? Hardcode overwrite=True for now
calculation_dumper = ProcessDumper(overwrite=True)

Expand All @@ -68,7 +68,6 @@ def _dump_calculations_hidden(self, calculations):
with contextlib.suppress(FileExistsError):
calculation_dumper.dump(process_node=calculation, output_path=calculation_dump_path)


# # To make development quicker
# if iworkflow_ > 1:
# break
Expand Down
8 changes: 3 additions & 5 deletions src/aiida/tools/dumping/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
###########################################################################
"""Functionality for dumping of a Collections of AiiDA ORMs."""

from aiida import orm
import logging
from collections import Counter

from aiida import orm

LOGGER = logging.getLogger(__name__)
# TODO: Could also get the entities, or UUIDs directly, rather than just counting them here

class CollectionDumper:

class CollectionDumper:
@staticmethod
def create_entity_counter(orm_collection: orm.Group | orm.Collection | None = None):
if orm_collection is None:
Expand All @@ -26,7 +27,6 @@ def create_entity_counter(orm_collection: orm.Group | orm.Collection | None = No

@staticmethod
def _create_entity_counter_profile():

nodes = orm.QueryBuilder().append(orm.Node).all(flat=True)
type_counter = Counter()

Expand Down Expand Up @@ -58,8 +58,6 @@ def _create_entity_counter_group(group: orm.Group | str):

return type_counter



# @staticmethod
# def _create_entity_counter_storage():
# # ? If the group only has one WorkChain assigned to it, this will only return a count of 1 for the
Expand Down
11 changes: 6 additions & 5 deletions src/aiida/tools/dumping/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
"""Functionality for dumping of Data nodes."""

from __future__ import annotations
from functools import singledispatchmethod

from aiida import orm
from aiida.orm.nodes.data.structure import StructureData
from pathlib import Path
import logging
from functools import singledispatchmethod
from pathlib import Path

import yaml

from aiida import orm
from aiida.orm.nodes.data.structure import StructureData

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -93,7 +94,7 @@ def _dump_code(
file_name: str | Path | None = None,
file_format: str = 'yaml',
*args,
**kwargs
**kwargs,
):
if output_path is None:
output_path = Path.cwd()
Expand Down
2 changes: 1 addition & 1 deletion src/aiida/tools/dumping/gio-dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ def export_structure(node, folder, **kargs): # GP: support both functions and cl
# GP: Not specified means use the default, for now from hardcoded list, in the future reading from some defined method of the plugin

# This could be entry point given in plugin
aiida.orm.data.StructureData.export_to_dir # think to a syntax for methods
aiida.orm.data.StructureData.export_to_dir # think to a syntax for methods
50 changes: 24 additions & 26 deletions src/aiida/tools/dumping/group.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import contextlib
import itertools
import logging
Expand All @@ -8,16 +7,17 @@

from aiida import orm
from aiida.common import timezone

from aiida.tools.dumping.collection import CollectionDumper
from aiida.tools.dumping.process import ProcessDumper
from aiida.tools.dumping.data import DataDumper

from aiida.tools.dumping.utils import _validate_make_dump_path, get_nodes_from_db
from aiida.tools.dumping.utils import get_nodes_from_db

# DEFAULT_ENTITIES_TO_DUMP = [WorkflowNode, StructureData, User, Code, Computer]
DEFAULT_PROCESSES_TO_DUMP = [orm.CalculationNode, orm.WorkflowNode] # , StructureData, User, Code, Computer]
DEFAULT_DATA_TO_DUMP = [orm.StructureData, orm.Code, orm.Computer, ] # , StructureData, User, Code, Computer]
DEFAULT_DATA_TO_DUMP = [
orm.StructureData,
orm.Code,
orm.Computer,
] # , StructureData, User, Code, Computer]
DEFAULT_ENTITIES_TO_DUMP = DEFAULT_PROCESSES_TO_DUMP + DEFAULT_DATA_TO_DUMP

# from aiida.common.utils import str_timedelta
Expand Down Expand Up @@ -77,19 +77,17 @@ def dump(self, group: orm.Group | str | None = None, output_path: Path | str | N
# self.group_path = Path.cwd() / 'groups'
# self.group_path = self.output_path / 'groups' / group_name

# logger.report(f'self.entity_counter for Group <{self.group}>: {self.entity_counter}')
# logger.report(f'Dumping calculations and workflows of group {group_name}...')
# logger.report(f'self.entity_counter for Group <{self.group}>: {self.entity_counter}')
# logger.report(f'Dumping calculations and workflows of group {group_name}...')

# TODO: This shouldn't be on a per-group basis? Possibly dump all data for the whole profile.
# TODO: Though, now that I think about it, it might actually be desirable to only limit that to the group only.
# logger.report(f'Dumping raw calculation data for group {group_name}...')
# logger.report(f'Dumping raw calculation data for group {group_name}...')

logger.report(f'Dumping processes for group {group_name}...')
self._dump_processes()


def _dump_processes(self):

if (
sum(
self.entity_counter.get(orm_process_class, 0)
Expand Down Expand Up @@ -142,25 +140,25 @@ def _dump_processes(self):
self._dump_calculations_hidden()
self._link_calculations_hidden()

# logger.report(f'Dumping other data nodes of group {group_name}...')
# logger.report(f'Dumping other data nodes of group {group_name}...')

# TODO: Here might also be pseudo.family.sssp, not just workflows/calculations
# TODO: Here might also be pseudo.family.sssp, not just workflows/calculations

# for entity in self.entities_to_dump:
# for entity in self.entities_to_dump:

# group_nodes = get_nodes_from_db(aiida_node_type=entity, with_group=group, flatten=True)
# group_nodes = get_nodes_from_db(aiida_node_type=entity, with_group=group, flatten=True)

# # print('_DUMP_TO_HIDDEN(SELF, AIIDA_ENTITY, AIIDA_NODES)')
# # print(entity, len(group_nodes))
# # print('_DUMP_TO_HIDDEN(SELF, AIIDA_ENTITY, AIIDA_NODES)')
# # print(entity, len(group_nodes))

# # print("ABC", aiida_entity==CalculationNode)
# if entity==CalculationNode:
# print('SELF._DUMP_CALCULATIONS_HIDDEN', len(group_nodes))
# self._dump_calculations_hidden(calculations=group_nodes)
# # print("ABC", aiida_entity==CalculationNode)
# if entity==CalculationNode:
# print('SELF._DUMP_CALCULATIONS_HIDDEN', len(group_nodes))
# self._dump_calculations_hidden(calculations=group_nodes)

# # if entity==WorkflowNode:
# # print('SELF._DUMP_WORKFLOWS_HIDDEN', len(group_nodes))
# # self._dump_workflows_hidden(workflows=group_nodes)
# # if entity==WorkflowNode:
# # print('SELF._DUMP_WORKFLOWS_HIDDEN', len(group_nodes))
# # self._dump_workflows_hidden(workflows=group_nodes)

def _dump_calculations_hidden(self):
# ? Dump only top-level workchains, as that includes sub-workchains already
Expand Down Expand Up @@ -211,7 +209,7 @@ def _dump_link_workflows(self, link_calculations: bool = True):
workflow_dump_path = (
self.output_path / 'workflows' / workflow_dumper._generate_default_dump_path(process_node=workflow_node)
)
# logger.report(f'WORKFLOW_DUMP_PATH: {workflow_dump_path}')
# logger.report(f'WORKFLOW_DUMP_PATH: {workflow_dump_path}')

workflow_dumper._dump_workflow(
workflow_node=workflow_node,
Expand All @@ -234,7 +232,7 @@ def _link_calculations_hidden(self):
calculation_dump_path = calculation_dump_path / calculation_dumper._generate_default_dump_path(
process_node=calculation_node
)
# logger.report(f'CALCULATION_DUMP_PATH: {calculation_dump_path}')
# logger.report(f'CALCULATION_DUMP_PATH: {calculation_dump_path}')

with contextlib.suppress(FileExistsError):
os.symlink(link_calculations_dir / calculation_node.uuid, calculation_dump_path)
Loading

0 comments on commit 38f3e91

Please sign in to comment.