Circuit parameters do not respect insertion order
See original GitHub issueEnvironment
- Qiskit Terra version: 0.19.2
- Python version: 3.7.7
- Operating system: OSX
What is happening?
Parameters are not implemented on a parametrized circuit in the order defined by a user, but alphabetically. The circuit diagram shows the insertion order, but binding parameters is not done in the same order.
How can we reproduce the issue?
In the following example, I want to assign value [1, 2, 3] to [theta, gamma, lam]. The circuit diagram shows the order I defined, .i.e. theta, gamma , lam but the values are assigned in the alphabetical order rather than the insertion order, therefore, the parameters get wrong values.
param_keys = Parameter('theta'), Parameter('gamma'), Parameter('lam')
ansatz = QuantumCircuit(1)
ansatz.u(*(param_keys), 0)
print(ansatz)
param_vals = np.array([1, 2, 3])
qc = ansatz.assign_parameters(param_vals)
print(qc)
ββββββββββββββββββββββ
q: β€ U(theta,gamma,lam) β
ββββββββββββββββββββββ
ββββββββββββ
q: β€ U(3,1,2) β
ββββββββββββ
What should happen?
The list of the parameters should be bound in the order that is given by a user.
Any suggestions?
No response
Issue Analytics
- State:
- Created a year ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Generic Key/Value pair collection in that preserves insertion ...
I'm looking for something like a Dictionary<K,V> however with a guarantee that it preserves insertion order. Since Dictionary is a hashtable, I do...
Read more >qiskit.circuit.QuantumCircuit
The snippet below shows that insertion order of parameters does not matter. >>> from qiskit.circuit import QuantumCircuit, Parameter >>> a, b,Β ...
Read more >RF engineering basic concepts: S-parameters
Abstract. The concept of describing RF circuits in terms of waves is discussed and the. S-matrix and related matrices are defined.
Read more >Understanding and Interpreting Standard-Logic Data Sheets
This means that any current that flows out of the respective terminal is considered to be a negative quantity.
Read more >SPICE Circuit Components
N1 and N2 are the two element nodes. VALUE is the resistance (in ohms) and may be positive or negative but not zero....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the explanation Julien, and Iβm glad this is all ok. Iβll close the issue now, but feel free to open a new one if there are bugs in the handling.
We decided against sorting by insertion because then the order in which you call the gate, a seemingly random choice, would have an effect on how the array of values will be bound. That wouldβve likely been a source of bugs in particular in the applications and implementation-wise it would be more effort since it would require book-keeping of the parameter order when ever we transpile or modify the circuit. Sorting by name is a global order which doesnβt have these drawbacks π