1
$\begingroup$

enter image description here

Is the parameter angle of the above picture the same, that is, each door rotates by an equal angle? How to assign different parameters to them, such as a[0], a1 of the same name? Is it possible to change the names of these parameters halfway through? That is, at a certain moment, change a[0], a1 two different variables into c[0], d1?

$\endgroup$

1 Answer 1

1
$\begingroup$

Is the parameter angle of the above picture the same

Yes. The code assigns the same parameter for all qubits.

How to assign different parameters to them, such as a[0], a1 of the same name?

You can use ParameterVector:

theta = ParameterVector("θ", 5)
theta_iter = iter(theta)

for i in range(n):
    qc.rz(next(theta_iter), i)

The result will be:

enter image description here

And when you bind the parameters to values, you can assign each parameter its own value:

from numpy import pi

bound_circuit = qc.bind_parameters({theta: [0, pi/5, 2*pi/5, 3*pi/5, 4*pi/5]})

Is it possible to change the names of these parameters halfway through?

Yes. You can use one Parameter with some qubits, and another one with the other qubits:

theta1 = Parameter('θ1')
theta2 = Parameter('θ2')

qc.rz(theta1, range(3))
qc.rz(theta2, range(3, 5))

The result:

enter image description here

$\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.