-
Notifications
You must be signed in to change notification settings - Fork 1
Sourcery refactored master branch #1
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: master
Are you sure you want to change the base?
Conversation
| print("Looking for " + names[k] + "'s number") | ||
| print(f"Looking for {names[k]}" + "'s number") | ||
|
|
||
| # oracle construction | ||
| fdef = bin(k)[2:] | ||
| fdef = "0"*(n-len(fdef)) + fdef | ||
| g.def_oracle(fdef) | ||
| print("We are looking for " + fdef) | ||
| print(f"We are looking for {fdef}") | ||
|
|
||
| # running the algorithm | ||
| reg = g.run_iteration() | ||
| final = "" | ||
| for i in range(reg.nbits-1): | ||
| _, p = reg.get_qbit(i) | ||
| if p.state[0]>0.5: | ||
| final += '0' | ||
| else: | ||
| final += '1' | ||
| final += '0' if p.state[0]>0.5 else '1' | ||
| for i in range(reg.nbits): | ||
| print(reg.get_qbit(i)[0]) | ||
|
|
||
| # output of answers | ||
| print("Probably looking for : "+final) | ||
| print("Found Number: " + numbers[int(final,2)]) | ||
| print(f"Probably looking for : {final}") | ||
| print(f"Found Number: {numbers[int(final,2)]}") |
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.
Function main refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Replace if statement with if expression (
assign-if-exp)
| target_state = int(base+"1",2) | ||
| target_state = int(f"{base}1", 2) | ||
| cmatrix[target_state,i_col] = 1 | ||
| target_state = int(base+"0",2) | ||
| cmatrix[target_state,i_col+1] = 1 | ||
| target_state = int(f"{base}0", 2) | ||
| else: | ||
| target_state = int(base+"0",2) | ||
| target_state = int(f"{base}0", 2) | ||
| cmatrix[target_state,i_col] = 1 | ||
| target_state = int(base+"1",2) | ||
| cmatrix[target_state,i_col+1] = 1 | ||
| target_state = int(f"{base}1", 2) | ||
| cmatrix[target_state,i_col+1] = 1 |
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.
Function construct_unitary_F refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Hoist repeated code outside conditional statement (
hoist-statement-from-if)
| assert qreg.nbits == self.qreg_size, "This gate cannot be applied to register of size {}. Expected size: {}".format(qreg.nbits, self.qreg_size) | ||
| assert ( | ||
| qreg.nbits == self.qreg_size | ||
| ), f"This gate cannot be applied to register of size {qreg.nbits}. Expected size: {self.qreg_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.
Function Gate.apply refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting)
| if isinstance(other, Sequence): | ||
| self.seq += other.seq | ||
| else: | ||
| self.seq += [other] | ||
| self.seq += other.seq if isinstance(other, Sequence) else [other] |
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.
Function Sequence.add refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
|
|
||
| self.matrix = matrix | ||
| self.msize = 2**len(qbpos) | ||
| self.qsize = 2**qreg_size | ||
| self.bases = np.arange(self.qsize) | ||
|
|
||
| self.qbpos = qbpos | ||
| self.specpos = list(filter(lambda x : not x in qbpos, range(qreg_size))) | ||
| self.specpos = list(filter(lambda x: x not in qbpos, range(qreg_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.
Function LazyGate.__init__ refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan)
| for i in range(0,self.rowSize): | ||
| for j in range(0,that.colSize): | ||
| for i in range(self.rowSize): | ||
| for j in range(that.colSize): |
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.
Function SparseMatrix.multiplySparseMatrix refactored with the following changes:
- Replace range(0, x) with range(x) (
remove-zero-from-range)
| new = SparseMatrix(matrix.shape[0],matrix.shape[1]) | ||
| for i in range(0,matrix.shape[0]): | ||
| for j in range(0,matrix.shape[1]): | ||
| new = SparseMatrix(matrix.shape[0],matrix.shape[1]) | ||
| for i in range(matrix.shape[0]): | ||
| for j in range(matrix.shape[1]): |
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.
Function SparseMatrix.convertToSparse refactored with the following changes:
- Replace range(0, x) with range(x) (
remove-zero-from-range)
|
|
||
| def scalarMultiply(self,scalar): | ||
| for i in range(0,len(self.elements)): | ||
| for i in range(len(self.elements)): |
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.
Function SparseMatrix.scalarMultiply refactored with the following changes:
- Replace range(0, x) with range(x) (
remove-zero-from-range)
| for i in range(0,len(new.elements)): | ||
| for i in range(len(new.elements)): | ||
| new.elements[i].value = element.value*new.elements[i].value | ||
| cornerRow = element.rowIndex*that.rowSize | ||
| cornerCol = element.colIndex*that.colSize | ||
| for i in range (0,len(new.elements)): | ||
| for i in range(len(new.elements)): | ||
| new.elements[i].rowIndex += cornerRow | ||
| new.elements[i].colIndex += cornerCol | ||
| for element in new.elements: | ||
| new1.append(element) | ||
| new1.extend(iter(new.elements)) |
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.
Function SparseMatrix.kronSparse refactored with the following changes:
- Simplify generator expression (
simplify-generator) - Replace range(0, x) with range(x) (
remove-zero-from-range) - Replace a for append loop with list extend (
for-append-to-extend)
| for i in range(0,3): | ||
| for j in range(0,3): | ||
| for i in range(3): | ||
| for j in range(3): |
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.
Function test_smatrix refactored with the following changes:
- Replace range(0, x) with range(x) (
remove-zero-from-range)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.38%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
Branch
masterrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
masterbranch, then run:Help us improve this pull request!