Miscellaneous

Here are a couple of functions that are useful when writing an interface in a simulation engine to use metatomic models.

metatomic.torch.pick_device(model_devices: List[str], desired_device: str | None) str[source]

Select the best device according to the list of model_devices from a model, the user-provided desired_device and what’s available on the current machine.

If desired_device is provided, it is checked against the model_devices and the machine availability. If it contains a device index (e.g. "cuda:1"), the base device type ("cuda") is used for these checks, and the full string is returned if successful.

If desired_device is None or an empty string, the first available device from model_devices will be picked and returned.

Parameters:
  • model_devices (List[str]) – list of devices supported by a model in order of preference

  • desired_device (str | None) – user-provided desired device.

Return type:

str

metatomic.torch.pick_output(requested_output: str, outputs: Dict[str, ModelOutput], desired_variant: str | None = None) str[source]

Pick the output for the given requested_output from the availabilities of the model’s outputs, according to the optional desired_variant.

Parameters:
  • requested_output (str) – name of the output to pick a variant for

  • outputs (Dict[str, ModelOutput]) – all available outputs from the model

  • desired_variant (str | None) – if provided, try to pick this specific variant

Return type:

str