gridparse 1.5.2__tar.gz → 1.5.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {gridparse-1.5.2/gridparse.egg-info → gridparse-1.5.4}/PKG-INFO +39 -29
- {gridparse-1.5.2 → gridparse-1.5.4}/README.md +36 -27
- {gridparse-1.5.2 → gridparse-1.5.4}/gridparse/__init__.py +1 -1
- {gridparse-1.5.2 → gridparse-1.5.4}/gridparse/grid_argument_parser.py +3 -3
- {gridparse-1.5.2 → gridparse-1.5.4}/gridparse/utils.py +3 -3
- {gridparse-1.5.2 → gridparse-1.5.4/gridparse.egg-info}/PKG-INFO +39 -29
- {gridparse-1.5.2 → gridparse-1.5.4}/pyproject.toml +1 -1
- {gridparse-1.5.2 → gridparse-1.5.4}/setup.py +1 -1
- {gridparse-1.5.2 → gridparse-1.5.4}/LICENSE +0 -0
- {gridparse-1.5.2 → gridparse-1.5.4}/MANIFEST.in +0 -0
- {gridparse-1.5.2 → gridparse-1.5.4}/gridparse.egg-info/SOURCES.txt +0 -0
- {gridparse-1.5.2 → gridparse-1.5.4}/gridparse.egg-info/dependency_links.txt +0 -0
- {gridparse-1.5.2 → gridparse-1.5.4}/gridparse.egg-info/requires.txt +0 -0
- {gridparse-1.5.2 → gridparse-1.5.4}/gridparse.egg-info/top_level.txt +0 -0
- {gridparse-1.5.2 → gridparse-1.5.4}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: gridparse
|
3
|
-
Version: 1.5.
|
3
|
+
Version: 1.5.4
|
4
4
|
Summary: Grid search directly from argparse
|
5
5
|
Home-page: https://github.com/gchochla/gridparse
|
6
6
|
Author: Georgios Chochlakis
|
@@ -49,10 +49,15 @@ Requires-Dist: black; extra == "dev"
|
|
49
49
|
Requires-Dist: pytest; extra == "dev"
|
50
50
|
Dynamic: author
|
51
51
|
Dynamic: home-page
|
52
|
+
Dynamic: license-file
|
52
53
|
|
53
|
-
|
54
|
+

|
54
55
|
|
55
|
-
|
56
|
+
***
|
57
|
+
|
58
|
+
`gridparse` is a lightweight (only dependency is `omegaconf` which also downloads `yaml`) `ArgumentParser` - aka `GridArgumentParser` - that supports your *grid-search* needs. Supports top-level parser and subparsers. Configuration files of any type (using `omegaconf`) are also supported through the argument `--gridparse-config` (also available with underscore `_`), where multiple configuration files can be passed and parsed.
|
59
|
+
|
60
|
+
To install: `pip install gridparse`
|
56
61
|
|
57
62
|
## Overview
|
58
63
|
|
@@ -70,7 +75,27 @@ So, for single arguments, it extends them similar to nargs="+". For multiple arg
|
|
70
75
|
|
71
76
|
## Examples
|
72
77
|
|
73
|
-
Example
|
78
|
+
Example with subspaces:
|
79
|
+
|
80
|
+
```python
|
81
|
+
parser = GridArgumentParser()
|
82
|
+
parser.add_argument("--hparam1", type=int, searchable=True)
|
83
|
+
parser.add_argument("--hparam2", type=int, searchable=True)
|
84
|
+
parser.add_argument("--hparam3", type=int, searchable=True, default=1000)
|
85
|
+
parser.add_argument("--hparam4", type=int, searchable=True, default=2000)
|
86
|
+
parser.add_argument("--normal", required=True, type=str)
|
87
|
+
|
88
|
+
args = parser.parse_args(
|
89
|
+
(
|
90
|
+
"--hparam1 1 2 "
|
91
|
+
"{--hparam2 1 2 3 {--normal normal --hparam4 100 101 102} {--normal maybe --hparam4 200 201 202 203}} "
|
92
|
+
"{--hparam2 4 5 6 --normal not-normal}"
|
93
|
+
).split()
|
94
|
+
)
|
95
|
+
assert len(args) == 2 * ((3 * (3 + 4)) + 3)
|
96
|
+
```
|
97
|
+
|
98
|
+
Example without subspaces but with lists for grid-search:
|
74
99
|
|
75
100
|
```python
|
76
101
|
parser = GridArgumentParser()
|
@@ -81,23 +106,23 @@ parser.add_argument(
|
|
81
106
|
"--lists",
|
82
107
|
required=True,
|
83
108
|
nargs="+",
|
84
|
-
type=
|
109
|
+
type=list_as_delim_str(int),
|
85
110
|
searchable=True,
|
86
111
|
)
|
87
112
|
parser.add_argument(
|
88
113
|
"--normal_lists",
|
89
114
|
required=True,
|
90
115
|
nargs="+",
|
91
|
-
type=
|
116
|
+
type=list_as_delim_str(str),
|
92
117
|
)
|
93
118
|
args = parser.parse_args(
|
94
119
|
(
|
95
|
-
"--hparam1 1
|
96
|
-
"--normal efrgthytfgn --lists 1
|
97
|
-
"--normal_lists
|
120
|
+
"--hparam1 1 2 3 --hparam2 4|3 5|4 6|5 "
|
121
|
+
"--normal efrgthytfgn --lists 1,-2,3 3,4,5|6,7 "
|
122
|
+
"--normal_lists a,b,c d,e,f"
|
98
123
|
).split()
|
99
124
|
)
|
100
|
-
assert len(args) ==
|
125
|
+
assert len(args) == 3 * 3 * 1 * 2 * 1 # corresponding number of different values in input CL arguments
|
101
126
|
|
102
127
|
pprint(args)
|
103
128
|
```
|
@@ -122,25 +147,10 @@ Namespace(hparam1=[1, 2, 3], hparam2=[6, 5], lists=[['3', '4', '5'], ['6', '7']]
|
|
122
147
|
]
|
123
148
|
```
|
124
149
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
parser = GridArgumentParser()
|
129
|
-
parser.add_argument("--hparam1", type=int, searchable=True)
|
130
|
-
parser.add_argument("--hparam2", type=int, searchable=True)
|
131
|
-
parser.add_argument("--hparam3", type=int, searchable=True, default=1000)
|
132
|
-
parser.add_argument("--hparam4", type=int, searchable=True, default=2000)
|
133
|
-
parser.add_argument("--normal", required=True, type=str)
|
150
|
+
Searchable argument always use space to designate a different configuration. Namely, notice that for:
|
151
|
+
- `nargs` and `searchable=True`, `nargs` is delimited by `|` and `searchable` uses the spaces.
|
152
|
+
- `nargs` and `searchable=True` and `list_as_delim_str`, `nargs` uses `|` within each configuration, and `list_as_delim_str` uses `,` within each list of the same configuration, and space is still used by `searchable` to split configurations.
|
134
153
|
|
135
|
-
args = parser.parse_args(
|
136
|
-
(
|
137
|
-
"--hparam1 1 2 "
|
138
|
-
"{--hparam2 1 2 3 {--normal normal --hparam4 100 101 102} {--normal maybe --hparam4 200 201 202 203}} "
|
139
|
-
"{--hparam2 4 5 6 --normal not-normal}"
|
140
|
-
).split()
|
141
|
-
)
|
142
|
-
assert len(args) == 2 * ((3 * (3 + 4)) + 3)
|
143
|
-
```
|
144
154
|
|
145
155
|
## Additional capabilities
|
146
156
|
|
@@ -1,6 +1,10 @@
|
|
1
|
-
|
1
|
+

|
2
2
|
|
3
|
-
|
3
|
+
***
|
4
|
+
|
5
|
+
`gridparse` is a lightweight (only dependency is `omegaconf` which also downloads `yaml`) `ArgumentParser` - aka `GridArgumentParser` - that supports your *grid-search* needs. Supports top-level parser and subparsers. Configuration files of any type (using `omegaconf`) are also supported through the argument `--gridparse-config` (also available with underscore `_`), where multiple configuration files can be passed and parsed.
|
6
|
+
|
7
|
+
To install: `pip install gridparse`
|
4
8
|
|
5
9
|
## Overview
|
6
10
|
|
@@ -18,7 +22,27 @@ So, for single arguments, it extends them similar to nargs="+". For multiple arg
|
|
18
22
|
|
19
23
|
## Examples
|
20
24
|
|
21
|
-
Example
|
25
|
+
Example with subspaces:
|
26
|
+
|
27
|
+
```python
|
28
|
+
parser = GridArgumentParser()
|
29
|
+
parser.add_argument("--hparam1", type=int, searchable=True)
|
30
|
+
parser.add_argument("--hparam2", type=int, searchable=True)
|
31
|
+
parser.add_argument("--hparam3", type=int, searchable=True, default=1000)
|
32
|
+
parser.add_argument("--hparam4", type=int, searchable=True, default=2000)
|
33
|
+
parser.add_argument("--normal", required=True, type=str)
|
34
|
+
|
35
|
+
args = parser.parse_args(
|
36
|
+
(
|
37
|
+
"--hparam1 1 2 "
|
38
|
+
"{--hparam2 1 2 3 {--normal normal --hparam4 100 101 102} {--normal maybe --hparam4 200 201 202 203}} "
|
39
|
+
"{--hparam2 4 5 6 --normal not-normal}"
|
40
|
+
).split()
|
41
|
+
)
|
42
|
+
assert len(args) == 2 * ((3 * (3 + 4)) + 3)
|
43
|
+
```
|
44
|
+
|
45
|
+
Example without subspaces but with lists for grid-search:
|
22
46
|
|
23
47
|
```python
|
24
48
|
parser = GridArgumentParser()
|
@@ -29,23 +53,23 @@ parser.add_argument(
|
|
29
53
|
"--lists",
|
30
54
|
required=True,
|
31
55
|
nargs="+",
|
32
|
-
type=
|
56
|
+
type=list_as_delim_str(int),
|
33
57
|
searchable=True,
|
34
58
|
)
|
35
59
|
parser.add_argument(
|
36
60
|
"--normal_lists",
|
37
61
|
required=True,
|
38
62
|
nargs="+",
|
39
|
-
type=
|
63
|
+
type=list_as_delim_str(str),
|
40
64
|
)
|
41
65
|
args = parser.parse_args(
|
42
66
|
(
|
43
|
-
"--hparam1 1
|
44
|
-
"--normal efrgthytfgn --lists 1
|
45
|
-
"--normal_lists
|
67
|
+
"--hparam1 1 2 3 --hparam2 4|3 5|4 6|5 "
|
68
|
+
"--normal efrgthytfgn --lists 1,-2,3 3,4,5|6,7 "
|
69
|
+
"--normal_lists a,b,c d,e,f"
|
46
70
|
).split()
|
47
71
|
)
|
48
|
-
assert len(args) ==
|
72
|
+
assert len(args) == 3 * 3 * 1 * 2 * 1 # corresponding number of different values in input CL arguments
|
49
73
|
|
50
74
|
pprint(args)
|
51
75
|
```
|
@@ -70,25 +94,10 @@ Namespace(hparam1=[1, 2, 3], hparam2=[6, 5], lists=[['3', '4', '5'], ['6', '7']]
|
|
70
94
|
]
|
71
95
|
```
|
72
96
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
parser = GridArgumentParser()
|
77
|
-
parser.add_argument("--hparam1", type=int, searchable=True)
|
78
|
-
parser.add_argument("--hparam2", type=int, searchable=True)
|
79
|
-
parser.add_argument("--hparam3", type=int, searchable=True, default=1000)
|
80
|
-
parser.add_argument("--hparam4", type=int, searchable=True, default=2000)
|
81
|
-
parser.add_argument("--normal", required=True, type=str)
|
97
|
+
Searchable argument always use space to designate a different configuration. Namely, notice that for:
|
98
|
+
- `nargs` and `searchable=True`, `nargs` is delimited by `|` and `searchable` uses the spaces.
|
99
|
+
- `nargs` and `searchable=True` and `list_as_delim_str`, `nargs` uses `|` within each configuration, and `list_as_delim_str` uses `,` within each list of the same configuration, and space is still used by `searchable` to split configurations.
|
82
100
|
|
83
|
-
args = parser.parse_args(
|
84
|
-
(
|
85
|
-
"--hparam1 1 2 "
|
86
|
-
"{--hparam2 1 2 3 {--normal normal --hparam4 100 101 102} {--normal maybe --hparam4 200 201 202 203}} "
|
87
|
-
"{--hparam2 4 5 6 --normal not-normal}"
|
88
|
-
).split()
|
89
|
-
)
|
90
|
-
assert len(args) == 2 * ((3 * (3 + 4)) + 3)
|
91
|
-
```
|
92
101
|
|
93
102
|
## Additional capabilities
|
94
103
|
|
@@ -5,7 +5,7 @@ from typing import Any, Tuple, List, Optional, Union, Sequence
|
|
5
5
|
from copy import deepcopy
|
6
6
|
from omegaconf import OmegaConf
|
7
7
|
|
8
|
-
from gridparse.utils import
|
8
|
+
from gridparse.utils import list_as_delim_str, strbool
|
9
9
|
|
10
10
|
|
11
11
|
class AuxArgumentParser(argparse.ArgumentParser):
|
@@ -604,7 +604,7 @@ class GridArgumentParser(_GridActionsContainer, AuxArgumentParser):
|
|
604
604
|
# if arg_string is "_None_", then return None
|
605
605
|
if (
|
606
606
|
arg_string == "_None_"
|
607
|
-
and action.dest in self._grid_args
|
607
|
+
# and action.dest in self._grid_args
|
608
608
|
and action.type is not strbool
|
609
609
|
):
|
610
610
|
return None
|
@@ -710,7 +710,7 @@ class GridArgumentParser(_GridActionsContainer, AuxArgumentParser):
|
|
710
710
|
type = kwargs.get("type", None)
|
711
711
|
|
712
712
|
if nargs == "+":
|
713
|
-
type =
|
713
|
+
type = list_as_delim_str(type, delimiter="|")
|
714
714
|
else:
|
715
715
|
nargs = "+"
|
716
716
|
|
@@ -2,12 +2,12 @@ import argparse
|
|
2
2
|
from typing import Callable
|
3
3
|
|
4
4
|
|
5
|
-
#
|
6
|
-
def
|
5
|
+
# NOTE: has issues with negative numbers if delim="-"
|
6
|
+
def list_as_delim_str(actual_type: Callable, delimiter: str = ","):
|
7
7
|
"""Creates a function that converts a string to a list of elements.
|
8
8
|
|
9
9
|
Can be used as the `type` argument in `argparse` to convert
|
10
|
-
a string to a list of elements, e.g.: `["1
|
10
|
+
a string to a list of elements, e.g.: `["1,2,3", "4,5,6"]` to
|
11
11
|
`[[1, 2, 3], [4, 5, 6]]` (note that this operates on a single
|
12
12
|
`str` at a time, use `nargs` to pass multiple).
|
13
13
|
|
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: gridparse
|
3
|
-
Version: 1.5.
|
3
|
+
Version: 1.5.4
|
4
4
|
Summary: Grid search directly from argparse
|
5
5
|
Home-page: https://github.com/gchochla/gridparse
|
6
6
|
Author: Georgios Chochlakis
|
@@ -49,10 +49,15 @@ Requires-Dist: black; extra == "dev"
|
|
49
49
|
Requires-Dist: pytest; extra == "dev"
|
50
50
|
Dynamic: author
|
51
51
|
Dynamic: home-page
|
52
|
+
Dynamic: license-file
|
52
53
|
|
53
|
-
|
54
|
+

|
54
55
|
|
55
|
-
|
56
|
+
***
|
57
|
+
|
58
|
+
`gridparse` is a lightweight (only dependency is `omegaconf` which also downloads `yaml`) `ArgumentParser` - aka `GridArgumentParser` - that supports your *grid-search* needs. Supports top-level parser and subparsers. Configuration files of any type (using `omegaconf`) are also supported through the argument `--gridparse-config` (also available with underscore `_`), where multiple configuration files can be passed and parsed.
|
59
|
+
|
60
|
+
To install: `pip install gridparse`
|
56
61
|
|
57
62
|
## Overview
|
58
63
|
|
@@ -70,7 +75,27 @@ So, for single arguments, it extends them similar to nargs="+". For multiple arg
|
|
70
75
|
|
71
76
|
## Examples
|
72
77
|
|
73
|
-
Example
|
78
|
+
Example with subspaces:
|
79
|
+
|
80
|
+
```python
|
81
|
+
parser = GridArgumentParser()
|
82
|
+
parser.add_argument("--hparam1", type=int, searchable=True)
|
83
|
+
parser.add_argument("--hparam2", type=int, searchable=True)
|
84
|
+
parser.add_argument("--hparam3", type=int, searchable=True, default=1000)
|
85
|
+
parser.add_argument("--hparam4", type=int, searchable=True, default=2000)
|
86
|
+
parser.add_argument("--normal", required=True, type=str)
|
87
|
+
|
88
|
+
args = parser.parse_args(
|
89
|
+
(
|
90
|
+
"--hparam1 1 2 "
|
91
|
+
"{--hparam2 1 2 3 {--normal normal --hparam4 100 101 102} {--normal maybe --hparam4 200 201 202 203}} "
|
92
|
+
"{--hparam2 4 5 6 --normal not-normal}"
|
93
|
+
).split()
|
94
|
+
)
|
95
|
+
assert len(args) == 2 * ((3 * (3 + 4)) + 3)
|
96
|
+
```
|
97
|
+
|
98
|
+
Example without subspaces but with lists for grid-search:
|
74
99
|
|
75
100
|
```python
|
76
101
|
parser = GridArgumentParser()
|
@@ -81,23 +106,23 @@ parser.add_argument(
|
|
81
106
|
"--lists",
|
82
107
|
required=True,
|
83
108
|
nargs="+",
|
84
|
-
type=
|
109
|
+
type=list_as_delim_str(int),
|
85
110
|
searchable=True,
|
86
111
|
)
|
87
112
|
parser.add_argument(
|
88
113
|
"--normal_lists",
|
89
114
|
required=True,
|
90
115
|
nargs="+",
|
91
|
-
type=
|
116
|
+
type=list_as_delim_str(str),
|
92
117
|
)
|
93
118
|
args = parser.parse_args(
|
94
119
|
(
|
95
|
-
"--hparam1 1
|
96
|
-
"--normal efrgthytfgn --lists 1
|
97
|
-
"--normal_lists
|
120
|
+
"--hparam1 1 2 3 --hparam2 4|3 5|4 6|5 "
|
121
|
+
"--normal efrgthytfgn --lists 1,-2,3 3,4,5|6,7 "
|
122
|
+
"--normal_lists a,b,c d,e,f"
|
98
123
|
).split()
|
99
124
|
)
|
100
|
-
assert len(args) ==
|
125
|
+
assert len(args) == 3 * 3 * 1 * 2 * 1 # corresponding number of different values in input CL arguments
|
101
126
|
|
102
127
|
pprint(args)
|
103
128
|
```
|
@@ -122,25 +147,10 @@ Namespace(hparam1=[1, 2, 3], hparam2=[6, 5], lists=[['3', '4', '5'], ['6', '7']]
|
|
122
147
|
]
|
123
148
|
```
|
124
149
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
parser = GridArgumentParser()
|
129
|
-
parser.add_argument("--hparam1", type=int, searchable=True)
|
130
|
-
parser.add_argument("--hparam2", type=int, searchable=True)
|
131
|
-
parser.add_argument("--hparam3", type=int, searchable=True, default=1000)
|
132
|
-
parser.add_argument("--hparam4", type=int, searchable=True, default=2000)
|
133
|
-
parser.add_argument("--normal", required=True, type=str)
|
150
|
+
Searchable argument always use space to designate a different configuration. Namely, notice that for:
|
151
|
+
- `nargs` and `searchable=True`, `nargs` is delimited by `|` and `searchable` uses the spaces.
|
152
|
+
- `nargs` and `searchable=True` and `list_as_delim_str`, `nargs` uses `|` within each configuration, and `list_as_delim_str` uses `,` within each list of the same configuration, and space is still used by `searchable` to split configurations.
|
134
153
|
|
135
|
-
args = parser.parse_args(
|
136
|
-
(
|
137
|
-
"--hparam1 1 2 "
|
138
|
-
"{--hparam2 1 2 3 {--normal normal --hparam4 100 101 102} {--normal maybe --hparam4 200 201 202 203}} "
|
139
|
-
"{--hparam2 4 5 6 --normal not-normal}"
|
140
|
-
).split()
|
141
|
-
)
|
142
|
-
assert len(args) == 2 * ((3 * (3 + 4)) + 3)
|
143
|
-
```
|
144
154
|
|
145
155
|
## Additional capabilities
|
146
156
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|