Skip to content

Commit 26f7dde

Browse files
authored
Fix default arguments for PyQrack. (#223)
I'm gonna open an issue on PyQrack repo about this it would be good to know what are good flags to pass into the `QrackSimulator` object. Currently, some configurations of options will cause a runtime error when executing the simulation instead of a value error when constructing the object. I'll add validation on the arguments passed into the `QrackSimulator` object as we slowly figure out the bad behavior.
1 parent badf341 commit 26f7dde

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/bloqade/pyqrack/base.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,28 @@ class PyQrackOptions(typing.TypedDict):
2626
isOpenCL: bool
2727

2828

29+
def _validate_pyqrack_options(options: PyQrackOptions) -> None:
30+
if options["isBinaryDecisionTree"] and options["isStabilizerHybrid"]:
31+
raise ValueError(
32+
"Cannot use both isBinaryDecisionTree and isStabilizerHybrid at the same time."
33+
)
34+
elif options["isTensorNetwork"] and options["isBinaryDecisionTree"]:
35+
raise ValueError(
36+
"Cannot use both isTensorNetwork and isBinaryDecisionTree at the same time."
37+
)
38+
elif options["isTensorNetwork"] and options["isStabilizerHybrid"]:
39+
raise ValueError(
40+
"Cannot use both isTensorNetwork and isStabilizerHybrid at the same time."
41+
)
42+
43+
2944
def _default_pyqrack_args() -> PyQrackOptions:
3045
return PyQrackOptions(
3146
qubitCount=-1,
3247
isTensorNetwork=False,
3348
isSchmidtDecomposeMulti=True,
3449
isSchmidtDecompose=True,
35-
isStabilizerHybrid=True,
50+
isStabilizerHybrid=False,
3651
isBinaryDecisionTree=True,
3752
isPaged=True,
3853
isCpuGpuHybrid=True,
@@ -45,6 +60,9 @@ class MemoryABC(abc.ABC):
4560
pyqrack_options: PyQrackOptions = field(default_factory=_default_pyqrack_args)
4661
sim_reg: "QrackSimulator" = field(init=False)
4762

63+
def __post_init__(self):
64+
_validate_pyqrack_options(self.pyqrack_options)
65+
4866
@abc.abstractmethod
4967
def allocate(self, n_qubits: int) -> tuple[int, ...]:
5068
"""Allocate `n_qubits` qubits and return their ids."""

test/pyqrack/test_target.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ def multiple_registers():
103103

104104
return q1
105105

106-
target = PyQrack(6)
106+
target = PyQrack(
107+
6, pyqrack_options={"isBinaryDecisionTree": False, "isStabilizerHybrid": True}
108+
)
107109
q1 = target.run(multiple_registers)
108110

109111
assert isinstance(q1, ilist.IList)

0 commit comments

Comments
 (0)