Skip to content

Commit 5b33798

Browse files
authored
Path too long error (#29)
* 🐛 if a qasm str is inserted it is checked for being a file path and led to an error because the str was too long for a path * test * 🐛 fixed a conversion from Path to str for the length check
1 parent 1daba1e commit 5b33798

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

src/mqt/predictor/driver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def generate_training_sample(
297297
if num_not_empty_entries == 0:
298298
return False
299299

300-
feature_vec = utils.create_feature_dict(Path(source_path) / file)
300+
feature_vec = utils.create_feature_dict(str(Path(source_path) / file))
301301
training_sample = (list(feature_vec.values()), np.argmax(scores))
302302
circuit_name = file.split(".")[0]
303303

src/mqt/predictor/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def init_all_config_files():
302302

303303
def create_feature_dict(qasm_str_or_path: str):
304304

305-
if Path(qasm_str_or_path).exists():
305+
if len(qasm_str_or_path) < 260 and Path(qasm_str_or_path).exists():
306306
qc = QuantumCircuit.from_qasm_file(qasm_str_or_path)
307307
elif "OPENQASM" in qasm_str_or_path:
308308
qc = QuantumCircuit.from_qasm_str(qasm_str_or_path)

tests/test_driver.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ def test_predict(mock_show):
2020
path = resources.files("mqt.predictor") / "trained_clf.joblib"
2121
assert path.is_file()
2222
filename = "test_qasm.qasm"
23-
benchmark_generator.get_one_benchmark("dj", 1, 8).qasm(filename=filename)
23+
qc = benchmark_generator.get_one_benchmark("dj", 1, 8)
24+
qc.qasm(filename=filename)
2425
predictor = Predictor()
2526
prediction = predictor.predict(filename)
2627
assert prediction >= 0 and prediction < len(utils.get_index_to_comppath_LUT())
28+
prediction = predictor.predict(qc.qasm())
29+
assert prediction >= 0 and prediction < len(utils.get_index_to_comppath_LUT())
2730
prediction = predictor.predict("fail test")
2831
assert not prediction
2932

0 commit comments

Comments
 (0)