Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Qureg.__int__ for multiple bits (little-endian) #71

Closed
wants to merge 3 commits into from

Conversation

Strilanc
Copy link
Contributor

@Strilanc Strilanc commented Apr 26, 2017

I think this is the natural thing to do when asking for the int in a quregister. (Existing tests weren't changed because they happened to not check for this.)

A reasonable follow-up change would be to remove the len==1 constraint from __bool__ and __non_zero__, and have them check if __int__ is non-zero instead. I can do that in this PR if you want.

@thomashaener
Copy link
Contributor

This is actually what our first implementation did, but we decided to drop this feature.

Rather than adding this functionality to Qureg, I would suggest to add a new quantum type Quint (and eventually also Qufixed, Qufloat, ...). This has the advantage that such a conversion must be performed explicitly (it's a different interpretation of a Quregafter all): a = Quint(qureg1) and it would also behave as expected in terms of operations:

...
a = Quint(qureg1)
b = Quint(qureg2)
a += b # as opposed to concatenation: qureg1+qureg2
Measure | a
m_a = int(a) # is actually a+b

I think this explicit conversion helps avoid bugs such as if bool(qureg): ..., where users might have wanted all(bool(q) for q in qureg).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants