Skip to content

Commit d03d474

Browse files
committed
Interactive setup runs through.
1 parent 74e0dec commit d03d474

File tree

3 files changed

+757
-378
lines changed

3 files changed

+757
-378
lines changed

src/aiida/cmdline/commands/cmd_computer.py

Lines changed: 105 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@
2525
from aiida.common.exceptions import EntryPointError, ValidationError
2626
from aiida.plugins.entry_point import get_entry_point_names
2727

28+
from .registry_helpers import (
29+
apply_computer_config,
30+
fetch_resource_registry_data,
31+
fetch_code_registry_data,
32+
get_computer_configure_config,
33+
get_computer_setup_config,
34+
interactive_computer_selector,
35+
interactive_system_selector,
36+
save_config_to_file,
37+
search_computers_in_aiida,
38+
_get_computers_table,
39+
_handle_computer_configuration,
40+
_process_template_variables,
41+
_replace_template_var,
42+
)
43+
2844

2945
@verdi.group('computer')
3046
def verdi_computer():
@@ -227,7 +243,7 @@ def _computer_use_login_shell_performance(transport, scheduler, authinfo, comput
227243

228244
if not isclose(timing_true, timing_false, rel_tol=rel_tol, abs_tol=abs_tol):
229245
return True, (
230-
f"\n\n{click.style('Warning:', fg='yellow', bold=True)} "
246+
f'\n\n{click.style("Warning:", fg="yellow", bold=True)} '
231247
'The computer is configured to use a login shell, which is slower compared to a normal shell.\n'
232248
f'Command execution time of {timing_true:.3f} versus {timing_false:.3f} seconds, respectively).\n'
233249
'Unless this setting is really necessary, consider disabling it with:\n'
@@ -345,7 +361,7 @@ def computer_duplicate(ctx, computer, non_interactive, **kwargs):
345361
from aiida.orm.utils.builders.computer import ComputerBuilder
346362

347363
if kwargs['label'] in get_computer_names():
348-
echo.echo_critical(f"A computer called {kwargs['label']} already exists")
364+
echo.echo_critical(f'A computer called {kwargs["label"]} already exists')
349365

350366
kwargs['transport'] = kwargs['transport'].name
351367
kwargs['scheduler'] = kwargs['scheduler'].name
@@ -716,7 +732,7 @@ def computer_config_show(computer, user, defaults, as_option_string):
716732
if config.get(option.name) or config.get(option.name) is False:
717733
if t_opt.get('switch'):
718734
option_value = (
719-
option.opts[-1] if config.get(option.name) else f"--no-{option.name.replace('_', '-')}"
735+
option.opts[-1] if config.get(option.name) else f'--no-{option.name.replace("_", "-")}'
720736
)
721737
elif t_opt.get('is_flag'):
722738
is_default = config.get(option.name) == transport_cli.transport_option_default(
@@ -832,3 +848,89 @@ def computer_export_config(computer, output_file, user, overwrite, sort):
832848
)
833849
else:
834850
echo.echo_success(f'Computer<{computer.pk}> {computer.label} configuration exported to file `{output_file}`.')
851+
852+
853+
# NOTE: variant_data
854+
855+
856+
@verdi_computer.command('search')
857+
@click.argument('pattern', required=False)
858+
@click.option('--save-only', is_flag=True, help='Only save configuration to files, do not apply to AiiDA')
859+
@with_dbenv()
860+
def computer_search(pattern, save_only):
861+
"""Search for computers in the AiiDA code registry and setup/configure them.
862+
863+
If PATTERN is provided, search for computers matching that pattern.
864+
If no pattern is provided, show all available computers in the registry.
865+
866+
This command allows you to discover and setup computers from the community
867+
AiiDA code registry at https://aiidateam.github.io/aiida-code-registry/
868+
"""
869+
from aiida.cmdline.utils.common import tabulate
870+
871+
try:
872+
echo.echo_info('Fetching AiiDA code registry...')
873+
# NOTE: There is quite some overlap between code registry and resource registry
874+
# code registry: 'daint.cscs.ch', 'imxgesrv1.epfl.ch', 'lsmosrv6', 'fidis.epfl.ch', 'tigu.empa.ch', 'paratera',
875+
# 'merlin.psi.ch', 'eiger.cscs.ch'
876+
# resource registry: 'eiger.cscs.ch', 'daint.cscs.ch', 'merlin.psi.ch', 'merlin7.psi.ch'
877+
registry_data = fetch_code_registry_data() | fetch_resource_registry_data()
878+
echo.echo_success(f'Successfully fetched AiiDA registry data. Found {len(registry_data)} computers.')
879+
880+
if pattern:
881+
matching_systems = [system for system in registry_data.keys() if pattern in system]
882+
table = _get_computers_table({match: registry_data[match] for match in matching_systems})
883+
if not matching_systems:
884+
echo.echo_warning(f"No computers found matching pattern '{pattern}'")
885+
if click.confirm('\nWould you like to show all available systems in the registry?'):
886+
table = _get_computers_table(registry_data)
887+
else:
888+
registry_data = {match: registry_data[match] for match in matching_systems}
889+
echo.echo_report(f"Systems in the registry matching the pattern '{pattern}'")
890+
table = _get_computers_table(registry_data)
891+
892+
else:
893+
echo.echo_report('All available systems in the registries:')
894+
table = _get_computers_table(registry_data)
895+
896+
echo.echo(
897+
tabulate(table, headers=['System', 'Variants', 'Hostname', 'Codes (default variant)'], tablefmt='grid')
898+
)
899+
900+
# Offer to setup a computer
901+
if click.confirm('\nWould you like to setup a computer from the registry?'):
902+
903+
if len(table) == 1:
904+
import ipdb; ipdb.set_trace()
905+
# Only one match, use it directly
906+
computer_name = matching_systems[0]
907+
# NOTE: Add here interactive variant selection
908+
# computer_data = registry_data[computer_name]
909+
# variant = computer_name['variant']
910+
# echo.echo_info(f'Setting up {computer_name} / {variant}')
911+
# _handle_computer_configuration(registry_data, computer_name, variant, save_only)
912+
else:
913+
# Multiple matches, let user choose
914+
selection = interactive_system_selector(registry_data)
915+
if not selection:
916+
return
917+
system_name, variant = selection
918+
_handle_computer_configuration(registry_data, system_name, variant, save_only)
919+
920+
# if click.confirm("Would you like to browse all available registry computers?"):
921+
# # Show all systems in table format
922+
# all_systems = find_matching_registry_systems(registry_data, "")
923+
# if all_systems:
924+
# echo.echo_info(f"\n🌐 All available computers in AiiDA registry ({len(all_systems)} total):")
925+
# _print_computers_table(all_systems)
926+
927+
# if click.confirm("\nWould you like to setup a computer?"):
928+
# selection = interactive_system_selector(registry_data)
929+
# if selection:
930+
# system_name, variant = selection
931+
# _handle_computer_configuration(registry_data, system_name, variant, save_only)
932+
# else:
933+
# echo.echo_warning("No computers found in registry")
934+
935+
except Exception as e:
936+
echo.echo_error(f'Failed to search registry: {e}')

0 commit comments

Comments
 (0)