We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[Bug] issues with named arguments in hydra.utils.instantiate
`hydra.utils.instantiate` converts to OmegaConf named arguments, making it impossible to use the named arguments syntax for arguments which cannot be represented in OmegaConf.

## To reproduce:

`conf.yaml`:

```yaml
class: torch.optim.Adam
params:
  lr: 1E-4
```

`test.py`:

```python
import hydra
import torch
import torchvision

@hydra.main(config_path="conf.yaml")
def my_app(cfg):
    print(cfg.pretty())
    model = torchvision.models.alexnet()
    hydra.utils.instantiate(cfg, model.parameters())  # OK
    hydra.utils.instantiate(cfg, params=model.parameters())  # FAILS

if __name__ == "__main__":
    my_app()
```

** Stack trace/error message **
```
ValueError: key params: generator is not a primitive type
```

As a side note, the fact that `hydra.utils.instantiate` takes as input an argument named `config` makes it impossible to instantiate an object which expects the same argument using named arguments, which seems an unnecessary restriction.

## The following solves both issues:

```python
def instantiate_f(config):
    assert config is not None, "Input config is None"
    class_name = config["class"]
    clazz = get_class(class_name)
    params = config.params if "params" in config else OmegaConf.create()
    assert isinstance(
        params, DictConfig
    ), "Input config params are expected to be a mapping, found {}".format(
        type(config.params)
    )
    params = OmegaConf.to_container(params, resolve=True)

    def f(*args, **kwargs):
        try:
            kwargs = {**params, **kwargs}
            return clazz(*args, **kwargs)
        except Exception as e:
            log.error("Error instantiating {} : {}".format(class_name, e))
            raise e

    return f

@hydra.main(config_path="conf.yaml")
def my_app(cfg):
    print(cfg.pretty())
    model = torchvision.models.alexnet()
    instantiate_f(cfg)(params=model.parameters())  # OK
    instantiate_f(cfg)(model.parameters())  # OK

if __name__ == "__main__":
    my_app()
```

A note in the documentation should be added explaining the behavior wrt `config`, as it gets resolved immediately.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `hydra/conf/__init__.py`
Content:
```
1 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
2 from dataclasses import dataclass, field
3 from typing import Any, Dict, List, Optional
4 
5 from omegaconf import MISSING
6 
7 from hydra.core.config_store import ConfigStore
8 
9 hydra_defaults = [
10     # Hydra's logging config
11     {"hydra/hydra_logging": "default"},
12     # Job's logging config
13     {"hydra/job_logging": "default"},
14     # Launcher config
15     {"hydra/launcher": "basic"},
16     # Sweeper config
17     {"hydra/sweeper": "basic"},
18     # Output directory
19     {"hydra/output": "default"},
20     # --help template
21     {"hydra/help": "default"},
22     # --hydra-help template
23     {"hydra/hydra_help": "default"},
24 ]
25 
26 
27 @dataclass
28 class PluginConf(Dict[str, Any]):
29     # class name for plugin
30     cls: str = MISSING
31     params: Dict[str, Any] = field(default_factory=dict)
32 
33 
34 @dataclass
35 class HelpConf:
36     app_name: str = MISSING
37     header: str = MISSING
38     footer: str = MISSING
39     template: str = MISSING
40 
41 
42 @dataclass
43 class HydraHelpConf:
44     hydra_help: str = MISSING
45     template: str = MISSING
46 
47 
48 @dataclass
49 class RunDir:
50     dir: str = MISSING
51 
52 
53 @dataclass
54 class SweepDir:
55     dir: str = MISSING
56     subdir: str = MISSING
57 
58 
59 @dataclass
60 class OverridesConf:
61     # Overrides for the hydra configuration
62     hydra: List[str] = field(default_factory=lambda: [])
63     # Overrides for the task configuration
64     task: List[str] = field(default_factory=lambda: [])
65 
66 
67 @dataclass
68 # job runtime information will be populated here
69 class JobConf:
70     # Job name, can be specified by the user (in config or cli) or populated automatically
71     name: str = MISSING
72 
73     # Concatenation of job overrides that can be used as a part
74     # of the directory name.
75     # This can be configured in hydra.job.config.override_dirname
76     override_dirname: str = MISSING
77 
78     # Job ID in underlying scheduling system
79     id: str = MISSING
80 
81     # Job number if job is a part of a sweep
82     num: str = MISSING
83 
84     # The config name used by the job
85     config_name: Optional[str] = MISSING
86 
87     @dataclass
88     # Job config
89     class JobConfig:
90         @dataclass
91         # configuration for the ${hydra.job.override_dirname} runtime variable
92         class OverrideDirname:
93             kv_sep: str = "="
94             item_sep: str = ","
95             exclude_keys: List[str] = field(default_factory=lambda: [])
96 
97         override_dirname: OverrideDirname = OverrideDirname()
98 
99     config: JobConfig = JobConfig()
100 
101 
102 @dataclass
103 class RuntimeConf:
104     version: str = MISSING
105     cwd: str = MISSING
106 
107 
108 @dataclass
109 class HydraConf:
110     # Normal run output configuration
111     run: RunDir = RunDir()
112     # Multi-run output configuration
113     sweep: SweepDir = SweepDir()
114     # Logging configuration for Hydra
115     hydra_logging: Any = MISSING
116     # Logging configuration for the job
117     job_logging: Any = MISSING
118 
119     # Sweeper configuration
120     sweeper: PluginConf = field(default_factory=PluginConf)
121     # Launcher configuration
122     launcher: PluginConf = field(default_factory=PluginConf)
123 
124     # Program Help template
125     help: HelpConf = HelpConf()
126     # Hydra's Help template
127     hydra_help: HydraHelpConf = HydraHelpConf()
128 
129     # Output directory for produced configuration files and overrides.
130     # E.g., hydra.yaml, overrides.yaml will go here. Useful for debugging
131     # and extra context when looking at past runs.
132     output_subdir: str = ".hydra"
133 
134     # Those lists will contain runtime overrides
135     overrides: OverridesConf = OverridesConf()
136 
137     job: JobConf = JobConf()
138 
139     # populated at runtime
140     runtime: RuntimeConf = RuntimeConf()
141 
142     # Can be a boolean, string or a list of strings
143     # If a boolean, setting to true will set the log level for the root logger to debug
144     # If a string, it's interpreted as a the list [string]
145     # If a list, each element is interpreted as a logger to have logging level set to debug.
146     # Typical command lines to manipulate hydra.verbose:
147     # hydra.verbose=true
148     # hydra.verbose=[hydra,__main__]
149     # TODO: good use case for Union support in OmegaConf
150     verbose: Any = False
151 
152 
153 ConfigStore.instance().store(
154     name="hydra_config",
155     node={
156         # Hydra composition defaults
157         "defaults": hydra_defaults,
158         # Hydra config
159         "hydra": HydraConf,
160     },
161     provider="hydra",
162 )
163
```

Path: `hydra/utils.py`
Content:
```
1 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
2 import logging.config
3 import warnings
4 from pathlib import Path
5 from typing import Any
6 
7 from omegaconf import DictConfig, OmegaConf
8 
9 from hydra.conf import PluginConf
10 from hydra.core.hydra_config import HydraConfig
11 
12 log = logging.getLogger(__name__)
13 
14 
15 def get_method(path: str) -> type:
16     return get_class(path)
17 
18 
19 def get_class(path: str) -> type:
20     try:
21         from importlib import import_module
22 
23         module_path, _, class_name = path.rpartition(".")
24         mod = import_module(module_path)
25         try:
26             klass: type = getattr(mod, class_name)
27         except AttributeError:
28             raise ImportError(
29                 "Class {} is not in module {}".format(class_name, module_path)
30             )
31         return klass
32     except ValueError as e:
33         log.error("Error initializing class " + path)
34         raise e
35 
36 
37 def get_static_method(full_method_name: str) -> type:
38     try:
39         spl = full_method_name.split(".")
40         method_name = spl.pop()
41         class_name = ".".join(spl)
42         clz = get_class(class_name)
43         ret: type = getattr(clz, method_name)
44         return ret
45     except Exception as e:
46         log.error("Error getting static method {} : {}".format(full_method_name, e))
47         raise e
48 
49 
50 def instantiate(config: PluginConf, *args: Any, **kwargs: Any) -> Any:
51     import copy
52 
53     # copy config to avoid mutating it when merging with kwargs
54 
55     config_copy = copy.deepcopy(config)
56 
57     # Manually set parent as deepcopy does not currently handles it (https://github.com/omry/omegaconf/issues/130)
58     # noinspection PyProtectedMember
59     config_copy._set_parent(config._get_parent())  # type: ignore
60     config = config_copy
61     classname = _get_class_name(config)
62     try:
63         clazz = get_class(classname)
64         params = config.params if "params" in config else OmegaConf.create()
65         assert isinstance(
66             params, DictConfig
67         ), "Input config params are expected to be a mapping, found {}".format(
68             type(config.params)
69         )
70         params.merge_with(OmegaConf.create(kwargs))
71 
72         return clazz(*args, **params)
73     except Exception as e:
74         log.error(f"Error instantiating '{classname}' : {e}")
75         raise e
76 
77 
78 def get_original_cwd() -> str:
79     ret = HydraConfig.instance().hydra.runtime.cwd
80     assert ret is not None and isinstance(ret, str)
81     return ret
82 
83 
84 def to_absolute_path(path: str) -> str:
85     """
86     converts the specified path to be absolute path.
87     if the input path is relative, it's interpreted as relative to the original working directory
88     if it's absolute, it's returned as is
89     :param path:
90     :return:
91     """
92     p = Path(path)
93     if p.is_absolute():
94         ret = p
95     else:
96         ret = Path(get_original_cwd()) / p
97     return str(ret)
98 
99 
100 def _get_class_name(config: PluginConf) -> str:
101     if "class" in config:
102         warnings.warn(
103             "\n"
104             "PluginConf field 'class' is deprecated since Hydra 1.0.0 and will be removed in a future Hydra version.\n"
105             "Offending config class:\n"
106             f"\tclass={config['class']}\n"
107             "Change your config to use 'cls' instead of 'class'.\n",
108             category=UserWarning,
109         )
110         classname = config["class"]
111         assert isinstance(classname, str)
112         return classname
113     else:
114         if "cls" in config:
115             return config.cls
116         else:
117             raise ValueError("Input config does not have a cls field")
118
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/hydra/conf/__init__.py b/hydra/conf/__init__.py
--- a/hydra/conf/__init__.py
+++ b/hydra/conf/__init__.py
@@ -25,6 +25,8 @@
 
 
 @dataclass
+# This extends Dict[str, Any] to allow for the deprecated "class" field.
+# Once support for class field removed this can stop extending Dict.
 class PluginConf(Dict[str, Any]):
     # class name for plugin
     cls: str = MISSING
diff --git a/hydra/utils.py b/hydra/utils.py
--- a/hydra/utils.py
+++ b/hydra/utils.py
@@ -4,7 +4,7 @@
 from pathlib import Path
 from typing import Any
 
-from omegaconf import DictConfig, OmegaConf
+from omegaconf import DictConfig, OmegaConf, _utils
 
 from hydra.conf import PluginConf
 from hydra.core.hydra_config import HydraConfig
@@ -67,9 +67,22 @@
         ), "Input config params are expected to be a mapping, found {}".format(
             type(config.params)
         )
-        params.merge_with(OmegaConf.create(kwargs))
-
-        return clazz(*args, **params)
+        primitives = {}
+        rest = {}
+        for k, v in kwargs.items():
+            if _utils._is_primitive_type(v) or isinstance(v, (dict, list)):
+                primitives[k] = v
+            else:
+                rest[k] = v
+        final_kwargs = {}
+        params.merge_with(OmegaConf.create(primitives))
+        for k, v in params.items():
+            final_kwargs[k] = v
+
+        for k, v in rest.items():
+            final_kwargs[k] = v
+
+        return clazz(*args, **final_kwargs)
     except Exception as e:
         log.error(f"Error instantiating '{classname}' : {e}")
         raise e

{"golden_diff": "diff --git a/hydra/conf/__init__.py b/hydra/conf/__init__.py\n--- a/hydra/conf/__init__.py\n+++ b/hydra/conf/__init__.py\n@@ -25,6 +25,8 @@\n \n \n @dataclass\n+# This extends Dict[str, Any] to allow for the deprecated \"class\" field.\n+# Once support for class field removed this can stop extending Dict.\n class PluginConf(Dict[str, Any]):\n     # class name for plugin\n     cls: str = MISSING\ndiff --git a/hydra/utils.py b/hydra/utils.py\n--- a/hydra/utils.py\n+++ b/hydra/utils.py\n@@ -4,7 +4,7 @@\n from pathlib import Path\n from typing import Any\n \n-from omegaconf import DictConfig, OmegaConf\n+from omegaconf import DictConfig, OmegaConf, _utils\n \n from hydra.conf import PluginConf\n from hydra.core.hydra_config import HydraConfig\n@@ -67,9 +67,22 @@\n         ), \"Input config params are expected to be a mapping, found {}\".format(\n             type(config.params)\n         )\n-        params.merge_with(OmegaConf.create(kwargs))\n-\n-        return clazz(*args, **params)\n+        primitives = {}\n+        rest = {}\n+        for k, v in kwargs.items():\n+            if _utils._is_primitive_type(v) or isinstance(v, (dict, list)):\n+                primitives[k] = v\n+            else:\n+                rest[k] = v\n+        final_kwargs = {}\n+        params.merge_with(OmegaConf.create(primitives))\n+        for k, v in params.items():\n+            final_kwargs[k] = v\n+\n+        for k, v in rest.items():\n+            final_kwargs[k] = v\n+\n+        return clazz(*args, **final_kwargs)\n     except Exception as e:\n         log.error(f\"Error instantiating '{classname}' : {e}\")\n         raise e\n", "issue": "[Bug] issues with named arguments in hydra.utils.instantiate\n`hydra.utils.instantiate` converts to OmegaConf named arguments, making it impossible to use the named arguments syntax for arguments which cannot be represented in OmegaConf.\r\n\r\n## To reproduce:\r\n\r\n`conf.yaml`:\r\n\r\n```yaml\r\nclass: torch.optim.Adam\r\nparams:\r\n  lr: 1E-4\r\n```\r\n\r\n`test.py`:\r\n\r\n```python\r\nimport hydra\r\nimport torch\r\nimport torchvision\r\n\r\n@hydra.main(config_path=\"conf.yaml\")\r\ndef my_app(cfg):\r\n    print(cfg.pretty())\r\n    model = torchvision.models.alexnet()\r\n    hydra.utils.instantiate(cfg, model.parameters())  # OK\r\n    hydra.utils.instantiate(cfg, params=model.parameters())  # FAILS\r\n\r\nif __name__ == \"__main__\":\r\n    my_app()\r\n```\r\n\r\n** Stack trace/error message **\r\n```\r\nValueError: key params: generator is not a primitive type\r\n```\r\n\r\nAs a side note, the fact that `hydra.utils.instantiate` takes as input an argument named `config` makes it impossible to instantiate an object which expects the same argument using named arguments, which seems an unnecessary restriction.\r\n\r\n## The following solves both issues:\r\n\r\n```python\r\ndef instantiate_f(config):\r\n    assert config is not None, \"Input config is None\"\r\n    class_name = config[\"class\"]\r\n    clazz = get_class(class_name)\r\n    params = config.params if \"params\" in config else OmegaConf.create()\r\n    assert isinstance(\r\n        params, DictConfig\r\n    ), \"Input config params are expected to be a mapping, found {}\".format(\r\n        type(config.params)\r\n    )\r\n    params = OmegaConf.to_container(params, resolve=True)\r\n\r\n    def f(*args, **kwargs):\r\n        try:\r\n            kwargs = {**params, **kwargs}\r\n            return clazz(*args, **kwargs)\r\n        except Exception as e:\r\n            log.error(\"Error instantiating {} : {}\".format(class_name, e))\r\n            raise e\r\n\r\n    return f\r\n\r\n@hydra.main(config_path=\"conf.yaml\")\r\ndef my_app(cfg):\r\n    print(cfg.pretty())\r\n    model = torchvision.models.alexnet()\r\n    instantiate_f(cfg)(params=model.parameters())  # OK\r\n    instantiate_f(cfg)(model.parameters())  # OK\r\n\r\nif __name__ == \"__main__\":\r\n    my_app()\r\n```\r\n\r\nA note in the documentation should be added explaining the behavior wrt `config`, as it gets resolved immediately.\n", "before_files": [{"content": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\nfrom dataclasses import dataclass, field\nfrom typing import Any, Dict, List, Optional\n\nfrom omegaconf import MISSING\n\nfrom hydra.core.config_store import ConfigStore\n\nhydra_defaults = [\n    # Hydra's logging config\n    {\"hydra/hydra_logging\": \"default\"},\n    # Job's logging config\n    {\"hydra/job_logging\": \"default\"},\n    # Launcher config\n    {\"hydra/launcher\": \"basic\"},\n    # Sweeper config\n    {\"hydra/sweeper\": \"basic\"},\n    # Output directory\n    {\"hydra/output\": \"default\"},\n    # --help template\n    {\"hydra/help\": \"default\"},\n    # --hydra-help template\n    {\"hydra/hydra_help\": \"default\"},\n]\n\n\n@dataclass\nclass PluginConf(Dict[str, Any]):\n    # class name for plugin\n    cls: str = MISSING\n    params: Dict[str, Any] = field(default_factory=dict)\n\n\n@dataclass\nclass HelpConf:\n    app_name: str = MISSING\n    header: str = MISSING\n    footer: str = MISSING\n    template: str = MISSING\n\n\n@dataclass\nclass HydraHelpConf:\n    hydra_help: str = MISSING\n    template: str = MISSING\n\n\n@dataclass\nclass RunDir:\n    dir: str = MISSING\n\n\n@dataclass\nclass SweepDir:\n    dir: str = MISSING\n    subdir: str = MISSING\n\n\n@dataclass\nclass OverridesConf:\n    # Overrides for the hydra configuration\n    hydra: List[str] = field(default_factory=lambda: [])\n    # Overrides for the task configuration\n    task: List[str] = field(default_factory=lambda: [])\n\n\n@dataclass\n# job runtime information will be populated here\nclass JobConf:\n    # Job name, can be specified by the user (in config or cli) or populated automatically\n    name: str = MISSING\n\n    # Concatenation of job overrides that can be used as a part\n    # of the directory name.\n    # This can be configured in hydra.job.config.override_dirname\n    override_dirname: str = MISSING\n\n    # Job ID in underlying scheduling system\n    id: str = MISSING\n\n    # Job number if job is a part of a sweep\n    num: str = MISSING\n\n    # The config name used by the job\n    config_name: Optional[str] = MISSING\n\n    @dataclass\n    # Job config\n    class JobConfig:\n        @dataclass\n        # configuration for the ${hydra.job.override_dirname} runtime variable\n        class OverrideDirname:\n            kv_sep: str = \"=\"\n            item_sep: str = \",\"\n            exclude_keys: List[str] = field(default_factory=lambda: [])\n\n        override_dirname: OverrideDirname = OverrideDirname()\n\n    config: JobConfig = JobConfig()\n\n\n@dataclass\nclass RuntimeConf:\n    version: str = MISSING\n    cwd: str = MISSING\n\n\n@dataclass\nclass HydraConf:\n    # Normal run output configuration\n    run: RunDir = RunDir()\n    # Multi-run output configuration\n    sweep: SweepDir = SweepDir()\n    # Logging configuration for Hydra\n    hydra_logging: Any = MISSING\n    # Logging configuration for the job\n    job_logging: Any = MISSING\n\n    # Sweeper configuration\n    sweeper: PluginConf = field(default_factory=PluginConf)\n    # Launcher configuration\n    launcher: PluginConf = field(default_factory=PluginConf)\n\n    # Program Help template\n    help: HelpConf = HelpConf()\n    # Hydra's Help template\n    hydra_help: HydraHelpConf = HydraHelpConf()\n\n    # Output directory for produced configuration files and overrides.\n    # E.g., hydra.yaml, overrides.yaml will go here. Useful for debugging\n    # and extra context when looking at past runs.\n    output_subdir: str = \".hydra\"\n\n    # Those lists will contain runtime overrides\n    overrides: OverridesConf = OverridesConf()\n\n    job: JobConf = JobConf()\n\n    # populated at runtime\n    runtime: RuntimeConf = RuntimeConf()\n\n    # Can be a boolean, string or a list of strings\n    # If a boolean, setting to true will set the log level for the root logger to debug\n    # If a string, it's interpreted as a the list [string]\n    # If a list, each element is interpreted as a logger to have logging level set to debug.\n    # Typical command lines to manipulate hydra.verbose:\n    # hydra.verbose=true\n    # hydra.verbose=[hydra,__main__]\n    # TODO: good use case for Union support in OmegaConf\n    verbose: Any = False\n\n\nConfigStore.instance().store(\n    name=\"hydra_config\",\n    node={\n        # Hydra composition defaults\n        \"defaults\": hydra_defaults,\n        # Hydra config\n        \"hydra\": HydraConf,\n    },\n    provider=\"hydra\",\n)\n", "path": "hydra/conf/__init__.py"}, {"content": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\nimport logging.config\nimport warnings\nfrom pathlib import Path\nfrom typing import Any\n\nfrom omegaconf import DictConfig, OmegaConf\n\nfrom hydra.conf import PluginConf\nfrom hydra.core.hydra_config import HydraConfig\n\nlog = logging.getLogger(__name__)\n\n\ndef get_method(path: str) -> type:\n    return get_class(path)\n\n\ndef get_class(path: str) -> type:\n    try:\n        from importlib import import_module\n\n        module_path, _, class_name = path.rpartition(\".\")\n        mod = import_module(module_path)\n        try:\n            klass: type = getattr(mod, class_name)\n        except AttributeError:\n            raise ImportError(\n                \"Class {} is not in module {}\".format(class_name, module_path)\n            )\n        return klass\n    except ValueError as e:\n        log.error(\"Error initializing class \" + path)\n        raise e\n\n\ndef get_static_method(full_method_name: str) -> type:\n    try:\n        spl = full_method_name.split(\".\")\n        method_name = spl.pop()\n        class_name = \".\".join(spl)\n        clz = get_class(class_name)\n        ret: type = getattr(clz, method_name)\n        return ret\n    except Exception as e:\n        log.error(\"Error getting static method {} : {}\".format(full_method_name, e))\n        raise e\n\n\ndef instantiate(config: PluginConf, *args: Any, **kwargs: Any) -> Any:\n    import copy\n\n    # copy config to avoid mutating it when merging with kwargs\n\n    config_copy = copy.deepcopy(config)\n\n    # Manually set parent as deepcopy does not currently handles it (https://github.com/omry/omegaconf/issues/130)\n    # noinspection PyProtectedMember\n    config_copy._set_parent(config._get_parent())  # type: ignore\n    config = config_copy\n    classname = _get_class_name(config)\n    try:\n        clazz = get_class(classname)\n        params = config.params if \"params\" in config else OmegaConf.create()\n        assert isinstance(\n            params, DictConfig\n        ), \"Input config params are expected to be a mapping, found {}\".format(\n            type(config.params)\n        )\n        params.merge_with(OmegaConf.create(kwargs))\n\n        return clazz(*args, **params)\n    except Exception as e:\n        log.error(f\"Error instantiating '{classname}' : {e}\")\n        raise e\n\n\ndef get_original_cwd() -> str:\n    ret = HydraConfig.instance().hydra.runtime.cwd\n    assert ret is not None and isinstance(ret, str)\n    return ret\n\n\ndef to_absolute_path(path: str) -> str:\n    \"\"\"\n    converts the specified path to be absolute path.\n    if the input path is relative, it's interpreted as relative to the original working directory\n    if it's absolute, it's returned as is\n    :param path:\n    :return:\n    \"\"\"\n    p = Path(path)\n    if p.is_absolute():\n        ret = p\n    else:\n        ret = Path(get_original_cwd()) / p\n    return str(ret)\n\n\ndef _get_class_name(config: PluginConf) -> str:\n    if \"class\" in config:\n        warnings.warn(\n            \"\\n\"\n            \"PluginConf field 'class' is deprecated since Hydra 1.0.0 and will be removed in a future Hydra version.\\n\"\n            \"Offending config class:\\n\"\n            f\"\\tclass={config['class']}\\n\"\n            \"Change your config to use 'cls' instead of 'class'.\\n\",\n            category=UserWarning,\n        )\n        classname = config[\"class\"]\n        assert isinstance(classname, str)\n        return classname\n    else:\n        if \"cls\" in config:\n            return config.cls\n        else:\n            raise ValueError(\"Input config does not have a cls field\")\n", "path": "hydra/utils.py"}], "after_files": [{"content": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\nfrom dataclasses import dataclass, field\nfrom typing import Any, Dict, List, Optional\n\nfrom omegaconf import MISSING\n\nfrom hydra.core.config_store import ConfigStore\n\nhydra_defaults = [\n    # Hydra's logging config\n    {\"hydra/hydra_logging\": \"default\"},\n    # Job's logging config\n    {\"hydra/job_logging\": \"default\"},\n    # Launcher config\n    {\"hydra/launcher\": \"basic\"},\n    # Sweeper config\n    {\"hydra/sweeper\": \"basic\"},\n    # Output directory\n    {\"hydra/output\": \"default\"},\n    # --help template\n    {\"hydra/help\": \"default\"},\n    # --hydra-help template\n    {\"hydra/hydra_help\": \"default\"},\n]\n\n\n@dataclass\n# This extends Dict[str, Any] to allow for the deprecated \"class\" field.\n# Once support for class field removed this can stop extending Dict.\nclass PluginConf(Dict[str, Any]):\n    # class name for plugin\n    cls: str = MISSING\n    params: Dict[str, Any] = field(default_factory=dict)\n\n\n@dataclass\nclass HelpConf:\n    app_name: str = MISSING\n    header: str = MISSING\n    footer: str = MISSING\n    template: str = MISSING\n\n\n@dataclass\nclass HydraHelpConf:\n    hydra_help: str = MISSING\n    template: str = MISSING\n\n\n@dataclass\nclass RunDir:\n    dir: str = MISSING\n\n\n@dataclass\nclass SweepDir:\n    dir: str = MISSING\n    subdir: str = MISSING\n\n\n@dataclass\nclass OverridesConf:\n    # Overrides for the hydra configuration\n    hydra: List[str] = field(default_factory=lambda: [])\n    # Overrides for the task configuration\n    task: List[str] = field(default_factory=lambda: [])\n\n\n@dataclass\n# job runtime information will be populated here\nclass JobConf:\n    # Job name, can be specified by the user (in config or cli) or populated automatically\n    name: str = MISSING\n\n    # Concatenation of job overrides that can be used as a part\n    # of the directory name.\n    # This can be configured in hydra.job.config.override_dirname\n    override_dirname: str = MISSING\n\n    # Job ID in underlying scheduling system\n    id: str = MISSING\n\n    # Job number if job is a part of a sweep\n    num: str = MISSING\n\n    # The config name used by the job\n    config_name: Optional[str] = MISSING\n\n    @dataclass\n    # Job config\n    class JobConfig:\n        @dataclass\n        # configuration for the ${hydra.job.override_dirname} runtime variable\n        class OverrideDirname:\n            kv_sep: str = \"=\"\n            item_sep: str = \",\"\n            exclude_keys: List[str] = field(default_factory=lambda: [])\n\n        override_dirname: OverrideDirname = OverrideDirname()\n\n    config: JobConfig = JobConfig()\n\n\n@dataclass\nclass RuntimeConf:\n    version: str = MISSING\n    cwd: str = MISSING\n\n\n@dataclass\nclass HydraConf:\n    # Normal run output configuration\n    run: RunDir = RunDir()\n    # Multi-run output configuration\n    sweep: SweepDir = SweepDir()\n    # Logging configuration for Hydra\n    hydra_logging: Any = MISSING\n    # Logging configuration for the job\n    job_logging: Any = MISSING\n\n    # Sweeper configuration\n    sweeper: PluginConf = field(default_factory=PluginConf)\n    # Launcher configuration\n    launcher: PluginConf = field(default_factory=PluginConf)\n\n    # Program Help template\n    help: HelpConf = HelpConf()\n    # Hydra's Help template\n    hydra_help: HydraHelpConf = HydraHelpConf()\n\n    # Output directory for produced configuration files and overrides.\n    # E.g., hydra.yaml, overrides.yaml will go here. Useful for debugging\n    # and extra context when looking at past runs.\n    output_subdir: str = \".hydra\"\n\n    # Those lists will contain runtime overrides\n    overrides: OverridesConf = OverridesConf()\n\n    job: JobConf = JobConf()\n\n    # populated at runtime\n    runtime: RuntimeConf = RuntimeConf()\n\n    # Can be a boolean, string or a list of strings\n    # If a boolean, setting to true will set the log level for the root logger to debug\n    # If a string, it's interpreted as a the list [string]\n    # If a list, each element is interpreted as a logger to have logging level set to debug.\n    # Typical command lines to manipulate hydra.verbose:\n    # hydra.verbose=true\n    # hydra.verbose=[hydra,__main__]\n    # TODO: good use case for Union support in OmegaConf\n    verbose: Any = False\n\n\nConfigStore.instance().store(\n    name=\"hydra_config\",\n    node={\n        # Hydra composition defaults\n        \"defaults\": hydra_defaults,\n        # Hydra config\n        \"hydra\": HydraConf,\n    },\n    provider=\"hydra\",\n)\n", "path": "hydra/conf/__init__.py"}, {"content": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\nimport logging.config\nimport warnings\nfrom pathlib import Path\nfrom typing import Any\n\nfrom omegaconf import DictConfig, OmegaConf, _utils\n\nfrom hydra.conf import PluginConf\nfrom hydra.core.hydra_config import HydraConfig\n\nlog = logging.getLogger(__name__)\n\n\ndef get_method(path: str) -> type:\n    return get_class(path)\n\n\ndef get_class(path: str) -> type:\n    try:\n        from importlib import import_module\n\n        module_path, _, class_name = path.rpartition(\".\")\n        mod = import_module(module_path)\n        try:\n            klass: type = getattr(mod, class_name)\n        except AttributeError:\n            raise ImportError(\n                \"Class {} is not in module {}\".format(class_name, module_path)\n            )\n        return klass\n    except ValueError as e:\n        log.error(\"Error initializing class \" + path)\n        raise e\n\n\ndef get_static_method(full_method_name: str) -> type:\n    try:\n        spl = full_method_name.split(\".\")\n        method_name = spl.pop()\n        class_name = \".\".join(spl)\n        clz = get_class(class_name)\n        ret: type = getattr(clz, method_name)\n        return ret\n    except Exception as e:\n        log.error(\"Error getting static method {} : {}\".format(full_method_name, e))\n        raise e\n\n\ndef instantiate(config: PluginConf, *args: Any, **kwargs: Any) -> Any:\n    import copy\n\n    # copy config to avoid mutating it when merging with kwargs\n\n    config_copy = copy.deepcopy(config)\n\n    # Manually set parent as deepcopy does not currently handles it (https://github.com/omry/omegaconf/issues/130)\n    # noinspection PyProtectedMember\n    config_copy._set_parent(config._get_parent())  # type: ignore\n    config = config_copy\n    classname = _get_class_name(config)\n    try:\n        clazz = get_class(classname)\n        params = config.params if \"params\" in config else OmegaConf.create()\n        assert isinstance(\n            params, DictConfig\n        ), \"Input config params are expected to be a mapping, found {}\".format(\n            type(config.params)\n        )\n        primitives = {}\n        rest = {}\n        for k, v in kwargs.items():\n            if _utils._is_primitive_type(v) or isinstance(v, (dict, list)):\n                primitives[k] = v\n            else:\n                rest[k] = v\n        final_kwargs = {}\n        params.merge_with(OmegaConf.create(primitives))\n        for k, v in params.items():\n            final_kwargs[k] = v\n\n        for k, v in rest.items():\n            final_kwargs[k] = v\n\n        return clazz(*args, **final_kwargs)\n    except Exception as e:\n        log.error(f\"Error instantiating '{classname}' : {e}\")\n        raise e\n\n\ndef get_original_cwd() -> str:\n    ret = HydraConfig.instance().hydra.runtime.cwd\n    assert ret is not None and isinstance(ret, str)\n    return ret\n\n\ndef to_absolute_path(path: str) -> str:\n    \"\"\"\n    converts the specified path to be absolute path.\n    if the input path is relative, it's interpreted as relative to the original working directory\n    if it's absolute, it's returned as is\n    :param path:\n    :return:\n    \"\"\"\n    p = Path(path)\n    if p.is_absolute():\n        ret = p\n    else:\n        ret = Path(get_original_cwd()) / p\n    return str(ret)\n\n\ndef _get_class_name(config: PluginConf) -> str:\n    if \"class\" in config:\n        warnings.warn(\n            \"\\n\"\n            \"PluginConf field 'class' is deprecated since Hydra 1.0.0 and will be removed in a future Hydra version.\\n\"\n            \"Offending config class:\\n\"\n            f\"\\tclass={config['class']}\\n\"\n            \"Change your config to use 'cls' instead of 'class'.\\n\",\n            category=UserWarning,\n        )\n        classname = config[\"class\"]\n        assert isinstance(classname, str)\n        return classname\n    else:\n        if \"cls\" in config:\n            return config.cls\n        else:\n            raise ValueError(\"Input config does not have a cls field\")\n", "path": "hydra/utils.py"}]}