Skip to content

Commit

Permalink
adding examples
Browse files Browse the repository at this point in the history
  • Loading branch information
scarrazza committed Sep 25, 2023
1 parent c5a128b commit 49234ca
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
1 change: 1 addition & 0 deletions doc/source/code-examples/applications.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Combinatorics
:maxdepth: 1

tutorials/qap/README.md
tutorials/mvc/README.md


Applications by algorithm
Expand Down
1 change: 1 addition & 0 deletions doc/source/code-examples/tutorials/mvc/README.md
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ physics problems.
- [Quantum k-medians clustering](qclustering/README.md)
- [Determining probability density functions with adiabatic quantum computing](adiabatic_qml/adiabatic-qml.ipynb)
- [Quadratic assignment problem (QAP)](qap/README.md)
- [Minimum Vertex Cover (MVC)](mvc/README.md)

In the `benchmarks` folder we have included examples concerning:
- A generic benchmark script for multiple circuits (`benchmarks/main.py`)
Expand Down
37 changes: 19 additions & 18 deletions examples/mvc/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
```python
import networkx as nx
import csv
import matplotlib.pyplot as plt

from mvc import qubo_mvc, qubo_mvc_penalty, mvc_feasibility, mvc_easy_fix, mvc_energy
```
# Minimum Vertex Cover (MVC)

# MVC Definition
Code at: [https://github.com/qiboteam/qibo/tree/master/examples/mvc](https://github.com/qiboteam/qibo/tree/master/examples/mvc)

Given an undirected graph with a set of nodes V and edges E, A vertex cover of a graph is a set of nodes that includes at
least one endpoint of every edge of the graph. The Minimum Vertex Cover (MVC) problem is an optimisation problem
that find smallest vertex cover of a given graph.

# Load graph from csv
## Load graph from csv


```python
import networkx as nx
import csv
import matplotlib.pyplot as plt

from mvc import qubo_mvc, qubo_mvc_penalty, mvc_feasibility, mvc_easy_fix, mvc_energy


def load_csv(filename:str):
""" Load graph from csv file
"""
Expand Down Expand Up @@ -88,9 +89,9 @@ print(f'Number of edge is {len(g.edges)}')
Number of edge is 9


# QUBO formulation
## QUBO formulation

## Estimate penalty
### Estimate penalty


```python
Expand All @@ -101,7 +102,7 @@ print(f'The penalty is {penalty}')
The penalty is 1.6548482220717595


## Formulate QUBO (weighted minimum vertex cover)
### Formulate QUBO (weighted minimum vertex cover)


```python
Expand All @@ -115,7 +116,7 @@ print(f'Number of quadratic terms: {len(quadratic)}\n')



## Generate random solutions
### Generate random solutions


```python
Expand All @@ -129,7 +130,7 @@ print(f'The random solution is {random_solution}\n')



## Check feasibility
### Check feasibility


```python
Expand All @@ -141,7 +142,7 @@ print(f'The feasibility is {feasibility}\n')



## Fix broken constraints
### Fix broken constraints


```python
Expand All @@ -163,7 +164,7 @@ print(f'The feasibility is {feasibility}\n')



## Visualisation
### Visualisation


```python
Expand All @@ -189,7 +190,7 @@ ax1.set_title(f'Vertex cover in orange after fix')



## Calculate energy
### Calculate energy


```python
Expand All @@ -200,7 +201,7 @@ print(f'The energy is {energy}')
The energy is 3.2102004750256556


# Hamiltonian of the MVC problem
## Hamiltonian of the MVC problem


```python
Expand Down

0 comments on commit 49234ca

Please sign in to comment.