|
25 | 25 | from aiida.common.exceptions import EntryPointError, ValidationError |
26 | 26 | from aiida.plugins.entry_point import get_entry_point_names |
27 | 27 |
|
| 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 | + |
28 | 44 |
|
29 | 45 | @verdi.group('computer') |
30 | 46 | def verdi_computer(): |
@@ -227,7 +243,7 @@ def _computer_use_login_shell_performance(transport, scheduler, authinfo, comput |
227 | 243 |
|
228 | 244 | if not isclose(timing_true, timing_false, rel_tol=rel_tol, abs_tol=abs_tol): |
229 | 245 | return True, ( |
230 | | - f"\n\n{click.style('Warning:', fg='yellow', bold=True)} " |
| 246 | + f'\n\n{click.style("Warning:", fg="yellow", bold=True)} ' |
231 | 247 | 'The computer is configured to use a login shell, which is slower compared to a normal shell.\n' |
232 | 248 | f'Command execution time of {timing_true:.3f} versus {timing_false:.3f} seconds, respectively).\n' |
233 | 249 | 'Unless this setting is really necessary, consider disabling it with:\n' |
@@ -345,7 +361,7 @@ def computer_duplicate(ctx, computer, non_interactive, **kwargs): |
345 | 361 | from aiida.orm.utils.builders.computer import ComputerBuilder |
346 | 362 |
|
347 | 363 | 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') |
349 | 365 |
|
350 | 366 | kwargs['transport'] = kwargs['transport'].name |
351 | 367 | kwargs['scheduler'] = kwargs['scheduler'].name |
@@ -716,7 +732,7 @@ def computer_config_show(computer, user, defaults, as_option_string): |
716 | 732 | if config.get(option.name) or config.get(option.name) is False: |
717 | 733 | if t_opt.get('switch'): |
718 | 734 | 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("_", "-")}' |
720 | 736 | ) |
721 | 737 | elif t_opt.get('is_flag'): |
722 | 738 | 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): |
832 | 848 | ) |
833 | 849 | else: |
834 | 850 | 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