I am reaching out because I have some questions regarding the writing of plugins. I quickly followed the documentation tutorial, but there is a fundamental concept that I think I am not understanding.
I am trying to write a workflow to autonomously perform pw.x and epsilon.x calculations. The first part of this involves writing a workflow to perform multiple scf and nscf calculations. For this purpose, I created a plugin called aiida-quantumespresso-rdmk in which I developed a workflow. After installing the plugin via pip, I see that the workflow has been correctly added to the list and is correctly recognized with verdi plugin list aiida.workflows quantumespresso_rdmk.random_kpoints, which displays the correct information about the workflow. However, I cannot import it using WorkflowFactory (even after restarting the daemon a couple of times):
Traceback (most recent call last):
File "/home/gjoalland/work/project/AuAu/jupyter/rdmk/calc_rdmk.py", line 12, in <module>
RdmKWorkchain = WorkflowFactory('quantumespresso_rdmk.random_kpoints')
File "/home/gjoalland/work/setup/aiida-core/src/aiida/plugins/factories.py", line 466, in WorkflowFactory
entry_point = BaseFactory(entry_point_group, entry_point_name, load=load)
File "/home/gjoalland/work/setup/aiida-core/src/aiida/plugins/factories.py", line 75, in BaseFactory
return load_entry_point(group, name)
File "/home/gjoalland/work/setup/aiida-core/src/aiida/plugins/entry_point.py", line 276, in load_entry_point
entry_point = get_entry_point(group, name)
File "/home/gjoalland/work/setup/aiida-core/src/aiida/plugins/entry_point.py", line 324, in get_entry_point
raise MissingEntryPointError(f"Entry point '{name}' not found in group '{group}'")
aiida.common.exceptions.MissingEntryPointError: Entry point 'quantumespresso_rdmk.random_kpoints' not found in group 'aiida.workflows'
Am I missing something for using the workflow with WorkflowFactory?
Hi, just as a first preliminary check: are you in the same virtual environment? And do you get that error from a script, or from a jupyter notebook or ipython shell? In the latter case, did you restart the kernel?
If all points above are taken care of, can you check, in the same script that fails, what is the content of the value eps defined as:
(Check also that it’s not registered twice)
Finally, if you still didn’t find the issue, check also that doing from XXX import YYY using the values from the value field works - maybe there is an import error that indirectly causes the problem
I am in the same virtual environement yes and restarted the kernel. It is correctly detected in the ipython shell:
In [1]: import importlib.metadata
...: eps = importlib.metadata.entry_points()
In [2]: eps['aiida.workflows'][0]
Out[2]: EntryPoint(name='quantumespresso_rdmk.random_kpoints', value='aiida_quantumespresso_rdmk.workflows.rdmk:PwRdmKpointsWorkChain', group='aiida.workflows')
In [3]: from aiida_quantumespresso_rdmk.workflows.rdmk import PwRdmKpointsWorkChain
In [4]: PwRdmKpointsWorkChain
Out[4]: aiida_quantumespresso_rdmk.workflows.rdmk.PwRdmKpointsWorkChain
In [5]: PwRdmKpointsWorkChain? # displays the help message
In [9]: from aiida.plugins import WorkflowFactory
In [10]: RdmKWorkchain = WorkflowFactory('quantumespresso_rdmk.random_kpoints')
In [11]: RdmKWorkchain
Out[11]: aiida_quantumespresso_rdmk.workflows.rdmk.PwRdmKpointsWorkChain
However running it with a python script results in an error:
(test-aiida) gjoalland@ctimac001:~/work/project/AuAu/jupyter/rdmk$ cat test.py
from aiida.plugins import WorkflowFactory
from aiida import load_profile
import importlib.metadata
load_profile()
eps = importlib.metadata.entry_points()['aiida.workflows'][0]
print(eps)
RdmKWorkchain = WorkflowFactory('quantumespresso_rdmk.random_kpoints')
(test-aiida) gjoalland@ctimac001:~/work/project/rdmk$ python test.py
EntryPoint(name='phonopy.ase', value='aiida_phonopy.workflows.ase:PhonopyAseWorkChain', group='aiida.workflows')
Traceback (most recent call last):
File "/home/gjoalland/work/project/rdmk/test.py", line 10, in <module>
RdmKWorkchain = WorkflowFactory('quantumespresso_rdmk.random_kpoints')
File "/home/gjoalland/work/setup/aiida-core/src/aiida/plugins/factories.py", line 466, in WorkflowFactory
entry_point = BaseFactory(entry_point_group, entry_point_name, load=load)
File "/home/gjoalland/work/setup/aiida-core/src/aiida/plugins/factories.py", line 75, in BaseFactory
return load_entry_point(group, name)
File "/home/gjoalland/work/setup/aiida-core/src/aiida/plugins/entry_point.py", line 276, in load_entry_point
entry_point = get_entry_point(group, name)
File "/home/gjoalland/work/setup/aiida-core/src/aiida/plugins/entry_point.py", line 324, in get_entry_point
raise MissingEntryPointError(f"Entry point '{name}' not found in group '{group}'")
aiida.common.exceptions.MissingEntryPointError: Entry point 'quantumespresso_rdmk.random_kpoints' not found in group 'aiida.workflows'
Additionally, I cannot directly import it with the from aiida_quantumespresso_rdmk.workflows.rdmk import PwRdmKpointsWorkChain line either in a script.
I think this means that python and ipython are actually in 2 different venvs. Maybe you mangled with the PATH and are picking the wrong python, or you didn’t install ipython and are picking a global one?
Check which python and which ipython to confirm where they are.
Even better, check from python in the two cases with import sys; print(sys.executable) to see if they are both calling the same and correct python.
Also instead of running with python you can run with verdi run that should use the correct python and does not require explicit loading the profile.
Apparently, there was indeed a problem with my Conda environment on my workstation. Even though which python, which pip, and which ipython were all pointing toward the correct binaries, the packages were not correctly installed. I had created this Conda environement with the git clone command, so is it due to that? Anyway, by creating a fresh Conda environment with Python 3.10 (instead of Python 3.9) now it works.