I am trying to run a QumodeCircuit on GPU with UAny gate. Initial states are set on 'cuda', but when the input unitary is np.array, RuntimeError turns out, saying unitary on cpu device.
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu and cuda:0! (when checking argument for argument mat2 in method wrapper_CUDA_mm)
Potential Reasons
UAnyGateclass in gate.py returns a new tensor without declaring the device, in line 830 :
if not isinstance(unitary, torch.Tensor):unitary = torch.tensor(unitary, dtype=torch.cfloat).reshape(-1, len(self.wires))
Possible Solutions
Though reasons are clear, I don't know how to refer device = init_state.device, as they seems to be run seperately.
If restricting users to revert unitary to torch.tensor and to('cuda') if they want to run on GPU, then we should convert it to complex data type instead of asserting a warning.
Problem Description
I am trying to run a
QumodeCircuit
on GPU withUAny
gate. Initial states are set on'cuda'
, but when the input unitary isnp.array
, RuntimeError turns out, saying unitary on cpu device.Potential Reasons
UAnyGate
class ingate.py
returns a new tensor without declaring the device, in line 830 :if not isinstance(unitary, torch.Tensor):
unitary = torch.tensor(unitary, dtype=torch.cfloat).reshape(-1, len(self.wires))
Possible Solutions
Though reasons are clear, I don't know how to refer device = init_state.device, as they seems to be run seperately.
If restricting users to revert unitary to torch.tensor and to('cuda') if they want to run on GPU, then we should convert it to complex data type instead of asserting a warning.