Sorting overhead vs dict implementation for tape.trainable_params
#1843
Labels
enhancement ✨
New feature or request
tape.trainable_params
#1843
Feature details
#1836 introduces two
sorted
statements in theTape
methodsget_parameters
andset_parameters
, applied totrainable_params
.In almost all known cases, the set
tape.trainable_params
already is sorted internally (in an unstable sense, as it is a set), which makes thesesorted
calls very fast (best case performance of Timsort isO(n)
).However,
get_parameters
andset_parameters
are called quite often and the overhead might add up.The "issue" would be to check whether implementing
trainable_params
as adict
instead of aset
would be faster. It has the benefit of preserving insertion order (trainable_params
is assumed to always be created from sorted integers) from Python3.7 onwards and one could simply set all values toNone
. Unfortunately, Python3.7 does not guarantee insertion order preservation forset
s which made #1836 necessary in the first place.Implementation
One would probably change
qml.math.trainable_indices
and some places intape/tape.py
to use adict
with dummy valuesNone
instead of aset
.The major work would be in the test suite, where there is a lot of explicit checks of the
trainable_params
that need to be adapted accordingly to check for such adict
with dummy values instead of the original set.How important would you say this feature is?
1: Not important. Would be nice to have.
Additional information
No response
The text was updated successfully, but these errors were encountered: