-
Notifications
You must be signed in to change notification settings - Fork 242
Open
Description
Consider the following code:
# TorchQuantum to Qiskit
import torchquantum as tq
from torchquantum import QuantumDevice
from torchquantum.plugin.qiskit.qiskit_plugin import tq2qiskit
from qiskit.quantum_info import Statevector
class MyQNN(tq.QuantumModule):
def __init__(self):
super().__init__()
self.u3_gate = tq.U3(has_params=True, trainable=True)
self.cu3_gate = tq.CU3(has_params=True, trainable=True)
def forward(self, q_device: QuantumDevice):
self.u3_gate(q_device, wires=0)
self.cu3_gate(q_device, wires=[0, 1])
def main():
model = MyQNN()
q_device = QuantumDevice(n_wires=2, bsz=1)
print("Initial state:", q_device.get_states_1d())
circ_1 = tq2qiskit(q_device, model)
statevector_1 = Statevector(circ_1)
print("Statevector from circ_1:", statevector_1)
model(q_device)
print("State after model forward:", q_device.get_states_1d())
circ_2 = tq2qiskit(q_device, model)
statevector_2 = Statevector(circ_2)
print("Statevector from circ_2:", statevector_2)
if __name__ == "__main__":
main()
The statevectors from circ_1 and circ_2 are identical. I don’t think they should be, because circ_2 is generated after the device state has changed. Am I correct, or is this a bug in the tq2qiskit function?
Metadata
Metadata
Assignees
Labels
No labels