This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # YOUR CODE GOES HERE | |
| qc.ry(prob_to_angle(0.7), 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from math import asin, sqrt | |
| def prob_to_angle(theta): | |
| return 2*asin(sqrt(theta)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from qiskit import QuantumCircuit, execute, Aer | |
| from qiskit.visualization import plot_histogram | |
| # Create a quantum circuit with one qubit | |
| qc = QuantumCircuit(1) | |
| # YOUR CODE GOES HERE | |
| qc.ry(pi/2, 0) | |
| # measure the qubit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from qiskit import QuantumRegister, QuantumCircuit, ClassicalRegister, Aer, execute | |
| from qiskit.visualization import plot_histogram | |
| DIGITS = 3 | |
| def oracle(secret, as_gate=True): | |
| o_qc = QuantumCircuit(DIGITS+1) | |
| for i in range(DIGITS): | |
| if secret[::-1][i] == '1': |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from qiskit import Aer, execute | |
| from qiskit.visualization import plot_histogram | |
| results = execute(qc,Aer.get_backend('qasm_simulator'), shots=1000).result().get_counts() | |
| plot_histogram(results) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from qiskit import ClassicalRegister | |
| cr = ClassicalRegister(DIGITS, "cr") | |
| qr = QuantumRegister(DIGITS, "digits") | |
| qc = QuantumCircuit(qr, aux, cr) | |
| # ... | |
| qc.measure(qr, cr) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| qc.h(qr) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| qc.append(oracle('101'), [*qr, *aux]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def oracle(secret, as_gate=True): | |
| o_qc = QuantumCircuit(DIGITS+1) | |
| for i in range(DIGITS): | |
| if secret[::-1][i] == '1': | |
| o_qc.cx(i,DIGITS) | |
| else: | |
| o_qc.i(i) | |
| return o_qc.to_gate(label="oracle") if as_gate else o_qc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| qc.x(aux) | |
| qc.h(aux) |
NewerOlder