EntangledQuery
  • Threads
  • Categories
  • Users
  • Seminar
  • forum
  • group
  • theaters
  • search
  1. Threads
  2. Qiskit
chevron_left Qiskit

How to create a list of parameters in qiskit?

  • forum 1 reply
  • last reply by Meng Oct. 28, 2021
  • Last
  • link
    Kosei
    Members 8 posts
    Oct. 28, 2021, 3:29 a.m. Oct. 28, 2021, 3:29 a.m.
    link

    I am trying to construct a parametrized circuit in qiskit, or a parametrized QAOA, which means I need to define a list of parameters. Currently I need to construct it one by one using

    theta = Parameter('θ')
    

    Is there a more efficient way that I can create $n$ number of parameters?

  • link
    BrownB
    Members 4 posts
    Oct. 28, 2021, 4:37 a.m. Oct. 28, 2021, 4:37 a.m.
    link

    You can use ParameterVector to create a list of parameters.

    from qiskit.circuit import ParameterVector, QuantumCircuit
    theta = ParameterVector('θ', 4)
    qc = QuantumCircuit(4)
    for i in range(4):
        qc.rx(theta[i],i)
    qc.draw()
    

    image.png

    Then bind the values:

    qc = qc.bind_parameters({theta: [2,3,4,5]})
    qc.draw()
    

    image.png

    image.png

    PNG, 14.1 KB, uploaded by BrownB on Oct. 28, 2021.

    image.png

    PNG, 15.5 KB, uploaded by BrownB on Oct. 28, 2021.

  • arrow_forward

    Thread has been moved from Quantum Computing Software.

    • By Meng on Oct. 28, 2021, 4:39 a.m..

There are no more posts in this thread.

  • EntangledQuery