# Path: xmanager/xm/pattern_matching.py
# R = TypeVar('R')
# class Case(Generic[R]):
#   def __init__(
#       self,
#       kind: Iterable[Type[Any]],
#       handler: Callable[..., R],
#   ) -> None:
#   def matches(self, *values: Any) -> bool:
# def _deduce_types(handler: Callable[..., Any]) -> Tuple[Type[Any]]:
#   def get_arg_type(arg: str):
# def match(*handlers: Union[Case[R], Callable[..., R]]) -> Callable[..., R]:
#   def apply(*values: Any) -> R:
# def async_match(*handlers: Callable[..., R]) -> Callable[..., Awaitable[R]]:


import enum
import functools
import itertools
import operator
import re
import immutabledict
from typing import Any, Iterable, Iterator, Dict, Mapping, MutableMapping, Optional, Tuple, Union
from xmanager.xm import pattern_matching as pm
    """Define a set of resources.

    Args:
      resources: resource amounts as a dictionary,
        for example {xm.ResourceType.V100: 2}.
      location: Place where the job should run. For example a cluster name or a
        Borg cell.
      replicas: Number of identical tasks to run winthin a job. 1 by default.
      service_tier: A service tier at which the job should run.
      **kw_resources: resource amounts as a kwargs, for example `v100=2` or
        `ram=1 * xm.GiB`. See xm.ResourceType enum for the list of supported
        types and aliases.

    Raises:
      ValueError:
        If several accelerator resources are supplied (i.e. GPU and TPU).
        If the same resource is passed in a `resources` dictionary and as
          a command line argument.
        If topology is supplied for a non acceelerator resource.
    """
    self.location = location
    self.service_tier = service_tier or ServiceTier.PROD

    self.task_requirements = ResourceDict()
    self.accelerator = None
    self.topology = None

    for resource_name, value in itertools.chain(resources.items(),
                                                kw_resources.items()):
      scalar, topology = _parse_resource_quantity(value)

# Path: xmanager/xm/pattern_matching.py
# R = TypeVar('R')
# class Case(Generic[R]):
#   def __init__(
#       self,
#       kind: Iterable[Type[Any]],
#       handler: Callable[..., R],
#   ) -> None:
#   def matches(self, *values: Any) -> bool:
# def _deduce_types(handler: Callable[..., Any]) -> Tuple[Type[Any]]:
#   def get_arg_type(arg: str):
# def match(*handlers: Union[Case[R], Callable[..., R]]) -> Callable[..., R]:
#   def apply(*values: Any) -> R:
# def async_match(*handlers: Callable[..., R]) -> Callable[..., Awaitable[R]]:


# Path: xmanager/xm/resources.py
import enum
import functools
import itertools
import operator
import re
import immutabledict
from typing import Any, Iterable, Iterator, Dict, Mapping, MutableMapping, Optional, Tuple, Union
from xmanager.xm import pattern_matching as pm

    """Define a set of resources.

    Args:
      resources: resource amounts as a dictionary,
        for example {xm.ResourceType.V100: 2}.
      location: Place where the job should run. For example a cluster name or a
        Borg cell.
      replicas: Number of identical tasks to run winthin a job. 1 by default.
      service_tier: A service tier at which the job should run.
      **kw_resources: resource amounts as a kwargs, for example `v100=2` or
        `ram=1 * xm.GiB`. See xm.ResourceType enum for the list of supported
        types and aliases.

    Raises:
      ValueError:
        If several accelerator resources are supplied (i.e. GPU and TPU).
        If the same resource is passed in a `resources` dictionary and as
          a command line argument.
        If topology is supplied for a non acceelerator resource.
    """
    self.location = location
    self.service_tier = service_tier or ServiceTier.PROD

    self.task_requirements = ResourceDict()
    self.accelerator = None
    self.topology = None

    for resource_name, value in itertools.chain(resources.items(),
                                                kw_resources.items()):
      scalar, topology = _parse_resource_quantity(value)

      resource = pm.match(