-
Notifications
You must be signed in to change notification settings - Fork 575
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
Wires as Sequence with new indexing #983
Wires as Sequence with new indexing #983
Conversation
…viour, incl. all tests
Codecov Report
@@ Coverage Diff @@
## master #983 +/- ##
==========================================
+ Coverage 96.79% 97.89% +1.10%
==========================================
Files 148 151 +3
Lines 10507 11059 +552
==========================================
+ Hits 10170 10826 +656
+ Misses 337 233 -104
Continue to review full report at Codecov.
|
…pdated accordingly
… instances than self
@mariaschuld Maybe you can give some input on this version of the |
Hey @dwierichs, the reason for the error is the following:
(I had to search the logs for WARNING, and there were quite a few benign ones 😆) This is likely because one of the imports in It can be fixed by navigating to .. automodapi:: pennylane.operation
:no-heading:
:include-all-objects:
:skip: Sequence, Enum, IntEnum, Variable, ClassPropertyDescriptor, multi_dot, pauli_eigs, Wires The |
Thanks @dwierichs! Is the PR ready for review? Did you have a chance to see if the speed improvement still holds? I don't mind reviewing even if the docs do not build yet error-free, and maybe I can help sorting out the issues and also do some profiling this side. |
…richs/pennylane into Wires_as_Sequence_with_new_indexing
Yes, this PR is ready for review. I think there would be more things to do, but maybe it is best to single out this rather basic change, what do you think?
I think this benchmark is somewhat imprecise, but given the properly different runtimes, I think one can claim a speedup :-) |
Great, thank you for the explanation and help! Is fixed. |
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.
On it.
The speedup is not as nicely measurable now, because the method of
Wires
in which most time is spent is a different one between PL 0.13 and this PR, but the runtime behaviour for the small benchmark I used so far, on 10 qubits, is
Just to understand, do you mean there is less time spent in _process
? Wouldn't that be good?
Co-authored-by: Maria Schuld <mariaschuld@gmail.com>
Sorry, that was unclear. In the previous PR the |
Perfect! I am still stunned by how few changes the new indexing requires, since indexing should change all sorts of things, like By the way, one could search for all occurrences of |
I fully agree, this change caused way less headaches than I anticipated! Yes, one could replace indexing of |
The modifications of |
Current design choice:
|
… performant. TF and Autograd DefaultQubit devices have very weird `wire_map`s, making test_compare_default_qubit fail currently.
…th_new_indexing Remove cases where lists of Wires are fed into Wires class
…for iterables that have hashable contents but raise an error when creating set from them
|
||
def map_wires(self, wires): | ||
"""Map the wire labels of wires using this device's wire map. | ||
|
||
Args: | ||
wires (Wires): wires whose labels we want to map to the device's internal labelling scheme | ||
|
||
Returns: | ||
Wires: wires with new labels | ||
""" | ||
wires = Wires([w.item() if isinstance(w, tensor) else w for w in wires]) | ||
mapped_wires = super().map_wires(wires) | ||
|
||
return mapped_wires |
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.
Since this is the same code with default_qubit_tf
, would it make sense to move this code to DeviceQubit
?
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 would make all QubitDevice
s, including the default qubits and default mixed state qubit, check for tensor instances, which maybe is not necessary?
except TypeError as e: | ||
# Make sure it really was a hashability issue | ||
if str(e).startswith("unhashable"): | ||
raise WireError("Wires must be hashable; got {}.".format(wires)) from e |
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 we should reraise e
if it wasn't this error.
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.
Actually, there was a dedicated error raised previously. But then codecov complained that that was not tested and I tried to find a test case raising this. Did not find one, maybe you can add it if you have an idea how to break this.
… consistent with __init__/_process
The latest design choice update removes the exception from Wires([2, 3]) in Wires(range(5)) # False As it is useful to be able to check for all elements of a a = Wires(range(10))
b = Wires(range(3))
a.contains_wires(b) # True
b.contains_wires(a) # False Note that |
Co-authored-by: Chase Roberts <keeper6928@gmail.com>
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.
Looks good to me!
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.
Looks good to me!
This PR had awesome benchmark improvements. Amazing work!
|
Very happy to see that it systematically improved the performance! Thank you for reviewing and benchmarking! |
Context
All details can be found in the previous PR attempt via subclassing
Wires
fromorderedset.OrderedSet
. #979Here we keep the subclassing from
collections.abc.Sequence
but change the indexing behaviour to standard pythoniterable behaviour like
list
ortuple
.