How to inspect an archive#

Note

This tutorial can be downloaded and run as a Jupyter Notebook: archive_profile.ipynb , together with the archive include/process.aiida.

The AiiDA archive is a file format for long term storage of data from a particular profile.

See Sharing AiiDA archives for information on how to create and migrate an archive. Once you have an archive at the latest version, you can inspect its contents in the same way you would with a standard AiiDA profile.

We first create a profile instance from the archive path:

from aiida import manage, orm, profile_context
from aiida.storage.sqlite_zip.backend import SqliteZipBackend

archive_profile = SqliteZipBackend.create_profile('include/process.aiida')
print(archive_profile)
Profile<uuid='329bb3dc086c466ea6c70d63bd3ed971' name='process.aiida'>

The profile_context() function works similarly to the load_profile() function, but is used within a context manager, that insures that the storage is properly closed when the context is exited. With this, we can load our archive as a profile:

with profile_context(archive_profile):
    print(manage.get_manager().get_profile())
Profile<uuid='329bb3dc086c466ea6c70d63bd3ed971' name='process.aiida'>

To directly access the storage backend, and view information about it, we can use:

import json
with profile_context(archive_profile):
    storage = manage.get_manager().get_profile_storage()
    print(storage)
    print(json.dumps(storage.get_info(), indent=2))
SqliteZip storage (read-only) [open] @ include/process.aiida
{
  "metadata": {
    "export_version": "main_0001",
    "aiida_version": "2.0.0a1",
    "key_format": "sha256",
    "compression": 6,
    "ctime": "2022-03-10T11:56:56.759722",
    "creation_parameters": {
      "entities_starting_set": {
        "node": [
          "cff1e914-5a34-4930-9429-9dcc6d38feb1"
        ]
      },
      "include_authinfos": false,
      "include_comments": true,
      "include_logs": true,
      "graph_traversal_rules": {
        "input_calc_forward": false,
        "input_calc_backward": true,
        "create_forward": true,
        "create_backward": true,
        "return_forward": true,
        "return_backward": false,
        "input_work_forward": false,
        "input_work_backward": true,
        "call_calc_forward": true,
        "call_calc_backward": true,
        "call_work_forward": true,
        "call_work_backward": true
      }
    }
  }
}

This is directly equivalent to the command-line call:

!verdi archive info include/process.aiida
-metadata:
  export_version: main_0001
  aiida_version: 2.0.0a1
  key_format: sha256
  compression: 6
  ctime: '2022-03-10T11:56:56.759722'
  creation_parameters:
    entities_starting_set:
      node:
      - cff1e914-5a34-4930-9429-9dcc6d38feb1
    include_authinfos: false
    include_comments: true
    include_logs: true
    graph_traversal_rules:
      input_calc_forward: false
      input_calc_backward: true
      create_forward: true
      create_backward: true
      return_forward: true
      return_backward: false
      input_work_forward: false
      input_work_backward: true
      call_calc_forward: true
      call_calc_backward: true
      call_work_forward: true
      call_work_backward: true

Note, that once the context manager is exited, the storage is closed, and will except on further calls.

print(storage)
SqliteZip storage (read-only) [closed] @ include/process.aiida

As per a standard profile, we can now use the QueryBuilder, to find and query for data:

with profile_context(archive_profile):
    process = orm.QueryBuilder().append(orm.ProcessNode).first(flat=True)
    print(process)
uuid: cff1e914-5a34-4930-9429-9dcc6d38feb1 (pk: 61)
/home/docs/checkouts/readthedocs.org/user_builds/aiida-core/envs/v2.0.0/lib/python3.8/site-packages/paramiko/transport.py:236: CryptographyDeprecationWarning: Blowfish has been deprecated
  "class": algorithms.Blowfish,

and also use Graph, to visualize data provenance:

from aiida.tools.visualization import Graph

with profile_context(archive_profile):
    process = orm.QueryBuilder().append(orm.ProcessNode).first(flat=True)
    graph = Graph(graph_attr={"size": "8!,8!", "rankdir": "LR"})
    graph.add_incoming(process, annotate_links="both")
    graph.add_outgoing(process, annotate_links="both")

graph.graphviz
../_images/archive_profile_13_0.svg