mqt-ddsim
mqt-ddsim copied to clipboard
✨ Statevector after partial measurement
What's the problem this feature will solve?
Add the possibility to extract the statevector after a partial measurement of the quantum circuit.
Context: Qiskit's Aer simulator allows extracting the statevector after measuring a subset of the qubits in the quantum circuit. Since the measurement outcome is random, it will pick one possible outcome of the partial measurement at random and return the resulting statevector after the measurement.
Small example that illustrates this behavior:
from qiskit import *
from mqt import ddsim
reg = QuantumRegister(2)
clreg = ClassicalRegister(2)
circ = QuantumCircuit(reg, clreg)
circ.h(reg[0])
circ.cx(reg[0], reg[1])
circ.measure(reg[0], clreg[0])
print(circ.draw(fold=-1))
backend = ddsim.DDSIMProvider().get_backend("statevector_simulator")
job = execute(circ, backend, shots=1000)
counts = job.result().get_counts(circ)
sv = job.result().get_statevector(circ)
print("DDSIM Statevector", sv)
print("DDSIM Counts", counts)
backend_aer = Aer.get_backend("aer_simulator")
tcirc = transpile(circ, backend_aer)
tcirc.save_statevector()
job = execute(tcirc, backend_aer, shots=1000)
counts = job.result().get_counts(tcirc)
sv = job.result().get_statevector(tcirc)
print("Aer Statevector", sv)
print("Aer Counts", counts)
The output DDSIM Statevector
will always be $1/\sqrt{2} (|00\rangle + |11\rangle)$. The output Aer Statevector
will alternate between $|00\rangle$ and $|11\rangle$ since these are the possible statevectors after the first qubit was measured.
Describe the solution you'd like
Since there is no one and only "correct" way, how the statevector should look like in the above scenario, I'd propose allowing both possbilities s.t. users can chose depending on their application area. So it might be possible to add a flag (maybe at the time of initializiation of the backend) that chooses the behavior.
One thing that is also not quite clear is how Qiskit chooses which statevector to return: Either by the measurement probability or with equal probability.
Or maybe it is possible to return all of them?
Thanks for the feature request. It should certainly be possible to get that working. I'll get back to you on that 👍🏻