Skip to content

Commit 79e3c99

Browse files
committed
Replace the function preparse to default_group_name.
1 parent 92eddc0 commit 79e3c99

File tree

5 files changed

+27
-29
lines changed

5 files changed

+27
-29
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/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
@@ -79,14 +79,14 @@ class ModelProto(typing.Protocol[ModelConfig]):
7979
config_t: type[ModelConfig]
8080

8181
@classmethod
82-
def preparse(cls, input_args: tuple[str, ...]) -> str:
82+
def default_group_name(cls, config: ModelConfig) -> str:
8383
"""
84-
Preparse the arguments to obtain the group name for logging perposes
84+
Get the default group name for logging purposes.
8585
8686
Parameters
8787
----------
88-
input_args : tuple[str, ...]
89-
The input arguments to the model.
88+
config : ModelConfig
89+
The config of model.
9090
9191
Returns
9292
-------

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)