Skip to content

Commit 5f40a4e

Browse files
committed
create localhost also in module2
1 parent c83b8d4 commit 5f40a4e

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

docs/source/tutorials/module2.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ load_profile()
4848
4949
# Shared tutorial profile — see Module 1 for details.
5050
import os
51+
import pathlib
52+
import sys
5153
5254
from aiida.manage.configuration import create_profile, get_config
5355
@@ -76,19 +78,34 @@ from aiida import load_profile
7678
load_profile(profile_name, allow_switch=True)
7779
os.environ['AIIDA_PROFILE'] = profile_name
7880
79-
# Pre-register a Code with a short label so that `verdi process list`
80-
# shows "python3@localhost" instead of the full virtualenv path.
81-
import sys
82-
81+
# Ensure a localhost Computer exists (create_profile does not create one,
82+
# unlike ``verdi presto``).
8383
from aiida.common.exceptions import NotExistent
84-
from aiida.orm import InstalledCode, load_code, load_computer
84+
from aiida.orm import Computer, InstalledCode, load_code, load_computer
8585
86+
try:
87+
computer = load_computer('localhost')
88+
except NotExistent:
89+
computer = Computer(
90+
label='localhost',
91+
hostname='localhost',
92+
description='Localhost for tutorial',
93+
transport_type='core.local',
94+
scheduler_type='core.direct',
95+
workdir=str(pathlib.Path(config.dirpath) / 'scratch' / profile_name),
96+
).store()
97+
computer.configure(safe_interval=0)
98+
computer.set_minimum_job_poll_interval(1)
99+
computer.set_default_mpiprocs_per_machine(1)
100+
101+
# Pre-register a Code with a short label so that `verdi process list`
102+
# shows "python3@localhost" instead of the full virtualenv path.
86103
try:
87104
python_code = load_code('python3@localhost')
88105
except NotExistent:
89106
python_code = InstalledCode(
90107
label='python3',
91-
computer=load_computer('localhost'),
108+
computer=computer,
92109
filepath_executable=sys.executable,
93110
default_calc_job_plugin='core.shell',
94111
).store()

0 commit comments

Comments
 (0)