Skip to content

Fix prepare_shell_job_inputs to be compatible with PortableCode - #119

Merged
GeigerJ2 merged 4 commits into
aiidateam:masterfrom
t-reents:fix/portable-code
Aug 13, 2026
Merged

Fix prepare_shell_job_inputs to be compatible with PortableCode#119
GeigerJ2 merged 4 commits into
aiidateam:masterfrom
t-reents:fix/portable-code

Conversation

@t-reents

Copy link
Copy Markdown
Member

A PortableCode is not associated with a computer, so the one specified through the metadata needs to be passed back so it reaches the ShellJob and is set on the CalcJobNode directly.

This is related to an issue reported on AiiDA Discourse: https://aiida.discourse.group/t/from-bash-to-aiida/752

@t-reents

Copy link
Copy Markdown
Member Author

@GeigerJ2 pinging you here, since I can't request a review

giovannipizzi
giovannipizzi previously approved these changes Jul 17, 2026

@giovannipizzi giovannipizzi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we essentially popping it, and then putting it back?

Anyway if you tested it, I'm OK (since it might have been put in the wrong place). Maybe a comment that you are putting back in the metadata, even when it was in metadata options (therefore the popping and reinsert), might be useful (and explaining instead that for InstalledCodes the metadata.computer is not set and mentioning why)

@t-reents

Copy link
Copy Markdown
Member Author

Thanks @giovannipizzi !

Indeed, and I was also thinking if it could be simplified (I just thought that there might be a reason against). After some further checks, I think that the change can be as easy as just replacing pop with get, as done in the latest commit. This avoids the nested logic.

The idea is that in case of a "string code", the code is anyway associated with the specified computer, see prepare_code. The same is true for a portable code. The only scenario that I could think of where it could cause problems is when an InstalledCode is specified and a different computer (than the one associated with the code) is specified in the metadata. However, in that case the validation of the CalcJob in aiida-core will simply raise, because it checks that the specified computer and the one of the code agree.

The new version still fixes the issue and the tests also pass. Unfortunately, a new approval is required.

giovannipizzi
giovannipizzi previously approved these changes Jul 17, 2026

@giovannipizzi giovannipizzi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot test but it seems ok. Approving but great to test explicitly that it works for the various cases (ideally is it possible to add a simple test?)

A ``PortableCode`` is not associated with a computer, so one needs to
specify the computer in the metadata. However, in the previous version,
the computer was popped from the metadata and therefore,
`launch_shell_job` would fail because no computer is associated with
the specified code.
@t-reents
t-reents force-pushed the fix/portable-code branch from 8bb5462 to 50286b8 Compare July 17, 2026 12:45
@t-reents

Copy link
Copy Markdown
Member Author

I adapted an existing test to test several code types (I also checked that the test actually fails without the fix). Moreover, since a new review was anyway required, I already squashed the commits in a single commit so that it can be easily merged.

@t-reents

Copy link
Copy Markdown
Member Author

@GeigerJ2 Could I request your review and ask you to take care of merging? :) Since Giovanni is on vacation etc.

@GeigerJ2
GeigerJ2 self-requested a review August 4, 2026 05:08
GeigerJ2
GeigerJ2 previously approved these changes Aug 13, 2026

@GeigerJ2 GeigerJ2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just posted one minor nit, as I don't like variable re-assignment, but not a blocker. Thanks, @t-reents!

Comment thread src/aiida_shell/launch.py Outdated
Comment on lines +136 to +138
metadata['computer'] = computer
else:
computer = metadata.pop('computer', None)
computer = metadata.get('computer', None)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One variable fed by options then conditionally re-fed from the top level, so the if/else reads as two ways to obtain a computer. What happens is simpler: a legacy spelling gets promoted, then one lookup resolves it. if computer: is also a truthiness test on an Optional, where line 220 already uses is not None. Suggestion for L126-138:

    metadata = metadata or {}
    options = metadata.get('options', {})

    if 'computer' in options:
        warnings.warn(
            'Specifying a computer through `metadata.options.computer` in `launch_shell_job` is deprecated. Please use '
            '`metadata.computer` instead.',
            AiidaDeprecationWarning,
            stacklevel=2,
        )
        metadata['computer'] = options.pop('computer')

    computer = metadata.get('computer')

Same mutation semantics, drop-in. Verified as written: 8/8 local cases (the four parametrisations, deprecated path for string and portable, no-computer-anywhere localhost fallback, degenerate metadata shapes None/{}/{'options': {}}), mypy clean, ruff@0.8.6 (the pinned version) All checks passed! and already formatted.

Two tidy-ups if you take it: metadata.get('computer', None)metadata.get('computer'), and launch.py:158 'metadata': metadata or {} is redundant after line 126.

Separate decision: prepare_shell_job_inputs mutates the caller's metadata (the pop predates this, the write is new), so a caller reusing one dict sees the deprecation warning only on the first launch. Copying both levels fixes it and also passes, but changes behaviour for anyone relying on the in-place edit.

@GeigerJ2 GeigerJ2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @t-reents, LGTM!

@GeigerJ2
GeigerJ2 merged commit ffd4b78 into aiidateam:master Aug 13, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants