0
$\begingroup$

I was running this code on a quantum computer how can I generate a state vector for each shot while running on a quantum computer?

qikit code

## initiate alpha beta with own values
vector = [alpha,beta]
print('non normalised vector form a multi vector is')
print(vector)
norm = np.linalg.norm(vector)
print(norm)

qc = QuantumCircuit(1)  # Create a quantum circuit with one qubit
initial_state = vector/np.linalg.norm(vector)
print('initial state is')
print(initial_state)
qc.initialize(initial_state, 0) 
qc.x(0) ###### for not gate
qc.h(0) ####### for hadamard gate
a = qc.draw() 
print(a)

simulator = Aer.get_backend('statevector_simulator') 
qobj = assemble(qc)     # Create a Qobj from the circuit for the simulator to run
result = simulator.run(qobj).result() # Do the simulation and return the result
out_state = result.get_statevector()
print(out_state)



 from qiskit import IBMQ

 IBMQ.load_account()
 #provider = IBMQ.get_provider = ('ibm-q')
 provider = IBMQ.load_account()
 qcomp= provider.get_backend('ibmq_qasm_simulator')
 job = execute(qc,backend=qcomp)
 from qiskit.tools.monitor import  job_monitor
 job_monitor(job)
 result = job.result()
 plot_histogram(result.get_counts(qc))
$\endgroup$
0
$\begingroup$

You can use the qiskit Snapshot extension. Here is an example:

from qiskit.providers.aer.extensions.snapshot import Snapshot
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit import QuantumCircuit, execute, Aer

circuit = QuantumCircuit(1, 1)
circuit.h(0)
circuit.measure([0], [0])
circuit.snapshot('final', snapshot_type='statevector')

print(circuit)
backend = Aer.get_backend('qasm_simulator')
job = execute(circuit, backend, shots = 10)
result = job.result()
pprint(result.data(0)['snapshots'])

     ┌───┐┌─┐┌───────┐
q_0: ┤ H ├┤M├┤ final ├
     └───┘└╥┘└───────┘
c: 1/══════╩══════════
           0          
{'statevector': {'final': [array([1.+0.j, 0.+0.j]),
                           array([1.+0.j, 0.+0.j]),
                           array([0.+0.j, 1.+0.j]),
                           array([0.+0.j, 1.+0.j]),
                           array([0.+0.j, 1.+0.j]),
                           array([1.+0.j, 0.+0.j]),
                           array([1.+0.j, 0.+0.j]),
                           array([0.+0.j, 1.+0.j]),
                           array([1.+0.j, 0.+0.j]),
                           array([0.+0.j, 1.+0.j])]}}

$\endgroup$
2
  • $\begingroup$ Thank you for responding, Is it possible to run the snapshot on the real quantum computer? $\endgroup$ – bhagi radh Mar 2 at 5:09
  • $\begingroup$ No. I don't think so. $\endgroup$ – KAJ226 Mar 2 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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