qadence
qadence copied to clipboard
[Feature] Generalize parameter constraints over certain range
When running parameterized digital-analog programs parameters often have to be optimized while bounded over a specific range. For example, currently in the AddressingPattern
class this is done by re-defining the parameters with a multiplication with a Heaviside function such that values outside the allowed range are counted as zero. To note that for optimization purposes, a smooth approximation of the Heaviside needs to be used for gradient calculation, as currently done in the addressing pattern.
This can potentially be generalized, either as a general function or directly inside the Qadence VariationalParameter
to be used in other modules.
Potentially related: can parameters like angles be defined mod 2 pi?
This is potentially needed to deal with the domain of certain functions in https://github.com/pasqal-io/qadence/issues/267
E.g., the trainable frequencies for a chebyshev feature map should respect the domain of acos
being (-1, 1). Since there is already a target_range
parameter that re-scales the data to that range, it would be enough that the trainable frequencies stay inside the (0, 1) range.
A few potentially relevant links from the web:
https://discuss.pytorch.org/t/set-constraints-on-parameters-or-layers/23620/3 https://discuss.pytorch.org/t/restrict-range-of-variable-during-gradient-descent/1933