Skip to content

Commit

Permalink
Add to_aiida_type to the public API (#4672)
Browse files Browse the repository at this point in the history
Since `to_aiida_type` is intended for public use,
this commit makes it part of the public API,
via `from aiida.orm import to_aiida_type`.
  • Loading branch information
chrisjsewell authored Jan 27, 2021
1 parent cdb2e57 commit 3cf1d2e
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions aiida/orm/nodes/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""Module with `Node` sub classes for data structures."""

from .array import ArrayData, BandsData, KpointsData, ProjectionData, TrajectoryData, XyData
from .base import BaseType
from .base import BaseType, to_aiida_type
from .bool import Bool
from .cif import CifData
from .code import Code
Expand All @@ -31,5 +31,5 @@
__all__ = (
'Data', 'BaseType', 'ArrayData', 'BandsData', 'KpointsData', 'ProjectionData', 'TrajectoryData', 'XyData', 'Bool',
'CifData', 'Code', 'Float', 'FolderData', 'Int', 'List', 'OrbitalData', 'Dict', 'RemoteData', 'SinglefileData',
'Str', 'StructureData', 'UpfData', 'NumericType'
'Str', 'StructureData', 'UpfData', 'NumericType', 'to_aiida_type'
)
1 change: 1 addition & 0 deletions docs/source/reference/api/public.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ If a module is mentioned, then all the resources defined in its ``__all__`` are
load_code
load_computer
load_group
to_aiida_type


``aiida.parsers``
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# -*- coding: utf-8 -*-
from aiida.engine import WorkChain
from aiida.orm.nodes.data import to_aiida_type
# The basic types need to be loaded such that they are registered with
# the 'to_aiida_type' function.
from aiida.orm.nodes.data.base import *
from aiida.orm import to_aiida_type


class SerializeWorkChain(WorkChain):
Expand Down
6 changes: 4 additions & 2 deletions docs/source/topics/processes/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,14 @@ This function, passed as ``serializer`` parameter to ``spec.input``, is invoked
For inputs which are stored in the database (``non_db=False``), the serialization function should return an AiiDA data type.
For ``non_db`` inputs, the function must be idempotent because it might be applied more than once.

The following example work chain takes three inputs ``a``, ``b``, ``c``, and simply returns the given inputs. The :func:`aiida.orm.nodes.data.base.to_aiida_type` function is used as serialization function.
The following example work chain takes three inputs ``a``, ``b``, ``c``, and simply returns the given inputs.
The :func:`~aiida.orm.nodes.data.base.to_aiida_type` function is used as serialization function.

.. include:: include/snippets/serialize/workchain_serialize.py
:code: python

This work chain can now be called with native Python types, which will automatically be converted to AiiDA types by the :func:`aiida.orm.nodes.data.base.to_aiida_type` function. Note that the module which defines the corresponding AiiDA type must be loaded for it to be recognized by :func:`aiida.orm.nodes.data.base.to_aiida_type`.
This work chain can now be called with native Python types, which will automatically be converted to AiiDA types by the :func:`~aiida.orm.nodes.data.base.to_aiida_type` function.
Note that the module which defines the corresponding AiiDA type must be loaded for it to be recognized by :func:`~aiida.orm.nodes.data.base.to_aiida_type`.

.. include:: include/snippets/serialize/run_workchain_serialize.py
:code: python
Expand Down
2 changes: 1 addition & 1 deletion tests/orm/data/test_to_aiida_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""
This module contains tests for the to_aiida_type serializer
"""
from aiida.orm.nodes.data.base import to_aiida_type
from aiida.orm import to_aiida_type
from aiida.orm import Dict, Int, Float, Bool, Str

from aiida.backends.testbase import AiidaTestCase
Expand Down

0 comments on commit 3cf1d2e

Please sign in to comment.