Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 054ba88

Browse files
committed
rework
1 parent 7c0d3b4 commit 054ba88

File tree

5 files changed

+4
-239
lines changed

5 files changed

+4
-239
lines changed

.idea/Traveling-Salesman-Problem 2.0.iml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Standard_Quantum_Solvers/Grover.py

-20
This file was deleted.

Standard_Quantum_Solvers/Shor.py

-20
This file was deleted.

Standard_Quantum_Solvers/Variational_Quantum_Eiegensolver.py

-30
This file was deleted.

Writerside/topics/How-the-Solvers-work.md

+1-169
Original file line numberDiff line numberDiff line change
@@ -1,173 +1,5 @@
11
# How the Solvers work
2-
3-
## Grover's algorithm
4-
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.
5-
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.
6-
7-
```python
8-
from qiskit import QuantumCircuit, execute, Aer, IBMQ
9-
from qiskit.providers.ibmq import least_busy
10-
from qiskit.visualization import plot_histogram
11-
12-
provider = IBMQ.load_account()
13-
backend = least_busy(provider.backends(filters=lambda x: x.configuration().n_qubits >= 3 and
14-
not x.configuration().simulator and x.status().operational))
15-
```
16-
17-
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.
18-
19-
```python
20-
qc = QuantumCircuit(3, 3)
21-
qc.h(range(3))
22-
```
23-
24-
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>`.
25-
26-
```python
27-
qc.x(range(3))
28-
qc.h(2)
29-
qc.ccx(0, 1, 2)
30-
qc.h(2)
31-
qc.x(range(3))
32-
```
33-
34-
The Grover diffusion operator is applied next. This part of the code amplifies the probability of the state we are searching for.
35-
36-
```python
37-
qc.h(range(3))
38-
qc.x(range(3))
39-
qc.h(2)
40-
qc.ccx(0, 1, 2)
41-
qc.h(2)
42-
qc.x(range(3))
43-
qc.h(range(3))
44-
```
45-
46-
The qubits are then measured and the results are stored in the classical bits.
47-
48-
```python
49-
qc.measure(range(3), range(3))
50-
```
51-
52-
Finally, the quantum circuit is executed on the selected backend, the results are retrieved, and a histogram of the results is plotted.
53-
54-
```python
55-
job = execute(qc, backend, shots=1024)
56-
result = job.result()
57-
counts = result.get_counts(qc)
58-
plot_histogram(counts)
59-
```
60-
61-
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.
62-
63-
## Shor's algorithm
64-
65-
Shor's algorithm is a quantum algorithm for integer factorization, which underlies the security of many cryptographic systems.
66-
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.
67-
68-
```python
69-
from qiskit import QuantumCircuit, execute, Aer, IBMQ
70-
from qiskit.providers.ibmq import least_busy
71-
from qiskit.visualization import plot_histogram
72-
import numpy as np
73-
74-
provider = IBMQ.load_account()
75-
backend = least_busy(provider.backends(filters=lambda x: x.configuration().n_qubits >= 3 and
76-
not x.configuration().simulator and x.status().operational))
77-
```
78-
79-
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.
80-
81-
```python
82-
qc = QuantumCircuit(3, 3)
83-
qc.h(range(3))
84-
```
85-
86-
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>`.
87-
88-
```python
89-
qc.x(range(3))
90-
qc.h(2)
91-
qc.ccx(0, 1, 2)
92-
qc.h(2)
93-
qc.x(range(2))
94-
```
95-
96-
The Shor's algorithm is applied next. This part of the code amplifies the probability of the state we are searching for.
97-
98-
```python
99-
qc.h(range(3))
100-
qc.measure(range(3), range(3))
101-
```
102-
103-
Finally, the quantum circuit is executed on the selected backend, the results are retrieved, and a histogram of the results is plotted.
104-
105-
```python
106-
job = execute(qc, backend, shots=1024)
107-
result = job.result()
108-
counts = result.get_counts(qc)
109-
plot_histogram(counts)
110-
```
111-
112-
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.
113-
114-
## Variational Quantum Eigensolver (VQE)
115-
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.
116-
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.
117-
118-
```python
119-
from qiskit import QuantumCircuit, execute, Aer, IBMQ
120-
from qiskit.visualization import plot_histogram
121-
from qiskit.aqua.algorithms import VQE
122-
from qiskit.aqua.components.optimizers import COBYLA
123-
from qiskit.aqua.components.variational_forms import RY
124-
from qiskit.aqua.operators import WeightedPauliOperator
125-
import numpy as np
126-
127-
provider = IBMQ.load_account()
128-
backend = least_busy(provider.backends(filters=lambda x: x.configuration().n_qubits >= 3 and
129-
not x.configuration().simulator and x.status().operational))
130-
```
131-
132-
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.
133-
134-
```python
135-
qc = QuantumCircuit(3, 3)
136-
qc.h(range(3))
137-
qc.x(range(3))
138-
qc.h(2)
139-
qc.ccx(0, 1, 2)
140-
qc.h(2)
141-
qc.x(range(3))
142-
```
143-
144-
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.
145-
146-
```python
147-
pauli_dict = {
148-
'paulis': [{"coeff": {"imag": 0.0, "real": -1.052373245772859}, "label": "II"},
149-
{"coeff": {"imag": 0.0, "real": 0.39793742484318045}, "label": "ZI"},
150-
{"coeff": {"imag": 0.0, "real": -0.39793742484318045}, "label": "IZ"},
151-
{"coeff": {"imag": 0.0, "real": -0.01128010425623538}, "label": "ZZ"},
152-
{"coeff": {"imag": 0.0, "real": 0.18093119978423156}, "label": "XX"}]
153-
}
154-
qubit_op = WeightedPauliOperator.from_dict(pauli_dict)
155-
var_form = RY(qubit_op.num_qubits, depth=3, entanglement='linear')
156-
optimizer = COBYLA(maxiter=1000)
157-
vqe = VQE(qubit_op, var_form, optimizer)
158-
```
159-
160-
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.
161-
162-
```python
163-
job = execute(qc, backend, shots=1024)
164-
result = job.result()
165-
counts = result.get_counts(qc)
166-
plot_histogram(counts)
167-
result = vqe.run(backend)
168-
```
169-
170-
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.
2+
This contains the explanation of how the solvers work.
1713

1724
## Boson Sampling
1735
Boson Sampling is a type of quantum computing algorithm that is used to simulate the behavior of photons in a linear optical system.

0 commit comments

Comments
 (0)