Create_profile not found

Hi,

I am trying to repeat the process about inspecting an archive
(How to inspect an archive — AiiDA 2.0.0b1 documentation) in Quantum Mobile 24.04.03.

The problem is that when creating an archive, the programe seems OK. But the .aiida file is not actually created. So I just get an error ‘UnreachableStorage: path not found: include/process.aiida’ in the following steps.

The same kind of error happens in both verdi shell and jupyterpy.

The codes are here

In [1]: from aiida import manage, orm, profile_context
  ...: from aiida.storage.sqlite_zip.backend import SqliteZipBackend
  ...: 
  ...: archive_profile = SqliteZipBackend.create_profile('include/process.aiida', allow_swi
  ...: tch=True)
  ...: print(archive_profile)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-93dccc2fd6f3> in <cell line: 4>()
     2 from aiida.storage.sqlite_zip.backend import SqliteZipBackend
     3 
----> 4 archive_profile = SqliteZipBackend.create_profile('include/process.aiida', allow_switch=True)
     5 print(archive_profile)

TypeError: create_profile() got an unexpected keyword argument 'allow_switch'

In [2]: 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='cd95513fabb84be387920357a26d86dc' name='process.aiida'>

In [3]: with profile_context(archive_profile):
  ...:     print(manage.get_manager().get_profile())
  ...: 
---------------------------------------------------------------------------
InvalidOperation                          Traceback (most recent call last)
<ipython-input-3-1fe3b9a659d1> in <cell line: 1>()
----> 1 with profile_context(archive_profile):
     2     print(manage.get_manager().get_profile())
     3 

~/.conda/envs/aiida/lib/python3.9/contextlib.py in __enter__(self)
   117         del self.args, self.kwds, self.func
   118         try:
--> 119             return next(self.gen)
   120         except StopIteration:
   121             raise RuntimeError("generator didn't yield") from None

~/.conda/envs/aiida/lib/python3.9/site-packages/aiida/manage/configuration/__init__.py in profile_context(profile, allow_switch)
   175     manager = get_manager()
   176     current_profile = manager.get_profile()
--> 177     manager.load_profile(profile, allow_switch)
   178     yield profile
   179     if current_profile is None:

~/.conda/envs/aiida/lib/python3.9/site-packages/aiida/manage/manager.py in load_profile(self, profile, allow_switch)
   124 
   125         if self._profile and self.profile_storage_loaded and not allow_switch:
--> 126             raise InvalidOperation(
   127                 f'cannot switch to profile {profile.name!r} because profile {self._profile.name!r} storage '
   128                 'is already loaded and allow_switch is False'

InvalidOperation: cannot switch to profile 'process.aiida' because profile 'generic' storage is already loaded and allow_switch is False

In [4]: archive_profile.allow_switch = True

In [5]: with profile_context(archive_profile):
  ...:     print(manage.get_manager().get_profile())
  ...: 
---------------------------------------------------------------------------
InvalidOperation                          Traceback (most recent call last)
<ipython-input-5-1fe3b9a659d1> in <cell line: 1>()
----> 1 with profile_context(archive_profile):
     2     print(manage.get_manager().get_profile())
     3 

~/.conda/envs/aiida/lib/python3.9/contextlib.py in __enter__(self)
   117         del self.args, self.kwds, self.func
   118         try:
--> 119             return next(self.gen)
   120         except StopIteration:
   121             raise RuntimeError("generator didn't yield") from None

~/.conda/envs/aiida/lib/python3.9/site-packages/aiida/manage/configuration/__init__.py in profile_context(profile, allow_switch)
   175     manager = get_manager()
   176     current_profile = manager.get_profile()
--> 177     manager.load_profile(profile, allow_switch)
   178     yield profile
   179     if current_profile is None:

~/.conda/envs/aiida/lib/python3.9/site-packages/aiida/manage/manager.py in load_profile(self, profile, allow_switch)
   124 
   125         if self._profile and self.profile_storage_loaded and not allow_switch:
--> 126             raise InvalidOperation(
   127                 f'cannot switch to profile {profile.name!r} because profile {self._profile.name!r} storage '
   128                 'is already loaded and allow_switch is False'

InvalidOperation: cannot switch to profile 'process.aiida' because profile 'generic' storage is already loaded and allow_switch is False

In [6]: print(archive_profile)
Profile<uuid='cd95513fabb84be387920357a26d86dc' name='process.aiida'>

In [7]: with profile_context(archive_profile,allow_switch=True):
  ...:     print(manage.get_manager().get_profile())
  ...: 
  ...: 
Profile<uuid='cd95513fabb84be387920357a26d86dc' name='process.aiida'>

In [8]: import json
  ...: with profile_context(archive_profile):
  ...:     storage = manage.get_manager().get_profile_storage()
  ...:     print(storage)
  ...:     print(json.dumps(storage.get_info(), indent=2))
  ...: 
---------------------------------------------------------------------------
UnreachableStorage                        Traceback (most recent call last)
<ipython-input-8-7cea7fe10409> in <cell line: 2>()
     1 import json
     2 with profile_context(archive_profile):
----> 3     storage = manage.get_manager().get_profile_storage()
     4     print(storage)
     5     print(json.dumps(storage.get_info(), indent=2))

~/.conda/envs/aiida/lib/python3.9/site-packages/aiida/manage/manager.py in get_profile_storage(self)
   253         # if the storage is not reachable, this will raise an exception
   254         # if the storage schema is not at the latest version, this will except and the user will be informed to migrate
--> 255         self._profile_storage = storage_cls(profile)
   256 
   257         # Reconfigure the logging with `with_orm=True` to make sure that profile specific logging configuration options

~/.conda/envs/aiida/lib/python3.9/site-packages/aiida/storage/sqlite_zip/backend.py in __init__(self, profile)
   156         super().__init__(profile)
   157         self._path = Path(profile.storage_config['path'])
--> 158         validate_storage(self._path)
   159         # lazy open the archive zipfile and extract the database file
   160         self._db_file: Optional[Path] = None

~/.conda/envs/aiida/lib/python3.9/site-packages/aiida/storage/sqlite_zip/migrator.py in validate_storage(inpath)
    59     """
    60     schema_version_code = get_schema_version_head()
---> 61     schema_version_archive = read_version(inpath)
    62     if schema_version_archive != schema_version_code:
    63         raise IncompatibleStorageSchema(

~/.conda/envs/aiida/lib/python3.9/site-packages/aiida/storage/sqlite_zip/utils.py in read_version(path, search_limit)
   112     :raises: ``UnreachableStorage`` if a version cannot be read from the file
   113     """
--> 114     metadata = extract_metadata(path, search_limit=search_limit)
   115     if 'export_version' in metadata:
   116         return metadata['export_version']

~/.conda/envs/aiida/lib/python3.9/site-packages/aiida/storage/sqlite_zip/utils.py in extract_metadata(path, search_limit)
    74     path = Path(path)
    75     if not path.exists():
---> 76         raise UnreachableStorage(f'path not found: {path}')
    77 
    78     if path.is_dir():

UnreachableStorage: path not found: include/process.aiida

The “, allow_switch=True” is copied from this website (How to interact with AiiDA — AiiDA 2.4.0.post0 documentation)

I am new to AiiDA. So there will be several questions. Many thanks for you~

Sincerely,
Dr. Guoyu Yang
Lecturer
Jimei Univ, School of Science, Digital Fujian Big Data Modeling and Intelligent Computing Institute
185 Yinjiang Rd.,
Jimei District, Xiamen,361021
Fujian, China
E-mail: 201961000100@jmu.edu.cn

Thanks for the report Guoyu Yang. This is actually a bug it seems in the example script. The second cell should be:

with profile_context(archive_profile, allow_switch=True):
    print(manage.get_manager().get_profile())

For the third cell, the problem is that the profile that is created points to the path include/process.aiida, but it probably is just process.aiida. This is why the command excepts as it cannot find the archive. We can work around it for the time being by fixing the path, like so

import json
with profile_context(archive_profile):
    profile.dictionary['storage']['config']['path'] = 'process.aiida'
    storage = manage.get_manager().get_profile_storage()
    print(storage)
    print(json.dumps(storage.get_info(), indent=2))

I will submit a fix to aiida-core.