# What is the best way to handle parametric circuits in Qiskit?

Quantum Computing Asked by Bidon on December 9, 2020

What is the best way to handle parametric circuits in Qiskit? When I create a variational form like TwoLocal and then do var_form.parameters it returns a set but that is an unordered structure so I fear that it will give me different results upon different calls.

Here is what I have:

var_form = TwoLocal(num_qubits=4,
rotation_blocks=["ry","rx"],
entanglement_blocks=["cx"],
entanglement="full",
reps=1,
skip_final_rotation_layer=False,
insert_barriers=True)

parameters=np.random.random(var_form.num_parameters)
param_dict={}
for i in range(var_form.num_parameters):
param_dict[list(var_form.parameters)[i]]=parameters[i]


Here is what I want:

def get_var_form(parameters):
"""parameters is a list like [0,1,2,3,4....]"""

##
# DO MAGIC HERE
var_form = TwoLocal(num_qubits=4,
rotation_blocks=["ry","rx"],
entanglement_blocks=["cx"],
entanglement="full",
reps=1,
skip_final_rotation_layer=False,
insert_barriers=True)

#I want to insert parameters----->var_form
##

return var_form #with given parameters


How can I do this?

This is what I came up with:

param_dict={}
for i in range(var_form.num_parameters):
param_dict[list(var_form.ordered_parameters)[i]]=parameters[i]

ansatz=var_form.bind_parameters(param_dict)


maybe its not the best way, but it works...

Answered by Bidon on December 9, 2020

## Related Questions

### How can I measure a qubit on a generic axis on Qiskit?

0  Asked on April 12, 2021 by marco-gobbo

### How does a map being “only” positive reflect on its Choi representation?

1  Asked on April 12, 2021

### What are the possible gates that I can use to vary input states before CNOT?

1  Asked on April 11, 2021 by gem

### Why is HHL the popular choice to solve QLSP and not the Childs et al. (2017) algorithm?

0  Asked on April 11, 2021

### How can a half-wave plate affect the position qubit and not the polarization qubit of a photon?

1  Asked on April 10, 2021

### Can I run Cirq on IBMQ?

2  Asked on April 9, 2021

### What makes representing qubits in a 3D real vector space possible?

4  Asked on April 9, 2021

### Condition that a tripartite/multipartite qubit state does/does not admit a Schmidt decomposition?

1  Asked on April 8, 2021

### Comparing QSVM & Classic SVM on BigData. Quantum Supremacy

1  Asked on April 7, 2021

### Decomposition of any 2-level matrix into single qubit and CNOT gates

1  Asked on April 6, 2021 by bilanush

### How do I determine if a given pure two-qubit state is separable?

1  Asked on April 6, 2021

### What is the relationship between these two definitions for the max-entropy?

1  Asked on April 6, 2021

### What are the available compilers for Trapped-Ion Quantum Computing Architecture?

2  Asked on April 5, 2021 by abdullah-ash-saki

### How can I generate a quaternion using Qiskit?

1  Asked on April 5, 2021

### What does the term efficiency mean when talking about quantum memories?

0  Asked on April 5, 2021 by jason-pereira

### Where do errors occur during error syndrome and recovery?

1  Asked on April 4, 2021

### Can the following Bell states have probability amplitudes other than 1/2 and still be entangled?

2  Asked on April 4, 2021

### Is back in time (classical) information transfer possible (based on delayed choice entanglement swapping)?

1  Asked on April 3, 2021

### Understanding partial trace

2  Asked on April 3, 2021 by snickers_stickers

### Sampling random circuits vs Solovay-Kitaev compiler

1  Asked on April 2, 2021 by yaroslav-kharkov