2
$\begingroup$

It seems that "assign_parameters" method introduces the values of the parameters in alphabetical order of different "ParameterVector"s' names. Here is a simple example:

import qiskit
from qiskit import QuantumCircuit

qc = QuantumCircuit(2)


b = qiskit.circuit.ParameterVector('beta', 2)  
a = qiskit.circuit.ParameterVector('alfa', 2)
d = qiskit.circuit.ParameterVector('delta', 1)

qc.rx(b[0],0)                             
qc.rx(b[1],1)
qc.ry(a[0],0)    
qc.ry(a[1],1)
qc.rz(d[0],0)     

values= [1,2,3,4,5]

print(qc.parameters)

qc.assign_parameters(values, inplace=True) 

qc.draw("mpl")

circuit with assigned parameter values

Is there a way to introduce them in the temporal order of the circuit diagram? Is the same order applied when introducing parameters as an argument in Estimator().run(circuit, observable, parameters) ?

Thank you in advance!

$\endgroup$

1 Answer 1

2
$\begingroup$

Since the "temporal order" is not unique if we compile the circuit (or e.g. if operations commute), Qiskit assigns the parameters sorted by parameter name. This remains unique under circuit transformation and therefore binding values at different compilation stages always gives the same result. See also the original PR for more info.

If you want to enforce a "temporal order", you could insert barriers after each timeslice, which will ensure the compiler doesn't move the operations around (note that this will also prevent some optimizations). Then you could name the parameters after the timeslices, something like Parameter("<slice_num>_...").

Is the same order applied when introducing parameters as an argument in Estimator().run(circuit, observable, parameters) ?

Yes, since this code internally calls circuit.assign_parameters(parameters).

$\endgroup$

Your Answer

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

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