Skip to content

Commit de0e87d

Browse files
committed
windows compat
1 parent b429de6 commit de0e87d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/klay/__init__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from collections.abc import Sequence
66
import tempfile
7+
import os
78
from pathlib import Path
89

910

@@ -52,9 +53,16 @@ def add_sdd(self: Circuit, sdd: "SddNode", true_lits: Sequence[int] = (), false_
5253
5354
.. _SDDNode: https://pysdd.readthedocs.io/en/latest/classes/SddNode.html
5455
"""
55-
with tempfile.NamedTemporaryFile() as tmp:
56-
sdd.save(bytes(Path(tmp.name)))
57-
return self.add_sdd_from_file(tmp.name, true_lits, false_lits)
56+
# Use delete=False for Windows compatibility - the file must be closed
57+
# before other processes can access it on Windows
58+
with tempfile.NamedTemporaryFile(delete=False) as tmp:
59+
tmp_path = tmp.name
60+
61+
try:
62+
sdd.save(bytes(Path(tmp_path)))
63+
return self.add_sdd_from_file(tmp_path, true_lits, false_lits)
64+
finally:
65+
os.unlink(tmp_path)
5866

5967

6068
Circuit.to_torch_module = to_torch_module

0 commit comments

Comments
 (0)