Is there a faster way to get 'a list of' result from 'a list of inputs'?

I had a question about obtaining the probability of a certain state from the histogram, still using this example, suppose there's a variable in my quantum circuit, it's values are stored in an 'np.linspace' array. This is the result obtained from one of the elements in that array: If I'm only interested in the probability of the '0010' state (0.831 here), is there a faster way I can get a list (or array) of the probability of '0010' using each element in my original linspace? I tried to incorporate a few commands (like job_sim and result_sim) into a function, but that doesn't work.

ps: The structure of my function looks something like this:

from qiskit import IBMQ
sim = provider.backends.ibmq_qasm_simulator
def qc(Variable):
qcz = QuantumCircuit(qrz,crz)
......
job_sim = execute(qcz, sim)
result_sim = job_sim.result()
counts = result_sim.get_counts()
probs = counts['0010'] / sum(counts.values())
return probs


After that I want to call the function using each of the elements in my linspace.

update:Sorry maybe I was a bit unclear in my original question, if my simulation result is determined by some variable X, for each value of X, I might obtain a different probability of the state '0010'. If there're N values of X, all of which are stored in an array and I want to run my circuit N times, is there a faster way I can do that instead of manually changing the variable and record the result? Thanks for the help:)

• sorry I missed read your question earlier :) Dec 7 '20 at 6:47
• @KAJ226 No problem, thanks:)
– ZR-
Dec 7 '20 at 6:52
• You might find it useful to use a parametrized circuit as documented here: qiskit.org/documentation/stubs/…
– giri
Dec 7 '20 at 6:58
• @Zhengrong so let's say $X$ has 10 variables, which resulted in 10 different circuits, are you then asking for a way to submit this 10 different circuits on a single job in Qiskit? instead of submit 10 different jobs with each job contains a single circuit. Dec 7 '20 at 7:01
• @KAJ226 Yes, this is exactly what I'm wondering:)
– ZR-
Dec 7 '20 at 7:10

You can do something like this:

%matplotlib inline
# Importing standard Qiskit libraries
from qiskit import QuantumCircuit, QuantumRegister,  IBMQ, ClassicalRegister
from qiskit.circuit import QuantumCircuit, ParameterVector
from qiskit.compiler import transpile, assemble
from qiskit.providers.ibmq.managed import IBMQJobManager
from qiskit.visualization import *
backend = provider.get_backend('ibmq_valencia')

def qc(Variable):
var_form = QuantumCircuit(2,2)
var_form.u1(Variable,0)
var_form.cx(0,1)
var_form.measure([0,1],[0,1])
return var_form

Variables = [1,2,3,4,5]
circuits = []
for i in range(len(Variables) ):
circuit =  QuantumCircuit(2,2)
circuit = qc(Variables[i])
circuits.append( circuit   )

circuits = transpile(circuits, backend=backend)
job_manager = IBMQJobManager()
MyExperiments = job_manager.run(circuits, backend=backend, name='MyExperiment')
results = MyExperiments.results()


Note that qc(Variable) is spitting out circuit output of the form:

so the Ry gate is taking in the variable. You can modify the circuit to your choice.

Now when I run this, and look in the IBMQX results tabs I see the following:

Hope this helps.

• Thanks, that's really helpful:) If I'm only interested in the probability of one of the states (say '11'), where should I put 'probs = counts['11'] / sum(counts.values())' so that I can get all the results in a list or array?
– ZR-
Dec 7 '20 at 17:09