-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtarget_test.cpp
More file actions
60 lines (48 loc) · 1.75 KB
/
target_test.cpp
File metadata and controls
60 lines (48 loc) · 1.75 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
59
/*
# This code is part of Qiskit.
#
# (C) Copyright IBM 2024.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
*/
// Test program for local target
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include "circuit/quantumcircuit.hpp"
#include "transpiler/target.hpp"
#include "transpiler/passmanager.hpp"
#include "transpiler/preset_passmanagers/generate_preset_pass_manager.hpp"
using namespace Qiskit::circuit;
using namespace Qiskit::transpiler;
int main()
{
QuantumRegister qr(4);
ClassicalRegister cr(4);
QuantumCircuit circ(qr, cr);
circ.h(0);
for (int i=1;i<4;i++) {
circ.cx(0, i);
}
for (int i=0;i<4;i++) {
circ.measure(i,i);
}
std::cout << "input circuit" << std::endl;
circ.draw();
auto target = Target({"h", "cx"}, {{0, 1}, {1, 0}, {1, 3}, {3, 1}, {0, 2}, {2, 0}, {2, 3}, {3, 2}});
// auto target = Target({"cz", "id", "rx", "rz", "rzz", "sx", "x"}, {{0, 1}, {1, 0}, {1, 3}, {3, 1}, {0, 2}, {2, 0}, {2, 3}, {3, 2}});
auto pass = StagedPassManager({"init", "layout", "routing", "translation", "optimization"}, target);
//auto pass = generate_preset_pass_manager(2, {"h", "cx"}, {{0, 1}, {1, 0}, {1, 3}, {3, 1}, {0, 2}, {2, 0}, {2, 3}, {3, 2}}, 1.0, 1);
auto transpiled = pass.run(circ);
std::cout << "transpiled circuit" << std::endl;
transpiled.draw();
return 0;
}