-
Notifications
You must be signed in to change notification settings - Fork 46
Arithmetic tools (jasp-compatible) #279
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
base: main
Are you sure you want to change the base?
Conversation
| for i in jrange(-a.exponent, a.size): | ||
| cx(a[i], b[i]) | ||
|
|
||
| return b |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By using duplicate, you create a QuantumFloat that could potentially have non-integer values. The result of floor can however be an integer only. I guess it depends on the usecase whether this is unnecessary. What do you think @renezander90 @cjn10?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've thought about this and I think that, since the operation is out of place and the initial variable still exists, it makes more sense to preserve the same structure in the output variable in order to allow operations between them.
| {(2, 1, 2): 0.5, (3, 1, 3): 0.5} | ||
| """ | ||
|
|
||
| res = QuantumFloat(a.size) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be made a bit more robust :)
res_mshape = [jnp.minimum(a.mshape[0], b.mshape[0]), jnp.maximum(a.mshape[1], b.mshape[1])]
new_msize = res_mshape[1] - res_mshape[0]
new_exponent = res_mshape[0]
res = QuantumFloat(new_msize, new_exponent)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes :) This will now work for QuantumFloats of different shape. (But, not yet for signed.)
Could work for signed with:
res = QuantumFloat(new_msize, new_exponent, signed=a.signed | b.signed)
| >>> multi_measurement([a,b,res_min]) | ||
| {(2, 1, 1): 0.5, (3, 1, 1): 0.5} | ||
| """ | ||
| res = QuantumFloat(a.size) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here as in q_max
| cx(a[i], res[i]) | ||
| with control(c, 0): | ||
| for i in jrange(b.size): | ||
| cx(b[i], res[i]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be more efficient like this:
cx(a, res)
with conjugate(cx)(a,b):
with control(c, 0):
cx(b, res)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But, this wouldn't work if an and b have different shape. With the proposed changes from above, this should work for QuantumFloats of different shape:
with control(c):
for i in jrange(a.size):
cx(a[i], res[i + a.exponent - new_exponent])
with control(c, 0):
for i in jrange(b.size):
cx(b[i], res[i + b.exponent - new_exponent])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The efficient approach should work on the digits where a and b overlap. On the disjoint digits, the straightforward way has to be employed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The extreme cases of the approach you suggest - no overlap and maximal overlap - will lead to a situation in which the cx is called with two empty lists of qubits. In this case the cx should not be appended to the circuit, but as of now this behaviour is simply not allowed.
| compare_func = lambda x, y: x <= y | ||
|
|
||
| with invert(): | ||
| (c << compare_func)(a, b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be more elegant and give an in-built custom control to do this via conjugation
|
Nice work! Added a few comments within the changed files :) Thanks |
This PR introduces a set of arithmetic utility functions for QuantumFloats
New Functions Added:
Additional Updates:
Comprehensive documentation for each new function
Corresponding unit tests