From 054ba886cd720b0a71c3630ea49a953d4e182b5a Mon Sep 17 00:00:00 2001 From: DarkStarStrix Date: Thu, 9 May 2024 11:05:10 -0400 Subject: [PATCH] rework --- .idea/Traveling-Salesman-Problem 2.0.iml | 3 + Standard_Quantum_Solvers/Grover.py | 20 --- Standard_Quantum_Solvers/Shor.py | 20 --- .../Variational_Quantum_Eiegensolver.py | 30 ---- Writerside/topics/How-the-Solvers-work.md | 170 +----------------- 5 files changed, 4 insertions(+), 239 deletions(-) delete mode 100644 Standard_Quantum_Solvers/Grover.py delete mode 100644 Standard_Quantum_Solvers/Shor.py delete mode 100644 Standard_Quantum_Solvers/Variational_Quantum_Eiegensolver.py diff --git a/.idea/Traveling-Salesman-Problem 2.0.iml b/.idea/Traveling-Salesman-Problem 2.0.iml index 2af3447..0dd173e 100644 --- a/.idea/Traveling-Salesman-Problem 2.0.iml +++ b/.idea/Traveling-Salesman-Problem 2.0.iml @@ -5,6 +5,9 @@ + + + diff --git a/Standard_Quantum_Solvers/Grover.py b/Standard_Quantum_Solvers/Grover.py deleted file mode 100644 index 4e520aa..0000000 --- a/Standard_Quantum_Solvers/Grover.py +++ /dev/null @@ -1,20 +0,0 @@ -from qiskit import QuantumCircuit -import matplotlib.pyplot as plt - - -def grover_circuit(): - qc = QuantumCircuit (3, 3) - qc.h (range (3)) - qc.x (range (3)) - qc.h (2) - qc.ccx (0, 1, 2) - qc.h (2) - qc.x (range (3)) - qc.h (range (3)) - qc.measure (range (3), range (3)) - return qc - - -# Draw the circuit -circuit = grover_circuit () -print (circuit) diff --git a/Standard_Quantum_Solvers/Shor.py b/Standard_Quantum_Solvers/Shor.py deleted file mode 100644 index 32deaf5..0000000 --- a/Standard_Quantum_Solvers/Shor.py +++ /dev/null @@ -1,20 +0,0 @@ -from qiskit import QuantumCircuit -from qiskit.visualization import plot_histogram - - -def shor_circuit(): - qc = QuantumCircuit (3, 3) - qc.h (range (3)) - qc.x (range (3)) - qc.h (2) - qc.ccx (0, 1, 2) - qc.h (2) - qc.x (range (2)) - qc.h (range (3)) - qc.measure (range (3), range (3)) - return qc - - -# print the counts and draw the circuit -circuit = shor_circuit () -print (circuit) diff --git a/Standard_Quantum_Solvers/Variational_Quantum_Eiegensolver.py b/Standard_Quantum_Solvers/Variational_Quantum_Eiegensolver.py deleted file mode 100644 index da706bd..0000000 --- a/Standard_Quantum_Solvers/Variational_Quantum_Eiegensolver.py +++ /dev/null @@ -1,30 +0,0 @@ -from qiskit import QuantumCircuit - - -def vqe_circuit(): - qc = QuantumCircuit (3, 3) - qc.h (range (3)) - qc.x (range (3)) - qc.h (2) - qc.ccx (0, 1, 2) - qc.h (2) - qc.x (range (3)) - return qc - - -def vqe_algorithm(): - pauli_dict = { - 'paulis': [{"coeff": {"imag": 0.0, "real": -1.052373245772859}, "label": "II"}, - {"coeff": {"imag": 0.0, "real": 0.39793742484318045}, "label": "ZI"}, - {"coeff": {"imag": 0.0, "real": -0.39793742484318045}, "label": "IZ"}, - {"coeff": {"imag": 0.0, "real": -0.01128010425623538}, "label": "ZZ"}, - {"coeff": {"imag": 0.0, "real": 0.18093119978423156}, "label": "XX"}] - } - qubit_op = WeightedPauliOperator.from_dict (pauli_dict) - var_form = RY (qubit_op.num_qubits, depth=3, entanglement='linear') - optimizer = COBYLA (maxiter=1000) - return VQE (qubit_op, var_form, optimizer) - - -# print the circuit -print (vqe_circuit ()) diff --git a/Writerside/topics/How-the-Solvers-work.md b/Writerside/topics/How-the-Solvers-work.md index b04a087..4a076eb 100644 --- a/Writerside/topics/How-the-Solvers-work.md +++ b/Writerside/topics/How-the-Solvers-work.md @@ -1,173 +1,5 @@ # How the Solvers work - -## Grover's algorithm -using the Qiskit library in Python. Grover's algorithm is a quantum algorithm that finds with high probability the unique input to a black box function that produces a particular output value, using just O(sqrt(N)) evaluations of the function, where N is the size of the function's domain. -The first part of the code imports necessary libraries from Qiskit, loads the IBM Q account, and selects the least busy backend device that has at least 3 qubits and is operational. - -```python -from qiskit import QuantumCircuit, execute, Aer, IBMQ -from qiskit.providers.ibmq import least_busy -from qiskit.visualization import plot_histogram - -provider = IBMQ.load_account() -backend = least_busy(provider.backends(filters=lambda x: x.configuration().n_qubits >= 3 and - not x.configuration().simulator and x.status().operational)) -``` - -Next, a quantum circuit is created with 3 qubits and 3 classical bits. The Hadamard gate is applied to all qubits to create a superposition of all possible states. - -```python -qc = QuantumCircuit(3, 3) -qc.h(range(3)) -``` - -The Oracle is then applied. This part of the code flips the sign of the state we are searching for. In this case, the Oracle is hard-coded to flip the sign of the state `|111>`. - -```python -qc.x(range(3)) -qc.h(2) -qc.ccx(0, 1, 2) -qc.h(2) -qc.x(range(3)) -``` - -The Grover diffusion operator is applied next. This part of the code amplifies the probability of the state we are searching for. - -```python -qc.h(range(3)) -qc.x(range(3)) -qc.h(2) -qc.ccx(0, 1, 2) -qc.h(2) -qc.x(range(3)) -qc.h(range(3)) -``` - -The qubits are then measured and the results are stored in the classical bits. - -```python -qc.measure(range(3), range(3)) -``` - -Finally, the quantum circuit is executed on the selected backend, the results are retrieved, and a histogram of the results is plotted. - -```python -job = execute(qc, backend, shots=1024) -result = job.result() -counts = result.get_counts(qc) -plot_histogram(counts) -``` - -In summary, this code is a complete implementation of Grover's algorithm for 3 qubits using the Qiskit library. It creates a quantum circuit, applies the Oracle and Grover diffusion operator, measures the qubits, and plots the results. - -## Shor's algorithm - -Shor's algorithm is a quantum algorithm for integer factorization, which underlies the security of many cryptographic systems. -The first part of the code imports necessary libraries from Qiskit, loads the IBM Q account, and selects the least busy backend device that has at least 3 qubits and is operational. - -```python -from qiskit import QuantumCircuit, execute, Aer, IBMQ -from qiskit.providers.ibmq import least_busy -from qiskit.visualization import plot_histogram -import numpy as np - -provider = IBMQ.load_account() -backend = least_busy(provider.backends(filters=lambda x: x.configuration().n_qubits >= 3 and - not x.configuration().simulator and x.status().operational)) -``` - -Next, a quantum circuit is created with 3 qubits and 3 classical bits. The Hadamard gate is applied to all qubits to create a superposition of all possible states. - -```python -qc = QuantumCircuit(3, 3) -qc.h(range(3)) -``` - -The Oracle is then applied. This part of the code flips the sign of the state we are searching for. In this case, the Oracle is hard-coded to flip the sign of the state `|111>`. - -```python -qc.x(range(3)) -qc.h(2) -qc.ccx(0, 1, 2) -qc.h(2) -qc.x(range(2)) -``` - -The Shor's algorithm is applied next. This part of the code amplifies the probability of the state we are searching for. - -```python -qc.h(range(3)) -qc.measure(range(3), range(3)) -``` - -Finally, the quantum circuit is executed on the selected backend, the results are retrieved, and a histogram of the results is plotted. - -```python -job = execute(qc, backend, shots=1024) -result = job.result() -counts = result.get_counts(qc) -plot_histogram(counts) -``` - -In summary, this code is a complete implementation of Shor's algorithm for 3 qubits using the Qiskit library. It creates a quantum circuit, applies the Oracle and Shor's algorithm, measures the qubits, and plots the results. - -## Variational Quantum Eigensolver (VQE) -The variational quantum eigensolver (VQE) is a quantum algorithm that can be used to find the ground state energy of a molecule or other quantum system. It combines a quantum circuit with a classical optimizer to minimize the energy of the system. -The first part of the code imports necessary libraries from Qiskit and numpy. It also loads the IBM Q account and selects the least busy backend device that has at least 3 qubits and is operational. - -```python -from qiskit import QuantumCircuit, execute, Aer, IBMQ -from qiskit.visualization import plot_histogram -from qiskit.aqua.algorithms import VQE -from qiskit.aqua.components.optimizers import COBYLA -from qiskit.aqua.components.variational_forms import RY -from qiskit.aqua.operators import WeightedPauliOperator -import numpy as np - -provider = IBMQ.load_account() -backend = least_busy(provider.backends(filters=lambda x: x.configuration().n_qubits >= 3 and - not x.configuration().simulator and x.status().operational)) -``` - -Next, a quantum circuit is created with 3 qubits and 3 classical bits. The Hadamard gate is applied to all qubits to create a superposition of all possible states. An Oracle is then applied which flips the sign of the state we are searching for. - -```python -qc = QuantumCircuit(3, 3) -qc.h(range(3)) -qc.x(range(3)) -qc.h(2) -qc.ccx(0, 1, 2) -qc.h(2) -qc.x(range(3)) -``` - -The VQE algorithm is then applied. This part of the code defines the Hamiltonian, the variational form, and the optimizer. The Hamiltonian is defined using a dictionary of Pauli operators, the variational form is defined using the RY gate, and the optimizer is defined using the COBYLA method. - -```python -pauli_dict = { - 'paulis': [{"coeff": {"imag": 0.0, "real": -1.052373245772859}, "label": "II"}, - {"coeff": {"imag": 0.0, "real": 0.39793742484318045}, "label": "ZI"}, - {"coeff": {"imag": 0.0, "real": -0.39793742484318045}, "label": "IZ"}, - {"coeff": {"imag": 0.0, "real": -0.01128010425623538}, "label": "ZZ"}, - {"coeff": {"imag": 0.0, "real": 0.18093119978423156}, "label": "XX"}] -} -qubit_op = WeightedPauliOperator.from_dict(pauli_dict) -var_form = RY(qubit_op.num_qubits, depth=3, entanglement='linear') -optimizer = COBYLA(maxiter=1000) -vqe = VQE(qubit_op, var_form, optimizer) -``` - -Finally, the quantum circuit is executed on the selected backend, the results are retrieved, and a histogram of the results is plotted. The VQE algorithm is then executed on the backend. - -```python -job = execute(qc, backend, shots=1024) -result = job.result() -counts = result.get_counts(qc) -plot_histogram(counts) -result = vqe.run(backend) -``` - -In summary, this code is a complete implementation of the VQE algorithm for 3 qubits using the Qiskit library. It creates a quantum circuit, applies the Oracle and VQE algorithm, measures the qubits, plots the results, and executes the VQE algorithm. +This contains the explanation of how the solvers work. ## Boson Sampling Boson Sampling is a type of quantum computing algorithm that is used to simulate the behavior of photons in a linear optical system.