-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxacc_app.cpp
52 lines (39 loc) · 1.2 KB
/
xacc_app.cpp
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
#include "xacc.hpp"
void tnqvm_simulation() {
//Choose the desired quantum accelerator:
auto qpu = xacc::getAccelerator("tnqvm", {std::make_pair("tnqvm-visitor", "exatn")});
//Choose the desired quantum programming language:
auto xasmCompiler = xacc::getCompiler("xasm");
//Compile a quantum kernel into the quantum IR:
auto ir = xasmCompiler->compile(
R"(__qpu__ void ansatz(qbit q, double theta) {
X(q[0]);
Ry(q[1], theta);
CX(q[1], q[0]);
H(q[0]);
H(q[1]);
Measure(q[0]);
Measure(q[1]);
})", qpu);
//Get the generated parameterized quantum circuit:
auto circuit = ir->getComposite("ansatz");
//Perform hybrid quantum/classical computation:
auto angles = xacc::linspace(-3.1415, 3.1415, 20);
for (auto & a: angles) {
auto evaled = (*circuit)({a});
auto qubits = xacc::qalloc(2);
qpu->execute(qubits, evaled);
auto exp_val = qubits->getExpectationValueZ();
std::cout << "<X0X1>(" << a << ") = " << exp_val << "\n";
}
return;
}
int main(int argc, char** argv) {
//Initialize the XACC runtime:
xacc::Initialize(argc, argv);
//Perform the quantum circuit simulation defined above:
tnqvm_simulation();
//Finalize the XACC runtime:
xacc::Finalize();
return 0;
}