-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Name-sorted parameters in qiskit.opflow
#7802
Comments
qiskit.opflow
Hello, is this issue still open? I am new to this project, happy to work on this with some guidance. |
Sure, thanks! I'll assign you now, so others know you're working on it. Feel free to ask questions here - @Cryoris knows rather more about opflow than I do, so he's the best person to ask. |
Nice to see you're interested! You can check out how the parameters are sorted in the quantum circuit and how they are assigned if not a dictionary but only a list of values is passed Let us know if you have any questions! |
I made an attempt to construct a circuit with parameters like this phase = Parameter("phase")
x = Parameter("x")
y = Parameter("y")
z = Parameter("z")
qc = QuantumCircuit(1, global_phase=phase)
qc.rx(x, 0)
qc.rz(z, 0)
qc.ry(y, 0)
my_values = [0.1,10,20,30]
param_dict = dict(zip(qc.parameters, my_values))
qc.bind_parameters(param_dict) <--- Is this a good working example for this issue where instead of passing |
Hi @pradkrish, for the from qiskit.circuit import Parameter, QuantumCircuit
from qiskit.opflow import StateFn, Z
phase = Parameter("phase")
x = Parameter("x")
y = Parameter("y")
z = Parameter("z")
qc = QuantumCircuit(1, global_phase=phase)
qc.rx(x, 0)
qc.rz(z, 0)
qc.ry(y, 0)
a = Parameter("a")
my_values = [-1, 0.1, 10, 20, 30] # a, phase, x, y ,z
expectation = StateFn(a * Z, is_measurement=True) @ StateFn(qc)
expectation.assign_parameters(my_values) # not possible right now! |
Hi @pradkrish any news on this? 🙂 |
@Cryoris, Well I'd love to give it a try. I'm dying to start my first open source contribution. May I be assigned? If not using array, can the parameters of "assign_parameters" be in a dictionary or boolean format? This snippiet is from the qiskit docs: |
Hi @nssensalo, of course you can work on this, I'll assign you 🙂 For opflow we don't allow |
@Cryoris Hello, my friend and I wanted to work on this issue if it is still open. This is our first project but we are interested and are happy to work on it. |
@Cryoris Hello, my friend and I would like to work on this issue, This is our first project but we are interested and happy to work on it |
hi @GaneshH0571 @AbhirMehrotra this issue has already been assigned to @nssensalo, there are many other open good first issues that haven't been assigned yet if you would like to take a look at those! for @nssensalo if you're new to open source and contributing to qiskit I recommend taking a look at these resources: Or if you are no longer interested in working on this also let us know so we can un-assign you and let someone else be assigned to it 😄 |
update: issue has been unassigned and open for other contributors to jump in 😄 |
What 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 settingwhich 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
Since Opflow objects already implement the
parameter
attribute, the steps to implement this could for instance beparameter
attribute returns aParameterView
object with parameters in the right orderbind_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!The text was updated successfully, but these errors were encountered: