Using importlib and gin-config
- Dominant language
- Python
- Stars
- 2.2k
- Forks
- 122
- Avg merge
- 5d 10h
- Merged PRs (30d)
- 2
Description
Hello, how to configure a parameter, used in a class that is imported using the importlib?
1. Running in the main.py
```
import gin
import importlib
gin.parse_config_file('config.gin')
module = importlib.import_module('src.external.SomeModule')
_class = getattr(module, 'SomeClass')
```
2. This is the externally defined module in src.external.SomeModule
```
@gin.configurable
SomeClass:
def __init__(self, variable):
self.variable = variable
```
3. This is the 'config.gin' file
```
SomeClass.variable=0
```
However if we define it this way, we get:
```
Traceback (most recent call last):
File "main_test.py", line 291, in
gin.parse_config_file(args.config_path)
File "/site-packages/gin/config.py", line 1599, in parse_config_file
parse_config(f, skip_unknown=skip_unknown)
File "/site-packages/gin/config.py", line 1517, in parse_config
bind_parameter((scope, selector, arg_name), value)
File "/contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "/site-packages/gin/utils.py", line 68, in try_with_location
augment_exception_message_and_reraise(exception, _format_location(location))
File "/site-packages/gin/utils.py", line 49, in augment_exception_message_and_reraise
six.raise_from(proxy.with_traceback(exception.__traceback__), None)
File "", line 3, in raise_from
File "/site-packages/gin/utils.py", line 66, in try_with_location
yield
File "/site-packages/gin/config.py", line 1517, in parse_config
bind_parameter((scope, selector, arg_name), value)
File "/site-packages/gin/config.py", line 643, in bind_parameter
pbk = ParsedBindingKey(binding_key)
File "/site-packages/gin/config.py", line 508, in __new__
raise ValueError("No configurable matching '{}'.".format(selector))
ValueError: No configurable matching 'src.data.SomeModule.SomeClass'.
In file "config/cnn_test.gin", line 35
src.external.SomeModule.SomeClass.variable=0.
```
Contributor guide
Assessment
This issue has not been assessed yet.