Classical simulation doesn't work for registers with non-empty shape and dtype != QUInt
Closed this issue · 1 comments
tanujkhattar commented
The following sample code fails with an error:
import attrs
from qualtran import QInt, Bloq, Signature, Register
@attrs.frozen
class TestMultiDimensionalReg(Bloq):
n: int
@property
def signature(self):
return Signature([Register('x', QInt(32), shape=(self.n,))])
def on_classical_vals(self, x):
print(x)
return {'x': x}
bloq = TestMultiDimensionalReg(10)
bloq.call_classically(x=[-1] * 10)
Issue is due to hardcoded casts to unsiged types np.uint
s in
Qualtran/qualtran/simulation/classical_sim.py
Lines 47 to 56 in db8b993
mpharrigan commented
I suspect those casts harken back to the time when there weren't data types and the classical simulation only did unsigned integers. This is used to initialize a multidimensional numpy array to contain the values. The data type of this numpy array should probably delegate to the QDType