aiida.backends package

Module for implementations of database backends.

aiida.backends.get_backend_manager(backend)[source]

Get an instance of the BackendManager for the current backend.

Parameters

backend – the type of the database backend

Returns

BackendManager

Submodules

Module for settings and utilities to determine and set the database schema versions.

class aiida.backends.manager.BackendManager[source]

Bases: object

Class to manage the database schema and environment.

__dict__ = mappingproxy({'__module__': 'aiida.backends.manager', '__doc__': 'Class to manage the database schema and environment.', '_settings_manager': None, 'get_settings_manager': <function BackendManager.get_settings_manager>, 'load_backend_environment': <function BackendManager.load_backend_environment>, '_load_backend_environment': <function BackendManager._load_backend_environment>, 'reset_backend_environment': <function BackendManager.reset_backend_environment>, 'migrate': <function BackendManager.migrate>, '_migrate_database_generation': <function BackendManager._migrate_database_generation>, '_migrate_database_version': <function BackendManager._migrate_database_version>, 'is_database_schema_ahead': <function BackendManager.is_database_schema_ahead>, 'get_schema_version_code': <function BackendManager.get_schema_version_code>, 'get_schema_version_reset': <function BackendManager.get_schema_version_reset>, 'get_schema_version_database': <function BackendManager.get_schema_version_database>, 'set_schema_version_database': <function BackendManager.set_schema_version_database>, 'get_schema_generation_database': <function BackendManager.get_schema_generation_database>, 'set_schema_generation_database': <function BackendManager.set_schema_generation_database>, 'validate_schema': <function BackendManager.validate_schema>, 'validate_schema_generation_for_migration': <function BackendManager.validate_schema_generation_for_migration>, 'validate_schema_version_for_migration': <function BackendManager.validate_schema_version_for_migration>, 'validate_schema_generation': <function BackendManager.validate_schema_generation>, 'validate_schema_version': <function BackendManager.validate_schema_version>, '__dict__': <attribute '__dict__' of 'BackendManager' objects>, '__weakref__': <attribute '__weakref__' of 'BackendManager' objects>})
__module__ = 'aiida.backends.manager'
__weakref__

list of weak references to the object (if defined)

abstract _load_backend_environment()[source]

Load the backend environment.

_migrate_database_generation()[source]

Migrate the database schema generation.

Warning

this should NEVER be called directly because there is no validation performed on whether the current database schema generation and version can actually be migrated.

This normally just consists out of setting the schema generation value, but depending on the backend more might be needed. In that case, this method should be overridden and call super first, followed by the additional logic that is required.

_migrate_database_version()[source]

Migrate the database to the current schema version.

Warning

this should NEVER be called directly because there is no validation performed on whether the current database schema generation and version can actually be migrated.

_settings_manager = None
get_schema_generation_database()[source]

Return the database schema generation.

Returns

distutils.version.LooseVersion with schema generation of the database

abstract get_schema_version_code()[source]

Return the code schema version.

abstract get_schema_version_database()[source]

Return the database schema version.

Returns

distutils.version.LooseVersion with schema version of the database

abstract get_schema_version_reset(schema_generation_code)[source]

Return schema version the database should have to be able to automatically reset to code schema generation.

Parameters

schema_generation_code – the schema generation of the code.

Returns

schema version

abstract get_settings_manager()[source]

Return an instance of the SettingsManager.

Returns

SettingsManager

abstract is_database_schema_ahead()[source]

Determine whether the database schema version is ahead of the code schema version.

Warning

this will not check whether the schema generations are equal

Returns

boolean, True if the database schema version is ahead of the code schema version.

load_backend_environment(profile, validate_schema=True)[source]

Load the backend environment.

Parameters
  • profile – the profile whose backend environment to load

  • validate_schema – boolean, if True, validate the schema first before loading the environment.

migrate()[source]

Migrate the database to the latest schema generation or version.

abstract reset_backend_environment()[source]

Reset the backend environment.

set_schema_generation_database(generation)[source]

Set the database schema generation.

Parameters

generation – string with schema generation to set

abstract set_schema_version_database(version)[source]

Set the database schema version.

Parameters

version – string with schema version to set

validate_schema(profile)[source]

Validate that the current database generation and schema are up-to-date with that of the code.

Parameters

profile – the profile for which to validate the database schema

Raises

aiida.common.exceptions.ConfigurationError – if database schema version or generation is not up-to-date

validate_schema_generation(profile)[source]

Validate that the current database schema generation is up-to-date with that of the code.

Raises

aiida.common.exceptions.IncompatibleDatabaseSchema – if database schema generation is not up-to-date

validate_schema_generation_for_migration()[source]

Validate whether the current database schema generation can be migrated.

Raises

aiida.common.exceptions.IncompatibleDatabaseSchema – if database schema generation cannot be migrated

validate_schema_version(profile)[source]

Validate that the current database schema version is up-to-date with that of the code.

Parameters

profile – the profile for which to validate the database schema

Raises

aiida.common.exceptions.IncompatibleDatabaseSchema – if database schema version is not up-to-date

validate_schema_version_for_migration()[source]

Validate whether the current database schema version can be migrated.

Warning

this will not validate that the schema generation is correct.

Raises

aiida.common.exceptions.IncompatibleDatabaseSchema – if database schema version cannot be migrated

class aiida.backends.manager.Setting(key, value, description, time)

Bases: tuple

__getnewargs__()

Return self as a plain tuple. Used by copy and pickle.

__module__ = 'aiida.backends.manager'
static __new__(_cls, key, value, description, time)

Create new instance of Setting(key, value, description, time)

__repr__()

Return a nicely formatted representation string

__slots__ = ()
_asdict()

Return a new OrderedDict which maps field names to their values.

_fields = ('key', 'value', 'description', 'time')
_fields_defaults = {}
classmethod _make(iterable)

Make a new Setting object from a sequence or iterable

_replace(**kwds)

Return a new Setting object replacing specified fields with new values

property description

Alias for field number 2

property key

Alias for field number 0

property time

Alias for field number 3

property value

Alias for field number 1

class aiida.backends.manager.SettingsManager[source]

Bases: object

Class to get, set and delete settings from the DbSettings table.

__dict__ = mappingproxy({'__module__': 'aiida.backends.manager', '__doc__': 'Class to get, set and delete settings from the `DbSettings` table.', 'get': <function SettingsManager.get>, 'set': <function SettingsManager.set>, 'delete': <function SettingsManager.delete>, '__dict__': <attribute '__dict__' of 'SettingsManager' objects>, '__weakref__': <attribute '__weakref__' of 'SettingsManager' objects>})
__module__ = 'aiida.backends.manager'
__weakref__

list of weak references to the object (if defined)

abstract delete(key)[source]

Delete the setting with the given key.

Parameters

key – the key identifying the setting

Raises

~aiida.common.exceptions.NotExistent if the settings does not exist

abstract get(key)[source]

Return the setting with the given key.

Parameters

key – the key identifying the setting

Returns

Setting

Raises

~aiida.common.exceptions.NotExistent if the settings does not exist

abstract set(key, value, description=None)[source]

Return the settings with the given key.

Parameters
  • key – the key identifying the setting

  • value – the value for the setting

  • description – optional setting description

Module for implementations of database backends.

Deprecated since version 1.0.0: Will be removed in v1.1.0, use aiida.backends instead.

Basic test classes.

class aiida.backends.testbase.AiidaPostgresTestCase(methodName='runTest')[source]

Bases: aiida.backends.testbase.AiidaTestCase

Setup postgres tests.

__module__ = 'aiida.backends.testbase'
classmethod setUpClass(*args, **kwargs)[source]

Setup the PGTest postgres test cluster.

classmethod tearDownClass(*args, **kwargs)[source]

Close the PGTest postgres test cluster.

class aiida.backends.testbase.AiidaTestCase(methodName='runTest')[source]

Bases: unittest.case.TestCase

This is the base class for AiiDA tests, independent of the backend.

Internally it loads the AiidaTestImplementation subclass according to the current backend.

_AiidaTestCase__backend_instance = None
__module__ = 'aiida.backends.testbase'
_class_was_setup = False
assertClickResultNoException(cli_result)[source]
assertClickSuccess(cli_result)[source]
backend = None
classmethod clean_db()[source]

Clean up database and reset caches.

Resets AiiDA manager cache, which could otherwise be left in an inconsistent state when cleaning the database.

classmethod clean_repository()[source]

Cleans up file repository.

computer

A class that, when used as a decorator, works as if the two decorators @property and @classmethod where applied together (i.e., the object works as a property, both for the Class and for any of its instance; and is called with the class cls rather than with the instance as its first argument).

classmethod create_computer()[source]
classmethod create_user()[source]
classmethod get_backend_class()[source]

Get backend class.

classmethod insert_data()[source]

This method setups the database (by creating a default user) and inserts default data into the database (which is for the moment a default computer).

reset_database()[source]

Reset the database to the default state deleting any content currently stored

setUp()[source]

Hook method for setting up the test fixture before exercising it.

classmethod setUpClass(*args, **kwargs)[source]

Hook method for setting up class fixture before running tests in the class.

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

classmethod tearDownClass(*args, **kwargs)[source]

Hook method for deconstructing the class fixture after running all tests in the class.

user_email

A class that, when used as a decorator, works as if the two decorators @property and @classmethod where applied together (i.e., the object works as a property, both for the Class and for any of its instance; and is called with the class cls rather than with the instance as its first argument).

aiida.backends.testbase.check_if_tests_can_run()[source]

Verify that the currently loaded profile is a test profile, otherwise raise TestsNotAllowedError.

Implementation-dependednt base tests

class aiida.backends.testimplbase.AiidaTestImplementation[source]

Bases: abc.ABC

For each implementation, define what to do at setUp and tearDown.

Each subclass must reimplement two standard methods (i.e., not classmethods), called respectively setUpClass_method and tearDownClass_method. It is also required to implement setUp_method and tearDown_method to be run for each single test They can set local properties (e.g. self.xxx = yyy) but remember that xxx is not visible to the upper (calling) Test class.

Moreover, it is required that they define in the setUpClass_method the two properties:

  • self.computer that must be a Computer object

  • self.user_email that must be a string

These two are then exposed by the self.get_computer() and self.get_user_email() methods.

__abstractmethods__ = frozenset({'clean_db', 'setUpClass_method', 'tearDownClass_method'})
__dict__ = mappingproxy({'__module__': 'aiida.backends.testimplbase', '__doc__': 'For each implementation, define what to do at setUp and tearDown.\n\n Each subclass must reimplement two *standard* methods (i.e., *not* classmethods), called\n respectively ``setUpClass_method`` and ``tearDownClass_method``.\n It is also required to implement setUp_method and tearDown_method to be run for each single test\n They can set local properties (e.g. ``self.xxx = yyy``) but remember that ``xxx``\n is not visible to the upper (calling) Test class.\n\n Moreover, it is required that they define in the setUpClass_method the two properties:\n\n - ``self.computer`` that must be a Computer object\n - ``self.user_email`` that must be a string\n\n These two are then exposed by the ``self.get_computer()`` and ``self.get_user_email()``\n methods.', 'backend': None, 'computer': None, 'user': None, 'user_email': None, 'setUpClass_method': <function AiidaTestImplementation.setUpClass_method>, 'tearDownClass_method': <function AiidaTestImplementation.tearDownClass_method>, 'clean_db': <function AiidaTestImplementation.clean_db>, 'insert_data': <function AiidaTestImplementation.insert_data>, 'create_user': <function AiidaTestImplementation.create_user>, 'create_computer': <function AiidaTestImplementation.create_computer>, 'get_computer': <function AiidaTestImplementation.get_computer>, 'get_user_email': <function AiidaTestImplementation.get_user_email>, '__dict__': <attribute '__dict__' of 'AiidaTestImplementation' objects>, '__weakref__': <attribute '__weakref__' of 'AiidaTestImplementation' objects>, '__abstractmethods__': frozenset({'setUpClass_method', 'clean_db', 'tearDownClass_method'}), '_abc_impl': <_abc_data object>})
__module__ = 'aiida.backends.testimplbase'
__weakref__

list of weak references to the object (if defined)

_abc_impl = <_abc_data object>
backend = None
abstract clean_db()[source]

This method implements the logic to fully clean the DB.

computer = None
create_computer()[source]

This method creates and stores a computer.

create_user()[source]

This method creates and stores the default user. It has the same effect as the verdi setup.

get_computer()[source]

An ORM Computer object present in the DB.

get_user_email()[source]

A string with the email of the User.

insert_data()[source]
abstract setUpClass_method()[source]

This class prepares the database (cleans it up and installs some basic entries). You have also to set a self.computer and a self.user_email as explained in the docstring of the AiidaTestImplemention docstring.

abstract tearDownClass_method()[source]

Backend-specific tasks for tearing down the test environment.

user = None
user_email = None
aiida.backends.utils.delete_nodes_and_connections(pks)[source]