Is there any way to get information from intermediate points in the execution of a quantum circuit. This is not possible on real quantum hardware but would be very useful on the Aer simulators for both learning quantum programming and for debugging.
-
2$\begingroup$ A short answer for now: check out the snapshot function introduced in 0.5 medium.com/qiskit/… $\endgroup$– James WoottonDec 29, 2018 at 9:57
-
$\begingroup$ Thanks @JamesWootton. I do not think this is currently implemented though: github.com/Qiskit/qiskit-terra/blob/… $\endgroup$– Daniel MahlerJan 1, 2019 at 8:07
1 Answer
This feature is now available using the snapshot
function of Qiskit Aer. Snapshots can be added to the circuit and the values are then returned in the results object.
This is an example of how you can create a circuit, add a snapshot to it and then get the result:
from qiskit import *
qc = QuantumCircuit(2)
qc.h(0)
qc.snapshot('1') # add a snapshot with the key '1'
qc.h(0) # add more gates after the snapshot
backend = Aer.get_backend('statevector_simulator')
result = execute(qc, backend).result()
snapshots = result.data()['snapshots']['statevector']
snapshots
now contains a dictionary where the keys are the names given to the snapshots, and the values are an array of state vectors associated with that key.
In this example it is{'1': [[[0.7071067811865476, 0.0], [0.7071067811865475, 0.0], [0.0, 0.0], [0.0, 0.0]]]}
.