aiida.orm.nodes.data.code package#
Data plugins that represent an executable code.
Submodules#
Abstract data plugin representing an executable code.
- class aiida.orm.nodes.data.code.abstract.AbstractCode(default_calc_job_plugin: Optional[str] = None, append_text: str = '', prepend_text: str = '', use_double_quotes: bool = False, is_hidden: bool = False, **kwargs)[source]#
Bases:
aiida.orm.nodes.data.data.Data
Abstract data plugin representing an executable code.
- __abstractmethods__ = frozenset({'can_run_on_computer', 'full_label', 'get_executable'})#
- __annotations__ = {'_KEY_ATTRIBUTE_APPEND_TEXT': 'str', '_KEY_ATTRIBUTE_DEFAULT_CALC_JOB_PLUGIN': 'str', '_KEY_ATTRIBUTE_PREPEND_TEXT': 'str', '_KEY_ATTRIBUTE_USE_DOUBLE_QUOTES': 'str', '_KEY_EXTRA_IS_HIDDEN': 'str', '_hash_ignored_attributes': 'Tuple[str, ...]', '_logger': 'Optional[Logger]', '_plugin_type_string': 'ClassVar[str]', '_query_type_string': 'ClassVar[str]', '_updatable_attributes': 'Tuple[str, ...]'}#
- __init__(default_calc_job_plugin: Optional[str] = None, append_text: str = '', prepend_text: str = '', use_double_quotes: bool = False, is_hidden: bool = False, **kwargs)[source]#
Construct a new instance.
- Parameters
default_calc_job_plugin – The entry point name of the default
CalcJob
plugin to use.append_text – The text that should be appended to the run line in the job script.
prepend_text – The text that should be prepended to the run line in the job script.
use_double_quotes – Whether the command line invocation of this code should be escaped with double quotes.
is_hidden – Whether the code is hidden.
- __module__ = 'aiida.orm.nodes.data.code.abstract'#
- __parameters__ = ()#
- _abc_impl = <_abc_data object>#
- classmethod _get_cli_options() dict [source]#
Return the CLI options that would allow to create an instance of this class.
- _logger: Optional[Logger] = <Logger aiida.orm.nodes.data.code.abstract.AbstractCode (REPORT)>#
- property append_text: str#
Return the text that should be appended to the run line in the job script.
- Returns
The text that should be appended to the run line in the job script.
- abstract can_run_on_computer(computer: aiida.orm.computers.Computer) bool [source]#
Return whether the code can run on a given computer.
- Parameters
computer – The computer.
- Returns
True
if the code can run oncomputer
,False
otherwise.
- static cli_validate_label_uniqueness(_, __, value)[source]#
Validate the uniqueness of the label of the code.
- property default_calc_job_plugin: str | None#
Return the optional default
CalcJob
plugin.- Returns
The entry point name of the default
CalcJob
plugin to use.
- abstract property full_label: str#
Return the full label of this code.
The full label can be just the label itself but it can be something else. However, it at the very least has to include the label of the code.
- Returns
The full label of the code.
- get_builder()[source]#
Create and return a new
ProcessBuilder
for theCalcJob
class of the plugin configured for this code.The configured calculation plugin class is defined by the
default_calc_job_plugin
property.Note
it also sets the
builder.code
value.- Returns
a
ProcessBuilder
instance with thecode
input already populated with ourselves- Raises
aiida.common.EntryPointError – if the specified plugin does not exist.
ValueError – if no default plugin was specified.
- classmethod get_cli_options() collections.OrderedDict [source]#
Return the CLI options that would allow to create an instance of this class.
- abstract get_executable() pathlib.Path [source]#
Return the executable that the submission script should execute to run the code.
- Returns
The executable to be called in the submission script.
- get_executable_cmdline_params(cmdline_params: list[str] | None = None) list [source]#
Return the list of executable with its command line parameters.
- Parameters
cmdline_params – List of command line parameters provided by the
CalcJob
plugin.- Returns
List of the executable followed by its command line parameters.
- get_prepend_cmdline_params(mpi_args: list[str] | None = None, extra_mpirun_params: list[str] | None = None) list[str] [source]#
Return List of command line parameters to be prepended to the executable in submission line. These command line parameters are typically parameters related to MPI invocations.
- Parameters
mpi_args – List of MPI parameters provided by the
Computer.get_mpirun_command
method.extra_mpiruns_params – List of MPI parameters provided by the
metadata.options.extra_mpirun_params
input of theCalcJob
.
- Returns
List of command line parameters to be prepended to the executable in submission line.
Return whether the code is hidden.
- Returns
True
if the code is hidden,False
otherwise, which is also the default.
- property prepend_text: str#
Return the text that should be prepended to the run line in the job script.
- Returns
The text that should be prepended to the run line in the job script.
- property use_double_quotes: bool#
Return whether the command line invocation of this code should be escaped with double quotes.
- Returns
True
if to escape with double quotes,False
otherwise.
- validate_working_directory(folder: aiida.common.folders.Folder)[source]#
Validate content of the working directory created by the
CalcJob
plugin.This method will be called by
presubmit()
when a new calculation job is launched, passing theFolder
that was used by the plugin used for the calculation to create the input files for the working directory. This method can be overridden by implementations of theAbstractCode
class that need to validate the contents of that folder.- Parameters
folder – A sandbox folder that the
CalcJob
plugin wrote input files to that will be copied to the working directory for the corresponding calculation job instance.- Raises
PluginInternalError – If the content of the sandbox folder is not valid.
Data plugin representing an executable code inside a container.
The containerized code allows specifying a container image and the executable filepath within that container that is to be executed when a calculation job is run with this code.
- class aiida.orm.nodes.data.code.containerized.ContainerizedCode(engine_command: str, image_name: str, **kwargs)[source]#
Bases:
aiida.orm.nodes.data.code.installed.InstalledCode
Data plugin representing an executable code in container on a remote computer.
- __abstractmethods__ = frozenset({})#
- __annotations__ = {'_KEY_ATTRIBUTE_APPEND_TEXT': 'str', '_KEY_ATTRIBUTE_DEFAULT_CALC_JOB_PLUGIN': 'str', '_KEY_ATTRIBUTE_ENGINE_COMMAND': 'str', '_KEY_ATTRIBUTE_FILEPATH_EXECUTABLE': 'str', '_KEY_ATTRIBUTE_IMAGE_NAME': 'str', '_KEY_ATTRIBUTE_PREPEND_TEXT': 'str', '_KEY_ATTRIBUTE_USE_DOUBLE_QUOTES': 'str', '_KEY_EXTRA_IS_HIDDEN': 'str', '_hash_ignored_attributes': 'Tuple[str, ...]', '_logger': 'Optional[Logger]', '_plugin_type_string': 'ClassVar[str]', '_query_type_string': 'ClassVar[str]', '_updatable_attributes': 'Tuple[str, ...]'}#
- __init__(engine_command: str, image_name: str, **kwargs)[source]#
Construct a new instance.
- Parameters
computer – The remote computer on which the executable is located.
filepath_executable – The absolute filepath of the executable on the remote computer.
- __module__ = 'aiida.orm.nodes.data.code.containerized'#
- __parameters__ = ()#
- _abc_impl = <_abc_data object>#
- classmethod _get_cli_options() dict [source]#
Return the CLI options that would allow to create an instance of this class.
- _logger: Optional[Logger] = <Logger aiida.orm.nodes.data.code.containerized.ContainerizedCode (REPORT)>#
- property engine_command: str#
Return the engine command with image as template field of the containerized code
- Returns
The engine command of the containerized code
- property filepath_executable: pathlib.PurePath#
Return the filepath of the executable that this code represents.
Note
This is overridden from the base class since the path does not have to be absolute.
- Returns
The filepath of the executable.
Data plugin representing an executable code on a remote computer.
This plugin should be used if an executable is pre-installed on a computer. The InstalledCode
represents the code by
storing the absolute filepath of the relevant executable and the computer on which it is installed. The computer is
represented by an instance of aiida.orm.computers.Computer
. Each time a aiida.engine.CalcJob
is run
using an InstalledCode
, it will run its executable on the associated computer.
- class aiida.orm.nodes.data.code.installed.InstalledCode(computer: aiida.orm.computers.Computer, filepath_executable: str, **kwargs)[source]#
Bases:
aiida.orm.nodes.data.code.legacy.Code
Data plugin representing an executable code on a remote computer.
- __abstractmethods__ = frozenset({})#
- __annotations__ = {'_KEY_ATTRIBUTE_APPEND_TEXT': 'str', '_KEY_ATTRIBUTE_DEFAULT_CALC_JOB_PLUGIN': 'str', '_KEY_ATTRIBUTE_FILEPATH_EXECUTABLE': <class 'str'>, '_KEY_ATTRIBUTE_PREPEND_TEXT': 'str', '_KEY_ATTRIBUTE_USE_DOUBLE_QUOTES': 'str', '_KEY_EXTRA_IS_HIDDEN': 'str', '_hash_ignored_attributes': 'Tuple[str, ...]', '_logger': 'Optional[Logger]', '_plugin_type_string': 'ClassVar[str]', '_query_type_string': 'ClassVar[str]', '_updatable_attributes': 'Tuple[str, ...]'}#
- __init__(computer: aiida.orm.computers.Computer, filepath_executable: str, **kwargs)[source]#
Construct a new instance.
- Parameters
computer – The remote computer on which the executable is located.
filepath_executable – The absolute filepath of the executable on the remote computer.
- __module__ = 'aiida.orm.nodes.data.code.installed'#
- __parameters__ = ()#
- _abc_impl = <_abc_data object>#
- classmethod _get_cli_options() dict [source]#
Return the CLI options that would allow to create an instance of this class.
- _logger: Optional[Logger] = <Logger aiida.orm.nodes.data.code.installed.InstalledCode (REPORT)>#
- _validate()[source]#
Validate the instance by checking that a computer has been defined.
:raises
aiida.common.exceptions.ValidationError
: If the state of the node is invalid.
- can_run_on_computer(computer: aiida.orm.computers.Computer) bool [source]#
Return whether the code can run on a given computer.
- Parameters
computer – The computer.
- Returns
True
if the provided computer is the same as the one configured for this code.
- static cli_validate_label_uniqueness(ctx, _, value)[source]#
Validate the uniqueness of the label of the code.
- property filepath_executable: pathlib.PurePath#
Return the absolute filepath of the executable that this code represents.
- Returns
The absolute filepath of the executable.
- property full_label: str#
Return the full label of this code.
The full label can be just the label itself but it can be something else. However, it at the very least has to include the label of the code.
- Returns
The full label of the code.
- get_executable() pathlib.Path [source]#
Return the executable that the submission script should execute to run the code.
- Returns
The executable to be called in the submission script.
- validate_filepath_executable()[source]#
Validate the
filepath_executable
attribute.Checks whether the executable exists on the remote computer if a transport can be opened to it. This method is intentionally not called in
_validate
as to allow the creation ofCode
instances whose computers can not yet be connected to and as to not require the overhead of opening transports in storing a new code.- Raises
ValidationError – if no transport could be opened or if the defined executable does not exist on the remote computer.
Data plugin represeting an executable code to be wrapped and called through a CalcJob plugin.
- class aiida.orm.nodes.data.code.legacy.Code(remote_computer_exec=None, local_executable=None, input_plugin_name=None, files=None, **kwargs)[source]#
Bases:
aiida.orm.nodes.data.code.abstract.AbstractCode
A code entity. It can either be ‘local’, or ‘remote’.
Local code: it is a collection of files/dirs (added using the add_path() method), where one file is flagged as executable (using the set_local_executable() method).
Remote code: it is a pair (remotecomputer, remotepath_of_executable) set using the set_remote_computer_exec() method.
For both codes, one can set some code to be executed right before or right after the execution of the code, using the set_preexec_code() and set_postexec_code() methods (e.g., the set_preexec_code() can be used to load specific modules required for the code to be run).
- HIDDEN_KEY = 'hidden'#
- __abstractmethods__ = frozenset({})#
- __init__(remote_computer_exec=None, local_executable=None, input_plugin_name=None, files=None, **kwargs)[source]#
Construct a new instance.
- Parameters
default_calc_job_plugin – The entry point name of the default
CalcJob
plugin to use.append_text – The text that should be appended to the run line in the job script.
prepend_text – The text that should be prepended to the run line in the job script.
use_double_quotes – Whether the command line invocation of this code should be escaped with double quotes.
is_hidden – Whether the code is hidden.
- __module__ = 'aiida.orm.nodes.data.code.legacy'#
- __parameters__ = ()#
- _abc_impl = <_abc_data object>#
- _logger: Optional[Logger] = <Logger aiida.orm.nodes.data.code.legacy.Code (REPORT)>#
- _set_local()[source]#
Set the code as a ‘local’ code, meaning that all the files belonging to the code will be copied to the cluster, and the file set with set_exec_filename will be run.
It also deletes the flags related to the local case (if any)
- _set_remote()[source]#
Set the code as a ‘remote’ code, meaning that the code itself has no files attached, but only a location on a remote computer (with an absolute path of the executable on the remote computer).
It also deletes the flags related to the local case (if any)
- _validate()[source]#
Validate information stored in Node object.
For the
Node
base class, this check is always valid. Subclasses can override this method to perform additional checks and should usually callsuper()._validate()
first!This method is called automatically before storing the node in the DB. Therefore, use
get()
and similar methods that automatically read either from the DB or from the internal attribute cache.
- can_run_on(computer)[source]#
Return True if this code can run on the given computer, False otherwise.
Local codes can run on any machine; remote codes can run only on the machine on which they reside.
TODO: add filters to mask the remote machines on which a local code can run.
- can_run_on_computer(computer: aiida.orm.computers.Computer) bool [source]#
Return whether the code can run on a given computer.
- Parameters
computer – The computer.
- Returns
True
if the code can run oncomputer
,False
otherwise.
- property full_label#
Get full label of this code.
Returns label of the form <code-label>@<computer-name>.
- classmethod get(pk=None, label=None, machinename=None)[source]#
Get a Computer object with given identifier string, that can either be the numeric ID (pk), or the label (and computername) (if unique).
- Parameters
pk – the numeric ID (pk) for code
label – the code label identifying the code to load
machinename – the machine name where code is setup
- Raises
aiida.common.NotExistent – if no code identified by the given string is found
aiida.common.MultipleObjectsError – if the string cannot identify uniquely a code
ValueError – if neither a pk nor a label was passed in
- get_append_text()[source]#
Return the postexec_code, or an empty string if no post-exec code was defined.
- classmethod get_code_helper(label, machinename=None, backend=None)[source]#
- Parameters
label – the code label identifying the code to load
machinename – the machine name where code is setup
- Raises
aiida.common.NotExistent – if no code identified by the given string is found
aiida.common.MultipleObjectsError – if the string cannot identify uniquely a code
- get_description()[source]#
Return a string description of this Code instance.
- Returns
string description of this Code instance
- get_execname()[source]#
Return the executable string to be put in the script. For local codes, it is ./LOCAL_EXECUTABLE_NAME For remote codes, it is the absolute path to the executable.
- get_executable() pathlib.Path [source]#
Return the executable that the submission script should execute to run the code.
- Returns
The executable to be called in the submission script.
- classmethod get_from_string(code_string)[source]#
Get a Computer object with given identifier string in the format label@machinename. See the note below for details on the string detection algorithm.
Note
the (leftmost) ‘@’ symbol is always used to split code and computername. Therefore do not use ‘@’ in the code name if you want to use this function (‘@’ in the computer name are instead valid).
- Parameters
code_string – the code string identifying the code to load
- Raises
aiida.common.NotExistent – if no code identified by the given string is found
aiida.common.MultipleObjectsError – if the string cannot identify uniquely a code
TypeError – if code_string is not of string type
- get_input_plugin_name()[source]#
Return the name of the default input plugin (or None if no input plugin was set.
- get_prepend_text()[source]#
Return the code that will be put in the scheduler script before the execution, or an empty string if no pre-exec code was defined.
- get_use_double_quotes() bool [source]#
Return whether the command line invocation of this code should be escaped with double quotes.
- Returns
True if to escape with double quotes, False otherwise which is also the default.
Determines whether the Code is hidden or not
- is_local()[source]#
Return True if the code is ‘local’, False if it is ‘remote’ (see also documentation of the set_local and set_remote functions).
- classmethod list_for_plugin(plugin, labels=True, backend=None)[source]#
Return a list of valid code strings for a given plugin.
- Parameters
plugin – The string of the plugin.
labels – if True, return a list of code names, otherwise return the code PKs (integers).
- Returns
a list of string, with the code names if labels is True, otherwise a list of integers with the code PKs.
- reveal()[source]#
Reveal the code (allows to show it in the verdi code list) By default, it is revealed
- set_append_text(code)[source]#
Pass a string of code that will be put in the scheduler script after the execution of the code.
- set_files(files)[source]#
Given a list of filenames (or a single filename string), add it to the path (all at level zero, i.e. without folders). Therefore, be careful for files with the same name!
- Todo
decide whether to check if the Code must be a local executable to be able to call this function.
- set_input_plugin_name(input_plugin)[source]#
Set the name of the default input plugin, to be used for the automatic generation of a new calculation.
- set_local_executable(exec_name)[source]#
Set the filename of the local executable. Implicitly set the code as local.
- set_prepend_text(code)[source]#
Pass a string of code that will be put in the scheduler script before the execution of the code.
- set_remote_computer_exec(remote_computer_exec)[source]#
Set the code as remote, and pass the computer on which it resides and the absolute path on that computer.
- Parameters
remote_computer_exec – a tuple (computer, remote_exec_path), where computer is a aiida.orm.Computer and remote_exec_path is the absolute path of the main executable on remote computer.
- set_use_double_quotes(use_double_quotes: bool)[source]#
Set whether the command line invocation of this code should be escaped with double quotes.
- Parameters
use_double_quotes – True if to escape with double quotes, False otherwise.
- validate_remote_exec_path()[source]#
Validate the
remote_exec_path
attribute.Checks whether the executable exists on the remote computer if a transport can be opened to it. This method is intentionally not called in
_validate
as to allow the creation ofCode
instances whose computers can not yet be connected to and as to not require the overhead of opening transports in storing a new code.- Raises
ValidationError – if no transport could be opened or if the defined executable does not exist on the remote computer.
Data plugin representing an executable code stored in AiiDA’s storage.
This plugin should be used for executables that are not already installed on the target computer, but instead are
available on the machine where AiiDA is running. The plugin assumes that the code is self-contained by a single
directory containing all the necessary files, including a main executable. When constructing a PortableCode
, passing
the absolute filepath as filepath_files
will make sure that all the files contained within are uploaded to AiiDA’s
storage. The filepath_executable
should indicate the filename of the executable within that directory. Each time a
aiida.engine.CalcJob
is run using a PortableCode
, the uploaded files will be automatically copied to the
working directory on the selected computer and the executable will be run there.
- class aiida.orm.nodes.data.code.portable.PortableCode(filepath_executable: str, filepath_files: pathlib.Path, **kwargs)[source]#
Bases:
aiida.orm.nodes.data.code.legacy.Code
Data plugin representing an executable code stored in AiiDA’s storage.
- __abstractmethods__ = frozenset({})#
- __annotations__ = {'_KEY_ATTRIBUTE_APPEND_TEXT': 'str', '_KEY_ATTRIBUTE_DEFAULT_CALC_JOB_PLUGIN': 'str', '_KEY_ATTRIBUTE_FILEPATH_EXECUTABLE': <class 'str'>, '_KEY_ATTRIBUTE_PREPEND_TEXT': 'str', '_KEY_ATTRIBUTE_USE_DOUBLE_QUOTES': 'str', '_KEY_EXTRA_IS_HIDDEN': 'str', '_hash_ignored_attributes': 'Tuple[str, ...]', '_logger': 'Optional[Logger]', '_plugin_type_string': 'ClassVar[str]', '_query_type_string': 'ClassVar[str]', '_updatable_attributes': 'Tuple[str, ...]'}#
- __init__(filepath_executable: str, filepath_files: pathlib.Path, **kwargs)[source]#
Construct a new instance.
Note
If the files necessary for this code are not all located in a single directory or the directory contains files that should not be uploaded, and so the
filepath_files
cannot be used. One can use the methods of theaiida.orm.nodes.repository.NodeRepository
class. This can be accessed through thebase.repository
attribute of the instance after it has been constructed. For example:code = PortableCode(filepath_executable='some_name.exe') code.put_object_from_file() code.put_object_from_filelike() code.put_object_from_tree()
- Parameters
filepath_executable – The relative filepath of the executable within the directory of uploaded files.
filepath_files – The filepath to the directory containing all the files of the code.
- __module__ = 'aiida.orm.nodes.data.code.portable'#
- __parameters__ = ()#
- _abc_impl = <_abc_data object>#
- classmethod _get_cli_options() dict [source]#
Return the CLI options that would allow to create an instance of this class.
- _logger: Optional[Logger] = <Logger aiida.orm.nodes.data.code.portable.PortableCode (REPORT)>#
- _validate()[source]#
Validate the instance by checking that an executable is defined and it is part of the repository files.
:raises
aiida.common.exceptions.ValidationError
: If the state of the node is invalid.
- can_run_on_computer(computer: aiida.orm.computers.Computer) bool [source]#
Return whether the code can run on a given computer.
A
PortableCode
should be able to be run on any computer in principle.- Parameters
computer – The computer.
- Returns
True
if the provided computer is the same as the one configured for this code.
- property filepath_executable: pathlib.PurePath#
Return the relative filepath of the executable that this code represents.
- Returns
The relative filepath of the executable.
- property full_label: str#
Return the full label of this code.
The full label can be just the label itself but it can be something else. However, it at the very least has to include the label of the code.
- Returns
The full label of the code.
- get_executable() pathlib.Path [source]#
Return the executable that the submission script should execute to run the code.
- Returns
The executable to be called in the submission script.
- validate_working_directory(folder: aiida.common.folders.Folder)[source]#
Validate content of the working directory created by the
CalcJob
plugin.This method will be called by
presubmit()
when a new calculation job is launched, passing theFolder
that was used by the plugin used for the calculation to create the input files for the working directory. This method can be overridden by implementations of theAbstractCode
class that need to validate the contents of that folder.- Parameters
folder – A sandbox folder that the
CalcJob
plugin wrote input files to that will be copied to the working directory for the corresponding calculation job instance.- Raises
PluginInternalError – The
CalcJob
plugin created a file that has the same relative filepath as the executable for this portable code.