Skip to content

Commit

Permalink
Refactor: Replace deprecated Code data type (#856)
Browse files Browse the repository at this point in the history
The `Code` data plugin has been deprecated. When using it to compare
types, it should be replaced with `AbstractCode`. For concrete
instances, the `InstalledCode` and `PortableCode` plugins should be used
for the "remote" and "local" variant of `Code`, respectively.

Old documentation is also updated to use `load_code` to load a code
instance instead of the various other old and deprecated methods that
were still being suggested.
  • Loading branch information
sphuber authored Nov 8, 2022
1 parent 6f86390 commit c117d8f
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 24 deletions.
3 changes: 1 addition & 2 deletions .github/config/code-ph.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
---
label: ph
description: Quantum ESPRESSO ph.x
input_plugin: quantumespresso.ph
on_computer: true
default_calc_job_plugin: quantumespresso.ph
computer: localhost
prepend_text: ' '
append_text: ' '
3 changes: 1 addition & 2 deletions .github/config/code-pw.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
---
label: pw
description: Quantum ESPRESSO pw.x
input_plugin: quantumespresso.pw
on_computer: true
default_calc_job_plugin: quantumespresso.pw
computer: localhost
prepend_text: ' '
append_text: ' '
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ jobs:
run: verdi computer configure core.local localhost -n --config .github/config/localhost-config.yaml

- name: Setup `pw.x`
run: verdi code setup -n --config .github/config/code-pw.yaml --remote-abs-path $(which pw.x)
run: verdi code create core.code.installed -n --config .github/config/code-pw.yaml --filepath-executable $(which pw.x)

- name: Setup `ph.x`
run: verdi code setup -n --config .github/config/code-ph.yaml --remote-abs-path $(which ph.x)
run: verdi code create core.code.installed -n --config .github/config/code-ph.yaml --filepath-executable $(which ph.x)

- name: Setup SSSP
run: aiida-pseudo install sssp
Expand Down
11 changes: 6 additions & 5 deletions docs/source/installation/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,21 +159,22 @@ In this example, we will setup the ``pw.x`` code that is installed on the comput

.. code-block:: console
$ verdi code setup -n --on-computer -Y localhost -L pw -P quantumespresso.pw --remote-abs-path /path/to/pw.x
$ verdi code create core.code.installed -n --computer localhost --label pw --default-calc-job-plugin quantumespresso.pw --filepath-executable /path/to/pw.x
.. tab-item:: API

To setup particular Quantum ESPRESSO code using the Python API, run the following code in a Python script or interactive shell:

.. code-block:: python
from aiida.orm import Code
from aiida.orm import InstalledCode
computer = load_computer('localhost')
code = Code(
code = InstalledCode(
label='pw',
remote_computer_exec=(computer, '/path/to/pw.x')
input_plugin_name='quantumespresso.pw',
computer=computer,
filepath_executable='/path/to/pw.x',
default_calc_job_plugin='quantumespresso.pw',
).store()
.. important::
Expand Down
6 changes: 3 additions & 3 deletions src/aiida_quantumespresso/tools/pwinputparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import re

from aiida.common.folders import Folder
from aiida.orm import Code, Dict
from aiida.orm import Dict, load_code
from aiida.plugins import CalculationFactory, DataFactory
import numpy as np
from qe_tools.parsers import PwInputFile as BasePwInputFile
Expand Down Expand Up @@ -69,7 +69,7 @@ def create_builder_from_file(input_folder, input_file_name, code, metadata, pseu
:param input_file_name: the name of the input file
:type input_file_name: str
:param code: the code associated with the calculation
:type code: aiida.orm.Code or str
:type code: aiida.orm.AbstractCode or str
:param metadata: metadata values for the calculation (e.g. resources)
:type metadata: dict
:param pseudo_folder_path: the folder containing the upf files (if None, then input_folder is used)
Expand All @@ -83,7 +83,7 @@ def create_builder_from_file(input_folder, input_file_name, code, metadata, pseu
builder.metadata = metadata

if isinstance(code, str):
code = Code.get_from_string(code)
code = load_code(code)
builder.code = code

# read input_file
Expand Down
2 changes: 1 addition & 1 deletion src/aiida_quantumespresso/workflows/ph/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def get_builder_from_protocol(cls, code, parent_folder=None, protocol=None, over
if isinstance(code, str):
code = orm.load_code(code)

type_check(code, orm.Code)
type_check(code, orm.AbstractCode)

inputs = cls.get_protocol_inputs(protocol, overrides)

Expand Down
2 changes: 1 addition & 1 deletion src/aiida_quantumespresso/workflows/pw/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def get_builder_from_protocol(
if isinstance(code, str):
code = orm.load_code(code)

type_check(code, orm.Code)
type_check(code, orm.AbstractCode)
type_check(electronic_type, ElectronicType)
type_check(spin_type, SpinType)

Expand Down
17 changes: 9 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,22 @@ def fixture_localhost(aiida_localhost):

@pytest.fixture
def fixture_code(fixture_localhost):
"""Return a ``Code`` instance configured to run calculations of given entry point on localhost ``Computer``."""
"""Return an ``InstalledCode`` instance configured to run calculations of given entry point on localhost."""

def _fixture_code(entry_point_name):
from aiida.common import exceptions
from aiida.orm import Code
from aiida.orm import InstalledCode, load_code

label = f'test.{entry_point_name}'

try:
return Code.collection.get(label=label) # pylint: disable=no-member
return load_code(label=label)
except exceptions.NotExistent:
return Code(
return InstalledCode(
label=label,
input_plugin_name=entry_point_name,
remote_computer_exec=[fixture_localhost, '/bin/true'],
computer=fixture_localhost,
filepath_executable='/bin/true',
default_calc_job_plugin=entry_point_name,
)

return _fixture_code
Expand All @@ -78,7 +79,7 @@ def serialize_builder():

def serialize_data(data):
# pylint: disable=too-many-return-statements
from aiida.orm import BaseType, Code, Dict
from aiida.orm import AbstractCode, BaseType, Dict
from aiida.plugins import DataFactory

StructureData = DataFactory('core.structure')
Expand All @@ -90,7 +91,7 @@ def serialize_data(data):
if isinstance(data, BaseType):
return data.value

if isinstance(data, Code):
if isinstance(data, AbstractCode):
return data.full_label

if isinstance(data, Dict):
Expand Down

0 comments on commit c117d8f

Please sign in to comment.