Skip to content

Commit

Permalink
rework
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkStarStrix committed May 9, 2024
1 parent 7c0d3b4 commit 054ba88
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 239 deletions.
3 changes: 3 additions & 0 deletions .idea/Traveling-Salesman-Problem 2.0.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 0 additions & 20 deletions Standard_Quantum_Solvers/Grover.py

This file was deleted.

20 changes: 0 additions & 20 deletions Standard_Quantum_Solvers/Shor.py

This file was deleted.

30 changes: 0 additions & 30 deletions Standard_Quantum_Solvers/Variational_Quantum_Eiegensolver.py

This file was deleted.

170 changes: 1 addition & 169 deletions Writerside/topics/How-the-Solvers-work.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit 054ba88

Please sign in to comment.