I'm trying to use the parametrized circuits to run a single model of quantum circuit with different values. Here's part of my code:

from qiskit import IBMQ
provider = IBMQ.load_account()
sim = provider.backends.ibmq_qasm_simulator
backend = provider.get_backend('ibmq_qasm_simulator')

probsu = []
for i in range(L):

    circuit = circuit.assign_parameters({Ei: EWi[i]})
    circuit = qc(Ei) 
    job_manager = IBMQJobManager()
    **MExperiment = job_manager.run(circuit, backend=backend, name='MExperiment')**
    result = MExperiment.result()

    Ta = '1'*N
    counts = result.get_counts(circuit)
    if Ta in counts:
        prob = counts[Ta]/sum(counts.values())
        prob = 0

Where qc(Ei) is a function of the quantum circuit model. EWi is an array of possible parameters that will be used. An error occurred at the line marked with **. Here's what qiskit shows me:

CircuitError: "Cannot bind parameters (['Ei']) not present in the circuit."

I'm not exactly sure, but it looks like parameterization requires the label 'Ei' to appear in the circuit. However, my circuit function takes the argument to accept some input like Ei. Is there a way I can fix this error? Thanks a lot for your help:)


If you want to create a parametrized quantum circuit in Qiskit, you can do it as follow:

%matplotlib inline
# Importing standard Qiskit libraries
from qiskit import QuantumCircuit, execute, Aer, IBMQ
from qiskit.compiler import transpile, assemble
from qiskit.tools.jupyter import *
from qiskit.visualization import *
from iqx import *
from qiskit.circuit import  ParameterVector
# Loading your IBM Q account(s)
provider = IBMQ.load_account()

param_circuit = QuantumCircuit(4)
params = ParameterVector('a', 4)
for i in range(4):
    param_circuit.ry(params[i], i)
param_circuit.draw('mpl',style={'name': 'bw'},  scale = 1)

enter image description here

You can pass the parameters in this circuit and update them through a classical optimizer etc.


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.