A comprehensive exploration of quantum computing using IBM's Qiskit. This project demonstrates the implementation of fundamental quantum concepts and their practical applications
- Superposition: A qubit can be in state |0β©, |1β©, or a combination of both
- Measurement: The act of measuring a qubit forces it to choose a definite state
- Quantum Gates: Operations that manipulate quantum states
- Entanglement: Correlation between qubits that enables parallel operations
Extract of Code :
def create_quantum_circuit() -> QuantumCircuit:
qc = QuantumCircuit(1, 1)
qc.h(0) # Apply Hadamard gate for superposition
qc.measure(0, 0) # Measure the qubit
return qc
def execute_circuit(qc: QuantumCircuit, shots: int = 1000) -> dict:
backend = Aer.get_backend('qasm_simulator')
job = execute(qc, backend, shots=shots)
result = job.result()
return result.get_counts(qc)
π» The complete code is available here: quantum_superposition.py π¬
Explanation:
-
Initial State: |0β©
-
After Hadamard Gate: |Οβ© = 1/β2(|0β© + |1β©)
-
Probabilities:
- P(|0β©) = 50%
- P(|1β©) = 50%
-
Measurements:
- Over 1000 measurements, we expect approximately 500 |0β© and 500 |1β©
- Error margin: Β±3% (β30 measurements)
Extract of Code :
# Create quantum and classical registers
qr = QuantumRegister(n_qbits, 'q')
cr = ClassicalRegister(n_qbits, 'c')
qc = QuantumCircuit(qr, cr)
# Encode binary data into quantum state
for i, bit in enumerate(binary_chunk):
if bit == '1':
qc.x(qr[i])
# Measure qbits
qc.measure(qr, cr)
Encoding Process:
-
ASCII: Character β 8 bits
H β 72 β 01001000 i β 105 β 01101001
-
Quantum: Bit β Qubit
0 β |0β© 1 β X|0β© = |1β©
Chunking Strategy: Message β Chunks
"Hello" β ["Hel", "lo"]
This approach allows:
- Processing messages of any length
- Working within qubit limitations
- Parallel processing of chunks
- Measurement: Qubits β Classical bits
|Οββ© β 01001000 (H) |Οββ© β 01101001 (i)
The chunking strategy was implemented to overcome hardware limitations on available qubits. By processing the text in smaller chunks (default size: 3 characters), we can:
- Handle messages of arbitrary length
- Stay within quantum hardware constraints
- Enable potential parallel processing of chunks
- Maintain quantum advantages for each chunk
Each chunk follows the full quantum encoding process independently, with results combined afterwards. This practical compromise allows us to leverage quantum properties while working within real-world limitations.
π» The complete code is available here: quantum_text_encoding.py π¬
Extract of Code :
def quantum_compare(a: int, b: int) -> bool:
# Create circuit with 1 qubit and 1 classical bit
qr = QuantumRegister(1, 'q')
cr = ClassicalRegister(1, 'c')
qc = QuantumCircuit(qr, cr)
# Encode numbers (if a > b, apply X on qubit)
if a > b:
qc.x(qr[0])
# Measure qubit into classical bit
qc.measure(qr[0], cr[0])
Explanation of the comparaison process:
- Encoding: |Οβ© = |aβ©|bβ©
- Comparison: U|aβ©|bβ© = |aβ©|a>bβ©
- Measurement: M|Οβ© β {0,1}
π» The complete code is available here: quantum_sort.py π¬
Extract of Code :
# Apply Grover's algorithm
# - The oracle (`create_oracle`) identifies the target state by inverting its phase
# - The diffuser (`diffuser`) amplifies the amplitude of the marked state
# - After ~βN iterations, the probability of measuring the target state is maximal
for i in range(n_iterations):
print(f"β‘ Iteration {i + 1}/{n_iterations}")
qc.compose(create_oracle(n_qubits, target_index), inplace=True)
qc.compose(diffuser(n_qubits), inplace=True)
qc.measure(qr, cr)
Explanation:
-
Initial State:
- After Hadamard gates: |Οβ© = 1/βN * (sum of all states)
- N = 2βΏ (where n = number of qubits)
- Creates equal probability for all states
-
Oracle Step:
- Marks target state by phase flip
- Changes sign of target state from + to -
- Other states remain unchanged
-
Diffusion Step:
- Reflects amplitudes around average
- Increases amplitude of target state
- Decreases amplitude of other states
-
Performance:
- Takes about Ο/4 * βN iterations
- Success rate close to 100%
- About βN times faster than classical search
π» The complete code is available here: quantum_grover.py π¬
The current implementations have several important limitations to consider:
-
Basic Usage of Quantum Paradigm
- The implemented algorithms don't fully leverage quantum computing potential
- The absence of quantum entanglement significantly limits performance
- Operations remain close to classical approaches, merely translated to quantum
-
Intermediate Development Stage
- These implementations represent a transitional phase between:
- Classical programming
- True optimized quantum computing
- They reflect the learning process and familiarization with quantum concepts
- These implementations represent a transitional phase between:
-
Educational Value
- Despite their limitations, these projects enabled:
- Understanding of core concepts
- Mastery of basic tools (Qiskit)
- Grasp of essential quantum principles
- Despite their limitations, these projects enabled:
These implementations represent an intermediate phase in my quantum computing learning journey. While they don't yet fully exploit the quantum paradigm, they provide a solid foundation for developing more sophisticated algorithms in the future. This progressive approach, although not harnessing the full power of quantum computing, has allowed me to build the fundamental understanding necessary to tackle more advanced implementations that will fully utilize quantum entanglement and parallelism. I am particularly pleased to have been able to develop and understand complex algorithms such as quantum sorting and text encoding, which have allowed me to put these advanced concepts into practice.
-
Search:
- Classical: O(N)
- Quantum: O(βN)
-
Sorting:
- Comparisons: O(NΒ²)
- Quantum advantage in comparisons
-
Encoding:
- Linear: O(N) bits β qubits
- Parallelization possible
- Python
- Qiskit
- Matplotlib
git clone https://github.com/DjeridiY/Quantum-Qiskit-Computing.git
cd quantum-computing
pip install -r requirements.txt
This project is licensed under the MIT License - see the LICENSE file for details.