Skip to content

Commit b1d5a38

Browse files
committed
Replace the function preparse to default_group_name.
The previous function name `preparse` is not proper, the only usage of it is to get the default group name, so change it to better function name, by the way, we also update the argument of it from `tuple[str, ...]` to `ModelConfig` as the process from tuple to config is common and we shall run it in `common.py`. PR: USTC-KnowledgeComputingLab/qmb#38 Signed-off-by: Hao Zhang <[email protected]>
2 parents ac2e41b + c220c64 commit b1d5a38

File tree

6 files changed

+29
-32
lines changed

6 files changed

+29
-32
lines changed

qmb/common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ def main(self, *, model_param: typing.Any = None, network_param: typing.Any = No
107107
if "-h" in self.network_args or "--help" in self.network_args:
108108
tyro.cli(network_config_t, args=self.network_args)
109109
if self.group_name is None:
110-
self.group_name = model_t.preparse(self.physics_args)
110+
model_param_for_group_name = tyro.cli(model_config_t, args=self.physics_args)
111+
self.group_name = model_t.default_group_name(model_param_for_group_name)
111112

112113
self.folder().mkdir(parents=True, exist_ok=True)
113114

qmb/fcidump.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,8 @@ class Model(ModelProto[ModelConfig]):
124124
config_t = ModelConfig
125125

126126
@classmethod
127-
def preparse(cls, input_args: tuple[str, ...]) -> str:
128-
args: ModelConfig = tyro.cli(ModelConfig, args=input_args)
129-
return args.model_name
127+
def default_group_name(cls, config: ModelConfig) -> str:
128+
return config.model_name
130129

131130
def __init__(self, args: ModelConfig) -> None:
132131
# pylint: disable=too-many-locals

qmb/hubbard.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ class Model(ModelProto[ModelConfig]):
5757
config_t = ModelConfig
5858

5959
@classmethod
60-
def preparse(cls, input_args: tuple[str, ...]) -> str:
61-
args = tyro.cli(ModelConfig, args=input_args)
62-
return f"Hubbard_{args.m}x{args.n}_t{args.t}_u{args.u}"
60+
def default_group_name(cls, config: ModelConfig) -> str:
61+
return f"Hubbard_{config.m}x{config.n}_t{config.t}_u{config.u}"
6362

6463
@classmethod
6564
def _prepare_hamiltonian(cls, args: ModelConfig) -> dict[tuple[tuple[int, int], ...], complex]:

qmb/ising.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,26 +72,25 @@ class Model(ModelProto[ModelConfig]):
7272
config_t = ModelConfig
7373

7474
@classmethod
75-
def preparse(cls, input_args: tuple[str, ...]) -> str:
75+
def default_group_name(cls, config: ModelConfig) -> str:
7676
# pylint: disable=too-many-locals
77-
args = tyro.cli(ModelConfig, args=input_args)
78-
x = f"_x{args.x}" if args.x != 0 else ""
79-
y = f"_y{args.y}" if args.y != 0 else ""
80-
z = f"_z{args.z}" if args.z != 0 else ""
81-
xh = f"_xh{args.xh}" if args.xh != 0 else ""
82-
yh = f"_yh{args.yh}" if args.yh != 0 else ""
83-
zh = f"_zh{args.zh}" if args.zh != 0 else ""
84-
xv = f"_xv{args.xv}" if args.xv != 0 else ""
85-
yv = f"_yv{args.yv}" if args.yv != 0 else ""
86-
zv = f"_zv{args.zv}" if args.zv != 0 else ""
87-
xd = f"_xd{args.xd}" if args.xd != 0 else ""
88-
yd = f"_yd{args.yd}" if args.yd != 0 else ""
89-
zd = f"_zd{args.zd}" if args.zd != 0 else ""
90-
xa = f"_xa{args.xa}" if args.xa != 0 else ""
91-
ya = f"_ya{args.ya}" if args.ya != 0 else ""
92-
za = f"_za{args.za}" if args.za != 0 else ""
77+
x = f"_x{config.x}" if config.x != 0 else ""
78+
y = f"_y{config.y}" if config.y != 0 else ""
79+
z = f"_z{config.z}" if config.z != 0 else ""
80+
xh = f"_xh{config.xh}" if config.xh != 0 else ""
81+
yh = f"_yh{config.yh}" if config.yh != 0 else ""
82+
zh = f"_zh{config.zh}" if config.zh != 0 else ""
83+
xv = f"_xv{config.xv}" if config.xv != 0 else ""
84+
yv = f"_yv{config.yv}" if config.yv != 0 else ""
85+
zv = f"_zv{config.zv}" if config.zv != 0 else ""
86+
xd = f"_xd{config.xd}" if config.xd != 0 else ""
87+
yd = f"_yd{config.yd}" if config.yd != 0 else ""
88+
zd = f"_zd{config.zd}" if config.zd != 0 else ""
89+
xa = f"_xa{config.xa}" if config.xa != 0 else ""
90+
ya = f"_ya{config.ya}" if config.ya != 0 else ""
91+
za = f"_za{config.za}" if config.za != 0 else ""
9392
desc = x + y + z + xh + yh + zh + xv + yv + zv + xd + yd + zd + xa + ya + za
94-
return f"Ising_{args.m}_{args.n}" + desc
93+
return f"Ising_{config.m}_{config.n}" + desc
9594

9695
@classmethod
9796
def _prepare_hamiltonian(cls, args: ModelConfig) -> dict[tuple[tuple[int, int], ...], complex]:

qmb/model_dict.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@ class ModelProto(typing.Protocol[ModelConfig]):
108108
config_t: type[ModelConfig]
109109

110110
@classmethod
111-
def preparse(cls, input_args: tuple[str, ...]) -> str:
111+
def default_group_name(cls, config: ModelConfig) -> str:
112112
"""
113-
Preparse the arguments to obtain the group name for logging perposes
113+
Get the default group name for logging purposes.
114114
115115
Parameters
116116
----------
117-
input_args : tuple[str, ...]
118-
The input arguments to the model.
117+
config : ModelConfig
118+
The config of model.
119119
120120
Returns
121121
-------

qmb/openfermion.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ class Model(ModelProto[ModelConfig]):
5050
config_t = ModelConfig
5151

5252
@classmethod
53-
def preparse(cls, input_args: tuple[str, ...]) -> str:
54-
args: ModelConfig = tyro.cli(ModelConfig, args=input_args)
55-
return args.model_name
53+
def default_group_name(cls, config: ModelConfig) -> str:
54+
return config.model_name
5655

5756
def __init__(self, args: ModelConfig) -> None:
5857
logging.info("Input arguments successfully parsed")

0 commit comments

Comments
 (0)