You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issues attempts to summarize possible enhancements for assigning parameters to circuits along with the main use-cases. Related to #5557 and #3910.
Status quo
To assign parameters to a circuit, one needs to pass
a dictionary of {parameter_instance: value}, or
a dictionary of {parameter_vector_instance: values_list}
The keys of the dictionary have to be the same instances as in the circuit.
Desired features
Allow assigning a list of values to a circuit to bind all parameters anonymously, i.e. without specifying the parameters they belong to.
Allow assigning values via name instead of instance. This is possible since parameter names are already required to be unique.
Use cases
I might forget some cases here, so feel free to add 🙂
From optimization algorithms:
Pretty much all classical optimization routines handle parameters as lists of values; including the numerical optimization routines used in algos like the VQE or QAOA. Since parameters are not sorted, running each optimization run might optimize the values in a different order, which leads to different results. The algorithms currently manually ensure that the parameters are sorted in a consistent manner -- though this might not be the order the user added them to the circuit, which has already led to some confusion in the past.
If the parameters were (insertion) sorted by default and one could assign a plain vector, all this logic would fall away and circuits could naturally interact with optimizers. This works e.g. nicely in pennylane.
From gradients:
Constructing gradients or hessian currently works like this
ansatz=# some ansatz with parameters [x, y, z, ...]expectation=# some expectation based on ansatzgrad=Gradient().convert(expectation, params=[x, y, z, ...])
hess=Hessian().convert(expectation, params=[x, y, z, ...])
the parameters have to be carried along and passed to the gradients, since this specifies the order of the vector or matrix entries. It would be a lot more convenient to just call
but this would also require some sorting, which might not be what users expect. This can make comparison to other frameworks and validation difficult; where the usual order is by insertion.
Consistency:
Some library circuits already have an ordered_parameters attribute, which exists for (1) reproducibility, (2) backward compatibility with some old variational forms (and (3) convenience). If we had sorted parameters, this attribute would no longer be needed (also mentioned in Make it easier to assign parameters to vector of parameters #5557).
or even for a full parametervector, x = ParameterVector('x', 10) and {'x': [0, 1, 2, ...}. This can be particularly useful if (1) the circuit is passed around or (2) users are playing with circuits and interact a lot by plotting.
The text was updated successfully, but these errors were encountered:
This issues attempts to summarize possible enhancements for assigning parameters to circuits along with the main use-cases. Related to #5557 and #3910.
Status quo
To assign parameters to a circuit, one needs to pass
{parameter_instance: value}
, or{parameter_vector_instance: values_list}
The keys of the dictionary have to be the same instances as in the circuit.
Desired features
Use cases
I might forget some cases here, so feel free to add 🙂
From optimization algorithms:
If the parameters were (insertion) sorted by default and one could assign a plain vector, all this logic would fall away and circuits could naturally interact with optimizers. This works e.g. nicely in pennylane.
From gradients:
Consistency:
ordered_parameters
attribute, which exists for (1) reproducibility, (2) backward compatibility with some old variational forms (and (3) convenience). If we had sorted parameters, this attribute would no longer be needed (also mentioned in Make it easier to assign parameters to vector of parameters #5557).From #5557:
x = ParameterVector('x', 10)
and{'x': [0, 1, 2, ...}
. This can be particularly useful if (1) the circuit is passed around or (2) users are playing with circuits and interact a lot by plotting.The text was updated successfully, but these errors were encountered: