Clean up unitary_generator a bit#3
Conversation
1) Use Python's abstract base classes to remove strict type assertions where they're not necessary 2) Use Python's support for a more mathematical (and therefore verifiable) syntax for relations (e.g., x < y < z) 3) Be more Pythonic in general.
jotterbach
left a comment
There was a problem hiding this comment.
Thanks @thomdixon for these valuable readability improvements!
It all looks good and I have only 2 comments to update the PR slightly.
| "permutation") | ||
| else: | ||
| # Don't permit NoneType or empty sequences, but allow 0 | ||
| if args is None or (isinstance(args, Sequence) and not args): |
There was a problem hiding this comment.
Thanks for the improvements here. args is a required argument and hence cannot be none, so we should be able to drop this check?
There was a problem hiding this comment.
If you set args to None in master, you wind up with args being set to [None]. I wanted to prevent that situation to the best of my ability. I can remove it, if that situation is acceptable though.
| raise TypeError("Need at least one qubit index to perform" | ||
| "permutation") | ||
| else: | ||
| # Don't permit NoneType or empty sequences, but allow 0 |
There was a problem hiding this comment.
we need to adjust the docstring parameter based on this.
jotterbach
left a comment
There was a problem hiding this comment.
@thomdixon This looks good! Thanks a lot!
type assertions where they're not necessary
verifiable) syntax for relations (e.g.,
x < y < z)divmodandnp.log2to calculate powers of 2