Skip to content

Commit

Permalink
feat: add progress bar and comment
Browse files Browse the repository at this point in the history
  • Loading branch information
milljoniaer committed Nov 11, 2022
1 parent 145b9e3 commit d1e3795
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@
This Repository contains quantum circuit simutlation using a Matrix-Product-State representation of the quantum state. It is an approximation algorithm to scale linear with the number of qubits and the depth of the circuit. It has been written for the Quantum Computing Seminar at the Technical University of Munich. The simulator is based on a paper about the ["Limits of the simulation of quantum computers on classical computers"](https://journals.aps.org/prx/abstract/10.1103/PhysRevX.10.041038).

## Installation
To install the dependencys of this project run `pip3 install numpy`. This project relies on the algebraic operations of numpy.
To use this simulation package you need to install some dependencies.

Run the following code to install them:

```
pip3 install numpy # needed for the tensor operations
pip3 install tqdm # displays a progress bar during running the circuit
# optional for recalculating the results (plotting)
# pip3 install matplotlib
```

## Examples

Expand Down
3 changes: 2 additions & 1 deletion simulation/circuit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
from tqdm import tqdm
from .operations import *

class Circuit:
Expand Down Expand Up @@ -39,7 +40,7 @@ def run(self):
Applies the circuit.
The Gates are applied on their qubits in the order they are in the array
"""
for gate in self.gates:
for gate in tqdm(self.gates):
if gate["type"] == "one":
if self.verbose:
print(f'One qubit gate at {gate["i"]}')
Expand Down
6 changes: 5 additions & 1 deletion simulation/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ def calculate_fidelity(fidelities, S, chi):

fidelity = np.sqrt(approx_sum) / np.sqrt(perfect_sum)
if math.isnan(fidelity):
# happens if the difference is to small, therefore we approximate with 1
# sometime the fidelity gets "nan", this is probably the case when small values due to the square and sqrt functions are rounded up to 0
# hence we get a "divided by 0 -> nan"
# I tried to leave those values out of the calculation of the average fidelity, but that turns out to return in a weird shaped curve
# I got better results (well-shaped curve) when approximating this one 2-qubit gate fidelity with "1"
# since this happens only with small values the error, which is added here, should not be large and occurs only in this specific gate.
fidelities.append(1)
else:
fidelities.append(fidelity)
Expand Down

0 comments on commit d1e3795

Please sign in to comment.