-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmps_mylib_test.cpp
More file actions
58 lines (44 loc) · 2.02 KB
/
mps_mylib_test.cpp
File metadata and controls
58 lines (44 loc) · 2.02 KB
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
//Copyright (c) 2019 Jij Inc.
#include <itensor/all.h>
#include <itensor/util/print_macro.h>
#include <vector>
#include <qcircuit.hpp>
#include <circuit_topology.hpp>
#include <quantum_gate.hpp>
#include <circuits.hpp>
using namespace qcircuit;
int main(int argc, char const* argv[]) {
const auto topology = make_ibmq_topology();
topology.exportDotString("test.dot");
const size_t size = topology.numberOfBits();
/* start with |00 ... 00> (53qubit) */
std::vector<std::pair<std::complex<double>, std::complex<double>>>
init_qbits(size, std::make_pair(1.0, 0.0));
QCircuit circuit(topology, init_qbits);
circuit.setCutoff(1e-5);
/* Below is the demonstration of generating GHZ state */
circuit.apply(H(6), X(11)); // apply Hadamard and X to gate (6,11)
circuit.apply(H(10)); // apply Hadamard to gate 10
circuit.apply(CNOT(10, 11)); // apply CNOT to gate (10, 11)
circuit.apply(CNOT(6, 11)); // apply CNOT to gate (6, 11)
circuit.apply(H(6), H(11)); // apply Hadamard to gate (6,11)
circuit.apply(H(10)); // apply Hadamard to gate 10
/* The result should be bell state (1/sqrt(2))(|000> + |111>) */
/*
* To show GHZ state is generated, calc the overlap between |0...000....0> and |0...111....0>,
* where 000 and 111 are located on the qubit (6,10,11).
*/
QCircuit circuit000(topology, init_qbits, circuit.site()); // |0...000....0>
QCircuit circuit111(topology, init_qbits, circuit.site()); // to be |0...111....0> just below
circuit111.apply(X(6), X(11)); // flip the qubit number (6,11)
circuit111.apply(X(10)); // flip the qubit number 10
std::vector<ITensor> op;
op.reserve(size);
for(size_t i = 0;i < size;i++) {
op.push_back(circuit.generateTensorOp(Id(i)));
}
Print(overlap(circuit, op, circuit000)); //result should be -1/sqrt(2)
Print(overlap(circuit, op, circuit111)); //result should be 1/sqrt(2)
Print(overlap(circuit, op, circuit)); //result should be 1
return 0;
}