Changes Partition to optionally take an input dtype#1812
Changes Partition to optionally take an input dtype#1812petim0 wants to merge 8 commits intoquantumlib:mainfrom
Partition to optionally take an input dtype#1812Conversation
|
This technically solves #1799, but I haven't done any tests so I am not sure. Also maybe still doing a classical partition is not a bad idea. |
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
|
main philosophical discussion on #1813 Yes, I think we should let you partition any data type so you can write safe, generic quantum programs. The constructor for I think this would work better as a new |
I changed partition to allow to optionally pass a dtype for the input register.
This change comes from a bug I encountered when partitioning a
QIntand runningassert_consistent_classical_action:The partition assumes that your input is a
QAny()andQAny()is assumed to have a_UIntencoding, therefore when the_classical_partitionfunction of_PartitionBaseusesself.lumped_dtype.to_bits(x)and you have a negative number as a input then you get an error you should not have, as the_UIntencoding doesn't allow for negative numbers.Mypy was really not happy with the
matchstatement and so I had do do a lot of uselessasserts. Maybe a better solution is I to just ignore the errors instead.I also added a
LegacyPartitionWarningthat I then put in thefilterwarningsof pytest as to not have it everywhere in the code when testing.I also choose to have the base dtype of the partition register to be a
QUIntas to more reflect the fact that we assume a_Uintencoding.