-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
CalcJob
process class (#2389)
This commit can be summarized in three steps: * Reimplementation of a job calculation as `Process` called `CalcJob` * Changing job calculation to be purely informational * Remove the old job calculation mechanics and business logic * Reimplementation of a job calculation as `Process` called `CalcJob` The old way of creating a job calculation, was to subclass the `JobCalculation` class and override the `_use_methods` class method to define the input nodes and the `_prepare_for_submission` to setup the input files for the calculation. The problem was that these methods were implemented on the `Node` class, thus mixing the responsabilities of running and introspecting the results of a completed calculation. Here we define the `CalcJob` class, a subclass of `Process`. This class replaces the old `JobCalculation` and allows a user to defined the inputs and outputs through the `ProcessSpec`, just as they would do for a `WorkChain`. Except, instead of defining an `outline`, one should implement the `prepare_for_submission`, which fulfills the exact same function as before, only it is now a public method of the `CalcJob` process class. * Changing job calculation to be purely informational Finally, the role of the job calculation state, stored as an attribute with the key `state` on the `CalcJobNode` has changed significantly. The original job calculations had a calculation state that controlled the logic during its lifetime. This was already superceded a long time ago by the process wrapper that now fully governs the progression of the calculation. Despite the calculation state no longer being authoritative during the calculation's lifetime, it was still present. Here we finally fully remove and only leave a stripped down version. The remaining state is stored as an attribute and is a sub state while the `CalcJob` process is in an active state and serves as a more granual state that can be queried for. This is useful, because the process status, which also keeps similar information is human readable and doesn't allow for easy querying. * Remove methods of `Node` to replace or remove links The `replace_*link_from` methods where only implemented because they were needed by the old job calculation created. Since that system is now removed, this functionality is no longer needed. Likewise, the methods to remove links, either from the cache or the database were not used nor tested and so they are removed. * Prevent adding links from or to sealed nodes When a `Node` instance is sealed, it should be impossible to add links to or from it. To enforce this, the `validate_incoming` and `validate_outgoing` methods are overridden in the `Sealable` mixin that will raise `ModificationNotAllowed` if the node is sealed.
- Loading branch information
Showing
103 changed files
with
1,866 additions
and
3,918 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
aiida/backends/djsite/db/migrations/0023_calc_job_option_attribute_keys.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
# -*- coding: utf-8 -*- | ||
########################################################################### | ||
# Copyright (c), The AiiDA team. All rights reserved. # | ||
# This file is part of the AiiDA code. # | ||
# # | ||
# The code is hosted on GitHub at https://github.com/aiidateam/aiida_core # | ||
# For further information on the license, see the LICENSE.txt file # | ||
# For further information please visit http://www.aiida.net # | ||
########################################################################### | ||
# pylint: disable=invalid-name,too-few-public-methods | ||
"""Migration of CalcJobNode attributes for metadata options whose key changed.""" | ||
from __future__ import division | ||
from __future__ import print_function | ||
from __future__ import unicode_literals | ||
from __future__ import absolute_import | ||
|
||
# Remove when https://github.com/PyCQA/pylint/issues/1931 is fixed | ||
# pylint: disable=no-name-in-module,import-error | ||
from django.db import migrations | ||
|
||
from aiida.backends.djsite.db.migrations import upgrade_schema_version | ||
|
||
REVISION = '1.0.23' | ||
DOWN_REVISION = '1.0.22' | ||
|
||
|
||
class Migration(migrations.Migration): | ||
"""Migration of CalcJobNode attributes for metadata options whose key changed. | ||
Renamed attribute keys: | ||
* `custom_environment_variables` -> `environment_variables` | ||
* `jobresource_params` -> `resources` | ||
* `_process_label` -> `process_label` | ||
* `parser` -> `parser_name` | ||
Deleted attributes: | ||
* `linkname_retrieved` (We do not actually delete it just in case some relies on it) | ||
""" | ||
|
||
dependencies = [ | ||
('db', '0022_dbgroup_type_string_change_content'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunSQL( | ||
sql=r""" | ||
UPDATE db_dbattribute AS attribute | ||
SET key = regexp_replace(attribute.key, '^custom_environment_variables', 'environment_variables') | ||
FROM db_dbnode AS node | ||
WHERE | ||
( | ||
attribute.key = 'custom_environment_variables' OR | ||
attribute.key LIKE 'custom\_environment\_variables.%' | ||
) AND | ||
node.type = 'node.process.calculation.calcjob.CalcJobNode.'; | ||
-- custom_environment_variables -> environment_variables | ||
UPDATE db_dbattribute AS attribute | ||
SET key = regexp_replace(attribute.key, '^jobresource_params', 'resources') | ||
FROM db_dbnode AS node | ||
WHERE | ||
( | ||
attribute.key = 'jobresource_params' OR | ||
attribute.key LIKE 'jobresource\_params.%' | ||
) AND | ||
node.type = 'node.process.calculation.calcjob.CalcJobNode.'; | ||
-- jobresource_params -> resources | ||
UPDATE db_dbattribute AS attribute | ||
SET key = regexp_replace(attribute.key, '^_process_label', 'process_label') | ||
FROM db_dbnode AS node | ||
WHERE | ||
attribute.key = '_process_label' AND | ||
node.type LIKE 'node.process.%'; | ||
-- _process_label -> process_label | ||
UPDATE db_dbattribute AS attribute | ||
SET key = regexp_replace(attribute.key, '^parser', 'parser_name') | ||
FROM db_dbnode AS node | ||
WHERE | ||
attribute.key = 'parser' AND | ||
node.type = 'node.process.calculation.calcjob.CalcJobNode.'; | ||
-- parser -> parser_name | ||
""", | ||
reverse_sql=r""" | ||
UPDATE db_dbattribute AS attribute | ||
SET key = regexp_replace(attribute.key, '^environment_variables', 'custom_environment_variables') | ||
FROM db_dbnode AS node | ||
WHERE | ||
( | ||
attribute.key = 'environment_variables' OR | ||
attribute.key LIKE 'environment\_variables.%' | ||
) AND | ||
node.type = 'node.process.calculation.calcjob.CalcJobNode.'; | ||
-- environment_variables -> custom_environment_variables | ||
UPDATE db_dbattribute AS attribute | ||
SET key = regexp_replace(attribute.key, '^resources', 'jobresource_params') | ||
FROM db_dbnode AS node | ||
WHERE | ||
( | ||
attribute.key = 'resources' OR | ||
attribute.key LIKE 'resources.%' | ||
) AND | ||
node.type = 'node.process.calculation.calcjob.CalcJobNode.'; | ||
-- resources -> jobresource_params | ||
UPDATE db_dbattribute AS attribute | ||
SET key = regexp_replace(attribute.key, '^process_label', '_process_label') | ||
FROM db_dbnode AS node | ||
WHERE | ||
attribute.key = 'process_label' AND | ||
node.type LIKE 'node.process.%'; | ||
-- process_label -> _process_label | ||
UPDATE db_dbattribute AS attribute | ||
SET key = regexp_replace(attribute.key, '^parser_name', 'parser') | ||
FROM db_dbnode AS node | ||
WHERE | ||
attribute.key = 'parser_name' AND | ||
node.type = 'node.process.calculation.calcjob.CalcJobNode.'; | ||
-- parser_name -> parser | ||
"""), | ||
upgrade_schema_version(REVISION, DOWN_REVISION) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.