This issue is a result of a Codex global code scan of deepmodeling/fpop at commit b05b337590c31a5237b2dcbd9c0833b841c08cd4.
Relevant code:
|
def read_inputf(inputf: Union[str,Path]) -> dict: |
|
"""Read INPUT and transfer to a dict. |
|
|
|
Parameters |
|
---------- |
|
inputf : str |
|
INPUT file name |
|
|
|
Returns |
|
------- |
|
dict[str,str] |
|
all input parameters |
|
""" |
|
input_context = {} |
|
with open(inputf) as f1: input_lines = f1.readlines() |
|
readinput = False |
|
for i,iline in enumerate(input_lines): |
|
if iline.strip() == 'INPUT_PARAMETERS': |
|
readinput = True |
|
elif iline.strip() == '' or iline.strip()[0] in ['#']: |
|
continue |
|
elif readinput: |
|
sline =re.split('[ \t]',iline.split("#")[0].strip(),maxsplit=1) |
|
if len(sline) == 2: |
|
input_context[sline[0].lower().strip()] = sline[1].strip() |
|
return input_context |
|
def write_deepks(self): |
|
"""Check if INPUT is a deepks job, if yes, will return the deepks descriptor file name, |
|
else will return None. |
|
|
|
Returns |
|
------- |
|
str |
|
deepks descriptor file name or None. |
|
""" |
|
need_descriptor = need_model = False |
|
if self._input.get("deepks_out_labels",False): |
|
need_descriptor = True |
|
if self._input.get("deepks_scf",False): |
|
need_descriptor = True |
|
need_model = True |
|
|
|
if need_descriptor: |
|
assert(self._deepks_descriptor != None) |
|
descriptor_file = self._deepks_descriptor[0] |
|
Path(descriptor_file).write_text(self._deepks_descriptor[1]) |
|
else: |
|
descriptor_file = None |
|
|
|
if need_model: |
|
assert(self._deepks_model != None) |
|
Path(self._deepks_model[0]).write_bytes(self._deepks_model[1]) |
|
|
|
return descriptor_file |
Problem:
AbacusInputs.read_inputf() stores all INPUT values as strings. AbacusInputs.write_deepks() then checks those values directly in boolean conditions:
if self._input.get("deepks_out_labels", False):
need_descriptor = True
if self._input.get("deepks_scf", False):
need_descriptor = True
need_model = True
Strings such as "0", "false", and "False" are truthy in Python, so an INPUT file that explicitly disables DeepKS can still force descriptor/model files and fail with an assertion.
Minimal reproduction:
INPUT_PARAMETERS
deepks_scf 0
deepks_out_labels 0
Constructing AbacusInputs(INPUT, {"H": "H.upf"}) and calling write_deepks() raises AssertionError because "0" is treated as enabled.
Expected behavior:
DeepKS switches should be parsed with ABACUS-compatible boolean semantics before write_deepks() decides whether descriptor or model files are required.
This issue is a result of a Codex global code scan of
deepmodeling/fpopat commitb05b337590c31a5237b2dcbd9c0833b841c08cd4.Relevant code:
fpop/fpop/abacus.py
Lines 399 to 424 in b05b337
fpop/fpop/abacus.py
Lines 466 to 493 in b05b337
Problem:
AbacusInputs.read_inputf()stores all INPUT values as strings.AbacusInputs.write_deepks()then checks those values directly in boolean conditions:Strings such as
"0","false", and"False"are truthy in Python, so an INPUT file that explicitly disables DeepKS can still force descriptor/model files and fail with an assertion.Minimal reproduction:
Constructing
AbacusInputs(INPUT, {"H": "H.upf"})and callingwrite_deepks()raisesAssertionErrorbecause"0"is treated as enabled.Expected behavior:
DeepKS switches should be parsed with ABACUS-compatible boolean semantics before
write_deepks()decides whether descriptor or model files are required.