-
Notifications
You must be signed in to change notification settings - Fork 3
/
Main.idr
94 lines (70 loc) · 1.96 KB
/
Main.idr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
module Main
import Data.Nat
import Data.Vect
import Data.List
import LinearTypes
import Control.Linear.LIO
import Unitary
import QStateT
import Teleportation
import System.Random
import Injection
import QFT
import Grover
import AlterningBitsOracle
import VQE
import Complex
import QuantumOp
import CoinToss
import QAOA
import Graph
import Examples
import RUS
-- %default total
||| Perform 1000 fair coin tosses and count the number of heads
||| (via simulating the quantum dynamics).
testCoins : IO ()
testCoins = do
let f = coin {t = SimulatedOp}
s <- sequence (Data.List.replicate 1000 f)
let heads = filter (== True) s
putStrLn $ "Number of heads: " ++ (show (length heads))
||| Test graph for the QAOA problem
export
graph1 : Graph 5
graph1 = AddVertex (AddVertex (AddVertex (AddVertex (AddVertex Empty []) [True]) [True, True]) [False, True, False]) [False, False, True, True]
||| Execute QAOA with 100 samples on the previous graph to solve the MAXCUT problem
export
testQAOA : IO (Cut 5)
testQAOA = do
QAOA {t = SimulatedOp} 100 1 graph1
||| Small test for the VQE algorithm
export
testVQE : IO Double
testVQE = do
putStrLn "Test VQE"
let hamiltonian = [(2, [PauliX, PauliY]),(3,[PauliZ, PauliI])]
VQE {t = SimulatedOp} 2 hamiltonian 5 10 5
export
main : IO ()
main = do
-- Execute the example file and draw the circuit examples
drawExamples
-- Draw the Quantum Fourier Transform for n = 3
-- putStrLn "\n\n\nQuantum Fourier Transform for n = 3"
-- draw (qft 3)
-- Execute the coin toss example
putStrLn "\nTest coin toss by performing 1000 coin tosses."
testCoins
-- Repeat until success
putStrLn "\nTest 'Repeat Until Success'. Probability to measure '1' is 2/3 for this example."
testMultipleRUS 10000
-- VQE
-- putStrLn "\nSmall test with VQE"
-- r <- testVQE
-- putStrLn $ "result from VQE : " ++ show r
-- QAOA
putStrLn "\nSmall test with QAOA"
cut <- testQAOA
putStrLn $ "result from QAOA : " ++ show cut
pure ()