Debian Codegraph @

ml_collections/config_flags/examples/define_config_dataclass_basic.py

raw symbols SCIP
1 # Copyright 2024 The ML Collections Authors.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 r"""Example of basic DEFINE_config_dataclass usage.
16
17 To run this example:
18 python define_config_dataclass_basic.py -- --my_config.field1=8 \
19 --my_config.nested.field=2.1 --my_config.tuple='(1, 2, (1, 2))'
20 """
21
22 import dataclasses
23 from typing import Any, Mapping, Sequence
24
25 from absl import app
26 from ml_collections import config_flags
27
28
29 @dataclasses.dataclass
30 class MyConfig:
31 field1: int
32 field2: str
33 nested: Mapping[str, Any]
34 tuple: Sequence[int]
35
36
37 config = MyConfig(
38 field1=1,
39 field2='tom',
40 nested={'field': 2.23},
41 tuple=(1, 2, 3),
42 )
43
44 _CONFIG = config_flags.DEFINE_config_dataclass('my_config', config)
45
46
47 def main(_):
48 print(_CONFIG.value)
49
50
51 if __name__ == '__main__':
52 app.run(main)