Name-sorted parameters in `qiskit.opflow`
See original GitHub issueWhat is the expected enhancement?
Binding parameters to a parameterized Opflow objects requires passing a dictionary with {parameter_instance: value}
pairs. More often than not, this is used in the following setting
my_circuit = # ...
expression = # some opflow expression using the circuit
param_dict = dict(zip(my_circuit.parameters, my_values))
bound_expression = expression.bind_parameters(param_dict)
which is a bit cumbersome as we either have to carry along the parameters we’re interested in or have to write an extra line defining the param_dict
.
Instead if would be nice to allow binding the parameters using only an array. Since we introduced a global parameter order in #5759, which says that parameters are sorted by name, that would be easy to implement. Using the same ordering convention as for the circuits, we could simply write
my_circuit = # ...
expression = # some opflow expression using the circuit
bound_expression = expression.bind_parameters(values)
Since Opflow objects already implement the parameter
attribute, the steps to implement this could for instance be
- ensure the
parameter
attribute returns aParameterView
object with parameters in the right order - if an array is passed into
bind_parameters
, construct the parameter dictionary for the user using the parameter order fromparameters
I’m labelling this as “good first issue”, but some previous experience with qiskit.opflow
would certainly be helpful!
Issue Analytics
- State:
- Created a year ago
- Comments:12 (9 by maintainers)
Top GitHub Comments
Hi @pradkrish, for the
QuantumCircuit
we’re already able to passmy_values
. But here’s a slightly modified example where we are currently not able to pass an array but would like toHello, is this issue still open? I am new to this project, happy to work on this with some guidance.