Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BaseRestartWorkChain's process_handler is not compatible with the deprecation decorator #5577

Open
2 tasks done
yakutovicha opened this issue Jun 20, 2022 · 0 comments
Open
2 tasks done
Labels

Comments

@yakutovicha
Copy link
Contributor

Describe the bug

I would like to deprecate a handler using the deprecation module. Unfortunately, this doesn't seem to be possible. If I place them like so:

    @deprecation.deprecated(deprecated_in="1.0", removed_in="2.0",
                        current_version="1.5.0",
                        details="Use the bar function instead")
    @process_handler(priority=401, exit_codes=[
        Cp2kCalculation.exit_codes.ERROR_OUT_OF_WALLTIME,
        Cp2kCalculation.exit_codes.ERROR_OUTPUT_INCOMPLETE,
    ], enabled=False)

I then get:

  File "/opt/conda/lib/python3.8/site-packages/plumpy/process_states.py", line 231, in execute
    result = self.run_fn(*self.args, **self.kwargs)
  File "/opt/conda/lib/python3.8/site-packages/aiida/engine/processes/workchains/workchain.py", line 214, in _do_step
    finished, stepper_result = self._stepper.step()
  File "/opt/conda/lib/python3.8/site-packages/plumpy/workchains.py", line 299, in step
    finished, result = self._child_stepper.step()
  File "/opt/conda/lib/python3.8/site-packages/plumpy/workchains.py", line 532, in step
    finished, result = self._child_stepper.step()
  File "/opt/conda/lib/python3.8/site-packages/plumpy/workchains.py", line 299, in step
    finished, result = self._child_stepper.step()
  File "/opt/conda/lib/python3.8/site-packages/plumpy/workchains.py", line 250, in step
    return True, self._fn(self._workchain)
  File "/opt/conda/lib/python3.8/site-packages/aiida/engine/processes/workchains/restart.py", line 238, in inspect_process
    report = handler(self, node)
  File "/opt/conda/lib/python3.8/site-packages/deprecation.py", line 260, in _inner
    return function(*args, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/aiida/engine/processes/workchains/utils.py", line 114, in wrapper
    if exit_codes is not None and node.exit_status not in [
AttributeError: 'Cp2kBaseWorkChain' object has no attribute 'exit_status'

06/20/2022 10:19:45 AM <28992> aiida.orm.nodes.process.workflow.workchain.WorkChainNode: [REPORT] [225|Cp2kBaseWorkChain|on_terminated]: remote folders will not be cleaned
Traceback (most recent call last):
  File "/opt/conda/bin/verdi", line 8, in <module>
    sys.exit(verdi())
  File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/aiida/cmdline/utils/decorators.py", line 74, in wrapper
    return wrapped(*args, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/aiida/cmdline/commands/cmd_run.py", line 147, in run
    exec(compile(handle.read(), scriptname, 'exec', dont_inherit=True), globals_dict)  # yapf: disable # pylint: disable=exec-used
  File "example_base_restart.py", line 142, in <module>
    cli()  # pylint: disable=no-value-for-parameter
  File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "example_base_restart.py", line 138, in cli
    example_base(code)
  File "example_base_restart.py", line 118, in example_base
    calc = run(builder)
  File "/opt/conda/lib/python3.8/site-packages/aiida/engine/launch.py", line 41, in run
    return runner.run(process, *args, **inputs)
  File "/opt/conda/lib/python3.8/site-packages/aiida/engine/runners.py", line 266, in run
    result, _ = self._run(process, *args, **inputs)
  File "/opt/conda/lib/python3.8/site-packages/aiida/engine/runners.py", line 250, in _run
    process_inited.execute()
  File "/opt/conda/lib/python3.8/site-packages/plumpy/processes.py", line 81, in func_wrapper
    return func(self, *args, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/plumpy/processes.py", line 1166, in execute
    return self.future().result()
  File "/opt/conda/lib/python3.8/site-packages/plumpy/process_states.py", line 231, in execute
    result = self.run_fn(*self.args, **self.kwargs)
  File "/opt/conda/lib/python3.8/site-packages/aiida/engine/processes/workchains/workchain.py", line 214, in _do_step
    finished, stepper_result = self._stepper.step()
  File "/opt/conda/lib/python3.8/site-packages/plumpy/workchains.py", line 299, in step
    finished, result = self._child_stepper.step()
  File "/opt/conda/lib/python3.8/site-packages/plumpy/workchains.py", line 532, in step
    finished, result = self._child_stepper.step()
  File "/opt/conda/lib/python3.8/site-packages/plumpy/workchains.py", line 299, in step
    finished, result = self._child_stepper.step()
  File "/opt/conda/lib/python3.8/site-packages/plumpy/workchains.py", line 250, in step
    return True, self._fn(self._workchain)
  File "/opt/conda/lib/python3.8/site-packages/aiida/engine/processes/workchains/restart.py", line 238, in inspect_process
    report = handler(self, node)
  File "/opt/conda/lib/python3.8/site-packages/deprecation.py", line 260, in _inner
    return function(*args, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/aiida/engine/processes/workchains/utils.py", line 114, in wrapper
    if exit_codes is not None and node.exit_status not in [
AttributeError: 'Cp2kBaseWorkChain' object has no attribute 'exit_status'

If I place those two decorators in the reverse order, I get this:

Traceback (most recent call last):
  File "/opt/conda/bin/verdi", line 8, in <module>
    sys.exit(verdi())
  File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/aiida/cmdline/utils/decorators.py", line 74, in wrapper
    return wrapped(*args, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/aiida/cmdline/commands/cmd_run.py", line 147, in run
    exec(compile(handle.read(), scriptname, 'exec', dont_inherit=True), globals_dict)  # yapf: disable # pylint: disable=exec-used
  File "example_base_restart.py", line 20, in <module>
    Cp2kBaseWorkChain = WorkflowFactory("cp2k.base")
  File "/opt/conda/lib/python3.8/site-packages/aiida/plugins/factories.py", line 216, in WorkflowFactory
    entry_point = BaseFactory(entry_point_group, entry_point_name)
  File "/opt/conda/lib/python3.8/site-packages/aiida/plugins/factories.py", line 46, in BaseFactory
    return load_entry_point(group, name)
  File "/opt/conda/lib/python3.8/site-packages/aiida/plugins/entry_point.py", line 209, in load_entry_point
    loaded_entry_point = entry_point.load()
  File "/opt/conda/lib/python3.8/site-packages/reentry/entrypoint.py", line 38, in load
    module = import_module(self.module_name)
  File "/opt/conda/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 848, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/opt/aiida-cp2k/aiida_cp2k/workchains/__init__.py", line 9, in <module>
    from .base import Cp2kBaseWorkChain
  File "/opt/aiida-cp2k/aiida_cp2k/workchains/base.py", line 24, in <module>
    class Cp2kBaseWorkChain(BaseRestartWorkChain):
  File "/opt/aiida-cp2k/aiida_cp2k/workchains/base.py", line 126, in Cp2kBaseWorkChain
    def restart_incomplete_calculation(self, calc):
  File "/opt/conda/lib/python3.8/site-packages/aiida/engine/processes/workchains/utils.py", line 102, in process_handler
    raise TypeError(f'process handler `{wrapped.__name__}` has invalid signature: should be (self, node)')
TypeError: process handler `restart_incomplete_calculation` has invalid signature: should be (self, node)

Steps to reproduce

Steps to reproduce the behaviour:

Decorate a process handler with deprecation.deprecated and try to run the work chain that calls it.

Expected behaviour

The process handler runs normally.

Your environment

  • Operating system Linux Ubuntu 20.04.3 LTS
  • Python version [e.g. 3.8.10]:
  • aiida-core version [e.g. 1.6.8]:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant