:py:mod:`aiida_hubbard.workflows.hp.base`
=========================================

.. py:module:: aiida_hubbard.workflows.hp.base

.. autoapi-nested-parse::

   Workchain to run a Quantum ESPRESSO hp.x calculation with automated error handling and restarts.



Module Contents
---------------

Classes
~~~~~~~

.. autoapisummary::

   aiida_hubbard.workflows.hp.base.HpBaseWorkChain




Attributes
~~~~~~~~~~

.. autoapisummary::

   aiida_hubbard.workflows.hp.base.HpCalculation


.. py:data:: HpCalculation

   

.. py:class:: HpBaseWorkChain(*args, **kwargs)


   Bases: :py:obj:`aiida.engine.BaseRestartWorkChain`, :py:obj:`aiida_quantumespresso.workflows.protocols.utils.ProtocolMixin`

   Workchain to run a Quantum ESPRESSO hp.x calculation with automated error handling and restarts.

   .. py:attribute:: _process_class

      

   .. py:attribute:: defaults

      

   .. py:method:: define(spec)
      :classmethod:

      Define the process specification.


   .. py:method:: get_protocol_filepath()
      :classmethod:

      Return ``pathlib.Path`` to the ``.yaml`` file that defines the protocols.


   .. py:method:: get_builder_from_protocol(code, protocol=None, parent_scf_folder=None, parent_hp_folders: dict = None, overrides=None, options=None, **_)
      :classmethod:

      Return a builder prepopulated with inputs selected according to the chosen protocol.

      :param code: the ``Code`` instance configured for the ``quantumespresso.hp`` plugin.
      :param protocol: protocol to use, if not specified, the default will be used.
      :param parent_scf_folder: the parent ``RemoteData`` of the respective SCF calcualtion.
      :param parent_hp_folders: the parent ``FolderData`` of the respective single atoms HP calcualtions.
      :param overrides: optional dictionary of inputs to override the defaults of the protocol.
      :param options: A dictionary of options that will be recursively set for the ``metadata.options`` input of all
          the ``CalcJobs`` that are nested in this work chain.
      :return: a process builder instance with all inputs defined ready for launch.


   .. py:method:: setup()

      Call the `setup` of the `BaseRestartWorkChain` and then create the inputs dictionary in `self.ctx.inputs`.

      This `self.ctx.inputs` dictionary will be used by the `BaseRestartWorkChain` to submit the calculations in the
      internal loop.


   .. py:method:: validate_parameters()

      Validate inputs that might depend on each other and cannot be validated by the spec.


   .. py:method:: set_max_seconds(max_wallclock_seconds)

      Set the `max_seconds` to a fraction of `max_wallclock_seconds` option to prevent out-of-walltime problems.

      :param max_wallclock_seconds: the maximum wallclock time that will be set in the scheduler settings.


   .. py:method:: prepare_process()

      Prepare the inputs for the next calculation.


   .. py:method:: report_error_handled(node, action)

      Report an action taken for a calculation that has failed.

      This should be called in a registered error handler if its condition is met and an action was taken.

      :param node: the failed calculation node
      :param action: a string message with the action taken


   .. py:method:: handle_unrecoverable_failure(node)

      Handle calculations with an exit status below 400 which are unrecoverable, so abort the work chain.


   .. py:method:: handle_computing_cholesky(_)

      Handle `ERROR_COMPUTING_CHOLESKY`: set parallel diagonalization to 1 and restart.

      Parallelization of diagonalization may produce in some cases too much numerical noise,
      giving rise to Cholesky factorization issues. As other diagonalization algorithms are
      not available in `hp.x`, we try to set the diagonalization flag to 1, if not already set.


   .. py:method:: handle_convergence_not_reached(_)

      Handle `ERROR_CONVERGENCE_NOT_REACHED`: decrease `alpha_mix` and restart.

      Since `hp.x` does not support restarting from incomplete calculations, the entire calculation will have to be
      restarted from scratch. By decreasing `alpha_mix` there is a chance that the next
      run will converge. If these keys are present in the input parameters, they will be scaled by a default factor,
      otherwise, a hardcoded default value will be set that is lower/higher than that of the code's default.


   .. py:method:: on_terminated()

      Clean the working directories of all child calculations if `clean_workdir=True` in the inputs.



