|
| 1 | +/* |
| 2 | +# This code is part of Qiskit. |
| 3 | +# |
| 4 | +# (C) Copyright IBM 2024. |
| 5 | +# |
| 6 | +# This code is licensed under the Apache License, Version 2.0. You may |
| 7 | +# obtain a copy of this license in the LICENSE.txt file in the root directory |
| 8 | +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. |
| 9 | +# |
| 10 | +# Any modifications or derivative works of this code must retain this |
| 11 | +# copyright notice, and modified files need to carry a notice indicating |
| 12 | +# that they have been altered from the originals. |
| 13 | +*/ |
| 14 | + |
| 15 | +// Test program for local target |
| 16 | + |
| 17 | +#define _USE_MATH_DEFINES |
| 18 | +#include <iostream> |
| 19 | +#include <cstdint> |
| 20 | +#include <cstdlib> |
| 21 | +#include <cmath> |
| 22 | + |
| 23 | +#include "circuit/quantumcircuit.hpp" |
| 24 | +#include "transpiler/target.hpp" |
| 25 | +#include "transpiler/passmanager.hpp" |
| 26 | +#include "transpiler/preset_passmanagers/generate_preset_pass_manager.hpp" |
| 27 | + |
| 28 | +using namespace Qiskit::circuit; |
| 29 | +using namespace Qiskit::transpiler; |
| 30 | + |
| 31 | +int main() |
| 32 | +{ |
| 33 | + QuantumRegister qr(4); |
| 34 | + ClassicalRegister cr(4); |
| 35 | + QuantumCircuit circ(qr, cr); |
| 36 | + |
| 37 | + circ.h(0); |
| 38 | + for (int i=1;i<4;i++) { |
| 39 | + circ.cx(0, i); |
| 40 | + } |
| 41 | + for (int i=0;i<4;i++) { |
| 42 | + circ.measure(i,i); |
| 43 | + } |
| 44 | + |
| 45 | + std::cout << "input circuit" << std::endl; |
| 46 | + circ.print(); |
| 47 | + |
| 48 | + |
| 49 | + auto target = Target({"h", "cx"}, {{0, 1}, {1, 0}, {1, 3}, {3, 1}, {0, 2}, {2, 0}, {2, 3}, {3, 2}}); |
| 50 | +// 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}}); |
| 51 | + auto pass = StagedPassManager({"init", "layout", "routing", "translation", "optimization"}, target); |
| 52 | + //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); |
| 53 | + auto transpiled = pass.run(circ); |
| 54 | + |
| 55 | + std::cout << "transpiled circuit" << std::endl; |
| 56 | + transpiled.print(); |
| 57 | + |
| 58 | + return 0; |
| 59 | +} |
| 60 | + |
0 commit comments