{"id":20018553,"url":"https://github.com/rupeshtr78/quantum","last_synced_at":"2025-07-16T01:46:53.886Z","repository":{"id":156959836,"uuid":"220304980","full_name":"rupeshtr78/quantum","owner":"rupeshtr78","description":"Quantum Computing Basics Using Python projectq","archived":false,"fork":false,"pushed_at":"2019-11-07T19:38:42.000Z","size":12,"stargazers_count":6,"open_issues_count":0,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-28T02:39:47.334Z","etag":null,"topics":["cnot","entanglement","hadamard","pauli-gates","projectq","python","quantum","quantum-computing","qubit","qubits","superposition","teleportation"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rupeshtr78.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-07T18:39:50.000Z","updated_at":"2024-08-12T19:54:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"30212362-ef3f-41ca-8069-f9b2f0d2f64d","html_url":"https://github.com/rupeshtr78/quantum","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rupeshtr78/quantum","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rupeshtr78%2Fquantum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rupeshtr78%2Fquantum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rupeshtr78%2Fquantum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rupeshtr78%2Fquantum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rupeshtr78","download_url":"https://codeload.github.com/rupeshtr78/quantum/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rupeshtr78%2Fquantum/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265475001,"owners_count":23772463,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cnot","entanglement","hadamard","pauli-gates","projectq","python","quantum","quantum-computing","qubit","qubits","superposition","teleportation"],"created_at":"2024-11-13T08:23:11.150Z","updated_at":"2025-07-16T01:46:53.854Z","avatar_url":"https://github.com/rupeshtr78.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Exploring  Basic Concepts of Quantum Computing using Python projectq\n\n- Classical computers are just dealing with simple states of 0 and 1. \n- **Quantum computers** on the other hand are working on **qubits** in quantum states and not simple 0s and 1s. \n-  In quantum computing, a qubit or quantum bit is the basic unit of quantum information.\n- The quantum state might be an electron in **superposition** between 1 and 0 .This makes it too fragile to be sent anywhere.A crude example of is the state when a coin is tossed up.While up in air it has equal probability of being heads or tails.\n- Usually denoted as  ![{\\displaystyle |0\\rangle ={\\bigl [}{\\begin{smallmatrix}1\\\\0\\end{smallmatrix}}{\\bigr ]}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/279f5336e8dcc639125e7dda2410319b81c9bf94) and ![{\\displaystyle |1\\rangle ={\\bigl [}{\\begin{smallmatrix}0\\\\1\\end{smallmatrix}}{\\bigr ]}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/e788c1d112bf1312c0a7d6416782b66eecb0788b)   pronounced \"ket 0\" and \"ket 1\" .\n- Additionally, the[ no-cloning-theorem](https://en.wikipedia.org/wiki/No-cloning_theorem) states that it is impossible to create an identical copy of an unknown quantum state because the **quantum state is collapsed when measured**, and thus the quantum state is destroyed.\n-  There are two possible outcomes for the measurement of a qubit— value \"0\" and \"1\", like a bit or binary digit.  \n- Quantum computations on a Qubit, where quantum computations refers to applying quantum logic gates such as   ,Pauli-X, CNOT etc to Qubits.\n\n\n\n##### Generating Quantum Random number using python package pythonq\n\n1. Create a new Qubit\n2. Applying a Hadamard gate to the Qubit to put it into a **superposition** of equal probability of being 0 and 1.\n3. Measuring the Qubit\n\n```python\npip3 install projectq\n\nfrom projectq.ops import H, Measure\nfrom projectq import MainEngine\n\n# initialises a new quantum backend\nquantum_engine = MainEngine()\n\n# Create Quibit\nqubit = quantum_engine.allocate_qubit()\n\n# Using Hadamard gate put it in superposition\nH | qubit\n\n#  Measure Quibit\nMeasure | qubit\n\n# print(int(qubit))\nrandom_number = int(qubit)\nprint(random_number)\n\n# Flushes the quantum engine from memory\nquantum_engine.flush()\n```\n\n\n\n**CNOT** **Gate**\n\n- The CNOT gate is two-qubit operation, where the first qubit is usually referred to as the **control** qubit and the second qubit as the **target** qubit. \n- Leaves the control qubit **unchanged** \n- Performs a **Pauli-X** gate on the **target** qubit when the control qubit is in state **∣1⟩**\n- Leaves the **target** **unchanged** when the control qubit is in state **∣0⟩**\n\n**The Bloch Sphere and Pauli-gates**\n\n- In quantum computing, we can imagine the qubit as a sphere- what's referred to as the[ Bloch sphere](https://en.wikipedia.org/wiki/Bloch_sphere). \n- The Bloch sphere is a geometrical representation of a qubit and represents the different states the Qubit can take on, in a 3D space.\n- The Pauli family of gates indicates which way the system is spinning around the x, y, or z-axes. Where the Pauli-X gate will equate on the X-axis and, the Pauli-Z will alter the Z axis on the sphere\n- **Pauli-X gate** is the direct quantum equivalent of the classical NOT gate . The Pauli-X gate takes one input and **inverts the output**, and is also referred to as a bit flip gate. A bit flip gate means that it will invert the value of the bit in such a way that |1⟩ becomes |0⟩, and |0⟩ becomes |1⟩.\n- **The Pauli-Z gate** alters the spin of the Bloch sphere on the Z axis by the defined π radians. Pauli-Z gate leaves state |0⟩ unchanged, but flips |1⟩ to |-1⟩.\n\n```python\nfrom projectq import MainEngine\nfrom projectq.ops import All, CNOT, H, Measure, X, Z\nfrom collections import OrderedDict\n\nquantum_engine = MainEngine()\nod = OrderedDict()\n\ncontrol = quantum_engine.allocate_qubit()\ntarget = quantum_engine.allocate_qubit()\n\nH | control\nMeasure | control\nod['Control'] = int(control)\n\nH | target\nMeasure | target\nod['Target'] = int(target)\n\nCNOT | (control, target)\nMeasure | target\nod['CNOT'] = int(target)\n\nquantum_engine.flush()\n\n\nfor key, value in od.items():\n    print(key, value)\n```\n\n| Control    | 0     | 0     | 1     | **1** |\n| ---------- | ----- | ----- | ----- | ----- |\n| **Target** | **0** | **1** | **0** | **1** |\n| **CNOT**   | **0** | **1** | **1** | **0** |\n\n\n\n**Entanglement**\n\n- In physics, the no-cloning theorem states that it is impossible to create an identical copy of an arbitrary unknown quantum state\n- The state of one system can be **entangled** with the state of another system.\n- For instance, one can use the controlled NOT gate (**CNOT)** and the **Hadamard** gate to **entangle** two qubits.\n- Entanglement is not cloning. No well-defined state can be attributed to a subsystem of an entangled state.\n- It is impossible to create an identical copy of an unknown quantum state because the quantum state is collapsed when measured, and thus the quantum state is destroyed.\n- These two particles are forced to hold mutual information and be **entangled**  in a way that if the information of one particle is known, the information of the other particle is also automatically known. \n\n**Create Bell Pair**\n\n1. To **entangle** the qubits in a Bell pair, start by applying the Hadamard gate to the first Qubit to put it in a superposition where there is an equal probability of measuring 1 or 0.\n2. With the Qubit in superposition, apply a CNOT gate to flip the second Qubit conditionally on the first qubit being in the state |1⟩. \n\n\n\n```python\nfrom projectq import MainEngine\nfrom projectq.ops import All, CNOT, H, Measure, X, Z\n\nquantum_engine = MainEngine()\n\ndef entangle(quantum_engine):\n\n    control = quantum_engine.allocate_qubit()\n    target = quantum_engine.allocate_qubit()\n    H | control\n    Measure | control\n    control_val = int(control)\n\n    CNOT | (control, target)\n    Measure | target\n    target_cnot_val = int(target)\n\n    return control_val, target_cnot_val\n\n\nbell_pair_list = []\nfor i in range(10):\n    bell_pair_list.append(entangle(quantum_engine))\nquantum_engine.flush()\nprint(bell_pair_list)\n\nbell_pair_list = [(1, 1), (1, 1), (1, 1), (1, 1), (1, 1)]\n```\n\n\n\n**Teleportation** \n\n- **Teleportation** here means transferring the **state of the particle** through two classical bits, where the state is destroyed by the **sender** when it is measured and recreated by the **receiver** when the classical bits are computed. Quantum teleportation makes use of four different gates, the Hadamard gate, the CNOT gate, the Pauli-X gate and Pauli-Z gate.\n\n\n\nThe process is executed in three steps.\n\n1. Function to create a Bell pair initially of sender qubit as control and Receiver qubit as Target\n2. Creation function to entangle a message into Senders share of the Bell pair, and return the message back as classical bits.\n3. Receiver function that takes a classical encoded message, and uses the second pair of the Bell pair to re-create the state of the message qubit.\n\n- Refer teleportation.py\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frupeshtr78%2Fquantum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frupeshtr78%2Fquantum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frupeshtr78%2Fquantum/lists"}