5
$\begingroup$

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.

$\endgroup$
2

1 Answer 1

3
$\begingroup$

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]]]}.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.