Modifies QAny to not have an implicit _Unit encoding#1813
Modifies QAny to not have an implicit _Unit encoding#1813petim0 wants to merge 14 commits intoquantumlib:mainfrom
QAny to not have an implicit _Unit encoding#1813Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
|
Thanks for investigating this! I'll have to look at the PR more closely, but wanted to offer some quick initial thoughts. I don't think we'll ever get rid of I think the semantics of some operations are pretty clearly defined on QAny, like partitioning a Other operations -- not so much. I don't think you should be able to simulate the addition of The classical simulation protocol uses Python values to simulate what would be quantum values flowing through your bloq composition. You could imagine having a Python type for each quantum type that better models the behavior of the quantum values. We could have We typically don't do this for conciseness and performance. When we first implemented fixed-point arithmetic operations we used a In summary, the way I think about it now is that there's an underlying abstract thing like a "quantum unsigned integer" whose type we can annotate but which we can model in different ways: a Python int, a python value class, a set of tensor indices, ...; and I think there is an underlying abstract thing "lumped register of qubits" that we could think about how to best model. |
This is an extension of the PR #1812.
The bug I encountered in #1812 mainly comes from the fact that
QAnyassumed a_Unitencoding. So I decided to change that, asQAnyshould not represent any encoding, the only assumed encoding is 0 inQAnyis the bit-string00...00.I saw that before #1717 you had the following comment:
# TODO: Raise an error once usage of QAny is minimized across the libraryIn this PR I throw an error now so that nobody can use
QAny"wrongly" anymore and I change the code whereQAnywas misused to transformQAnyintoQUInt. This enforces a better use of types in the code to prevent the backlog from growing too much. The warnings would not be permanent (I hope), and be transformed into errors when the usage of QAny is minimized across the library.I don't know if you dropped the comment in #1717 because you felt like it was impossible to change the current code as the implicit encoding is used everywhere. I would understand that this is just a lost cause, and assuming a
_UIntencoding is not that bad, it just causes problems if you aren't careful when doing classical simulations.Note that I used the
LegacyPartitionWarningwarning, maybe I should create aLegacyQAnyWarninginstead.Tell me what you think.