Skip to content

Commit 5bc97d0

Browse files
committed
[review] use set instead of list
1 parent 5b190a4 commit 5bc97d0

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

pkg/suggestion/v1beta1/nas/common/validation.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
def validate_operations(operations: list[api_pb2.Operation]) -> (bool, str):
1919

2020
# Validate each operation
21-
for operation in operations:
21+
for operation in set(operations):
2222

2323
# Check OperationType
2424
if not operation.operation_type:
@@ -29,8 +29,7 @@ def validate_operations(operations: list[api_pb2.Operation]) -> (bool, str):
2929
return False, "Missing ParameterConfigs in Operation:\n{}".format(operation)
3030

3131
# Validate each ParameterConfig in Operation
32-
parameters_list = list(operation.parameter_specs.parameters)
33-
for parameter in parameters_list:
32+
for parameter in set(operation.parameter_specs.parameters):
3433

3534
# Check Name
3635
if not parameter.name:

pkg/suggestion/v1beta1/nas/darts/service.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,17 +167,17 @@ def validate_algorithm_settings(algorithm_settings: list[api_pb2.AlgorithmSettin
167167
return False, "{} should be greater than zero".format(s.name)
168168

169169
# Validate learning rate
170-
if s.name in ["w_lr", "w_lr_min", "alpha_lr"]:
170+
if s.name in {"w_lr", "w_lr_min", "alpha_lr"}:
171171
if not float(s.value) >= 0.0:
172172
return False, "{} should be greater than or equal to zero".format(s.name)
173173

174174
# Validate weight decay
175-
if s.name in ["w_weight_decay", "alpha_weight_decay"]:
175+
if s.name in {"w_weight_decay", "alpha_weight_decay"}:
176176
if not float(s.value) >= 0.0:
177177
return False, "{} should be greater than or equal to zero".format(s.name)
178178

179179
# Validate w_momentum and w_grad_clip
180-
if s.name in ["w_momentum", "w_grad_clip"]:
180+
if s.name in {"w_momentum", "w_grad_clip"}:
181181
if not float(s.value) >= 0.0:
182182
return False, "{} should be greater than or equal to zero".format(s.name)
183183

@@ -190,7 +190,7 @@ def validate_algorithm_settings(algorithm_settings: list[api_pb2.AlgorithmSettin
190190
return False, "num_workers should be greater than or equal to zero"
191191

192192
# Validate "init_channels", "print_step", "num_nodes" and "stem_multiplier"
193-
if s.name in ["init_channels", "print_step", "num_nodes", "stem_multiplier"]:
193+
if s.name in {"init_channels", "print_step", "num_nodes", "stem_multiplier"}:
194194
if not int(s.value) >= 1:
195195
return False, "{} should be greater than or equal to one".format(s.name)
196196

0 commit comments

Comments
 (0)