-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Implement Deutsch-Jozsa Algorithm In Qiskit #3447
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
Implement Deutsch-Jozsa Algorithm In Qiskit #3447
Conversation
78894a5
to
cf60aa6
Compare
8dd6f21
to
a387935
Compare
a387935
to
e9c3d82
Compare
b7ea8ec
to
ce74e77
Compare
ce74e77
to
d408785
Compare
a766869
to
d740492
Compare
Implemented the Deutsch-Jozsa Algorithm, one of the first examples of a quantum algorithm that is exponentially faster than any possible deterministic classical algorithm |
d740492
to
8d9ce52
Compare
809321b
to
7c5da9e
Compare
Signed-off-by: Abhishek Jaisingh <abhi2254015@gmail.com>
7c5da9e
to
931a9dd
Compare
f17c98a
to
e4d6caf
Compare
quantum/deutsch_jozsa.py
Outdated
classical algorithm | ||
|
||
Premise: | ||
We are given a hidden Boolean function f , |
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.
We are given a hidden Boolean function f , | |
We are given a hidden Boolean function f, |
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.
@cclauss fixed extra whitespace in newly added commit
e4d6caf
to
56bcf6f
Compare
06d8e34
to
07d33ab
Compare
Signed-off-by: Abhishek Jaisingh <abhi2254015@gmail.com>
07d33ab
to
4e2a95b
Compare
55faf64
to
517d327
Compare
@cclauss What's the deal with this GitHub action which applies Oh, nevermind. I get it why it works on some and not on others. The user has turned on the workflow in their forked copy and this is coming from there. I propose to remove it and the codespell action as both of them are checked with |
The thing that it does do is... If a maintainer (with write privileges to the repo) creates a PR then the Action blackens the entire repo. This ensures that from time to time the entire repo is blackened even if someone lands a PR that is not green. Go ahead and make the changes that you suggest above. |
quantum/deutsch_jozsa.py
Outdated
counts = deutsch_jozsa("constant", 3) | ||
print(f"Deutsch Jozsa - Constant Oracle: {counts}") | ||
|
||
counts = deutsch_jozsa("balanced", 3) | ||
print(f"Deutsch Jozsa - Balanced Oracle: {counts}") |
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.
counts = deutsch_jozsa("constant", 3) | |
print(f"Deutsch Jozsa - Constant Oracle: {counts}") | |
counts = deutsch_jozsa("balanced", 3) | |
print(f"Deutsch Jozsa - Balanced Oracle: {counts}") | |
print(f"Deutsch Jozsa - Constant Oracle: {deutsch_jozsa("constant", 3)}") | |
print(f"Deutsch Jozsa - Balanced Oracle: {deutsch_jozsa("balanced", 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.
fixed 👍
quantum/deutsch_jozsa.py
Outdated
# wrap in X-gates: | ||
b = np.random.randint(1, 2 ** n) | ||
# Next, format 'b' as a binary string of length 'n', padded with zeros: | ||
b_str = format(b, "0" + str(n) + "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.
Please use a f-string.
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.
switched to f-string
quantum/deutsch_jozsa.py
Outdated
# Next, we place the first X-gates. Each digit in our binary string | ||
# correspopnds to a qubit, if the digit is 0, we do nothing, if it's 1 | ||
# we apply an X-gate to that qubit: | ||
for qubit in range(len(b_str)): |
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.
Please use enumerate() instead of range(len()).
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.
qubit is not a qubit, it is an int. Maybe call it I or index.
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.
using enumerate now, changed var name to index
quantum/deutsch_jozsa.py
Outdated
for qubit in range(n): | ||
oracle_qc.cx(qubit, n) | ||
# Next, place the final X-gates | ||
for qubit in range(len(b_str)): |
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.
enumerate()
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.
fixed
quantum/deutsch_jozsa.py
Outdated
import qiskit as q | ||
|
||
|
||
def dj_oracle(case: str, n: int) -> q.QuantumCircuit: |
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.
Perhaps this should be two separate functions.
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 variable name n is not self documenting. Can we come up with a more descriptive name.
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.
changed var name from n to num_qubits
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.
However, I feel the function is fine as it is.
I think we shouldn't split the function, as it seems to be more complete in its current form. @cclauss what do you think?
517d327
to
1a33ec4
Compare
5745184
to
c818db8
Compare
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.
RSLGTM
* Implement Deutsch-Jozsa Algorithm In Qiskit Signed-off-by: Abhishek Jaisingh <abhi2254015@gmail.com> * Add Changes Requested In Review Signed-off-by: Abhishek Jaisingh <abhi2254015@gmail.com> * Address Further Review Comments * fixup! Format Python code with psf/black push Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
* Implement Deutsch-Jozsa Algorithm In Qiskit Signed-off-by: Abhishek Jaisingh <abhi2254015@gmail.com> * Add Changes Requested In Review Signed-off-by: Abhishek Jaisingh <abhi2254015@gmail.com> * Address Further Review Comments * fixup! Format Python code with psf/black push Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
* Implement Deutsch-Jozsa Algorithm In Qiskit Signed-off-by: Abhishek Jaisingh <abhi2254015@gmail.com> * Add Changes Requested In Review Signed-off-by: Abhishek Jaisingh <abhi2254015@gmail.com> * Address Further Review Comments * fixup! Format Python code with psf/black push Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Signed-off-by: Abhishek Jaisingh abhi2254015@gmail.com
Describe your change:
Implement Deutsch-Jozsa Algorithm In Qiskit
Checklist:
Fixes: #{$ISSUE_NO}
.