|
| 1 | +#include "quartz/gate/gate_utils.h" |
| 2 | +#include "quartz/verifier/verifier.h" |
| 3 | +#include "test/test_optimization_steps.h" |
| 4 | + |
| 5 | +#include <filesystem> |
| 6 | +#include <iostream> |
| 7 | + |
| 8 | +using namespace quartz; |
| 9 | + |
| 10 | +const std::vector<std::string> kCircuitNames = { |
| 11 | + "tof_3", "barenco_tof_3", "mod5_4", "tof_4", |
| 12 | + "tof_5", "barenco_tof_4", "mod_mult_55", "vbe_adder_3", |
| 13 | + "barenco_tof_5", "csla_mux_3", "rc_adder_6", "gf2^4_mult", |
| 14 | + "tof_10", "mod_red_21", "gf2^5_mult", "csum_mux_9", |
| 15 | + "qcla_com_7", "barenco_tof_10", "gf2^6_mult", "qcla_adder_10", |
| 16 | + "gf2^7_mult", "gf2^8_mult", "qcla_mod_7", "adder_8", |
| 17 | + "gf2^9_mult", "gf2^10_mult"}; |
| 18 | +int main() { |
| 19 | + ParamInfo param_info; |
| 20 | + Context ctx({GateType::input_qubit, GateType::input_param, GateType::cx, |
| 21 | + GateType::h, GateType::rz, GateType::x, GateType::pi, |
| 22 | + GateType::mult, GateType::add}, |
| 23 | + ¶m_info); |
| 24 | + EquivalenceSet eqs; |
| 25 | + // Load equivalent dags from file |
| 26 | + if (!eqs.load_json( |
| 27 | + &ctx, |
| 28 | + (kQuartzRootPath / "eccset/Nam_6_3_complete_ECC_set.json").string(), |
| 29 | + /*from_verifier=*/false)) { |
| 30 | + std::cout |
| 31 | + << "Failed to load equivalence file \"" |
| 32 | + << (kQuartzRootPath / "eccset/Nam_6_3_complete_ECC_set.json").string() |
| 33 | + << "\"." << std::endl; |
| 34 | + assert(false); |
| 35 | + } |
| 36 | + if (!std::filesystem::exists(kQuartzRootPath / "benchmark-logs")) { |
| 37 | + std::filesystem::create_directory(kQuartzRootPath / "benchmark-logs"); |
| 38 | + } |
| 39 | + Verifier verifier; |
| 40 | + auto xfers = GraphXfer::get_all_xfers_from_ecc( |
| 41 | + &ctx, |
| 42 | + (kQuartzRootPath / "eccset/Nam_6_3_complete_ECC_set.json").string()); |
| 43 | + for (const auto &circuit : kCircuitNames) { |
| 44 | + freopen(((kQuartzRootPath / "benchmark-logs" / circuit).string() + ".log") |
| 45 | + .c_str(), |
| 46 | + "w", stdout); |
| 47 | + test_optimization(&ctx, |
| 48 | + (kQuartzRootPath / "circuit/nam-benchmarks" / |
| 49 | + (circuit + ".qasm.toffoli_flip")) |
| 50 | + .string(), |
| 51 | + xfers, |
| 52 | + /*timeout=*/1, |
| 53 | + (kQuartzRootPath / "benchmark-logs" / circuit).string() + |
| 54 | + "_"); |
| 55 | + bool verified = verifier.verify_transformation_steps( |
| 56 | + &ctx, (kQuartzRootPath / "benchmark-logs" / circuit).string() + "_", |
| 57 | + /*verbose=*/false); |
| 58 | + if (verified) { |
| 59 | + std::cout << "All transformations are verified." << std::endl; |
| 60 | + } else { |
| 61 | + std::cout << "Some transformation is not verified." << std::endl; |
| 62 | + } |
| 63 | + } |
| 64 | + return 0; |
| 65 | +} |
0 commit comments