-
Notifications
You must be signed in to change notification settings - Fork 0
/
testCircuit1.py
executable file
·92 lines (70 loc) · 2.7 KB
/
testCircuit1.py
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
from QuESTPy.QuESTBase import init_QuESTLib
from TNPy.TNBase import init_TNLib
# If set up
QuESTPath = "build/TN/QuEST/"
TNPath = "build/TN/"
init_QuESTLib(QuESTPath)
init_TNLib(TNPath)
#!/usr/bin/env python3
from QuESTPy.QuESTFunc import *
from TNPy.TNFunc import *
from TNPy.TNAdditionalGates import *
print("---------------------------------")
print("---- Create QuEST environment----")
print("---------------------------------")
env = createQuESTEnv()
reportQuESTEnv(env)
print("\n\n--------------------------------------------------------------")
print("---- QuEST example of a two qubit circuit: X(0), CNOT(0,1)----")
print("--------------------------------------------------------------")
print("Create qureg. It will be in the zero state by default")
qureg = createQureg(2, env);
print("qureg:")
print(qureg)
print("Apply PauliX to qubit 0")
pauliX(qureg, 0);
print("qureg:")
print(qureg)
print("Apply controlled not controlled by qubit 0 to qubit 1")
controlledNot(qureg, 0, 1);
print("qureg:")
print(qureg)
print("\n\n-----------------------------------------------------------")
print("---- TN example of a two qubit circuit: X(0), CNOT(0,1)----")
print("-----------------------------------------------------------")
print("Create tensor1. It will be in the zero state by default");
tensor1 = createTensor(1, 1, env)
print("Tensor1:");
print(tensor1.qureg)
print("Create tensor2. It will be in the zero state by default");
tensor2 = createTensor(1, 1, env)
print("Tensor2:");
print(tensor2.qureg)
print("Apply pauliX to global qubit 0, which is qubit 0 in tensor1");
TN_singleQubitGate(pauliX, tensor1, 0)
print("Tensor1:");
print(tensor1.qureg)
print("Apply a controlled not gate controlled by global qubit 0, to global qubit 1");
TN_controlledGateControlHalf(controlledNot, tensor1, 0, 1)
TN_controlledGateTargetHalf(controlledNot, tensor2, 1, 0)
print("Tensor1:");
print(tensor1.qureg)
print("Tensor2:");
print(tensor2.qureg)
print("Contract tensor1 and tensor2 across their virtual qubit index");
tensor1Contractions = [1]
tensor2Contractions = [1]
tensor1FreeIndices = [0]
tensor2FreeIndices = [0]
numContractions = 1
numTensor1FreeIndices = 1
numTensor2FreeIndices = 1
# Cast to correct type for c
tensor1Contractions = (c_int*numContractions)(*tensor1Contractions)
tensor2Contractions = (c_int*numContractions)(*tensor2Contractions)
tensor1FreeIndices = (c_int*numTensor1FreeIndices)(*tensor1FreeIndices)
tensor2FreeIndices = (c_int*numTensor2FreeIndices)(*tensor2FreeIndices)
outputTensor = contractIndices(tensor1, tensor2, tensor1Contractions, tensor2Contractions, numContractions,
tensor1FreeIndices, numTensor2FreeIndices, tensor2FreeIndices, numTensor2FreeIndices, env)
print("output tensor:")
print(outputTensor.qureg)