Skip to content

Commit 6c99137

Browse files
adam-grofeAdam Grofe
andauthored
Raise Value Error for empty list. (#664)
* Raise Value Error for empty list * Add check for empty line at begining of xyz * Add test for empty line in xyz input --------- Co-authored-by: Adam Grofe <[email protected]>
1 parent 5b78c88 commit 6c99137

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

azure-quantum/azure/quantum/target/microsoft/elements/dft/target.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ def submit(self,
7979

8080
if isinstance(input_data, list):
8181

82+
if len(input_data) < 1:
83+
raise ValueError("Input data list has no elements.")
84+
8285
if all(isinstance(task,str) for task in input_data):
8386
qcschema_data = self.assemble_qcschema_from_files(input_data, input_params)
8487

@@ -257,7 +260,7 @@ def _xyz_to_qcschema_mol(self, file_data: str ) -> Dict[str, Any]:
257260
"""
258261

259262
lines = file_data.split("\n")
260-
if len(lines) < 3:
263+
if len(lines) < 3 or not lines[0]:
261264
raise ValueError("Invalid xyz format.")
262265
n_atoms = int(lines.pop(0))
263266
comment = lines.pop(0)

azure-quantum/tests/unit/test_microsoft_elements_dft.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,14 +332,22 @@ def test_xyz_parsing_correct_xyz_files(data_regression, xyz_str):
332332
H 1.00 0.00 0.00
333333
H -1.00 1.00 1.00
334334
H -1.00 1.00 1.00 -0.6
335+
""",
336+
"""
337+
3
338+
water
339+
O 0.00 0.00 0.00
340+
H 1.00 0.00 0.00
341+
H -1.00 1.00 1.00
335342
""",
336343
],
337344
ids=[
338345
'atom_missing',
339346
'atom_on_previous_line',
340347
'empty_line_in_middle',
341348
'duplicated_line',
342-
'mm_atom_without_dash'
349+
'mm_atom_without_dash',
350+
'empty_line_at_beginning'
343351
]
344352
)
345353
def test_xyz_raises_for_bad_input(xyz_str):

0 commit comments

Comments
 (0)