Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quantum-kittens
GitHub Repository: quantum-kittens/platypus
Path: blob/main/notebooks/problem-sets/quantum_enigma_problem_set.ipynb
3353 views
Kernel: Python 3

Quantum Enigma 001 - The Treasure Door Problem Set

University of Sherbrooke, Institute of Quantique

Overview

Watch the following video before attempting this problem set

Quick quiz

Ready for your quiz?

  1. Yes -- Let's go!

  1. Not yet, I need to watch the video again.

Problem 1

Sometimes a quantum circuit can be simplified. One way of achieving this is by cancelling some quantum gates. Could you simplify the following circuit?

# Click run to draw the circuit from qiskit import QuantumCircuit problem_qc = QuantumCircuit(3) problem_qc.h(0) problem_qc.h(2) problem_qc.cx(0, 1) problem_qc.barrier(0, 1, 2) problem_qc.cx(2, 1) problem_qc.x(2) problem_qc.cx(2, 0) problem_qc.x(2) problem_qc.barrier(0, 1, 2) problem_qc.swap(0, 1) problem_qc.x(1) problem_qc.cx(2, 1) problem_qc.x(0) problem_qc.x(2) problem_qc.cx(2, 0) problem_qc.x(2) problem_qc.draw()

Try simplifying the circuit and rerun the calculation between each simplification to make sure you always get the same histogram. Check your answer by clicking the Grade button

Hints

Hint 1 The NOT, CNOT, and Hadamard gates are their own inverse. That means that if two of these gates are placed side by side they can simply be taken off.
Hint 2 The SWAP gate can be taken off if the subsequent operations are adjusted between the two qubits.
Hint 3 If a CNOT has the same control and target as another CNOT for which two NOT gates are applied before and after the control qubit, this can be simplified to a single NOT gate on the target qubit of the CNOT as a NOT gate is applied to the target whether the control qubit is initially in state 0 or 1.
Hint 4 The circuit can be simplified until only three gates remain in the algorithm.
from qiskit import QuantumCircuit, Aer, transpile from qiskit.visualization import plot_histogram # Start your work here. # We've provided the circuit that is shown above # Your circuit MUST be named qc # Remove all barriers before submitting for grading qc = QuantumCircuit(3) qc.h(0) qc.h(2) qc.cx(0, 1) qc.barrier(0, 1, 2) qc.cx(2, 1) qc.x(2) qc.cx(2, 0) qc.x(2) qc.barrier(0, 1, 2) qc.swap(0, 1) qc.x(1) qc.cx(2, 1) qc.x(0) qc.x(2) qc.cx(2, 0) qc.x(2) # Execute the circuit and draw the histogram measured_qc = qc.measure_all(inplace=False) backend = Aer.get_backend('qasm_simulator') # the device to run on result = backend.run(transpile(measured_qc, backend), shots=1024).result() counts = result.get_counts(measured_qc) plot_histogram(counts)
# Use this cell to draw the quantum circuit you're creating qc.draw()

Problem 2

Quick quiz

Can you interpret the results of Question 1?

  1. After simplification, q0q_0, q1q_1, and q2q_2 remain entangled altogether.

  1. After simplification, q0q_0 and q1q_1 are entangled with a H and a CNOT gates, while q2q_2 only has a H gate.

  1. After simplification, we finally know which guardian is lying.

Problem 3

Quick quiz

Launching algorithms on modern quantum computers do not always lead to 100% successful results as some noise bring a portion of bad results. If you launch the whole circuit on a real quantum computer, what is the percentage of good answers you get?

  1. 50%

  1. 40%

  1. 85%

  1. 100%

You can try this on a real quantum system below (which could take up to ~1 hour to run), but you can also solve the question without needing to run on quantum hardware

# 1. Create a simple quantum program called a 'quantum circuit'. from qiskit import QuantumCircuit qc = QuantumCircuit(3) qc.h(0) qc.h(2) qc.cx(0, 1) qc.barrier(0, 1, 2) qc.cx(2, 1) qc.x(2) qc.cx(2, 0) qc.x(2) qc.barrier(0, 1, 2) qc.swap(0, 1) qc.x(1) qc.cx(2, 1) qc.x(0) qc.x(2) qc.cx(2, 0) qc.x(2) measured_qc = qc.measure_all(inplace=False) # 2. Ask IBM Quantum for its least busy device that isn't a simulator. # If you're running this example locally, you need to load your # account with your IBM Quantum API token # IBMQ.save_account(token="XYZ") # IBMQ.load_account() from qiskit.providers.ibmq import IBMQ, least_busy provider = IBMQ.get_provider('ibm-q') device = least_busy( provider.backends( filters= lambda x: not x.configuration().simulator ) ) print(f'Running on {device.name()}') # 3. Convert the program to a form the device can run. # This is known as 'transpiling' from qiskit import transpile transpiled_qc = transpile(measured_qc, device) # 4. Send the program off to IBM Quantum to run on a real device # and monitor its status. from qiskit.tools import job_monitor job = device.run(transpiled_qc) job_monitor(job) # 5. Plot the results as a histogram. from qiskit.visualization import plot_histogram plot_histogram(job.result().get_counts())

Share Feedback