1
$\begingroup$

I'm running a quantum simulation and want to obtain some information from a single shot of an experiment. Here's part of the code I'm working on:

for i in range(Nshot):
    Expeb = []
    for measure_circuit in [circ_1, circ_2, circ_3, circ_4]:
        measure_circuit = transpile(measure_circuit,backend=backend,optimization_level=2,initial_layout = [1])
        counts = execute(measure_circuit, backend = backend, shots=1).result().get_counts()
        for output in ['0','1']:
            if output not in counts:
                counts[output] = 0
        expe = (counts['0'] - counts['1']) 
        Expeb.append(expe)
    Est = sum(x*y for x,y in zip(Expeb,[a,b,c,d]))

The code works on simulators, but it might take a very long time if Nshot gets large (Like 5000, I think that's because I generated a lot of circuits) and I submit the jobs to a quantum device. I wonder is there a way I can extract information (like making calculations for) a single shot but in a more efficient way? Thanks for the help!

$\endgroup$
4
  • $\begingroup$ If I understand your question correctly, then in general this is probably not the case since a single shot won't give you enough statistic. $\endgroup$
    – KAJ226
    Aug 9, 2021 at 16:20
  • $\begingroup$ @KAJ226 Thanks for the comment! I want to do some calculations from the results of a single shot and repeat the process many times to get more statistics:) (shots = 1, but Nshot could be large) $\endgroup$
    – ZR-
    Aug 9, 2021 at 16:24
  • $\begingroup$ Ah, I see what you mean now. I should note that if this is the case then this means you have to resubmit the circuit from start every time... which adds a lot of overhead time (validation etc...) $\endgroup$
    – KAJ226
    Aug 9, 2021 at 18:10
  • $\begingroup$ @KAJ226 Haha thanks! $\endgroup$
    – ZR-
    Aug 9, 2021 at 18:51

1 Answer 1

2
$\begingroup$

You can use memory option. It will make the per-shot measurement bit-strings returned in the result:

memory = execute(measure_circuit, backend = backend, memory = True, shots = 1024).result().get_memory()
$\endgroup$
3
  • 1
    $\begingroup$ Thanks for the answer! I just checked out the document here: qiskit.org/documentation/stubs/…. Does the length of bitstring represents how many qubits you have, and the length of the returned list represents the number of shots? $\endgroup$
    – ZR-
    Aug 9, 2021 at 16:45
  • 1
    $\begingroup$ Yes. For 1024 shots, the returned list will contain 1024 entries. $\endgroup$ Aug 9, 2021 at 16:50
  • $\begingroup$ Awesome! Thank you! $\endgroup$
    – ZR-
    Aug 9, 2021 at 16:54

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.