-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathargs.py
126 lines (113 loc) · 3.31 KB
/
args.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import argparse
import yaml
IMB_TYPES = ["step", "natural"]
GNN_ARCHS = ["GCN", "GAT", "SAGE"]
BAT_MODES = ["dummy", "bat0", "bat1", "all"]
def parse_args(config_path="config.yaml"):
"""
Parses command-line arguments and returns an argparse.Namespace object containing the parsed arguments.
Args:
- config_path: str
Path to the config.yaml file.
Returns:
- args: argparse.Namespace
Parsed command-line arguments.
"""
# Load default configuration from config.yaml
with open(config_path, "r") as config_file:
config = yaml.safe_load(config_file)
parser = argparse.ArgumentParser(description="Argument parser for your script")
# General
parser.add_argument(
"--gpu_id", type=int, default=config["general"]["gpu_id"], help="GPU ID"
)
parser.add_argument(
"--seed", type=int, default=config["general"]["seed"], help="Random seed"
)
parser.add_argument(
"--n_runs",
type=int,
default=config["general"]["n_runs"],
help="The number of independent runs",
)
parser.add_argument(
"--debug", type=bool, default=config["general"]["debug"], help="Debug mode"
)
# Dataset
parser.add_argument(
"--dataset", type=str, default=config["dataset"]["dataset"], help="Dataset Name"
)
parser.add_argument(
"--imb_type",
type=str,
default=config["dataset"]["imb_type"],
choices=IMB_TYPES,
help="Imbalance type",
)
parser.add_argument(
"--imb_ratio",
type=int,
default=config["dataset"]["imb_ratio"],
help="Imbalance Ratio",
)
# Architecture
parser.add_argument(
"--gnn_arch",
type=str,
default=config["architecture"]["gnn_arch"],
choices=GNN_ARCHS,
)
parser.add_argument(
"--n_layer",
type=int,
default=config["architecture"]["n_layer"],
help="The number of layers",
)
parser.add_argument(
"--hid_dim",
type=int,
default=config["architecture"]["hid_dim"],
help="Hidden dimension",
)
# Training
parser.add_argument(
"--lr",
type=float,
default=config["training"]["lr"],
help="Initial learning rate",
)
parser.add_argument(
"--weight_decay",
type=float,
default=config["training"]["weight_decay"],
help="Weight decay",
)
parser.add_argument(
"--epochs",
type=int,
default=config["training"]["epochs"],
help="The number of training epochs",
)
parser.add_argument(
"--early_stop",
type=int,
default=config["training"]["early_stop"],
help="Early stop patience",
)
parser.add_argument(
"--tqdm",
type=bool,
default=config["training"]["tqdm"],
help="Enable tqdm progress bar",
)
# ToBE parameters
parser.add_argument(
"--bat_mode",
type=str,
default=config["bat_parameters"]["bat_mode"],
choices=BAT_MODES,
help="Mode of BAT, can be 'dummy', 'bat0', 'bat1', or 'all'",
)
# Parse args
args = parser.parse_args()
return args