From 549db4058bcdab0076bbb6026b2b237ce83c6153 Mon Sep 17 00:00:00 2001 From: burgholzer Date: Mon, 12 Aug 2024 20:19:39 +0200 Subject: [PATCH 01/13] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20reorganize=20library?= =?UTF-8?q?=20structure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: burgholzer --- cmake/mqt-core-config.cmake.in | 3 - eval/CMakeLists.txt | 3 +- eval/eval_dd_package.cpp | 2 +- include/mqt-core/Definitions.hpp | 10 +- .../mqt-core/algorithms/BernsteinVazirani.hpp | 2 +- include/mqt-core/algorithms/Entanglement.hpp | 2 +- .../GoogleRandomCircuitSampling.hpp | 62 - include/mqt-core/algorithms/Grover.hpp | 2 +- include/mqt-core/algorithms/QFT.hpp | 2 +- include/mqt-core/algorithms/QPE.hpp | 2 +- .../algorithms/RandomCliffordCircuit.hpp | 2 +- include/mqt-core/algorithms/WState.hpp | 2 +- .../CircuitOptimizer.hpp | 8 +- include/mqt-core/datastructures/Layer.hpp | 6 +- include/mqt-core/dd/DDpackageConfig.hpp | 2 +- .../mqt-core/dd/FunctionalityConstruction.hpp | 13 +- include/mqt-core/dd/NoiseFunctionality.hpp | 4 +- include/mqt-core/dd/Operations.hpp | 14 +- include/mqt-core/dd/Package.hpp | 4 +- include/mqt-core/dd/Simulation.hpp | 8 +- include/mqt-core/{ => ir}/Permutation.hpp | 0 .../mqt-core/{ => ir}/QuantumComputation.hpp | 9 +- .../{ => ir}/operations/AodOperation.hpp | 2 +- .../operations/ClassicControlledOperation.hpp | 6 +- .../{ => ir}/operations/CompoundOperation.hpp | 4 +- .../mqt-core/{ => ir}/operations/Control.hpp | 0 .../{ => ir}/operations/Expression.hpp | 0 .../operations/NonUnitaryOperation.hpp | 6 +- .../mqt-core/{ => ir}/operations/OpType.hpp | 0 .../{ => ir}/operations/Operation.hpp | 4 +- .../{ => ir}/operations/StandardOperation.hpp | 6 +- .../{ => ir}/operations/SymbolicOperation.hpp | 6 +- .../parsers/qasm3_parser/Exception.hpp | 0 .../{ => ir}/parsers/qasm3_parser/Gate.hpp | 2 +- .../parsers/qasm3_parser/InstVisitor.hpp | 0 .../qasm3_parser/NestedEnvironment.hpp | 0 .../{ => ir}/parsers/qasm3_parser/Parser.hpp | 6 +- .../{ => ir}/parsers/qasm3_parser/Scanner.hpp | 0 .../parsers/qasm3_parser/Statement.hpp | 4 +- .../parsers/qasm3_parser/StdGates.hpp | 2 +- .../{ => ir}/parsers/qasm3_parser/Token.hpp | 0 .../{ => ir}/parsers/qasm3_parser/Types.hpp | 0 .../qasm3_parser/passes/CompilerPass.hpp | 2 +- .../qasm3_parser/passes/ConstEvalPass.hpp | 8 +- .../qasm3_parser/passes/TypeCheckPass.hpp | 10 +- include/mqt-core/na/NAComputation.hpp | 4 +- include/mqt-core/na/NADefinitions.hpp | 6 +- .../na/operations/NAGlobalOperation.hpp | 5 +- .../na/operations/NALocalOperation.hpp | 5 +- .../mqt-core/na/operations/NAOperation.hpp | 1 + .../na/operations/NAShuttlingOperation.hpp | 4 +- .../mqt-core/python/qiskit/QuantumCircuit.hpp | 7 +- .../mqt-core/zx/FunctionalityConstruction.hpp | 12 +- include/mqt-core/zx/Rules.hpp | 2 +- include/mqt-core/zx/Simplify.hpp | 6 +- include/mqt-core/zx/Utils.hpp | 2 +- include/mqt-core/zx/ZXDefinitions.hpp | 4 +- include/mqt-core/zx/ZXDiagram.hpp | 4 +- src/CMakeLists.txt | 133 +- src/algorithms/CMakeLists.txt | 52 + src/algorithms/Entanglement.cpp | 2 +- .../GoogleRandomCircuitSampling.cpp | 165 -- src/algorithms/Grover.cpp | 4 +- src/algorithms/QFT.cpp | 2 +- src/algorithms/QPE.cpp | 2 +- src/algorithms/RandomCliffordCircuit.cpp | 4 +- src/algorithms/WState.cpp | 2 +- src/circuit_optimizer/CMakeLists.txt | 56 + .../CircuitOptimizer.cpp | 106 +- src/datastructures/CMakeLists.txt | 32 +- src/datastructures/Layer.cpp | 8 +- src/dd/Benchmark.cpp | 101 +- src/dd/CMakeLists.txt | 54 +- src/dd/FunctionalityConstruction.cpp | 97 +- src/dd/NoiseFunctionality.cpp | 4 +- src/dd/Operations.cpp | 8 +- src/dd/Simulation.cpp | 36 +- src/ir/CMakeLists.txt | 49 + src/{ => ir}/QuantumComputation.cpp | 157 +- src/{ => ir}/operations/AodOperation.cpp | 10 +- .../operations/ClassicControlledOperation.cpp | 2 +- src/{ => ir}/operations/CompoundOperation.cpp | 16 +- src/{ => ir}/operations/Expression.cpp | 2 +- .../operations/NonUnitaryOperation.cpp | 8 +- src/{ => ir}/operations/Operation.cpp | 8 +- src/{ => ir}/operations/StandardOperation.cpp | 8 +- src/{ => ir}/operations/SymbolicOperation.cpp | 12 +- src/{ => ir}/parsers/QASM3Parser.cpp | 38 +- src/{ => ir}/parsers/QCParser.cpp | 8 +- src/{ => ir}/parsers/RealParser.cpp | 8 +- src/{ => ir}/parsers/TFCParser.cpp | 6 +- src/{ => ir}/parsers/qasm3_parser/Parser.cpp | 12 +- src/{ => ir}/parsers/qasm3_parser/Scanner.cpp | 4 +- .../parsers/qasm3_parser/Statement.cpp | 4 +- src/{ => ir}/parsers/qasm3_parser/Types.cpp | 2 +- .../qasm3_parser/passes/ConstEvalPass.cpp | 8 +- .../qasm3_parser/passes/TypeCheckPass.cpp | 8 +- src/na/CMakeLists.txt | 32 +- src/parsers/GRCSParser.cpp | 50 - src/python/CMakeLists.txt | 2 +- .../register_classic_controlled_operation.cpp | 4 +- .../register_compound_operation.cpp | 4 +- src/python/operations/register_control.cpp | 2 +- .../register_non_unitary_operation.cpp | 6 +- src/python/operations/register_operation.cpp | 4 +- src/python/operations/register_optype.cpp | 2 +- .../register_standard_operation.cpp | 8 +- .../register_symbolic_operation.cpp | 10 +- src/python/qiskit/QuantumCircuit.cpp | 14 +- src/python/register_permutation.cpp | 4 +- src/python/register_quantum_computation.cpp | 10 +- src/python/symbolic/register_expression.cpp | 2 +- src/python/symbolic/register_term.cpp | 2 +- src/python/symbolic/register_variable.cpp | 2 +- src/zx/CMakeLists.txt | 40 +- src/zx/FunctionalityConstruction.cpp | 12 +- src/zx/ZXDiagram.cpp | 2 +- test/CMakeLists.txt | 41 +- test/algorithms/CMakeLists.txt | 5 + test/algorithms/eval_dynamic_circuits.cpp | 18 +- test/algorithms/test_bernsteinvazirani.cpp | 2 +- test/algorithms/test_grcs.cpp | 39 - test/algorithms/test_qpe.cpp | 2 +- test/circuit_optimizer/CMakeLists.txt | 6 + .../test_backpropagate_output_permutation.cpp | 4 +- test/circuit_optimizer/test_cancel_cnots.cpp | 75 + .../circuit_optimizer/test_collect_blocks.cpp | 4 +- .../circuit_optimizer/test_decompose_swap.cpp | 137 + .../test_defer_measurements.cpp | 8 +- .../test_elide_permutations.cpp | 6 +- .../test_eliminate_resets.cpp | 227 ++ .../test_flatten_operations.cpp | 102 + ...t_remove_diagonal_gates_before_measure.cpp | 119 + .../test_remove_final_measurements.cpp | 163 ++ .../test_remove_operation.cpp | 87 + .../test_replace_mcx_with_mcz.cpp | 92 + .../test_single_qubit_gate_fusion.cpp | 115 + .../test_swap_reconstruction.cpp | 64 + test/circuits/grcs/bris_4_40_9_v2.txt | 295 -- test/circuits/grcs/bris_7_40_9_v2.txt | 752 ----- test/circuits/grcs/inst_4x4_80_9_v2.txt | 765 ------ test/circuits/grcs/inst_5x6_80_9_v2.txt | 1465 ---------- test/circuits/grcs/inst_7x7_80_9_v2.txt | 2433 ----------------- test/datastructures/test_layer.cpp | 6 +- test/dd/CMakeLists.txt | 5 + test/dd/test_dd_functionality.cpp | 12 +- test/dd/test_dd_noise_functionality.cpp | 4 +- test/dd/test_package.cpp | 2 +- test/ir/CMakeLists.txt | 4 + test/{unittests => ir}/test_io.cpp | 29 +- test/{ => ir}/test_operation.cpp | 16 +- test/{unittests => ir}/test_qasm3_parser.cpp | 18 +- .../test_qfr_functionality.cpp | 1134 +------- test/{unittests => ir}/test_symbolic.cpp | 8 +- test/na/test_nacomputation.cpp | 2 +- test/na/test_nadefinitions.cpp | 4 +- test/na/test_naoperation.cpp | 2 +- .../test_reorder_operations.cpp | 40 - test/zx/CMakeLists.txt | 4 + test/zx/test_expression.cpp | 2 +- test/zx/test_simplify.cpp | 2 +- test/zx/test_zx_functionality.cpp | 12 +- 162 files changed, 2131 insertions(+), 7943 deletions(-) delete mode 100644 include/mqt-core/algorithms/GoogleRandomCircuitSampling.hpp rename include/mqt-core/{ => circuit_optimizer}/CircuitOptimizer.hpp (95%) rename include/mqt-core/{ => ir}/Permutation.hpp (100%) rename include/mqt-core/{ => ir}/QuantumComputation.hpp (99%) rename include/mqt-core/{ => ir}/operations/AodOperation.hpp (98%) rename include/mqt-core/{ => ir}/operations/ClassicControlledOperation.hpp (98%) rename include/mqt-core/{ => ir}/operations/CompoundOperation.hpp (99%) rename include/mqt-core/{ => ir}/operations/Control.hpp (100%) rename include/mqt-core/{ => ir}/operations/Expression.hpp (100%) rename include/mqt-core/{ => ir}/operations/NonUnitaryOperation.hpp (97%) rename include/mqt-core/{ => ir}/operations/OpType.hpp (100%) rename include/mqt-core/{ => ir}/operations/Operation.hpp (99%) rename include/mqt-core/{ => ir}/operations/StandardOperation.hpp (97%) rename include/mqt-core/{ => ir}/operations/SymbolicOperation.hpp (98%) rename include/mqt-core/{ => ir}/parsers/qasm3_parser/Exception.hpp (100%) rename include/mqt-core/{ => ir}/parsers/qasm3_parser/Gate.hpp (97%) rename include/mqt-core/{ => ir}/parsers/qasm3_parser/InstVisitor.hpp (100%) rename include/mqt-core/{ => ir}/parsers/qasm3_parser/NestedEnvironment.hpp (100%) rename include/mqt-core/{ => ir}/parsers/qasm3_parser/Parser.hpp (97%) rename include/mqt-core/{ => ir}/parsers/qasm3_parser/Scanner.hpp (100%) rename include/mqt-core/{ => ir}/parsers/qasm3_parser/Statement.hpp (99%) rename include/mqt-core/{ => ir}/parsers/qasm3_parser/StdGates.hpp (99%) rename include/mqt-core/{ => ir}/parsers/qasm3_parser/Token.hpp (100%) rename include/mqt-core/{ => ir}/parsers/qasm3_parser/Types.hpp (100%) rename include/mqt-core/{ => ir}/parsers/qasm3_parser/passes/CompilerPass.hpp (79%) rename include/mqt-core/{ => ir}/parsers/qasm3_parser/passes/ConstEvalPass.hpp (96%) rename include/mqt-core/{ => ir}/parsers/qasm3_parser/passes/TypeCheckPass.hpp (94%) create mode 100644 src/algorithms/CMakeLists.txt delete mode 100644 src/algorithms/GoogleRandomCircuitSampling.cpp create mode 100644 src/circuit_optimizer/CMakeLists.txt rename src/{ => circuit_optimizer}/CircuitOptimizer.cpp (94%) create mode 100644 src/ir/CMakeLists.txt rename src/{ => ir}/QuantumComputation.cpp (88%) rename src/{ => ir}/operations/AodOperation.cpp (96%) rename src/{ => ir}/operations/ClassicControlledOperation.cpp (93%) rename src/{ => ir}/operations/CompoundOperation.cpp (96%) rename src/{ => ir}/operations/Expression.cpp (92%) rename src/{ => ir}/operations/NonUnitaryOperation.cpp (97%) rename src/{ => ir}/operations/Operation.cpp (97%) rename src/{ => ir}/operations/StandardOperation.cpp (99%) rename src/{ => ir}/operations/SymbolicOperation.cpp (98%) rename src/{ => ir}/parsers/QASM3Parser.cpp (97%) rename src/{ => ir}/parsers/QCParser.cpp (98%) rename src/{ => ir}/parsers/RealParser.cpp (98%) rename src/{ => ir}/parsers/TFCParser.cpp (98%) rename src/{ => ir}/parsers/qasm3_parser/Parser.cpp (99%) rename src/{ => ir}/parsers/qasm3_parser/Scanner.cpp (99%) rename src/{ => ir}/parsers/qasm3_parser/Statement.cpp (86%) rename src/{ => ir}/parsers/qasm3_parser/Types.cpp (97%) rename src/{ => ir}/parsers/qasm3_parser/passes/ConstEvalPass.cpp (98%) rename src/{ => ir}/parsers/qasm3_parser/passes/TypeCheckPass.cpp (98%) delete mode 100644 src/parsers/GRCSParser.cpp create mode 100644 test/algorithms/CMakeLists.txt delete mode 100644 test/algorithms/test_grcs.cpp create mode 100644 test/circuit_optimizer/CMakeLists.txt rename test/{unittests => }/circuit_optimizer/test_backpropagate_output_permutation.cpp (98%) create mode 100644 test/circuit_optimizer/test_cancel_cnots.cpp rename test/{unittests => }/circuit_optimizer/test_collect_blocks.cpp (98%) create mode 100644 test/circuit_optimizer/test_decompose_swap.cpp rename test/{unittests => }/circuit_optimizer/test_defer_measurements.cpp (98%) rename test/{unittests => }/circuit_optimizer/test_elide_permutations.cpp (97%) create mode 100644 test/circuit_optimizer/test_eliminate_resets.cpp create mode 100644 test/circuit_optimizer/test_flatten_operations.cpp create mode 100644 test/circuit_optimizer/test_remove_diagonal_gates_before_measure.cpp create mode 100644 test/circuit_optimizer/test_remove_final_measurements.cpp create mode 100644 test/circuit_optimizer/test_remove_operation.cpp create mode 100644 test/circuit_optimizer/test_replace_mcx_with_mcz.cpp create mode 100644 test/circuit_optimizer/test_single_qubit_gate_fusion.cpp create mode 100644 test/circuit_optimizer/test_swap_reconstruction.cpp delete mode 100644 test/circuits/grcs/bris_4_40_9_v2.txt delete mode 100644 test/circuits/grcs/bris_7_40_9_v2.txt delete mode 100644 test/circuits/grcs/inst_4x4_80_9_v2.txt delete mode 100644 test/circuits/grcs/inst_5x6_80_9_v2.txt delete mode 100644 test/circuits/grcs/inst_7x7_80_9_v2.txt create mode 100644 test/dd/CMakeLists.txt create mode 100644 test/ir/CMakeLists.txt rename test/{unittests => ir}/test_io.cpp (97%) rename test/{ => ir}/test_operation.cpp (96%) rename test/{unittests => ir}/test_qasm3_parser.cpp (99%) rename test/{unittests => ir}/test_qfr_functionality.cpp (51%) rename test/{unittests => ir}/test_symbolic.cpp (97%) delete mode 100644 test/unittests/circuit_optimizer/test_reorder_operations.cpp create mode 100644 test/zx/CMakeLists.txt diff --git a/cmake/mqt-core-config.cmake.in b/cmake/mqt-core-config.cmake.in index 9666f5068..8a325e3bc 100644 --- a/cmake/mqt-core-config.cmake.in +++ b/cmake/mqt-core-config.cmake.in @@ -23,11 +23,8 @@ if(TARGET MQT::Core) endif() include("${CMAKE_CURRENT_LIST_DIR}/Cache.cmake") -include("${CMAKE_CURRENT_LIST_DIR}/CompilerOptions.cmake") -include("${CMAKE_CURRENT_LIST_DIR}/CompilerWarnings.cmake") include("${CMAKE_CURRENT_LIST_DIR}/PackageAddTest.cmake") include("${CMAKE_CURRENT_LIST_DIR}/PreventInSourceBuilds.cmake") -include("${CMAKE_CURRENT_LIST_DIR}/Sanitizers.cmake") include("${CMAKE_CURRENT_LIST_DIR}/StandardProjectSettings.cmake") include("${CMAKE_CURRENT_LIST_DIR}/mqt-core-targets.cmake") diff --git a/eval/CMakeLists.txt b/eval/CMakeLists.txt index 6db8f1270..a12d079b8 100644 --- a/eval/CMakeLists.txt +++ b/eval/CMakeLists.txt @@ -1,2 +1,3 @@ add_executable(mqt-core-dd-eval eval_dd_package.cpp) -target_link_libraries(mqt-core-dd-eval PRIVATE MQT::CoreDD MQT::ProjectOptions MQT::ProjectWarnings) +target_link_libraries(mqt-core-dd-eval PRIVATE MQT::CoreDD MQT::CoreAlgo MQT::CoreCircuitOptimizer + MQT::ProjectOptions MQT::ProjectWarnings) diff --git a/eval/eval_dd_package.cpp b/eval/eval_dd_package.cpp index 271fbe495..027bf49b6 100644 --- a/eval/eval_dd_package.cpp +++ b/eval/eval_dd_package.cpp @@ -1,4 +1,3 @@ -#include "CircuitOptimizer.hpp" #include "algorithms/BernsteinVazirani.hpp" #include "algorithms/Entanglement.hpp" #include "algorithms/Grover.hpp" @@ -6,6 +5,7 @@ #include "algorithms/QPE.hpp" #include "algorithms/RandomCliffordCircuit.hpp" #include "algorithms/WState.hpp" +#include "circuit_optimizer/CircuitOptimizer.hpp" #include "dd/Benchmark.hpp" #include "dd/FunctionalityConstruction.hpp" #include "dd/Package.hpp" diff --git a/include/mqt-core/Definitions.hpp b/include/mqt-core/Definitions.hpp index 0fd0e0716..4f1e4af34 100644 --- a/include/mqt-core/Definitions.hpp +++ b/include/mqt-core/Definitions.hpp @@ -64,15 +64,7 @@ static constexpr size_t OUTPUT_INDENT_SIZE = 2; class Operation; // supported file formats -enum class Format : uint8_t { - Real, - OpenQASM2, - OpenQASM3, - GRCS, - TFC, - QC, - Tensor -}; +enum class Format : uint8_t { Real, OpenQASM2, OpenQASM3, TFC, QC, Tensor }; using DAG = std::vector*>>; using DAGIterator = std::deque*>::iterator; diff --git a/include/mqt-core/algorithms/BernsteinVazirani.hpp b/include/mqt-core/algorithms/BernsteinVazirani.hpp index 658943ba9..7e6af3a59 100644 --- a/include/mqt-core/algorithms/BernsteinVazirani.hpp +++ b/include/mqt-core/algorithms/BernsteinVazirani.hpp @@ -1,7 +1,7 @@ #pragma once #include "Definitions.hpp" -#include "QuantumComputation.hpp" +#include "ir/QuantumComputation.hpp" #include #include diff --git a/include/mqt-core/algorithms/Entanglement.hpp b/include/mqt-core/algorithms/Entanglement.hpp index 661255221..0617b62e0 100644 --- a/include/mqt-core/algorithms/Entanglement.hpp +++ b/include/mqt-core/algorithms/Entanglement.hpp @@ -1,6 +1,6 @@ #pragma once -#include "QuantumComputation.hpp" +#include "ir/QuantumComputation.hpp" #include diff --git a/include/mqt-core/algorithms/GoogleRandomCircuitSampling.hpp b/include/mqt-core/algorithms/GoogleRandomCircuitSampling.hpp deleted file mode 100644 index 68aa562ec..000000000 --- a/include/mqt-core/algorithms/GoogleRandomCircuitSampling.hpp +++ /dev/null @@ -1,62 +0,0 @@ -#pragma once - -#include "Definitions.hpp" -#include "QuantumComputation.hpp" -#include "operations/Operation.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace qc { -enum Layout : std::uint8_t { Rectangular, Bristlecone }; - -class GoogleRandomCircuitSampling : public QuantumComputation { -public: - std::vector>> cycles; - Layout layout = Rectangular; - std::string pathPrefix = - "../../../Benchmarks/GoogleRandomCircuitSampling/inst/"; - - explicit GoogleRandomCircuitSampling(const std::string& filename); - - [[maybe_unused]] GoogleRandomCircuitSampling(std::string prefix, - std::uint16_t device, - std::uint16_t depth, - std::uint16_t instance); - - [[maybe_unused]] GoogleRandomCircuitSampling(std::string prefix, - std::uint16_t x, std::uint16_t y, - std::uint16_t depth, - std::uint16_t instance); - - void importGRCS(const std::string& filename); - - [[nodiscard]] size_t getNops() const override; - - std::ostream& print(std::ostream& os) const override; - - std::ostream& printStatistics(std::ostream& os) const override; - - void removeCycles(const std::size_t ncycles) { - if (ncycles > cycles.size() - 2) { - std::stringstream ss{}; - ss << "Cannot remove " << ncycles - << " cycles out of a circuit containing 1+" << cycles.size() - 2 - << "+1 cycles."; - throw QFRException(ss.str()); - } - auto last = std::move(cycles.back()); - cycles.pop_back(); - for (std::size_t i = 0; i < ncycles; ++i) { - cycles.pop_back(); - } - cycles.emplace_back(std::move(last)); - } -}; -} // namespace qc diff --git a/include/mqt-core/algorithms/Grover.hpp b/include/mqt-core/algorithms/Grover.hpp index bc9f496f9..9f9f26838 100644 --- a/include/mqt-core/algorithms/Grover.hpp +++ b/include/mqt-core/algorithms/Grover.hpp @@ -1,7 +1,7 @@ #pragma once #include "Definitions.hpp" -#include "QuantumComputation.hpp" +#include "ir/QuantumComputation.hpp" #include #include diff --git a/include/mqt-core/algorithms/QFT.hpp b/include/mqt-core/algorithms/QFT.hpp index 98cd40a7a..340bfc47f 100644 --- a/include/mqt-core/algorithms/QFT.hpp +++ b/include/mqt-core/algorithms/QFT.hpp @@ -1,6 +1,6 @@ #pragma once -#include "QuantumComputation.hpp" +#include "ir/QuantumComputation.hpp" #include #include diff --git a/include/mqt-core/algorithms/QPE.hpp b/include/mqt-core/algorithms/QPE.hpp index c1bcfc9c3..b91bfd1a8 100644 --- a/include/mqt-core/algorithms/QPE.hpp +++ b/include/mqt-core/algorithms/QPE.hpp @@ -1,7 +1,7 @@ #pragma once #include "Definitions.hpp" -#include "QuantumComputation.hpp" +#include "ir/QuantumComputation.hpp" #include #include diff --git a/include/mqt-core/algorithms/RandomCliffordCircuit.hpp b/include/mqt-core/algorithms/RandomCliffordCircuit.hpp index df94fb61a..96e16e252 100644 --- a/include/mqt-core/algorithms/RandomCliffordCircuit.hpp +++ b/include/mqt-core/algorithms/RandomCliffordCircuit.hpp @@ -1,7 +1,7 @@ #pragma once #include "Definitions.hpp" -#include "QuantumComputation.hpp" +#include "ir/QuantumComputation.hpp" #include #include diff --git a/include/mqt-core/algorithms/WState.hpp b/include/mqt-core/algorithms/WState.hpp index 4385ed695..1e499a625 100644 --- a/include/mqt-core/algorithms/WState.hpp +++ b/include/mqt-core/algorithms/WState.hpp @@ -1,7 +1,7 @@ #pragma once #include "Definitions.hpp" -#include "QuantumComputation.hpp" +#include "ir/QuantumComputation.hpp" namespace qc { class WState : public QuantumComputation { diff --git a/include/mqt-core/CircuitOptimizer.hpp b/include/mqt-core/circuit_optimizer/CircuitOptimizer.hpp similarity index 95% rename from include/mqt-core/CircuitOptimizer.hpp rename to include/mqt-core/circuit_optimizer/CircuitOptimizer.hpp index aaaac070c..5462e3540 100644 --- a/include/mqt-core/CircuitOptimizer.hpp +++ b/include/mqt-core/circuit_optimizer/CircuitOptimizer.hpp @@ -1,9 +1,9 @@ #pragma once #include "Definitions.hpp" -#include "QuantumComputation.hpp" -#include "operations/OpType.hpp" -#include "operations/Operation.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/OpType.hpp" +#include "ir/operations/Operation.hpp" #include #include @@ -49,8 +49,6 @@ class CircuitOptimizer { static bool isDynamicCircuit(QuantumComputation& qc); - static void reorderOperations(QuantumComputation& qc); - static void flattenOperations(QuantumComputation& qc, bool customGatesOnly = false); diff --git a/include/mqt-core/datastructures/Layer.hpp b/include/mqt-core/datastructures/Layer.hpp index c6f85d1d9..3946c2406 100644 --- a/include/mqt-core/datastructures/Layer.hpp +++ b/include/mqt-core/datastructures/Layer.hpp @@ -1,10 +1,10 @@ #pragma once #include "Definitions.hpp" -#include "QuantumComputation.hpp" #include "datastructures/UndirectedGraph.hpp" -#include "operations/OpType.hpp" -#include "operations/Operation.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/OpType.hpp" +#include "ir/operations/Operation.hpp" #include #include diff --git a/include/mqt-core/dd/DDpackageConfig.hpp b/include/mqt-core/dd/DDpackageConfig.hpp index 717fc7064..853b37753 100644 --- a/include/mqt-core/dd/DDpackageConfig.hpp +++ b/include/mqt-core/dd/DDpackageConfig.hpp @@ -1,6 +1,6 @@ #pragma once -#include "operations/OpType.hpp" +#include "ir/operations/OpType.hpp" #include diff --git a/include/mqt-core/dd/FunctionalityConstruction.hpp b/include/mqt-core/dd/FunctionalityConstruction.hpp index 5a02dbb6b..8ff563d61 100644 --- a/include/mqt-core/dd/FunctionalityConstruction.hpp +++ b/include/mqt-core/dd/FunctionalityConstruction.hpp @@ -1,11 +1,10 @@ #pragma once -#include "Permutation.hpp" -#include "QuantumComputation.hpp" -#include "algorithms/Grover.hpp" #include "dd/Operations.hpp" #include "dd/Package_fwd.hpp" -#include "operations/OpType.hpp" +#include "ir/Permutation.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/OpType.hpp" #include #include @@ -29,12 +28,6 @@ bool buildFunctionalityRecursive(const QuantumComputation* qc, std::stack& s, Permutation& permutation, Package& dd); -template -MatrixDD buildFunctionality(const qc::Grover* qc, Package& dd); - -template -MatrixDD buildFunctionalityRecursive(const qc::Grover* qc, Package& dd); - inline void dumpTensorNetwork(std::ostream& of, const QuantumComputation& qc) { of << "{\"tensors\": [\n"; diff --git a/include/mqt-core/dd/NoiseFunctionality.hpp b/include/mqt-core/dd/NoiseFunctionality.hpp index fe9e2ee20..2ed1675a9 100644 --- a/include/mqt-core/dd/NoiseFunctionality.hpp +++ b/include/mqt-core/dd/NoiseFunctionality.hpp @@ -5,8 +5,8 @@ #include "dd/DDpackageConfig.hpp" #include "dd/Node.hpp" #include "dd/Package.hpp" -#include "operations/OpType.hpp" -#include "operations/Operation.hpp" +#include "ir/operations/OpType.hpp" +#include "ir/operations/Operation.hpp" #include #include diff --git a/include/mqt-core/dd/Operations.hpp b/include/mqt-core/dd/Operations.hpp index e1782e25e..6b3b5753a 100644 --- a/include/mqt-core/dd/Operations.hpp +++ b/include/mqt-core/dd/Operations.hpp @@ -1,16 +1,16 @@ #pragma once #include "Definitions.hpp" -#include "Permutation.hpp" #include "dd/DDDefinitions.hpp" #include "dd/GateMatrixDefinitions.hpp" #include "dd/Package.hpp" -#include "operations/ClassicControlledOperation.hpp" -#include "operations/CompoundOperation.hpp" -#include "operations/Control.hpp" -#include "operations/OpType.hpp" -#include "operations/Operation.hpp" -#include "operations/StandardOperation.hpp" +#include "ir/Permutation.hpp" +#include "ir/operations/ClassicControlledOperation.hpp" +#include "ir/operations/CompoundOperation.hpp" +#include "ir/operations/Control.hpp" +#include "ir/operations/OpType.hpp" +#include "ir/operations/Operation.hpp" +#include "ir/operations/StandardOperation.hpp" #include #include diff --git a/include/mqt-core/dd/Package.hpp b/include/mqt-core/dd/Package.hpp index 046bfbaa6..0488f4dac 100644 --- a/include/mqt-core/dd/Package.hpp +++ b/include/mqt-core/dd/Package.hpp @@ -1,7 +1,6 @@ #pragma once #include "Definitions.hpp" -#include "Permutation.hpp" #include "dd/CachedEdge.hpp" #include "dd/Complex.hpp" #include "dd/ComplexNumbers.hpp" @@ -20,7 +19,8 @@ #include "dd/StochasticNoiseOperationTable.hpp" #include "dd/UnaryComputeTable.hpp" #include "dd/UniqueTable.hpp" -#include "operations/Control.hpp" +#include "ir/Permutation.hpp" +#include "ir/operations/Control.hpp" #include #include diff --git a/include/mqt-core/dd/Simulation.hpp b/include/mqt-core/dd/Simulation.hpp index 3458c93f2..066e6c689 100644 --- a/include/mqt-core/dd/Simulation.hpp +++ b/include/mqt-core/dd/Simulation.hpp @@ -1,10 +1,9 @@ #pragma once -#include "QuantumComputation.hpp" -#include "algorithms/GoogleRandomCircuitSampling.hpp" #include "dd/DDDefinitions.hpp" #include "dd/Operations.hpp" #include "dd/Package_fwd.hpp" +#include "ir/QuantumComputation.hpp" #include #include @@ -53,9 +52,4 @@ void extractProbabilityVectorRecursive( decltype(qc->begin()) currentIt, Permutation& permutation, std::map measurements, dd::fp commonFactor, dd::SparsePVec& probVector, Package& dd); - -template -VectorDD simulate(GoogleRandomCircuitSampling* qc, const VectorDD& in, - Package& dd, - std::optional ncycles = std::nullopt); } // namespace dd diff --git a/include/mqt-core/Permutation.hpp b/include/mqt-core/ir/Permutation.hpp similarity index 100% rename from include/mqt-core/Permutation.hpp rename to include/mqt-core/ir/Permutation.hpp diff --git a/include/mqt-core/QuantumComputation.hpp b/include/mqt-core/ir/QuantumComputation.hpp similarity index 99% rename from include/mqt-core/QuantumComputation.hpp rename to include/mqt-core/ir/QuantumComputation.hpp index 5642eb744..9548dac0f 100644 --- a/include/mqt-core/QuantumComputation.hpp +++ b/include/mqt-core/ir/QuantumComputation.hpp @@ -70,7 +70,6 @@ class QuantumComputation { int readQCHeader(std::istream& is, std::map& varMap); void readQCGateDescriptions(std::istream& is, int line, std::map& varMap); - void importGRCS(std::istream& is); template static void printSortedRegisters(const RegisterMap& regmap, @@ -871,6 +870,14 @@ class QuantumComputation { outputPermutation.clear(); } + /** + * @brief Reorders the operations in the quantum computation to establish a + * canonical order + * @details Uses iterative breadth-first search starting from the topmost + * qubit. + */ + void reorderOperations(); + /** * Pass-Through */ diff --git a/include/mqt-core/operations/AodOperation.hpp b/include/mqt-core/ir/operations/AodOperation.hpp similarity index 98% rename from include/mqt-core/operations/AodOperation.hpp rename to include/mqt-core/ir/operations/AodOperation.hpp index 13865d386..d9a670462 100644 --- a/include/mqt-core/operations/AodOperation.hpp +++ b/include/mqt-core/ir/operations/AodOperation.hpp @@ -3,7 +3,7 @@ #include "Control.hpp" #include "Definitions.hpp" #include "OpType.hpp" -#include "operations/Operation.hpp" +#include "Operation.hpp" #include #include diff --git a/include/mqt-core/operations/ClassicControlledOperation.hpp b/include/mqt-core/ir/operations/ClassicControlledOperation.hpp similarity index 98% rename from include/mqt-core/operations/ClassicControlledOperation.hpp rename to include/mqt-core/ir/operations/ClassicControlledOperation.hpp index c3e04a50e..1291e327d 100644 --- a/include/mqt-core/operations/ClassicControlledOperation.hpp +++ b/include/mqt-core/ir/operations/ClassicControlledOperation.hpp @@ -1,10 +1,10 @@ #pragma once +#include "../Permutation.hpp" +#include "Control.hpp" #include "Definitions.hpp" +#include "OpType.hpp" #include "Operation.hpp" -#include "Permutation.hpp" -#include "operations/Control.hpp" -#include "operations/OpType.hpp" #include #include diff --git a/include/mqt-core/operations/CompoundOperation.hpp b/include/mqt-core/ir/operations/CompoundOperation.hpp similarity index 99% rename from include/mqt-core/operations/CompoundOperation.hpp rename to include/mqt-core/ir/operations/CompoundOperation.hpp index 5cf259b63..336d0d02b 100644 --- a/include/mqt-core/operations/CompoundOperation.hpp +++ b/include/mqt-core/ir/operations/CompoundOperation.hpp @@ -1,9 +1,9 @@ #pragma once +#include "../Permutation.hpp" +#include "Control.hpp" #include "Definitions.hpp" #include "Operation.hpp" -#include "Permutation.hpp" -#include "operations/Control.hpp" #include #include diff --git a/include/mqt-core/operations/Control.hpp b/include/mqt-core/ir/operations/Control.hpp similarity index 100% rename from include/mqt-core/operations/Control.hpp rename to include/mqt-core/ir/operations/Control.hpp diff --git a/include/mqt-core/operations/Expression.hpp b/include/mqt-core/ir/operations/Expression.hpp similarity index 100% rename from include/mqt-core/operations/Expression.hpp rename to include/mqt-core/ir/operations/Expression.hpp diff --git a/include/mqt-core/operations/NonUnitaryOperation.hpp b/include/mqt-core/ir/operations/NonUnitaryOperation.hpp similarity index 97% rename from include/mqt-core/operations/NonUnitaryOperation.hpp rename to include/mqt-core/ir/operations/NonUnitaryOperation.hpp index 247343134..d0f9618d7 100644 --- a/include/mqt-core/operations/NonUnitaryOperation.hpp +++ b/include/mqt-core/ir/operations/NonUnitaryOperation.hpp @@ -1,10 +1,10 @@ #pragma once +#include "../Permutation.hpp" +#include "Control.hpp" #include "Definitions.hpp" +#include "OpType.hpp" #include "Operation.hpp" -#include "Permutation.hpp" -#include "operations/Control.hpp" -#include "operations/OpType.hpp" #include #include diff --git a/include/mqt-core/operations/OpType.hpp b/include/mqt-core/ir/operations/OpType.hpp similarity index 100% rename from include/mqt-core/operations/OpType.hpp rename to include/mqt-core/ir/operations/OpType.hpp diff --git a/include/mqt-core/operations/Operation.hpp b/include/mqt-core/ir/operations/Operation.hpp similarity index 99% rename from include/mqt-core/operations/Operation.hpp rename to include/mqt-core/ir/operations/Operation.hpp index c9465c46d..2b8ed3792 100644 --- a/include/mqt-core/operations/Operation.hpp +++ b/include/mqt-core/ir/operations/Operation.hpp @@ -1,9 +1,9 @@ #pragma once +#include "../Permutation.hpp" +#include "Control.hpp" #include "Definitions.hpp" #include "OpType.hpp" -#include "Permutation.hpp" -#include "operations/Control.hpp" #include #include diff --git a/include/mqt-core/operations/StandardOperation.hpp b/include/mqt-core/ir/operations/StandardOperation.hpp similarity index 97% rename from include/mqt-core/operations/StandardOperation.hpp rename to include/mqt-core/ir/operations/StandardOperation.hpp index 3dbda5703..6769cfe12 100644 --- a/include/mqt-core/operations/StandardOperation.hpp +++ b/include/mqt-core/ir/operations/StandardOperation.hpp @@ -1,10 +1,10 @@ #pragma once +#include "../Permutation.hpp" +#include "Control.hpp" #include "Definitions.hpp" +#include "OpType.hpp" #include "Operation.hpp" -#include "Permutation.hpp" -#include "operations/Control.hpp" -#include "operations/OpType.hpp" #include #include diff --git a/include/mqt-core/operations/SymbolicOperation.hpp b/include/mqt-core/ir/operations/SymbolicOperation.hpp similarity index 98% rename from include/mqt-core/operations/SymbolicOperation.hpp rename to include/mqt-core/ir/operations/SymbolicOperation.hpp index de36a737d..9227a893d 100644 --- a/include/mqt-core/operations/SymbolicOperation.hpp +++ b/include/mqt-core/ir/operations/SymbolicOperation.hpp @@ -1,11 +1,11 @@ #pragma once +#include "../Permutation.hpp" +#include "Control.hpp" #include "Definitions.hpp" #include "Expression.hpp" -#include "Permutation.hpp" +#include "OpType.hpp" #include "StandardOperation.hpp" -#include "operations/Control.hpp" -#include "operations/OpType.hpp" #include #include diff --git a/include/mqt-core/parsers/qasm3_parser/Exception.hpp b/include/mqt-core/ir/parsers/qasm3_parser/Exception.hpp similarity index 100% rename from include/mqt-core/parsers/qasm3_parser/Exception.hpp rename to include/mqt-core/ir/parsers/qasm3_parser/Exception.hpp diff --git a/include/mqt-core/parsers/qasm3_parser/Gate.hpp b/include/mqt-core/ir/parsers/qasm3_parser/Gate.hpp similarity index 97% rename from include/mqt-core/parsers/qasm3_parser/Gate.hpp rename to include/mqt-core/ir/parsers/qasm3_parser/Gate.hpp index 784720c92..fe6868549 100644 --- a/include/mqt-core/parsers/qasm3_parser/Gate.hpp +++ b/include/mqt-core/ir/parsers/qasm3_parser/Gate.hpp @@ -1,7 +1,7 @@ #pragma once #include "Statement.hpp" -#include "operations/OpType.hpp" +#include "ir/operations/OpType.hpp" #include #include diff --git a/include/mqt-core/parsers/qasm3_parser/InstVisitor.hpp b/include/mqt-core/ir/parsers/qasm3_parser/InstVisitor.hpp similarity index 100% rename from include/mqt-core/parsers/qasm3_parser/InstVisitor.hpp rename to include/mqt-core/ir/parsers/qasm3_parser/InstVisitor.hpp diff --git a/include/mqt-core/parsers/qasm3_parser/NestedEnvironment.hpp b/include/mqt-core/ir/parsers/qasm3_parser/NestedEnvironment.hpp similarity index 100% rename from include/mqt-core/parsers/qasm3_parser/NestedEnvironment.hpp rename to include/mqt-core/ir/parsers/qasm3_parser/NestedEnvironment.hpp diff --git a/include/mqt-core/parsers/qasm3_parser/Parser.hpp b/include/mqt-core/ir/parsers/qasm3_parser/Parser.hpp similarity index 97% rename from include/mqt-core/parsers/qasm3_parser/Parser.hpp rename to include/mqt-core/ir/parsers/qasm3_parser/Parser.hpp index b70cc0f93..a2366a882 100644 --- a/include/mqt-core/parsers/qasm3_parser/Parser.hpp +++ b/include/mqt-core/ir/parsers/qasm3_parser/Parser.hpp @@ -7,12 +7,12 @@ #pragma once #include "Exception.hpp" -#include "Permutation.hpp" #include "Scanner.hpp" #include "Statement.hpp" #include "StdGates.hpp" -#include "parsers/qasm3_parser/Token.hpp" -#include "parsers/qasm3_parser/Types.hpp" +#include "Token.hpp" +#include "Types.hpp" +#include "ir/Permutation.hpp" #include #include diff --git a/include/mqt-core/parsers/qasm3_parser/Scanner.hpp b/include/mqt-core/ir/parsers/qasm3_parser/Scanner.hpp similarity index 100% rename from include/mqt-core/parsers/qasm3_parser/Scanner.hpp rename to include/mqt-core/ir/parsers/qasm3_parser/Scanner.hpp diff --git a/include/mqt-core/parsers/qasm3_parser/Statement.hpp b/include/mqt-core/ir/parsers/qasm3_parser/Statement.hpp similarity index 99% rename from include/mqt-core/parsers/qasm3_parser/Statement.hpp rename to include/mqt-core/ir/parsers/qasm3_parser/Statement.hpp index 7f9363fda..f77263d05 100644 --- a/include/mqt-core/parsers/qasm3_parser/Statement.hpp +++ b/include/mqt-core/ir/parsers/qasm3_parser/Statement.hpp @@ -1,9 +1,9 @@ #pragma once #include "InstVisitor.hpp" -#include "Permutation.hpp" #include "Types.hpp" -#include "operations/ClassicControlledOperation.hpp" +#include "ir/Permutation.hpp" +#include "ir/operations/ClassicControlledOperation.hpp" #include #include diff --git a/include/mqt-core/parsers/qasm3_parser/StdGates.hpp b/include/mqt-core/ir/parsers/qasm3_parser/StdGates.hpp similarity index 99% rename from include/mqt-core/parsers/qasm3_parser/StdGates.hpp rename to include/mqt-core/ir/parsers/qasm3_parser/StdGates.hpp index 6216336bc..3cfef87f6 100644 --- a/include/mqt-core/parsers/qasm3_parser/StdGates.hpp +++ b/include/mqt-core/ir/parsers/qasm3_parser/StdGates.hpp @@ -1,7 +1,7 @@ #pragma once #include "Gate.hpp" -#include "operations/OpType.hpp" +#include "ir/operations/OpType.hpp" #include #include diff --git a/include/mqt-core/parsers/qasm3_parser/Token.hpp b/include/mqt-core/ir/parsers/qasm3_parser/Token.hpp similarity index 100% rename from include/mqt-core/parsers/qasm3_parser/Token.hpp rename to include/mqt-core/ir/parsers/qasm3_parser/Token.hpp diff --git a/include/mqt-core/parsers/qasm3_parser/Types.hpp b/include/mqt-core/ir/parsers/qasm3_parser/Types.hpp similarity index 100% rename from include/mqt-core/parsers/qasm3_parser/Types.hpp rename to include/mqt-core/ir/parsers/qasm3_parser/Types.hpp diff --git a/include/mqt-core/parsers/qasm3_parser/passes/CompilerPass.hpp b/include/mqt-core/ir/parsers/qasm3_parser/passes/CompilerPass.hpp similarity index 79% rename from include/mqt-core/parsers/qasm3_parser/passes/CompilerPass.hpp rename to include/mqt-core/ir/parsers/qasm3_parser/passes/CompilerPass.hpp index d3bc5c4cd..062a0ac9f 100644 --- a/include/mqt-core/parsers/qasm3_parser/passes/CompilerPass.hpp +++ b/include/mqt-core/ir/parsers/qasm3_parser/passes/CompilerPass.hpp @@ -1,6 +1,6 @@ #pragma once -#include "parsers/qasm3_parser/Statement.hpp" +#include "../Statement.hpp" namespace qasm3 { class CompilerPass { diff --git a/include/mqt-core/parsers/qasm3_parser/passes/ConstEvalPass.hpp b/include/mqt-core/ir/parsers/qasm3_parser/passes/ConstEvalPass.hpp similarity index 96% rename from include/mqt-core/parsers/qasm3_parser/passes/ConstEvalPass.hpp rename to include/mqt-core/ir/parsers/qasm3_parser/passes/ConstEvalPass.hpp index aafd22271..57a190390 100644 --- a/include/mqt-core/parsers/qasm3_parser/passes/ConstEvalPass.hpp +++ b/include/mqt-core/ir/parsers/qasm3_parser/passes/ConstEvalPass.hpp @@ -1,11 +1,11 @@ #pragma once +#include "../Exception.hpp" +#include "../InstVisitor.hpp" +#include "../NestedEnvironment.hpp" +#include "../Statement.hpp" #include "CompilerPass.hpp" #include "Definitions.hpp" -#include "parsers/qasm3_parser/Exception.hpp" -#include "parsers/qasm3_parser/InstVisitor.hpp" -#include "parsers/qasm3_parser/NestedEnvironment.hpp" -#include "parsers/qasm3_parser/Statement.hpp" #include #include diff --git a/include/mqt-core/parsers/qasm3_parser/passes/TypeCheckPass.hpp b/include/mqt-core/ir/parsers/qasm3_parser/passes/TypeCheckPass.hpp similarity index 94% rename from include/mqt-core/parsers/qasm3_parser/passes/TypeCheckPass.hpp rename to include/mqt-core/ir/parsers/qasm3_parser/passes/TypeCheckPass.hpp index 54f8b6299..126720e9c 100644 --- a/include/mqt-core/parsers/qasm3_parser/passes/TypeCheckPass.hpp +++ b/include/mqt-core/ir/parsers/qasm3_parser/passes/TypeCheckPass.hpp @@ -1,11 +1,11 @@ #pragma once +#include "../Exception.hpp" +#include "../InstVisitor.hpp" +#include "../Statement.hpp" +#include "../Types.hpp" +#include "CompilerPass.hpp" #include "ConstEvalPass.hpp" -#include "parsers/qasm3_parser/Exception.hpp" -#include "parsers/qasm3_parser/InstVisitor.hpp" -#include "parsers/qasm3_parser/Statement.hpp" -#include "parsers/qasm3_parser/Types.hpp" -#include "parsers/qasm3_parser/passes/CompilerPass.hpp" #include #include diff --git a/include/mqt-core/na/NAComputation.hpp b/include/mqt-core/na/NAComputation.hpp index 7610a4082..f0cf567ed 100644 --- a/include/mqt-core/na/NAComputation.hpp +++ b/include/mqt-core/na/NAComputation.hpp @@ -1,7 +1,7 @@ #pragma once -#include "na/NADefinitions.hpp" -#include "na/operations/NAOperation.hpp" +#include "NADefinitions.hpp" +#include "operations/NAOperation.hpp" #include #include diff --git a/include/mqt-core/na/NADefinitions.hpp b/include/mqt-core/na/NADefinitions.hpp index 36df5966b..749a19454 100644 --- a/include/mqt-core/na/NADefinitions.hpp +++ b/include/mqt-core/na/NADefinitions.hpp @@ -1,9 +1,9 @@ #pragma once #include "Definitions.hpp" -#include "operations/CompoundOperation.hpp" -#include "operations/OpType.hpp" -#include "operations/Operation.hpp" +#include "ir/operations/CompoundOperation.hpp" +#include "ir/operations/OpType.hpp" +#include "ir/operations/Operation.hpp" #include #include diff --git a/include/mqt-core/na/operations/NAGlobalOperation.hpp b/include/mqt-core/na/operations/NAGlobalOperation.hpp index e854b4d71..11cd37b02 100644 --- a/include/mqt-core/na/operations/NAGlobalOperation.hpp +++ b/include/mqt-core/na/operations/NAGlobalOperation.hpp @@ -1,14 +1,15 @@ #pragma once +#include "../NADefinitions.hpp" #include "Definitions.hpp" -#include "na/NADefinitions.hpp" -#include "na/operations/NAOperation.hpp" +#include "NAOperation.hpp" #include #include #include #include #include + namespace na { class NAGlobalOperation : public NAOperation { protected: diff --git a/include/mqt-core/na/operations/NALocalOperation.hpp b/include/mqt-core/na/operations/NALocalOperation.hpp index 0dc81b726..9d85974d4 100644 --- a/include/mqt-core/na/operations/NALocalOperation.hpp +++ b/include/mqt-core/na/operations/NALocalOperation.hpp @@ -1,8 +1,8 @@ #pragma once +#include "../NADefinitions.hpp" #include "Definitions.hpp" -#include "na/NADefinitions.hpp" -#include "na/operations/NAOperation.hpp" +#include "NAOperation.hpp" #include #include @@ -10,6 +10,7 @@ #include #include #include + namespace na { class NALocalOperation : public NAOperation { protected: diff --git a/include/mqt-core/na/operations/NAOperation.hpp b/include/mqt-core/na/operations/NAOperation.hpp index 207ce2326..2b8d4aada 100644 --- a/include/mqt-core/na/operations/NAOperation.hpp +++ b/include/mqt-core/na/operations/NAOperation.hpp @@ -3,6 +3,7 @@ #include #include #include + namespace na { class NAOperation { public: diff --git a/include/mqt-core/na/operations/NAShuttlingOperation.hpp b/include/mqt-core/na/operations/NAShuttlingOperation.hpp index 9784949bf..9f3ffbe83 100644 --- a/include/mqt-core/na/operations/NAShuttlingOperation.hpp +++ b/include/mqt-core/na/operations/NAShuttlingOperation.hpp @@ -1,7 +1,7 @@ #pragma once -#include "na/NADefinitions.hpp" -#include "na/operations/NAOperation.hpp" +#include "../NADefinitions.hpp" +#include "NAOperation.hpp" #include #include diff --git a/include/mqt-core/python/qiskit/QuantumCircuit.hpp b/include/mqt-core/python/qiskit/QuantumCircuit.hpp index 3eb1b41b3..9daf1ed82 100644 --- a/include/mqt-core/python/qiskit/QuantumCircuit.hpp +++ b/include/mqt-core/python/qiskit/QuantumCircuit.hpp @@ -1,15 +1,14 @@ #pragma once -#include "operations/Expression.hpp" -#include "operations/OpType.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/Expression.hpp" +#include "ir/operations/OpType.hpp" #include "python/pybind11.hpp" // IWYU pragma: keep #include namespace py = pybind11; -#include "QuantumComputation.hpp" - namespace qc::qiskit { using namespace pybind11::literals; diff --git a/include/mqt-core/zx/FunctionalityConstruction.hpp b/include/mqt-core/zx/FunctionalityConstruction.hpp index d1f0f3aa1..04aa37138 100644 --- a/include/mqt-core/zx/FunctionalityConstruction.hpp +++ b/include/mqt-core/zx/FunctionalityConstruction.hpp @@ -1,11 +1,11 @@ #pragma once -#include "Permutation.hpp" -#include "QuantumComputation.hpp" -#include "operations/Expression.hpp" -#include "operations/Operation.hpp" -#include "zx/ZXDefinitions.hpp" -#include "zx/ZXDiagram.hpp" +#include "ZXDefinitions.hpp" +#include "ZXDiagram.hpp" +#include "ir/Permutation.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/Expression.hpp" +#include "ir/operations/Operation.hpp" #include #include diff --git a/include/mqt-core/zx/Rules.hpp b/include/mqt-core/zx/Rules.hpp index 25ac886f3..b201e1241 100644 --- a/include/mqt-core/zx/Rules.hpp +++ b/include/mqt-core/zx/Rules.hpp @@ -1,6 +1,6 @@ #pragma once -#include "zx/ZXDefinitions.hpp" +#include "ZXDefinitions.hpp" namespace zx { class ZXDiagram; diff --git a/include/mqt-core/zx/Simplify.hpp b/include/mqt-core/zx/Simplify.hpp index 4077c708e..a39ac5fb8 100644 --- a/include/mqt-core/zx/Simplify.hpp +++ b/include/mqt-core/zx/Simplify.hpp @@ -1,8 +1,8 @@ #pragma once -#include "zx/Rules.hpp" -#include "zx/ZXDefinitions.hpp" -#include "zx/ZXDiagram.hpp" +#include "Rules.hpp" +#include "ZXDefinitions.hpp" +#include "ZXDiagram.hpp" #include diff --git a/include/mqt-core/zx/Utils.hpp b/include/mqt-core/zx/Utils.hpp index de59f3d44..303078721 100644 --- a/include/mqt-core/zx/Utils.hpp +++ b/include/mqt-core/zx/Utils.hpp @@ -1,6 +1,6 @@ #pragma once -#include "zx/ZXDefinitions.hpp" +#include "ZXDefinitions.hpp" #include #include diff --git a/include/mqt-core/zx/ZXDefinitions.hpp b/include/mqt-core/zx/ZXDefinitions.hpp index 5539d08e3..487e4beaf 100644 --- a/include/mqt-core/zx/ZXDefinitions.hpp +++ b/include/mqt-core/zx/ZXDefinitions.hpp @@ -1,7 +1,7 @@ #pragma once -#include "operations/Expression.hpp" -#include "zx/Rational.hpp" +#include "Rational.hpp" +#include "ir/operations/Expression.hpp" #include #include diff --git a/include/mqt-core/zx/ZXDiagram.hpp b/include/mqt-core/zx/ZXDiagram.hpp index 90b0055da..3363e7ad8 100644 --- a/include/mqt-core/zx/ZXDiagram.hpp +++ b/include/mqt-core/zx/ZXDiagram.hpp @@ -1,7 +1,7 @@ #pragma once -#include "zx/Utils.hpp" -#include "zx/ZXDefinitions.hpp" +#include "Utils.hpp" +#include "ZXDefinitions.hpp" #include #include diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 713588362..a5a11dc7a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,127 +23,50 @@ if(MQT_CORE_INSTALL) set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) endif() -if(NOT TARGET project_warnings) - # Use the warnings specified in CompilerWarnings.cmake +if(NOT TARGET MQT::ProjectWarnings) + # use the warnings specified in CompilerWarnings.cmake add_library(project_warnings INTERFACE) - # Standard compiler warnings + # standard compiler warnings include(${PROJECT_SOURCE_DIR}/cmake/CompilerWarnings.cmake) set_project_warnings(project_warnings) - # Add MQT alias + # add MQT alias add_library(MQT::ProjectWarnings ALIAS project_warnings) set_target_properties(project_warnings PROPERTIES EXPORT_NAME ProjectWarnings) + + # add to list of MQT core targets + list(APPEND MQT_CORE_TARGETS project_warnings) endif() -if(NOT TARGET project_options) - # Use the options specified in CompilerOptions.cmake +if(NOT TARGET MQT::ProjectOptions) + # use the options specified in CompilerOptions.cmake add_library(project_options INTERFACE) - # Standard compiler options + # standard compiler options include(${PROJECT_SOURCE_DIR}/cmake/CompilerOptions.cmake) enable_project_options(project_options) - # Sanitizer options if supported by compiler + # sanitizer options if supported by compiler include(${PROJECT_SOURCE_DIR}/cmake/Sanitizers.cmake) enable_sanitizers(project_options) - # Add MQT alias + # add MQT alias add_library(MQT::ProjectOptions ALIAS project_options) set_target_properties(project_options PROPERTIES EXPORT_NAME ProjectOptions) + + # add to list of MQT core targets + list(APPEND MQT_CORE_TARGETS project_options) endif() -if(NOT TARGET ${MQT_CORE_TARGET_NAME}) - # main project library - add_library( - ${MQT_CORE_TARGET_NAME} - ${MQT_CORE_INCLUDE_BUILD_DIR}/algorithms/BernsteinVazirani.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/algorithms/Entanglement.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/algorithms/GoogleRandomCircuitSampling.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/algorithms/Grover.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/algorithms/QFT.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/algorithms/QPE.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/algorithms/RandomCliffordCircuit.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/algorithms/WState.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/CircuitOptimizer.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/Definitions.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/operations/Expression.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/operations/ClassicControlledOperation.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/operations/CompoundOperation.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/operations/Control.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/operations/NonUnitaryOperation.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/operations/Operation.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/operations/StandardOperation.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/operations/SymbolicOperation.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/operations/AodOperation.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/parsers/qasm3_parser/Scanner.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/parsers/qasm3_parser/Token.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/parsers/qasm3_parser/Parser.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/parsers/qasm3_parser/Statement.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/parsers/qasm3_parser/Types.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/parsers/qasm3_parser/InstVisitor.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/parsers/qasm3_parser/NestedEnvironment.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/parsers/qasm3_parser/Exception.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/parsers/qasm3_parser/Gate.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/parsers/qasm3_parser/StdGates.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/parsers/qasm3_parser/passes/CompilerPass.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/parsers/qasm3_parser/passes/ConstEvalPass.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/parsers/qasm3_parser/passes/TypeCheckPass.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/Permutation.hpp - ${MQT_CORE_INCLUDE_BUILD_DIR}/QuantumComputation.hpp - algorithms/BernsteinVazirani.cpp - algorithms/Entanglement.cpp - algorithms/GoogleRandomCircuitSampling.cpp - algorithms/Grover.cpp - algorithms/QFT.cpp - algorithms/QPE.cpp - algorithms/RandomCliffordCircuit.cpp - algorithms/WState.cpp - CircuitOptimizer.cpp - operations/ClassicControlledOperation.cpp - operations/CompoundOperation.cpp - operations/Expression.cpp - operations/NonUnitaryOperation.cpp - operations/Operation.cpp - operations/StandardOperation.cpp - operations/SymbolicOperation.cpp - operations/AodOperation.cpp - parsers/GRCSParser.cpp - parsers/QASM3Parser.cpp - parsers/QCParser.cpp - parsers/RealParser.cpp - parsers/TFCParser.cpp - parsers/qasm3_parser/Parser.cpp - parsers/qasm3_parser/Scanner.cpp - parsers/qasm3_parser/Types.cpp - parsers/qasm3_parser/Statement.cpp - parsers/qasm3_parser/passes/ConstEvalPass.cpp - parsers/qasm3_parser/passes/TypeCheckPass.cpp - QuantumComputation.cpp) - - # set include directories - target_include_directories( - ${MQT_CORE_TARGET_NAME} PUBLIC $ - $) - - # add options and warnings to the library - target_link_libraries(${MQT_CORE_TARGET_NAME} PRIVATE MQT::ProjectOptions MQT::ProjectWarnings) +# add the IR package +add_subdirectory(ir) - # add MQT alias - add_library(MQT::Core ALIAS ${MQT_CORE_TARGET_NAME}) - set_target_properties( - ${MQT_CORE_TARGET_NAME} - PROPERTIES VERSION ${PROJECT_VERSION} - SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} - EXPORT_NAME Core) - list(APPEND MQT_CORE_TARGETS ${MQT_CORE_TARGET_NAME}) +# add the algorithms package +add_subdirectory(algorithms) - include(GenerateExportHeader) - generate_export_header(${MQT_CORE_TARGET_NAME} BASE_NAME mqt_core) - if(NOT BUILD_SHARED_LIBS) - target_compile_definitions(${MQT_CORE_TARGET_NAME} PUBLIC MQT_CORE_STATIC_DEFINE) - endif() -endif() +# add the circuit_optimizer package +add_subdirectory(circuit_optimizer) # add datastructures package add_subdirectory(datastructures) @@ -166,9 +89,10 @@ if(BINDINGS AND NOT TARGET mqt-core-python) python/qiskit/QuantumCircuit.cpp) # link with main project library and pybind11 libraries - target_link_libraries(${MQT_CORE_TARGET_NAME}-python PUBLIC MQT::Core pybind11::pybind11) - target_link_libraries(${MQT_CORE_TARGET_NAME}-python PRIVATE MQT::ProjectOptions - MQT::ProjectWarnings) + target_link_libraries( + ${MQT_CORE_TARGET_NAME}-python + PUBLIC MQT::CoreIR pybind11::pybind11 + PRIVATE MQT::ProjectOptions MQT::ProjectWarnings) # add MQT alias add_library(MQT::CorePython ALIAS ${MQT_CORE_TARGET_NAME}-python) @@ -201,7 +125,7 @@ if(MQT_CORE_INSTALL) DESTINATION ${MQT_CORE_CONFIG_INSTALL_DIR}) install( - TARGETS ${MQT_CORE_TARGETS} project_warnings project_options + TARGETS ${MQT_CORE_TARGETS} EXPORT ${MQT_CORE_TARGETS_EXPORT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${MQT_CORE_TARGET_NAME}_Runtime LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} @@ -212,8 +136,6 @@ if(MQT_CORE_INSTALL) DESTINATION ${MQT_CORE_INCLUDE_INSTALL_DIR}) install(DIRECTORY ${MQT_CORE_INCLUDE_BUILD_DIR}/ DESTINATION ${MQT_CORE_INCLUDE_INSTALL_DIR}) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mqt_core_export.h - DESTINATION ${MQT_CORE_INCLUDE_INSTALL_DIR}) install( EXPORT ${MQT_CORE_TARGETS_EXPORT_NAME} @@ -224,12 +146,9 @@ if(MQT_CORE_INSTALL) install( FILES ${PROJECT_SOURCE_DIR}/cmake/Cache.cmake - ${PROJECT_SOURCE_DIR}/cmake/CompilerOptions.cmake - ${PROJECT_SOURCE_DIR}/cmake/CompilerWarnings.cmake ${PROJECT_SOURCE_DIR}/cmake/FindGMP.cmake ${PROJECT_SOURCE_DIR}/cmake/PackageAddTest.cmake ${PROJECT_SOURCE_DIR}/cmake/PreventInSourceBuilds.cmake - ${PROJECT_SOURCE_DIR}/cmake/Sanitizers.cmake ${PROJECT_SOURCE_DIR}/cmake/StandardProjectSettings.cmake DESTINATION ${MQT_CORE_CONFIG_INSTALL_DIR}) endif() diff --git a/src/algorithms/CMakeLists.txt b/src/algorithms/CMakeLists.txt new file mode 100644 index 000000000..9080818b3 --- /dev/null +++ b/src/algorithms/CMakeLists.txt @@ -0,0 +1,52 @@ +# +# This file is part of the MQT CORE library released under the MIT license. See README.md or go to +# https://github.com/cda-tum/mqt-core for more information. +# + +if(NOT TARGET ${MQT_CORE_TARGET_NAME}-algo) + # collect headers and source files + file(GLOB_RECURSE ALGO_HEADERS ${MQT_CORE_INCLUDE_BUILD_DIR}/algorithms/**.hpp) + file(GLOB_RECURSE ALGO_SOURCES **.cpp) + + # add algo package library + add_library(${MQT_CORE_TARGET_NAME}-algo ${ALGO_HEADERS} ${ALGO_SOURCES}) + + # add link libraries + target_link_libraries( + ${MQT_CORE_TARGET_NAME}-algo + PUBLIC MQT::CoreIR + PRIVATE MQT::ProjectOptions MQT::ProjectWarnings) + + # set include directories + target_include_directories( + ${MQT_CORE_TARGET_NAME}-algo PUBLIC $ + $) + + # add MQT alias + add_library(MQT::CoreAlgo ALIAS ${MQT_CORE_TARGET_NAME}-algo) + + # set versioning information + set_target_properties( + ${MQT_CORE_TARGET_NAME}-algo + PROPERTIES VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} + EXPORT_NAME CoreAlgo) + + # generate export header + include(GenerateExportHeader) + generate_export_header(${MQT_CORE_TARGET_NAME}-algo BASE_NAME mqt_core_algo) + if(NOT BUILD_SHARED_LIBS) + target_compile_definitions(${MQT_CORE_TARGET_NAME}-algo PUBLIC MQT_CORE_ALGO_STATIC_DEFINE) + endif() + + # install export header + if(MQT_CORE_INSTALL) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mqt_core_algo_export.h + DESTINATION ${MQT_CORE_INCLUDE_INSTALL_DIR}) + endif() + + # add to list of MQT core targets + set(MQT_CORE_TARGETS + ${MQT_CORE_TARGETS} ${MQT_CORE_TARGET_NAME}-algo + PARENT_SCOPE) +endif() diff --git a/src/algorithms/Entanglement.cpp b/src/algorithms/Entanglement.cpp index 24f4ec1c7..63ac8a9e4 100644 --- a/src/algorithms/Entanglement.cpp +++ b/src/algorithms/Entanglement.cpp @@ -1,7 +1,7 @@ #include "algorithms/Entanglement.hpp" #include "Definitions.hpp" -#include "QuantumComputation.hpp" +#include "ir/QuantumComputation.hpp" #include #include diff --git a/src/algorithms/GoogleRandomCircuitSampling.cpp b/src/algorithms/GoogleRandomCircuitSampling.cpp deleted file mode 100644 index dac6c740e..000000000 --- a/src/algorithms/GoogleRandomCircuitSampling.cpp +++ /dev/null @@ -1,165 +0,0 @@ -#include "algorithms/GoogleRandomCircuitSampling.hpp" - -#include "Definitions.hpp" -#include "operations/OpType.hpp" -#include "operations/StandardOperation.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace qc { -GoogleRandomCircuitSampling::GoogleRandomCircuitSampling( - const std::string& filename) { - importGRCS(filename); -} - -GoogleRandomCircuitSampling::GoogleRandomCircuitSampling( - std::string prefix, const std::uint16_t device, const std::uint16_t depth, - const std::uint16_t instance) - : layout(Bristlecone), pathPrefix(std::move(prefix)) { - std::stringstream ss; - ss << pathPrefix; - ss << "bristlecone/cz_v2/bris_"; - ss << device; - ss << "/bris_"; - ss << device; - ss << "_"; - ss << depth; - ss << "_"; - ss << instance; - ss << ".txt"; - - importGRCS(ss.str()); -} - -GoogleRandomCircuitSampling::GoogleRandomCircuitSampling( - std::string prefix, const std::uint16_t x, const std::uint16_t y, - const std::uint16_t depth, const std::uint16_t instance) - : pathPrefix(std::move(prefix)) { - std::stringstream ss; - ss << pathPrefix; - ss << "rectangular/cz_v2/"; - ss << x; - ss << "x"; - ss << y; - ss << "/inst_"; - ss << x; - ss << "x"; - ss << y; - ss << "_"; - ss << depth; - ss << "_"; - ss << instance; - ss << ".txt"; - importGRCS(ss.str()); -} - -void GoogleRandomCircuitSampling::importGRCS(const std::string& filename) { - auto ifs = std::ifstream(filename); - if (!ifs.good()) { - throw QFRException("Error opening/reading from file: " + filename); - } - const std::size_t slash = filename.find_last_of('/'); - const std::size_t dot = filename.find_last_of('.'); - std::string benchmark = filename.substr(slash + 1, dot - slash - 1); - name = benchmark; - layout = (benchmark[0] == 'b') ? Bristlecone : Rectangular; - std::size_t nq{}; - ifs >> nq; - - addQubitRegister(nq); - addClassicalRegister(nq); - - std::string line; - std::string identifier; - std::size_t control = 0; - std::size_t target = 0; - std::size_t cycle = 0; - while (std::getline(ifs, line)) { - if (line.empty()) { - continue; - } - std::stringstream ss(line); - ss >> cycle; - if (cycles.size() <= cycle) { - cycles.emplace_back(); - } - - ss >> identifier; - if (identifier == "cz") { - ss >> control; - ss >> target; - cycles[cycle].emplace_back(std::make_unique( - Control{static_cast(control)}, static_cast(target), Z)); - } else if (identifier == "is") { - ss >> control; - ss >> target; - cycles[cycle].emplace_back(std::make_unique( - qc::Controls{}, static_cast(control), - static_cast(target), iSWAP)); - } else { - ss >> target; - if (identifier == "h") { - cycles[cycle].emplace_back( - std::make_unique(static_cast(target), H)); - } else if (identifier == "t") { - cycles[cycle].emplace_back( - std::make_unique(static_cast(target), T)); - } else if (identifier == "x_1_2") { - cycles[cycle].emplace_back(std::make_unique( - static_cast(target), RX, std::vector{PI_2})); - } else if (identifier == "y_1_2") { - cycles[cycle].emplace_back(std::make_unique( - static_cast(target), RY, std::vector{PI_2})); - } else { - throw QFRException("Unknown gate '" + identifier); - } - } - } -} - -std::size_t GoogleRandomCircuitSampling::getNops() const { - std::size_t nops = 0; - for (const auto& cycle : cycles) { - nops += cycle.size(); - } - return nops; -} - -std::ostream& GoogleRandomCircuitSampling::print(std::ostream& os) const { - std::size_t i = 0; - std::size_t j = 0; - for (const auto& cycle : cycles) { - os << "Cycle " << i++ << ":\n"; - for (const auto& op : cycle) { - os << std::setw(static_cast(std::log10(getNops()) + 1.)) << ++j - << ": "; - op->print(os, initialLayout, 0U, nqubits); - os << "\n"; - } - } - return os; -} - -std::ostream& -GoogleRandomCircuitSampling::printStatistics(std::ostream& os) const { - os << "GoogleRandomCircuitSampling Statistics:\n"; - os << "\tLayout: " - << ((layout == Rectangular) ? "Rectangular" : "Bristlecone") << "\n"; - os << "\tn: " << static_cast(nqubits) << "\n"; - os << "\tm: " << getNops() << "\n"; - os << "\tc: 1 + " << cycles.size() - 2 << " + 1" - << "\n"; - os << "--------------" - << "\n"; - return os; -} -} // namespace qc diff --git a/src/algorithms/Grover.cpp b/src/algorithms/Grover.cpp index eac01e9ff..b18715290 100644 --- a/src/algorithms/Grover.cpp +++ b/src/algorithms/Grover.cpp @@ -1,8 +1,8 @@ #include "algorithms/Grover.hpp" #include "Definitions.hpp" -#include "QuantumComputation.hpp" -#include "operations/Control.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/Control.hpp" #include #include diff --git a/src/algorithms/QFT.cpp b/src/algorithms/QFT.cpp index cc646ba7b..54b7ae4ee 100644 --- a/src/algorithms/QFT.cpp +++ b/src/algorithms/QFT.cpp @@ -1,7 +1,7 @@ #include "algorithms/QFT.hpp" #include "Definitions.hpp" -#include "operations/OpType.hpp" +#include "ir/operations/OpType.hpp" #include #include diff --git a/src/algorithms/QPE.cpp b/src/algorithms/QPE.cpp index c5cf2c2c5..ff5e5bbe0 100644 --- a/src/algorithms/QPE.cpp +++ b/src/algorithms/QPE.cpp @@ -1,7 +1,7 @@ #include "algorithms/QPE.hpp" #include "Definitions.hpp" -#include "operations/OpType.hpp" +#include "ir/operations/OpType.hpp" #include #include diff --git a/src/algorithms/RandomCliffordCircuit.cpp b/src/algorithms/RandomCliffordCircuit.cpp index 48348c428..200cf755b 100644 --- a/src/algorithms/RandomCliffordCircuit.cpp +++ b/src/algorithms/RandomCliffordCircuit.cpp @@ -1,8 +1,8 @@ #include "algorithms/RandomCliffordCircuit.hpp" #include "Definitions.hpp" -#include "QuantumComputation.hpp" -#include "operations/CompoundOperation.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/CompoundOperation.hpp" #include #include diff --git a/src/algorithms/WState.cpp b/src/algorithms/WState.cpp index 1c0e0ad82..0f5ebf86b 100644 --- a/src/algorithms/WState.cpp +++ b/src/algorithms/WState.cpp @@ -1,7 +1,7 @@ #include "algorithms/WState.hpp" #include "Definitions.hpp" -#include "QuantumComputation.hpp" +#include "ir/QuantumComputation.hpp" #include #include diff --git a/src/circuit_optimizer/CMakeLists.txt b/src/circuit_optimizer/CMakeLists.txt new file mode 100644 index 000000000..2e679fdb1 --- /dev/null +++ b/src/circuit_optimizer/CMakeLists.txt @@ -0,0 +1,56 @@ +# +# This file is part of the MQT CORE library released under the MIT license. See README.md or go to +# https://github.com/cda-tum/mqt-core for more information. +# + +if(NOT TARGET ${MQT_CORE_TARGET_NAME}-circuit-optimizer) + # collect headers and source files + file(GLOB_RECURSE CIRCUIT_OPTIMIZER_HEADERS ${MQT_CORE_INCLUDE_BUILD_DIR}/circuit_optimizer/*.hpp) + file(GLOB_RECURSE CIRCUIT_OPTIMIZER_SOURCES **.cpp) + + # add circuit_optimizer Package library + add_library(${MQT_CORE_TARGET_NAME}-circuit-optimizer ${CIRCUIT_OPTIMIZER_HEADERS} + ${CIRCUIT_OPTIMIZER_SOURCES}) + + # add link libraries + target_link_libraries( + ${MQT_CORE_TARGET_NAME}-circuit-optimizer + PUBLIC MQT::CoreIR + PRIVATE MQT::ProjectOptions MQT::ProjectWarnings) + + # add include directories + target_include_directories( + ${MQT_CORE_TARGET_NAME}-circuit-optimizer + PUBLIC $ + $) + + # add MQT alias + add_library(MQT::CoreCircuitOptimizer ALIAS ${MQT_CORE_TARGET_NAME}-circuit-optimizer) + + # set versioning information + set_target_properties( + ${MQT_CORE_TARGET_NAME}-circuit-optimizer + PROPERTIES VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} + EXPORT_NAME CoreCircuitOptimizer) + + # generate export header + include(GenerateExportHeader) + generate_export_header(${MQT_CORE_TARGET_NAME}-circuit-optimizer BASE_NAME + mqt_core_circuit_optimizer) + if(NOT BUILD_SHARED_LIBS) + target_compile_definitions(${MQT_CORE_TARGET_NAME}-circuit-optimizer + PUBLIC MQT_CORE_CIRCUIT_OPTIMIZER_STATIC_DEFINE) + endif() + + # install export header + if(MQT_CORE_INSTALL) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mqt_core_circuit_optimizer_export.h + DESTINATION ${MQT_CORE_INCLUDE_INSTALL_DIR}) + endif() + + # add to list of MQT core targets + set(MQT_CORE_TARGETS + ${MQT_CORE_TARGETS} ${MQT_CORE_TARGET_NAME}-circuit-optimizer + PARENT_SCOPE) +endif() diff --git a/src/CircuitOptimizer.cpp b/src/circuit_optimizer/CircuitOptimizer.cpp similarity index 94% rename from src/CircuitOptimizer.cpp rename to src/circuit_optimizer/CircuitOptimizer.cpp index 6b43347b1..c14a65f3b 100644 --- a/src/CircuitOptimizer.cpp +++ b/src/circuit_optimizer/CircuitOptimizer.cpp @@ -1,11 +1,11 @@ -#include "CircuitOptimizer.hpp" +#include "circuit_optimizer/CircuitOptimizer.hpp" #include "Definitions.hpp" -#include "QuantumComputation.hpp" -#include "operations/CompoundOperation.hpp" -#include "operations/NonUnitaryOperation.hpp" -#include "operations/OpType.hpp" -#include "operations/StandardOperation.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/CompoundOperation.hpp" +#include "ir/operations/NonUnitaryOperation.hpp" +#include "ir/operations/OpType.hpp" +#include "ir/operations/StandardOperation.hpp" #include #include @@ -1055,98 +1055,6 @@ bool CircuitOptimizer::isDynamicCircuit(QuantumComputation& qc) { return false; } -/// this method can be used to reorder the operations of a given quantum -/// computation in order to get a canonical ordering it uses iterative -/// breadth-first search starting from the topmost qubit -void CircuitOptimizer::reorderOperations(QuantumComputation& qc) { - auto dag = constructDAG(qc); - - // initialize iterators - DAGIterators dagIterators{dag.size()}; - for (size_t q = 0; q < dag.size(); ++q) { - if (dag.at(q).empty()) { - // qubit is isdle - dagIterators.at(q) = dag.at(q).end(); - } else { - // point to first operation - dagIterators.at(q) = dag.at(q).begin(); - } - } - - std::vector> ops{}; - - // iterate over DAG in depth-first fashion starting from the top-most qubit - const auto msq = dag.size() - 1; - bool done = false; - while (!done) { - // assume that everything is done - done = true; - - // iterate over qubits in reverse order - for (auto q = static_cast>(msq); q >= 0; --q) { - // nothing to be done for this qubit - if (dagIterators.at(static_cast(q)) == - dag.at(static_cast(q)).end()) { - continue; - } - done = false; - - // get the current operation on the qubit - auto& it = dagIterators.at(static_cast(q)); - auto& op = **it; - - // warning for classically controlled operations - if (op->getType() == ClassicControlled) { - std::cerr << "Caution! Reordering operations might not work if the " - "circuit contains classically controlled operations\n"; - } - - // check whether the gate can be scheduled, i.e. whether all qubits it - // acts on are at this operation - bool executable = true; - std::vector actsOn(dag.size()); - actsOn[static_cast(q)] = true; - for (std::size_t i = 0; i < dag.size(); ++i) { - // actually check in reverse order - const auto qb = - static_cast>(dag.size() - 1 - i); - if (qb != q && op->actsOn(static_cast(qb))) { - actsOn[static_cast(qb)] = true; - - assert(dagIterators.at(static_cast(qb)) != - dag.at(static_cast(qb)).end()); - // check whether operation is executable for the currently considered - // qubit - if (*dagIterators.at(static_cast(qb)) != *it) { - executable = false; - break; - } - } - } - - // continue, if this gate is not yet executable - if (!executable) { - continue; - } - - // gate is executable, move it to the new vector - ops.emplace_back(std::move(op)); - - // now increase all corresponding iterators - for (std::size_t i = 0; i < dag.size(); ++i) { - if (actsOn[i]) { - ++(dagIterators.at(i)); - } - } - } - } - - // clear all the operations from the quantum circuit - qc.ops.clear(); - // move all operations from the newly created vector to the original one - std::move(ops.begin(), ops.end(), std::back_inserter(qc.ops)); -} - void CircuitOptimizer::printDAG(const DAG& dag) { for (const auto& qubitDag : dag) { std::cout << " - "; @@ -1636,7 +1544,7 @@ void CircuitOptimizer::collectBlocks(qc::QuantumComputation& qc, } // ensure canonical ordering and that measurements are as far back as possible - reorderOperations(qc); + qc.reorderOperations(); deferMeasurements(qc); // create an empty disjoint set union data structure diff --git a/src/datastructures/CMakeLists.txt b/src/datastructures/CMakeLists.txt index bc1346d89..ab0a0eeef 100644 --- a/src/datastructures/CMakeLists.txt +++ b/src/datastructures/CMakeLists.txt @@ -4,22 +4,48 @@ # if(NOT TARGET ${MQT_CORE_TARGET_NAME}-ds) + # collect headers and source files file(GLOB_RECURSE DS_HEADERS ${MQT_CORE_INCLUDE_BUILD_DIR}/datastructures/**.hpp) file(GLOB_RECURSE DS_SOURCES **.cpp) - # add NA package library + # add ds package library add_library(${MQT_CORE_TARGET_NAME}-ds ${DS_HEADERS} ${DS_SOURCES}) - target_link_libraries(${MQT_CORE_TARGET_NAME}-ds PUBLIC MQT::Core) - target_link_libraries(${MQT_CORE_TARGET_NAME}-ds PRIVATE MQT::ProjectOptions MQT::ProjectWarnings) + # add link libraries + target_link_libraries( + ${MQT_CORE_TARGET_NAME}-ds + PUBLIC MQT::CoreIR + PRIVATE MQT::ProjectOptions MQT::ProjectWarnings) + + # set include directories + target_include_directories( + ${MQT_CORE_TARGET_NAME}-ds PUBLIC $ + $) # add MQT alias add_library(MQT::CoreDS ALIAS ${MQT_CORE_TARGET_NAME}-ds) + + # set versioning information set_target_properties( ${MQT_CORE_TARGET_NAME}-ds PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} EXPORT_NAME CoreDS) + + # generate export header + include(GenerateExportHeader) + generate_export_header(${MQT_CORE_TARGET_NAME}-ds BASE_NAME mqt_core_ds) + if(NOT BUILD_SHARED_LIBS) + target_compile_definitions(${MQT_CORE_TARGET_NAME}-ds PUBLIC MQT_CORE_DS_STATIC_DEFINE) + endif() + + # install export header + if(MQT_CORE_INSTALL) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mqt_core_ds_export.h + DESTINATION ${MQT_CORE_INCLUDE_INSTALL_DIR}) + endif() + + # add to list of MQT core target set(MQT_CORE_TARGETS ${MQT_CORE_TARGETS} ${MQT_CORE_TARGET_NAME}-ds PARENT_SCOPE) diff --git a/src/datastructures/Layer.cpp b/src/datastructures/Layer.cpp index bd84c61e8..d89462dde 100644 --- a/src/datastructures/Layer.cpp +++ b/src/datastructures/Layer.cpp @@ -1,8 +1,8 @@ #include "datastructures/Layer.hpp" #include "Definitions.hpp" -#include "QuantumComputation.hpp" -#include "operations/OpType.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/OpType.hpp" #include #include @@ -110,8 +110,8 @@ auto Layer::constructDAG(const QuantumComputation& qc, ->commutesAtQubit(*current->getOperation(), qubit) || std::find_if( currentGroup[qubit].cbegin(), currentGroup[qubit].cend(), - [¤t](const auto& vertex) { - return *vertex->getOperation() == *current->getOperation(); + [¤t](const auto& v) { + return *v->getOperation() == *current->getOperation(); }) != currentGroup[qubit].cend())) { // here: the current operation does not commute with the current // group members and is not the inverse of the lookahead diff --git a/src/dd/Benchmark.cpp b/src/dd/Benchmark.cpp index 6e205f7fe..ea1de40ea 100644 --- a/src/dd/Benchmark.cpp +++ b/src/dd/Benchmark.cpp @@ -1,12 +1,15 @@ #include "dd/Benchmark.hpp" -#include "QuantumComputation.hpp" +#include "algorithms/Grover.hpp" #include "dd/FunctionalityConstruction.hpp" #include "dd/Package.hpp" #include "dd/Simulation.hpp" #include "dd/statistics/PackageStatistics.hpp" +#include "ir/QuantumComputation.hpp" +#include #include +#include #include #include #include @@ -14,6 +17,87 @@ namespace dd { +template +MatrixDD buildFunctionality(const qc::Grover* qc, Package& dd) { + QuantumComputation groverIteration(qc->getNqubits()); + qc->oracle(groverIteration); + qc->diffusion(groverIteration); + + auto iteration = buildFunctionality(&groverIteration, dd); + + auto e = iteration; + dd.incRef(e); + + for (std::size_t i = 0U; i < qc->iterations - 1U; ++i) { + auto f = dd.multiply(iteration, e); + dd.incRef(f); + dd.decRef(e); + e = f; + dd.garbageCollect(); + } + + QuantumComputation setup(qc->getNqubits()); + qc->setup(setup); + auto g = buildFunctionality(&setup, dd); + auto f = dd.multiply(e, g); + dd.incRef(f); + dd.decRef(e); + dd.decRef(g); + e = f; + + dd.decRef(iteration); + return e; +} + +template +MatrixDD buildFunctionalityRecursive(const qc::Grover* qc, + Package& dd) { + QuantumComputation groverIteration(qc->getNqubits()); + qc->oracle(groverIteration); + qc->diffusion(groverIteration); + + auto iter = buildFunctionalityRecursive(&groverIteration, dd); + auto e = iter; + std::bitset<128U> iterBits(qc->iterations); + auto msb = static_cast(std::floor(std::log2(qc->iterations))); + auto f = iter; + dd.incRef(f); + bool zero = !iterBits[0U]; + for (std::size_t j = 1U; j <= msb; ++j) { + auto tmp = dd.multiply(f, f); + dd.incRef(tmp); + dd.decRef(f); + f = tmp; + if (iterBits[j]) { + if (zero) { + dd.incRef(f); + dd.decRef(e); + e = f; + zero = false; + } else { + auto g = dd.multiply(e, f); + dd.incRef(g); + dd.decRef(e); + e = g; + dd.garbageCollect(); + } + } + } + dd.decRef(f); + + // apply state preparation setup + qc::QuantumComputation statePrep(qc->getNqubits()); + qc->setup(statePrep); + auto s = buildFunctionality(&statePrep, dd); + auto tmp = dd.multiply(e, s); + dd.incRef(tmp); + dd.decRef(s); + dd.decRef(e); + e = tmp; + + return e; +} + std::unique_ptr benchmarkSimulate(const QuantumComputation& qc) { std::unique_ptr exp = @@ -38,10 +122,19 @@ benchmarkFunctionalityConstruction(const QuantumComputation& qc, const auto nq = qc.getNqubits(); exp->dd = std::make_unique>(nq); const auto start = std::chrono::high_resolution_clock::now(); - if (recursive) { - exp->func = buildFunctionalityRecursive(&qc, *(exp->dd)); + + if (const auto* grover = dynamic_cast(&qc)) { + if (recursive) { + exp->func = buildFunctionalityRecursive(grover, *(exp->dd)); + } else { + exp->func = buildFunctionality(grover, *(exp->dd)); + } } else { - exp->func = buildFunctionality(&qc, *(exp->dd)); + if (recursive) { + exp->func = buildFunctionalityRecursive(&qc, *(exp->dd)); + } else { + exp->func = buildFunctionality(&qc, *(exp->dd)); + } } const auto end = std::chrono::high_resolution_clock::now(); exp->runtime = diff --git a/src/dd/CMakeLists.txt b/src/dd/CMakeLists.txt index a9d70ccf1..fd4d688ad 100644 --- a/src/dd/CMakeLists.txt +++ b/src/dd/CMakeLists.txt @@ -1,36 +1,46 @@ if(NOT TARGET ${MQT_CORE_TARGET_NAME}-dd) + # collect headers and source files file(GLOB_RECURSE DD_HEADERS ${MQT_CORE_INCLUDE_BUILD_DIR}/dd/*.hpp) + file(GLOB_RECURSE DD_SOURCES **.cpp) # add DD Package library - add_library( + add_library(${MQT_CORE_TARGET_NAME}-dd ${DD_HEADERS} ${DD_SOURCES}) + + # add link libraries + target_link_libraries( ${MQT_CORE_TARGET_NAME}-dd - ${DD_HEADERS} - Benchmark.cpp - CachedEdge.cpp - Complex.cpp - ComplexNumbers.cpp - ComplexValue.cpp - Edge.cpp - FunctionalityConstruction.cpp - MemoryManager.cpp - Node.cpp - NoiseFunctionality.cpp - Operations.cpp - RealNumber.cpp - RealNumberUniqueTable.cpp - Simulation.cpp - statistics/MemoryManagerStatistics.cpp - statistics/Statistics.cpp - statistics/TableStatistics.cpp - statistics/UniqueTableStatistics.cpp) - target_link_libraries(${MQT_CORE_TARGET_NAME}-dd PUBLIC MQT::Core nlohmann_json::nlohmann_json) - target_link_libraries(${MQT_CORE_TARGET_NAME}-dd PRIVATE MQT::ProjectOptions MQT::ProjectWarnings) + PUBLIC MQT::CoreIR nlohmann_json::nlohmann_json + PRIVATE MQT::ProjectOptions MQT::ProjectWarnings) + + # add include directories + target_include_directories( + ${MQT_CORE_TARGET_NAME}-dd PUBLIC $ + $) + + # add MQT alias add_library(MQT::CoreDD ALIAS ${MQT_CORE_TARGET_NAME}-dd) + + # set versioning information set_target_properties( mqt-core-dd PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} EXPORT_NAME CoreDD) + + # generate export header + include(GenerateExportHeader) + generate_export_header(${MQT_CORE_TARGET_NAME}-dd BASE_NAME mqt_core_dd) + if(NOT BUILD_SHARED_LIBS) + target_compile_definitions(${MQT_CORE_TARGET_NAME}-dd PUBLIC MQT_CORE_DD_STATIC_DEFINE) + endif() + + # install export header + if(MQT_CORE_INSTALL) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mqt_core_dd_export.h + DESTINATION ${MQT_CORE_INCLUDE_INSTALL_DIR}) + endif() + + # add to list of MQT core targets set(MQT_CORE_TARGETS ${MQT_CORE_TARGETS} ${MQT_CORE_TARGET_NAME}-dd PARENT_SCOPE) diff --git a/src/dd/FunctionalityConstruction.cpp b/src/dd/FunctionalityConstruction.cpp index 08bd9498d..6a4fc3bad 100644 --- a/src/dd/FunctionalityConstruction.cpp +++ b/src/dd/FunctionalityConstruction.cpp @@ -1,10 +1,8 @@ #include "dd/FunctionalityConstruction.hpp" -#include "QuantumComputation.hpp" -#include "algorithms/Grover.hpp" #include "dd/Package.hpp" +#include "ir/QuantumComputation.hpp" -#include #include #include #include @@ -17,10 +15,6 @@ MatrixDD buildFunctionality(const QuantumComputation* qc, Package& dd) { return MatrixDD::one(); } - if (const auto* grover = dynamic_cast(qc)) { - return buildFunctionality(grover, dd); - } - auto permutation = qc->initialLayout; auto e = dd.createInitialMatrix(qc->ancillary); @@ -48,10 +42,6 @@ MatrixDD buildFunctionalityRecursive(const QuantumComputation* qc, return MatrixDD::one(); } - if (const auto* grover = dynamic_cast(qc)) { - return buildFunctionalityRecursive(grover, dd); - } - auto permutation = qc->initialLayout; if (qc->size() == 1U) { @@ -125,87 +115,6 @@ bool buildFunctionalityRecursive(const QuantumComputation* qc, return success; } -template -MatrixDD buildFunctionality(const qc::Grover* qc, Package& dd) { - QuantumComputation groverIteration(qc->getNqubits()); - qc->oracle(groverIteration); - qc->diffusion(groverIteration); - - auto iteration = buildFunctionality(&groverIteration, dd); - - auto e = iteration; - dd.incRef(e); - - for (std::size_t i = 0U; i < qc->iterations - 1U; ++i) { - auto f = dd.multiply(iteration, e); - dd.incRef(f); - dd.decRef(e); - e = f; - dd.garbageCollect(); - } - - QuantumComputation setup(qc->getNqubits()); - qc->setup(setup); - auto g = buildFunctionality(&setup, dd); - auto f = dd.multiply(e, g); - dd.incRef(f); - dd.decRef(e); - dd.decRef(g); - e = f; - - dd.decRef(iteration); - return e; -} - -template -MatrixDD buildFunctionalityRecursive(const qc::Grover* qc, - Package& dd) { - QuantumComputation groverIteration(qc->getNqubits()); - qc->oracle(groverIteration); - qc->diffusion(groverIteration); - - auto iter = buildFunctionalityRecursive(&groverIteration, dd); - auto e = iter; - std::bitset<128U> iterBits(qc->iterations); - auto msb = static_cast(std::floor(std::log2(qc->iterations))); - auto f = iter; - dd.incRef(f); - bool zero = !iterBits[0U]; - for (std::size_t j = 1U; j <= msb; ++j) { - auto tmp = dd.multiply(f, f); - dd.incRef(tmp); - dd.decRef(f); - f = tmp; - if (iterBits[j]) { - if (zero) { - dd.incRef(f); - dd.decRef(e); - e = f; - zero = false; - } else { - auto g = dd.multiply(e, f); - dd.incRef(g); - dd.decRef(e); - e = g; - dd.garbageCollect(); - } - } - } - dd.decRef(f); - - // apply state preparation setup - qc::QuantumComputation statePrep(qc->getNqubits()); - qc->setup(statePrep); - auto s = buildFunctionality(&statePrep, dd); - auto tmp = dd.multiply(e, s); - dd.incRef(tmp); - dd.decRef(s); - dd.decRef(e); - e = tmp; - - return e; -} - template MatrixDD buildFunctionality(const qc::QuantumComputation* qc, Package& dd); template MatrixDD @@ -223,8 +132,4 @@ template bool buildFunctionalityRecursive(const qc::QuantumComputation* qc, std::stack& s, qc::Permutation& permutation, Package& dd); -template MatrixDD buildFunctionality(const qc::Grover* qc, - Package& dd); -template MatrixDD buildFunctionalityRecursive(const qc::Grover* qc, - Package& dd); } // namespace dd diff --git a/src/dd/NoiseFunctionality.cpp b/src/dd/NoiseFunctionality.cpp index a3fbc3c07..a1795e3c5 100644 --- a/src/dd/NoiseFunctionality.cpp +++ b/src/dd/NoiseFunctionality.cpp @@ -7,8 +7,8 @@ #include "dd/GateMatrixDefinitions.hpp" #include "dd/Node.hpp" #include "dd/Package.hpp" -#include "operations/OpType.hpp" -#include "operations/Operation.hpp" +#include "ir/operations/OpType.hpp" +#include "ir/operations/Operation.hpp" #include #include diff --git a/src/dd/Operations.cpp b/src/dd/Operations.cpp index 9b1b8cb3a..725522c11 100644 --- a/src/dd/Operations.cpp +++ b/src/dd/Operations.cpp @@ -3,10 +3,10 @@ #include "Definitions.hpp" #include "dd/DDDefinitions.hpp" #include "dd/Package.hpp" -#include "operations/CompoundOperation.hpp" -#include "operations/Control.hpp" -#include "operations/OpType.hpp" -#include "operations/Operation.hpp" +#include "ir/operations/CompoundOperation.hpp" +#include "ir/operations/Control.hpp" +#include "ir/operations/OpType.hpp" +#include "ir/operations/Operation.hpp" #include #include diff --git a/src/dd/Simulation.cpp b/src/dd/Simulation.cpp index 2c8de8842..bb298d917 100644 --- a/src/dd/Simulation.cpp +++ b/src/dd/Simulation.cpp @@ -1,15 +1,14 @@ #include "dd/Simulation.hpp" #include "Definitions.hpp" -#include "QuantumComputation.hpp" -#include "algorithms/GoogleRandomCircuitSampling.hpp" #include "dd/DDDefinitions.hpp" #include "dd/GateMatrixDefinitions.hpp" #include "dd/Package.hpp" #include "dd/RealNumber.hpp" -#include "operations/ClassicControlledOperation.hpp" -#include "operations/NonUnitaryOperation.hpp" -#include "operations/OpType.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/ClassicControlledOperation.hpp" +#include "ir/operations/NonUnitaryOperation.hpp" +#include "ir/operations/OpType.hpp" #include #include @@ -424,29 +423,6 @@ void extractProbabilityVectorRecursive(const QuantumComputation* qc, } } -template -VectorDD simulate(GoogleRandomCircuitSampling* qc, const VectorDD& in, - Package& dd, - const std::optional ncycles) { - if (ncycles.has_value() && (*ncycles < qc->cycles.size() - 2U)) { - qc->removeCycles(qc->cycles.size() - 2U - *ncycles); - } - - Permutation permutation = qc->initialLayout; - auto e = in; - dd.incRef(e); - for (const auto& cycle : qc->cycles) { - for (const auto& op : cycle) { - auto tmp = dd.multiply(getDD(op.get(), dd, permutation), e); - dd.incRef(tmp); - dd.decRef(e); - e = tmp; - dd.garbageCollect(); - } - } - return e; -} - template std::map simulate(const QuantumComputation* qc, const VectorDD& in, Package& dd, std::size_t shots, @@ -459,8 +435,4 @@ template void extractProbabilityVectorRecursive( decltype(qc->begin()) currentIt, Permutation& permutation, std::map measurements, fp commonFactor, SparsePVec& probVector, Package& dd); -template VectorDD -simulate(GoogleRandomCircuitSampling* qc, const VectorDD& in, - Package& dd, - const std::optional ncycles); } // namespace dd diff --git a/src/ir/CMakeLists.txt b/src/ir/CMakeLists.txt new file mode 100644 index 000000000..0be4b0d1c --- /dev/null +++ b/src/ir/CMakeLists.txt @@ -0,0 +1,49 @@ +# +# This file is part of the MQT CORE library released under the MIT license. See README.md or go to +# https://github.com/cda-tum/mqt-core for more information. +# + +if(NOT TARGET MQT::CoreIR) + # collect headers and source files + file(GLOB_RECURSE IR_HEADERS ${MQT_CORE_INCLUDE_BUILD_DIR}/ir/*.hpp) + file(GLOB_RECURSE IR_SOURCES **.cpp) + + # add IR Package library + add_library(${MQT_CORE_TARGET_NAME}-ir ${IR_HEADERS} ${IR_SOURCES}) + + # add link libraries + target_link_libraries(${MQT_CORE_TARGET_NAME}-ir PRIVATE MQT::ProjectOptions MQT::ProjectWarnings) + + # set include directories + target_include_directories( + ${MQT_CORE_TARGET_NAME}-ir PUBLIC $ + $) + + # add MQT alias + add_library(MQT::CoreIR ALIAS ${MQT_CORE_TARGET_NAME}-ir) + + # set versioning information + set_target_properties( + ${MQT_CORE_TARGET_NAME}-ir + PROPERTIES VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} + EXPORT_NAME CoreIR) + + # generate export header + include(GenerateExportHeader) + generate_export_header(${MQT_CORE_TARGET_NAME}-ir BASE_NAME mqt_core_ir) + if(NOT BUILD_SHARED_LIBS) + target_compile_definitions(${MQT_CORE_TARGET_NAME}-ir PUBLIC MQT_CORE_IR_STATIC_DEFINE) + endif() + + # install export header + if(MQT_CORE_INSTALL) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mqt_core_ir_export.h + DESTINATION ${MQT_CORE_INCLUDE_INSTALL_DIR}) + endif() + + # add to list of MQT core target + set(MQT_CORE_TARGETS + ${MQT_CORE_TARGETS} ${MQT_CORE_TARGET_NAME}-ir + PARENT_SCOPE) +endif() diff --git a/src/QuantumComputation.cpp b/src/ir/QuantumComputation.cpp similarity index 88% rename from src/QuantumComputation.cpp rename to src/ir/QuantumComputation.cpp index 0779a118d..9277c431e 100644 --- a/src/QuantumComputation.cpp +++ b/src/ir/QuantumComputation.cpp @@ -1,13 +1,13 @@ -#include "QuantumComputation.hpp" +#include "ir/QuantumComputation.hpp" #include "Definitions.hpp" -#include "operations/CompoundOperation.hpp" -#include "operations/Control.hpp" -#include "operations/Expression.hpp" -#include "operations/NonUnitaryOperation.hpp" -#include "operations/OpType.hpp" -#include "operations/StandardOperation.hpp" -#include "operations/SymbolicOperation.hpp" +#include "ir/operations/CompoundOperation.hpp" +#include "ir/operations/Control.hpp" +#include "ir/operations/Expression.hpp" +#include "ir/operations/NonUnitaryOperation.hpp" +#include "ir/operations/OpType.hpp" +#include "ir/operations/StandardOperation.hpp" +#include "ir/operations/SymbolicOperation.hpp" #include #include @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -97,8 +98,6 @@ void QuantumComputation::import(const std::string& filename) { import(filename, Format::Real); } else if (extension == "qasm") { import(filename, Format::OpenQASM3); - } else if (extension == "txt") { - import(filename, Format::GRCS); } else if (extension == "tfc") { import(filename, Format::TFC); } else if (extension == "qc") { @@ -133,9 +132,6 @@ void QuantumComputation::import(std::istream& is, Format format) { case Format::OpenQASM3: importOpenQASM3(is); break; - case Format::GRCS: - importGRCS(is); - break; case Format::TFC: importTFC(is); break; @@ -536,8 +532,7 @@ std::ostream& QuantumComputation::print(std::ostream& os) const { for (const auto& physicalQubit : initialLayout) { auto it = outputPermutation.find(physicalQubit.first); if (it == outputPermutation.end()) { - os << "\033[31m" << std::setw(4) << "|" - << "\033[0m"; + os << "\033[31m" << std::setw(4) << "|" << "\033[0m"; } else { os << std::setw(4) << it->second; } @@ -671,9 +666,6 @@ void QuantumComputation::dump(std::ostream& of, Format format) { case Format::Real: std::cerr << "Dumping in real format currently not supported\n"; break; - case Format::GRCS: - std::cerr << "Dumping in GRCS format currently not supported\n"; - break; case Format::TFC: std::cerr << "Dumping in TFC format currently not supported\n"; break; @@ -1132,4 +1124,133 @@ void QuantumComputation::measureAll(const bool addBits) { measure(q, start + q); } } + +void QuantumComputation::reorderOperations() { + Qubit highestPhysicalQubit = 0; + for (const auto& q : initialLayout) { + highestPhysicalQubit = std::max(q.first, highestPhysicalQubit); + } + + auto dag = DAG(highestPhysicalQubit + 1); + + for (auto& op : ops) { + if (!op->isStandardOperation()) { + // compound operations are added "as-is" + if (op->isCompoundOperation()) { + const auto usedQubits = op->getUsedQubits(); + for (const auto q : usedQubits) { + dag.at(q).push_back(&op); + } + } else if (op->isNonUnitaryOperation()) { + for (const auto& b : op->getTargets()) { + dag.at(b).push_back(&op); + } + } else if (op->isClassicControlledOperation()) { + auto* cop = + dynamic_cast(op.get())->getOperation(); + for (const auto& control : cop->getControls()) { + dag.at(control.qubit).push_back(&op); + } + for (const auto& target : cop->getTargets()) { + dag.at(target).push_back(&op); + } + } else { + throw QFRException("Unexpected operation encountered"); + } + } else { + for (const auto& control : op->getControls()) { + dag.at(control.qubit).push_back(&op); + } + for (const auto& target : op->getTargets()) { + dag.at(target).push_back(&op); + } + } + } + + // initialize iterators + DAGIterators dagIterators{dag.size()}; + for (size_t q = 0; q < dag.size(); ++q) { + if (dag.at(q).empty()) { + // qubit is isdle + dagIterators.at(q) = dag.at(q).end(); + } else { + // point to first operation + dagIterators.at(q) = dag.at(q).begin(); + } + } + + std::vector> newOps{}; + + // iterate over DAG in depth-first fashion starting from the top-most qubit + const auto msq = dag.size() - 1; + bool done = false; + while (!done) { + // assume that everything is done + done = true; + + // iterate over qubits in reverse order + for (auto q = static_cast>(msq); q >= 0; --q) { + // nothing to be done for this qubit + if (dagIterators.at(static_cast(q)) == + dag.at(static_cast(q)).end()) { + continue; + } + done = false; + + // get the current operation on the qubit + auto& it = dagIterators.at(static_cast(q)); + auto& op = **it; + + // warning for classically controlled operations + if (op->getType() == ClassicControlled) { + std::cerr << "Caution! Reordering operations might not work if the " + "circuit contains classically controlled operations\n"; + } + + // check whether the gate can be scheduled, i.e. whether all qubits it + // acts on are at this operation + bool executable = true; + std::vector actsOn(dag.size()); + actsOn[static_cast(q)] = true; + for (std::size_t i = 0; i < dag.size(); ++i) { + // actually check in reverse order + const auto qb = + static_cast>(dag.size() - 1 - i); + if (qb != q && op->actsOn(static_cast(qb))) { + actsOn[static_cast(qb)] = true; + + assert(dagIterators.at(static_cast(qb)) != + dag.at(static_cast(qb)).end()); + // check whether operation is executable for the currently considered + // qubit + if (*dagIterators.at(static_cast(qb)) != *it) { + executable = false; + break; + } + } + } + + // continue, if this gate is not yet executable + if (!executable) { + continue; + } + + // gate is executable, move it to the new vector + newOps.emplace_back(std::move(op)); + + // now increase all corresponding iterators + for (std::size_t i = 0; i < dag.size(); ++i) { + if (actsOn[i]) { + ++(dagIterators.at(i)); + } + } + } + } + + // clear all the operations from the quantum circuit + ops.clear(); + // move all operations from the newly created vector to the original one + std::move(newOps.begin(), newOps.end(), std::back_inserter(ops)); +} + } // namespace qc diff --git a/src/operations/AodOperation.cpp b/src/ir/operations/AodOperation.cpp similarity index 96% rename from src/operations/AodOperation.cpp rename to src/ir/operations/AodOperation.cpp index 25a0cee0b..143681835 100644 --- a/src/operations/AodOperation.cpp +++ b/src/ir/operations/AodOperation.cpp @@ -1,14 +1,14 @@ -#include "operations/AodOperation.hpp" +#include "ir/operations/AodOperation.hpp" #include "Definitions.hpp" -#include "cassert" -#include "iomanip" -#include "limits" -#include "operations/OpType.hpp" +#include "ir/operations/OpType.hpp" +#include #include #include +#include #include +#include #include #include #include diff --git a/src/operations/ClassicControlledOperation.cpp b/src/ir/operations/ClassicControlledOperation.cpp similarity index 93% rename from src/operations/ClassicControlledOperation.cpp rename to src/ir/operations/ClassicControlledOperation.cpp index 36838f7b2..93dfd923a 100644 --- a/src/operations/ClassicControlledOperation.cpp +++ b/src/ir/operations/ClassicControlledOperation.cpp @@ -1,4 +1,4 @@ -#include "operations/ClassicControlledOperation.hpp" +#include "ir/operations/ClassicControlledOperation.hpp" #include "Definitions.hpp" diff --git a/src/operations/CompoundOperation.cpp b/src/ir/operations/CompoundOperation.cpp similarity index 96% rename from src/operations/CompoundOperation.cpp rename to src/ir/operations/CompoundOperation.cpp index a5b1e9f1f..7fa67eeaa 100644 --- a/src/operations/CompoundOperation.cpp +++ b/src/ir/operations/CompoundOperation.cpp @@ -1,16 +1,14 @@ -#include "operations/CompoundOperation.hpp" +#include "ir/operations/CompoundOperation.hpp" #include "Definitions.hpp" -#include "Permutation.hpp" -#include "operations/Control.hpp" -#include "operations/OpType.hpp" +#include "ir/Permutation.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/Control.hpp" +#include "ir/operations/OpType.hpp" -#include -#include #include #include #include -#include #include #include #include @@ -208,9 +206,9 @@ auto CompoundOperation::isInverseOf(const Operation& other) const -> bool { QuantumComputation otherQc(otherMaxQubit + 1); std::for_each(co.cbegin(), co.cend(), [&](const auto& op) { otherQc.emplace_back(op->clone()); }); - CircuitOptimizer::reorderOperations(thisQc); + thisQc.reorderOperations(); otherQc.invert(); - CircuitOptimizer::reorderOperations(otherQc); + otherQc.reorderOperations(); return std::equal( thisQc.cbegin(), thisQc.cend(), otherQc.cbegin(), [](const auto& op1, const auto& op2) { return *op1 == *op2; }); diff --git a/src/operations/Expression.cpp b/src/ir/operations/Expression.cpp similarity index 92% rename from src/operations/Expression.cpp rename to src/ir/operations/Expression.cpp index 854315029..be9d441e9 100644 --- a/src/operations/Expression.cpp +++ b/src/ir/operations/Expression.cpp @@ -1,4 +1,4 @@ -#include "operations/Expression.hpp" +#include "ir/operations/Expression.hpp" #include #include diff --git a/src/operations/NonUnitaryOperation.cpp b/src/ir/operations/NonUnitaryOperation.cpp similarity index 97% rename from src/operations/NonUnitaryOperation.cpp rename to src/ir/operations/NonUnitaryOperation.cpp index 877c60823..3fad05825 100644 --- a/src/operations/NonUnitaryOperation.cpp +++ b/src/ir/operations/NonUnitaryOperation.cpp @@ -4,12 +4,12 @@ * more information. */ -#include "operations/NonUnitaryOperation.hpp" +#include "ir/operations/NonUnitaryOperation.hpp" #include "Definitions.hpp" -#include "Permutation.hpp" -#include "operations/OpType.hpp" -#include "operations/Operation.hpp" +#include "ir/Permutation.hpp" +#include "ir/operations/OpType.hpp" +#include "ir/operations/Operation.hpp" #include #include diff --git a/src/operations/Operation.cpp b/src/ir/operations/Operation.cpp similarity index 97% rename from src/operations/Operation.cpp rename to src/ir/operations/Operation.cpp index 3a67da8c9..2b63be4d5 100644 --- a/src/operations/Operation.cpp +++ b/src/ir/operations/Operation.cpp @@ -1,9 +1,9 @@ -#include "operations/Operation.hpp" +#include "ir/operations/Operation.hpp" #include "Definitions.hpp" -#include "Permutation.hpp" -#include "operations/Control.hpp" -#include "operations/OpType.hpp" +#include "ir/Permutation.hpp" +#include "ir/operations/Control.hpp" +#include "ir/operations/OpType.hpp" #include #include diff --git a/src/operations/StandardOperation.cpp b/src/ir/operations/StandardOperation.cpp similarity index 99% rename from src/operations/StandardOperation.cpp rename to src/ir/operations/StandardOperation.cpp index 78ca58873..ebc39ee57 100644 --- a/src/operations/StandardOperation.cpp +++ b/src/ir/operations/StandardOperation.cpp @@ -1,9 +1,9 @@ -#include "operations/StandardOperation.hpp" +#include "ir/operations/StandardOperation.hpp" #include "Definitions.hpp" -#include "operations/Control.hpp" -#include "operations/OpType.hpp" -#include "operations/Operation.hpp" +#include "ir/operations/Control.hpp" +#include "ir/operations/OpType.hpp" +#include "ir/operations/Operation.hpp" #include #include diff --git a/src/operations/SymbolicOperation.cpp b/src/ir/operations/SymbolicOperation.cpp similarity index 98% rename from src/operations/SymbolicOperation.cpp rename to src/ir/operations/SymbolicOperation.cpp index 61a28d707..6e2d5b079 100644 --- a/src/operations/SymbolicOperation.cpp +++ b/src/ir/operations/SymbolicOperation.cpp @@ -1,11 +1,11 @@ -#include "operations/SymbolicOperation.hpp" +#include "ir/operations/SymbolicOperation.hpp" #include "Definitions.hpp" -#include "Permutation.hpp" -#include "operations/Control.hpp" -#include "operations/Expression.hpp" -#include "operations/OpType.hpp" -#include "operations/StandardOperation.hpp" +#include "ir/Permutation.hpp" +#include "ir/operations/Control.hpp" +#include "ir/operations/Expression.hpp" +#include "ir/operations/OpType.hpp" +#include "ir/operations/StandardOperation.hpp" #include #include diff --git a/src/parsers/QASM3Parser.cpp b/src/ir/parsers/QASM3Parser.cpp similarity index 97% rename from src/parsers/QASM3Parser.cpp rename to src/ir/parsers/QASM3Parser.cpp index e1d6502a2..f65341016 100644 --- a/src/parsers/QASM3Parser.cpp +++ b/src/ir/parsers/QASM3Parser.cpp @@ -1,23 +1,23 @@ #include "Definitions.hpp" -#include "Permutation.hpp" -#include "QuantumComputation.hpp" -#include "operations/ClassicControlledOperation.hpp" -#include "operations/CompoundOperation.hpp" -#include "operations/Control.hpp" -#include "operations/NonUnitaryOperation.hpp" -#include "operations/OpType.hpp" -#include "operations/Operation.hpp" -#include "operations/StandardOperation.hpp" -#include "parsers/qasm3_parser/Exception.hpp" -#include "parsers/qasm3_parser/Gate.hpp" -#include "parsers/qasm3_parser/InstVisitor.hpp" -#include "parsers/qasm3_parser/NestedEnvironment.hpp" -#include "parsers/qasm3_parser/Parser.hpp" -#include "parsers/qasm3_parser/Statement.hpp" -#include "parsers/qasm3_parser/StdGates.hpp" -#include "parsers/qasm3_parser/Types.hpp" -#include "parsers/qasm3_parser/passes/ConstEvalPass.hpp" -#include "parsers/qasm3_parser/passes/TypeCheckPass.hpp" +#include "ir/Permutation.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/ClassicControlledOperation.hpp" +#include "ir/operations/CompoundOperation.hpp" +#include "ir/operations/Control.hpp" +#include "ir/operations/NonUnitaryOperation.hpp" +#include "ir/operations/OpType.hpp" +#include "ir/operations/Operation.hpp" +#include "ir/operations/StandardOperation.hpp" +#include "ir/parsers/qasm3_parser/Exception.hpp" +#include "ir/parsers/qasm3_parser/Gate.hpp" +#include "ir/parsers/qasm3_parser/InstVisitor.hpp" +#include "ir/parsers/qasm3_parser/NestedEnvironment.hpp" +#include "ir/parsers/qasm3_parser/Parser.hpp" +#include "ir/parsers/qasm3_parser/Statement.hpp" +#include "ir/parsers/qasm3_parser/StdGates.hpp" +#include "ir/parsers/qasm3_parser/Types.hpp" +#include "ir/parsers/qasm3_parser/passes/ConstEvalPass.hpp" +#include "ir/parsers/qasm3_parser/passes/TypeCheckPass.hpp" #include #include diff --git a/src/parsers/QCParser.cpp b/src/ir/parsers/QCParser.cpp similarity index 98% rename from src/parsers/QCParser.cpp rename to src/ir/parsers/QCParser.cpp index bff037545..32334ccbd 100644 --- a/src/parsers/QCParser.cpp +++ b/src/ir/parsers/QCParser.cpp @@ -1,8 +1,8 @@ #include "Definitions.hpp" -#include "QuantumComputation.hpp" -#include "operations/Control.hpp" -#include "operations/OpType.hpp" -#include "operations/StandardOperation.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/Control.hpp" +#include "ir/operations/OpType.hpp" +#include "ir/operations/StandardOperation.hpp" #include #include diff --git a/src/parsers/RealParser.cpp b/src/ir/parsers/RealParser.cpp similarity index 98% rename from src/parsers/RealParser.cpp rename to src/ir/parsers/RealParser.cpp index 03e514bc6..fa3c960eb 100644 --- a/src/parsers/RealParser.cpp +++ b/src/ir/parsers/RealParser.cpp @@ -1,8 +1,8 @@ #include "Definitions.hpp" -#include "QuantumComputation.hpp" -#include "operations/Control.hpp" -#include "operations/OpType.hpp" -#include "operations/StandardOperation.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/Control.hpp" +#include "ir/operations/OpType.hpp" +#include "ir/operations/StandardOperation.hpp" #include #include diff --git a/src/parsers/TFCParser.cpp b/src/ir/parsers/TFCParser.cpp similarity index 98% rename from src/parsers/TFCParser.cpp rename to src/ir/parsers/TFCParser.cpp index d9aa342a7..b8939d983 100644 --- a/src/parsers/TFCParser.cpp +++ b/src/ir/parsers/TFCParser.cpp @@ -1,7 +1,7 @@ #include "Definitions.hpp" -#include "QuantumComputation.hpp" -#include "operations/Control.hpp" -#include "operations/OpType.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/Control.hpp" +#include "ir/operations/OpType.hpp" #include #include diff --git a/src/parsers/qasm3_parser/Parser.cpp b/src/ir/parsers/qasm3_parser/Parser.cpp similarity index 99% rename from src/parsers/qasm3_parser/Parser.cpp rename to src/ir/parsers/qasm3_parser/Parser.cpp index aa42fbbca..28b2a3eef 100644 --- a/src/parsers/qasm3_parser/Parser.cpp +++ b/src/ir/parsers/qasm3_parser/Parser.cpp @@ -1,11 +1,11 @@ -#include "parsers/qasm3_parser/Parser.hpp" +#include "ir/parsers/qasm3_parser/Parser.hpp" #include "Definitions.hpp" -#include "Permutation.hpp" -#include "parsers/qasm3_parser/Statement.hpp" -#include "parsers/qasm3_parser/StdGates.hpp" -#include "parsers/qasm3_parser/Token.hpp" -#include "parsers/qasm3_parser/Types.hpp" +#include "ir/Permutation.hpp" +#include "ir/parsers/qasm3_parser/Statement.hpp" +#include "ir/parsers/qasm3_parser/StdGates.hpp" +#include "ir/parsers/qasm3_parser/Token.hpp" +#include "ir/parsers/qasm3_parser/Types.hpp" #include #include diff --git a/src/parsers/qasm3_parser/Scanner.cpp b/src/ir/parsers/qasm3_parser/Scanner.cpp similarity index 99% rename from src/parsers/qasm3_parser/Scanner.cpp rename to src/ir/parsers/qasm3_parser/Scanner.cpp index acf0dc294..8128c5e8a 100644 --- a/src/parsers/qasm3_parser/Scanner.cpp +++ b/src/ir/parsers/qasm3_parser/Scanner.cpp @@ -1,6 +1,6 @@ -#include "parsers/qasm3_parser/Scanner.hpp" +#include "ir/parsers/qasm3_parser/Scanner.hpp" -#include "parsers/qasm3_parser/Token.hpp" +#include "ir/parsers/qasm3_parser/Token.hpp" #include #include diff --git a/src/parsers/qasm3_parser/Statement.cpp b/src/ir/parsers/qasm3_parser/Statement.cpp similarity index 86% rename from src/parsers/qasm3_parser/Statement.cpp rename to src/ir/parsers/qasm3_parser/Statement.cpp index 03a4047f2..4e66199eb 100644 --- a/src/parsers/qasm3_parser/Statement.cpp +++ b/src/ir/parsers/qasm3_parser/Statement.cpp @@ -1,6 +1,6 @@ -#include "parsers/qasm3_parser/Statement.hpp" +#include "ir/parsers/qasm3_parser/Statement.hpp" -#include "operations/ClassicControlledOperation.hpp" +#include "ir/operations/ClassicControlledOperation.hpp" #include diff --git a/src/parsers/qasm3_parser/Types.cpp b/src/ir/parsers/qasm3_parser/Types.cpp similarity index 97% rename from src/parsers/qasm3_parser/Types.cpp rename to src/ir/parsers/qasm3_parser/Types.cpp index 323dae6c0..01e56c209 100644 --- a/src/parsers/qasm3_parser/Types.cpp +++ b/src/ir/parsers/qasm3_parser/Types.cpp @@ -1,4 +1,4 @@ -#include "parsers/qasm3_parser/Types.hpp" +#include "ir/parsers/qasm3_parser/Types.hpp" #include #include diff --git a/src/parsers/qasm3_parser/passes/ConstEvalPass.cpp b/src/ir/parsers/qasm3_parser/passes/ConstEvalPass.cpp similarity index 98% rename from src/parsers/qasm3_parser/passes/ConstEvalPass.cpp rename to src/ir/parsers/qasm3_parser/passes/ConstEvalPass.cpp index 9d7ac0bbc..d371a16bc 100644 --- a/src/parsers/qasm3_parser/passes/ConstEvalPass.cpp +++ b/src/ir/parsers/qasm3_parser/passes/ConstEvalPass.cpp @@ -1,8 +1,8 @@ -#include "parsers/qasm3_parser/passes/ConstEvalPass.hpp" +#include "ir/parsers/qasm3_parser/passes/ConstEvalPass.hpp" -#include "parsers/qasm3_parser/Exception.hpp" -#include "parsers/qasm3_parser/Statement.hpp" -#include "parsers/qasm3_parser/Types.hpp" +#include "ir/parsers/qasm3_parser/Exception.hpp" +#include "ir/parsers/qasm3_parser/Statement.hpp" +#include "ir/parsers/qasm3_parser/Types.hpp" #include #include diff --git a/src/parsers/qasm3_parser/passes/TypeCheckPass.cpp b/src/ir/parsers/qasm3_parser/passes/TypeCheckPass.cpp similarity index 98% rename from src/parsers/qasm3_parser/passes/TypeCheckPass.cpp rename to src/ir/parsers/qasm3_parser/passes/TypeCheckPass.cpp index e536260e6..a191e3fd9 100644 --- a/src/parsers/qasm3_parser/passes/TypeCheckPass.cpp +++ b/src/ir/parsers/qasm3_parser/passes/TypeCheckPass.cpp @@ -1,8 +1,8 @@ -#include "parsers/qasm3_parser/passes/TypeCheckPass.hpp" +#include "ir/parsers/qasm3_parser/passes/TypeCheckPass.hpp" -#include "parsers/qasm3_parser/Exception.hpp" -#include "parsers/qasm3_parser/Statement.hpp" -#include "parsers/qasm3_parser/Types.hpp" +#include "ir/parsers/qasm3_parser/Exception.hpp" +#include "ir/parsers/qasm3_parser/Statement.hpp" +#include "ir/parsers/qasm3_parser/Types.hpp" #include #include diff --git a/src/na/CMakeLists.txt b/src/na/CMakeLists.txt index ee2463fa6..632c3c19c 100644 --- a/src/na/CMakeLists.txt +++ b/src/na/CMakeLists.txt @@ -4,22 +4,48 @@ # if(NOT TARGET ${MQT_CORE_TARGET_NAME}-na) + # collect headers and source files file(GLOB_RECURSE NA_HEADERS ${MQT_CORE_INCLUDE_BUILD_DIR}/na/**.hpp) file(GLOB_RECURSE NA_SOURCES **.cpp) - # add NA package library + # add na package library add_library(${MQT_CORE_TARGET_NAME}-na ${NA_HEADERS} ${NA_SOURCES}) - target_link_libraries(${MQT_CORE_TARGET_NAME}-na PUBLIC MQT::Core MQT::CoreDS) - target_link_libraries(${MQT_CORE_TARGET_NAME}-na PRIVATE MQT::ProjectOptions MQT::ProjectWarnings) + # add link libraries + target_link_libraries( + ${MQT_CORE_TARGET_NAME}-na + PUBLIC MQT::CoreIR MQT::CoreDS + PRIVATE MQT::ProjectOptions MQT::ProjectWarnings) + + # set include directories + target_include_directories( + ${MQT_CORE_TARGET_NAME}-na PUBLIC $ + $) # add MQT alias add_library(MQT::CoreNA ALIAS ${MQT_CORE_TARGET_NAME}-na) + + # set versioning information set_target_properties( ${MQT_CORE_TARGET_NAME}-na PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} EXPORT_NAME CoreNA) + + # generate export header + include(GenerateExportHeader) + generate_export_header(${MQT_CORE_TARGET_NAME}-na BASE_NAME mqt_core_na) + if(NOT BUILD_SHARED_LIBS) + target_compile_definitions(${MQT_CORE_TARGET_NAME}-na PUBLIC MQT_CORE_NA_STATIC_DEFINE) + endif() + + # install export header + if(MQT_CORE_INSTALL) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mqt_core_na_export.h + DESTINATION ${MQT_CORE_INCLUDE_INSTALL_DIR}) + endif() + + # add to list of MQT core targets set(MQT_CORE_TARGETS ${MQT_CORE_TARGETS} ${MQT_CORE_TARGET_NAME}-na PARENT_SCOPE) diff --git a/src/parsers/GRCSParser.cpp b/src/parsers/GRCSParser.cpp deleted file mode 100644 index 66b3b4bc0..000000000 --- a/src/parsers/GRCSParser.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "Definitions.hpp" -#include "QuantumComputation.hpp" - -#include -#include -#include -#include - -void qc::QuantumComputation::importGRCS(std::istream& is) { - std::size_t nq{}; - is >> nq; - addQubitRegister(nq); - addClassicalRegister(nq); - - std::string line; - std::string identifier; - Qubit control = 0; - Qubit target = 0; - std::size_t cycle = 0; - while (std::getline(is, line)) { - if (line.empty()) { - continue; - } - std::stringstream ss(line); - ss >> cycle; - ss >> identifier; - if (identifier == "cz") { - ss >> control; - ss >> target; - cz(control, target); - } else if (identifier == "is") { - ss >> control; - ss >> target; - iswap(control, target); - } else { - ss >> target; - if (identifier == "h") { - h(target); - } else if (identifier == "t") { - t(target); - } else if (identifier == "x_1_2") { - rx(qc::PI_2, target); - } else if (identifier == "y_1_2") { - ry(qc::PI_2, target); - } else { - throw QFRException("[grcs parser] unknown gate '" + identifier + "'"); - } - } - } -} diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt index a5c33089f..091670a57 100644 --- a/src/python/CMakeLists.txt +++ b/src/python/CMakeLists.txt @@ -24,7 +24,7 @@ if(NOT TARGET _core) symbolic/register_variable.cpp symbolic/register_term.cpp symbolic/register_expression.cpp) - target_link_libraries(_core PRIVATE MQT::Core MQT::ProjectOptions MQT::ProjectWarnings) + target_link_libraries(_core PRIVATE MQT::CoreIR MQT::ProjectOptions MQT::ProjectWarnings) # Install directive for scikit-build-core install( diff --git a/src/python/operations/register_classic_controlled_operation.cpp b/src/python/operations/register_classic_controlled_operation.cpp index 79c6c5936..eadaa6e45 100644 --- a/src/python/operations/register_classic_controlled_operation.cpp +++ b/src/python/operations/register_classic_controlled_operation.cpp @@ -1,6 +1,6 @@ #include "Definitions.hpp" -#include "operations/ClassicControlledOperation.hpp" -#include "operations/Operation.hpp" +#include "ir/operations/ClassicControlledOperation.hpp" +#include "ir/operations/Operation.hpp" #include "python/pybind11.hpp" #include diff --git a/src/python/operations/register_compound_operation.cpp b/src/python/operations/register_compound_operation.cpp index 18bcdd550..b46ddfb7a 100644 --- a/src/python/operations/register_compound_operation.cpp +++ b/src/python/operations/register_compound_operation.cpp @@ -1,5 +1,5 @@ -#include "operations/CompoundOperation.hpp" -#include "operations/Operation.hpp" +#include "ir/operations/CompoundOperation.hpp" +#include "ir/operations/Operation.hpp" #include "python/pybind11.hpp" #include diff --git a/src/python/operations/register_control.cpp b/src/python/operations/register_control.cpp index f5ad5722c..a1e0e9d15 100644 --- a/src/python/operations/register_control.cpp +++ b/src/python/operations/register_control.cpp @@ -1,5 +1,5 @@ #include "Definitions.hpp" -#include "operations/Control.hpp" +#include "ir/operations/Control.hpp" #include "python/pybind11.hpp" #include diff --git a/src/python/operations/register_non_unitary_operation.cpp b/src/python/operations/register_non_unitary_operation.cpp index 8f940f0e9..172ddf349 100644 --- a/src/python/operations/register_non_unitary_operation.cpp +++ b/src/python/operations/register_non_unitary_operation.cpp @@ -1,7 +1,7 @@ #include "Definitions.hpp" -#include "operations/NonUnitaryOperation.hpp" -#include "operations/OpType.hpp" -#include "operations/Operation.hpp" +#include "ir/operations/NonUnitaryOperation.hpp" +#include "ir/operations/OpType.hpp" +#include "ir/operations/Operation.hpp" #include "python/pybind11.hpp" #include diff --git a/src/python/operations/register_operation.cpp b/src/python/operations/register_operation.cpp index c1e3bfa13..ae87bc216 100644 --- a/src/python/operations/register_operation.cpp +++ b/src/python/operations/register_operation.cpp @@ -1,5 +1,5 @@ -#include "operations/Control.hpp" -#include "operations/Operation.hpp" +#include "ir/operations/Control.hpp" +#include "ir/operations/Operation.hpp" #include "python/pybind11.hpp" #include diff --git a/src/python/operations/register_optype.cpp b/src/python/operations/register_optype.cpp index 945b3c2ca..e50078413 100644 --- a/src/python/operations/register_optype.cpp +++ b/src/python/operations/register_optype.cpp @@ -1,4 +1,4 @@ -#include "operations/OpType.hpp" +#include "ir/operations/OpType.hpp" #include "python/pybind11.hpp" #include diff --git a/src/python/operations/register_standard_operation.cpp b/src/python/operations/register_standard_operation.cpp index 84d8a0e97..3f8e7533b 100644 --- a/src/python/operations/register_standard_operation.cpp +++ b/src/python/operations/register_standard_operation.cpp @@ -1,8 +1,8 @@ #include "Definitions.hpp" -#include "operations/Control.hpp" -#include "operations/OpType.hpp" -#include "operations/Operation.hpp" -#include "operations/StandardOperation.hpp" +#include "ir/operations/Control.hpp" +#include "ir/operations/OpType.hpp" +#include "ir/operations/Operation.hpp" +#include "ir/operations/StandardOperation.hpp" #include "python/pybind11.hpp" #include diff --git a/src/python/operations/register_symbolic_operation.cpp b/src/python/operations/register_symbolic_operation.cpp index 305f41958..c2fc344f4 100644 --- a/src/python/operations/register_symbolic_operation.cpp +++ b/src/python/operations/register_symbolic_operation.cpp @@ -1,9 +1,9 @@ #include "Definitions.hpp" -#include "operations/Control.hpp" -#include "operations/Expression.hpp" -#include "operations/OpType.hpp" -#include "operations/StandardOperation.hpp" -#include "operations/SymbolicOperation.hpp" +#include "ir/operations/Control.hpp" +#include "ir/operations/Expression.hpp" +#include "ir/operations/OpType.hpp" +#include "ir/operations/StandardOperation.hpp" +#include "ir/operations/SymbolicOperation.hpp" #include "python/pybind11.hpp" #include diff --git a/src/python/qiskit/QuantumCircuit.cpp b/src/python/qiskit/QuantumCircuit.cpp index a71714784..8fd381e22 100644 --- a/src/python/qiskit/QuantumCircuit.cpp +++ b/src/python/qiskit/QuantumCircuit.cpp @@ -1,13 +1,13 @@ #include "python/qiskit/QuantumCircuit.hpp" #include "Definitions.hpp" -#include "QuantumComputation.hpp" -#include "operations/Control.hpp" -#include "operations/Expression.hpp" -#include "operations/NonUnitaryOperation.hpp" -#include "operations/OpType.hpp" -#include "operations/StandardOperation.hpp" -#include "operations/SymbolicOperation.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/Control.hpp" +#include "ir/operations/Expression.hpp" +#include "ir/operations/NonUnitaryOperation.hpp" +#include "ir/operations/OpType.hpp" +#include "ir/operations/StandardOperation.hpp" +#include "ir/operations/SymbolicOperation.hpp" #include #include diff --git a/src/python/register_permutation.cpp b/src/python/register_permutation.cpp index fe44eb49a..48a1e1de1 100644 --- a/src/python/register_permutation.cpp +++ b/src/python/register_permutation.cpp @@ -1,6 +1,6 @@ #include "Definitions.hpp" -#include "Permutation.hpp" -#include "operations/Control.hpp" +#include "ir/Permutation.hpp" +#include "ir/operations/Control.hpp" #include "python/pybind11.hpp" #include diff --git a/src/python/register_quantum_computation.cpp b/src/python/register_quantum_computation.cpp index e2e5faf9f..6f50e4195 100644 --- a/src/python/register_quantum_computation.cpp +++ b/src/python/register_quantum_computation.cpp @@ -1,9 +1,9 @@ #include "Definitions.hpp" -#include "QuantumComputation.hpp" -#include "operations/Control.hpp" -#include "operations/Expression.hpp" -#include "operations/OpType.hpp" -#include "operations/Operation.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/Control.hpp" +#include "ir/operations/Expression.hpp" +#include "ir/operations/OpType.hpp" +#include "ir/operations/Operation.hpp" #include "python/pybind11.hpp" #include diff --git a/src/python/symbolic/register_expression.cpp b/src/python/symbolic/register_expression.cpp index 85b59e7e7..f80abb763 100644 --- a/src/python/symbolic/register_expression.cpp +++ b/src/python/symbolic/register_expression.cpp @@ -1,4 +1,4 @@ -#include "operations/Expression.hpp" +#include "ir/operations/Expression.hpp" #include "python/pybind11.hpp" #include diff --git a/src/python/symbolic/register_term.cpp b/src/python/symbolic/register_term.cpp index 1f0db2184..71d833c93 100644 --- a/src/python/symbolic/register_term.cpp +++ b/src/python/symbolic/register_term.cpp @@ -1,4 +1,4 @@ -#include "operations/Expression.hpp" +#include "ir/operations/Expression.hpp" #include "python/pybind11.hpp" #include diff --git a/src/python/symbolic/register_variable.cpp b/src/python/symbolic/register_variable.cpp index 39b20754f..3f4af6ce8 100644 --- a/src/python/symbolic/register_variable.cpp +++ b/src/python/symbolic/register_variable.cpp @@ -1,4 +1,4 @@ -#include "operations/Expression.hpp" +#include "ir/operations/Expression.hpp" #include "python/pybind11.hpp" #include diff --git a/src/zx/CMakeLists.txt b/src/zx/CMakeLists.txt index 65475b3ce..e86d0d4e6 100644 --- a/src/zx/CMakeLists.txt +++ b/src/zx/CMakeLists.txt @@ -36,20 +36,18 @@ if(NOT TARGET ${MQT_CORE_TARGET_NAME}-zx) endif() endif() + # collect headers and source files file(GLOB_RECURSE ZX_HEADERS ${MQT_CORE_INCLUDE_BUILD_DIR}/zx/*.hpp) + file(GLOB_RECURSE ZX_SOURCES **.cpp) # add ZX package library - add_library( + add_library(${MQT_CORE_TARGET_NAME}-zx ${ZX_HEADERS} ${ZX_SOURCES}) + + # add link libraries + target_link_libraries( ${MQT_CORE_TARGET_NAME}-zx - ${ZX_HEADERS} - Rational.cpp - ZXDiagram.cpp - Rules.cpp - Simplify.cpp - Utils.cpp - FunctionalityConstruction.cpp) - target_link_libraries(${MQT_CORE_TARGET_NAME}-zx PUBLIC MQT::Core MQT::Multiprecision) - target_link_libraries(${MQT_CORE_TARGET_NAME}-zx PRIVATE MQT::ProjectOptions MQT::ProjectWarnings) + PUBLIC MQT::CoreIR MQT::Multiprecision + PRIVATE MQT::ProjectOptions MQT::ProjectWarnings) option(MQT_CORE_WITH_GMP "Whether to use GMP for multiprecision arithmetic" OFF) if(MQT_CORE_WITH_GMP) @@ -59,13 +57,35 @@ if(NOT TARGET ${MQT_CORE_TARGET_NAME}-zx) target_link_libraries(${MQT_CORE_TARGET_NAME}-zx PUBLIC GMP::gmp GMP::gmpxx) endif() + # set include directories + target_include_directories( + ${MQT_CORE_TARGET_NAME}-zx PUBLIC $ + $) + # add MQT alias add_library(MQT::CoreZX ALIAS ${MQT_CORE_TARGET_NAME}-zx) + + # set versioning information set_target_properties( ${MQT_CORE_TARGET_NAME}-zx PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} EXPORT_NAME CoreZX) + + # generate export header + include(GenerateExportHeader) + generate_export_header(${MQT_CORE_TARGET_NAME}-zx BASE_NAME mqt_core_zx) + if(NOT BUILD_SHARED_LIBS) + target_compile_definitions(${MQT_CORE_TARGET_NAME}-zx PUBLIC MQT_CORE_ZX_STATIC_DEFINE) + endif() + + # install export header + if(MQT_CORE_INSTALL) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mqt_core_zx_export.h + DESTINATION ${MQT_CORE_INCLUDE_INSTALL_DIR}) + endif() + + # add to list of MQT core targets set(MQT_CORE_TARGETS ${MQT_CORE_TARGETS} ${MQT_CORE_TARGET_NAME}-zx multiprecision PARENT_SCOPE) diff --git a/src/zx/FunctionalityConstruction.cpp b/src/zx/FunctionalityConstruction.cpp index 2f1647eb7..5b47e822c 100644 --- a/src/zx/FunctionalityConstruction.cpp +++ b/src/zx/FunctionalityConstruction.cpp @@ -1,11 +1,11 @@ #include "zx/FunctionalityConstruction.hpp" -#include "Permutation.hpp" -#include "QuantumComputation.hpp" -#include "operations/CompoundOperation.hpp" -#include "operations/Expression.hpp" -#include "operations/OpType.hpp" -#include "operations/SymbolicOperation.hpp" +#include "ir/Permutation.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/CompoundOperation.hpp" +#include "ir/operations/Expression.hpp" +#include "ir/operations/OpType.hpp" +#include "ir/operations/SymbolicOperation.hpp" #include "zx/Rational.hpp" #include "zx/ZXDefinitions.hpp" #include "zx/ZXDiagram.hpp" diff --git a/src/zx/ZXDiagram.cpp b/src/zx/ZXDiagram.cpp index 6f6e83b31..e2f7ea31a 100644 --- a/src/zx/ZXDiagram.cpp +++ b/src/zx/ZXDiagram.cpp @@ -1,6 +1,6 @@ #include "zx/ZXDiagram.hpp" -#include "operations/Expression.hpp" +#include "ir/operations/Expression.hpp" #include "zx/Rational.hpp" #include "zx/Utils.hpp" #include "zx/ZXDefinitions.hpp" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a402124cd..2c6598590 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,37 +1,8 @@ -# add unit tests -package_add_test( - ${PROJECT_NAME}-test - ${PROJECT_NAME} - unittests/test_io.cpp - unittests/test_qfr_functionality.cpp - unittests/test_symbolic.cpp - unittests/test_qasm3_parser.cpp - test_operation.cpp) - -file(GLOB_RECURSE circuit_optimizer_tests "unittests/circuit_optimizer/*.cpp") -package_add_test(${PROJECT_NAME}-test-circuit-optimizer ${PROJECT_NAME} ${circuit_optimizer_tests}) - -package_add_test( - ${PROJECT_NAME}-test-dd - ${PROJECT_NAME}-dd - dd/test_complex.cpp - dd/test_package.cpp - dd/test_dd_functionality.cpp - dd/test_dd_noise_functionality.cpp - algorithms/eval_dynamic_circuits.cpp - algorithms/test_qft.cpp - algorithms/test_grover.cpp - algorithms/test_bernsteinvazirani.cpp - algorithms/test_entanglement.cpp - algorithms/test_grcs.cpp - algorithms/test_random_clifford.cpp - algorithms/test_qpe.cpp - algorithms/test_wstate.cpp) - -package_add_test(${PROJECT_NAME}-test-dd-edge ${PROJECT_NAME}-dd dd/test_edge_functionality.cpp) - -file(GLOB_RECURSE zx_tests "zx/*.cpp") -package_add_test(${PROJECT_NAME}-test-zx ${PROJECT_NAME}-zx ${zx_tests}) - +# add various subdirectories containing tests +add_subdirectory(algorithms) +add_subdirectory(circuit_optimizer) add_subdirectory(datastructures) +add_subdirectory(dd) +add_subdirectory(ir) add_subdirectory(na) +add_subdirectory(zx) diff --git a/test/algorithms/CMakeLists.txt b/test/algorithms/CMakeLists.txt new file mode 100644 index 000000000..a618ecd51 --- /dev/null +++ b/test/algorithms/CMakeLists.txt @@ -0,0 +1,5 @@ +if(TARGET MQT::CoreAlgo) + file(GLOB_RECURSE ALGO_TEST_SOURCES *.cpp) + package_add_test(mqt-core-algo-test MQT::CoreAlgo ${ALGO_TEST_SOURCES}) + target_link_libraries(mqt-core-algo-test PRIVATE MQT::CoreDD MQT::CoreCircuitOptimizer) +endif() diff --git a/test/algorithms/eval_dynamic_circuits.cpp b/test/algorithms/eval_dynamic_circuits.cpp index 9946a56f9..309c32956 100644 --- a/test/algorithms/eval_dynamic_circuits.cpp +++ b/test/algorithms/eval_dynamic_circuits.cpp @@ -1,8 +1,8 @@ -#include "CircuitOptimizer.hpp" #include "Definitions.hpp" #include "algorithms/BernsteinVazirani.hpp" #include "algorithms/QFT.hpp" #include "algorithms/QPE.hpp" +#include "circuit_optimizer/CircuitOptimizer.hpp" #include "dd/Benchmark.hpp" #include "dd/DDDefinitions.hpp" #include "dd/Operations.hpp" @@ -105,7 +105,7 @@ INSTANTIATE_TEST_SUITE_P( }); TEST_P(DynamicCircuitEvalExactQPE, UnitaryTransformation) { - qc::CircuitOptimizer::reorderOperations(*qpe); + qpe->reorderOperations(); const auto start = std::chrono::steady_clock::now(); // transform dynamic circuit to unitary circuit by first eliminating reset // operations and afterwards deferring measurements to the end of the circuit @@ -114,7 +114,7 @@ TEST_P(DynamicCircuitEvalExactQPE, UnitaryTransformation) { // remove final measurements in order to just obtain the unitary functionality qc::CircuitOptimizer::removeFinalMeasurements(*iqpe); - qc::CircuitOptimizer::reorderOperations(*iqpe); + iqpe->reorderOperations(); const auto finishedTransformation = std::chrono::steady_clock::now(); qc::MatrixDD e = dd->makeIdent(); @@ -311,7 +311,7 @@ INSTANTIATE_TEST_SUITE_P(Eval, DynamicCircuitEvalInexactQPE, }); TEST_P(DynamicCircuitEvalInexactQPE, UnitaryTransformation) { - qc::CircuitOptimizer::reorderOperations(*qpe); + qpe->reorderOperations(); const auto start = std::chrono::steady_clock::now(); // transform dynamic circuit to unitary circuit by first eliminating reset // operations and afterwards deferring measurements to the end of the circuit @@ -320,7 +320,7 @@ TEST_P(DynamicCircuitEvalInexactQPE, UnitaryTransformation) { // remove final measurements in order to just obtain the unitary functionality qc::CircuitOptimizer::removeFinalMeasurements(*iqpe); - qc::CircuitOptimizer::reorderOperations(*iqpe); + iqpe->reorderOperations(); const auto finishedTransformation = std::chrono::steady_clock::now(); qc::MatrixDD e = dd->makeIdent(); @@ -467,7 +467,7 @@ INSTANTIATE_TEST_SUITE_P( }); TEST_P(DynamicCircuitEvalBV, UnitaryTransformation) { - qc::CircuitOptimizer::reorderOperations(*bv); + bv->reorderOperations(); const auto start = std::chrono::steady_clock::now(); // transform dynamic circuit to unitary circuit by first eliminating reset // operations and afterwards deferring measurements to the end of the circuit @@ -476,7 +476,7 @@ TEST_P(DynamicCircuitEvalBV, UnitaryTransformation) { // remove final measurements in order to just obtain the unitary functionality qc::CircuitOptimizer::removeFinalMeasurements(*dbv); - qc::CircuitOptimizer::reorderOperations(*dbv); + dbv->reorderOperations(); const auto finishedTransformation = std::chrono::steady_clock::now(); qc::MatrixDD e = dd->makeIdent(); @@ -615,7 +615,7 @@ INSTANTIATE_TEST_SUITE_P( }); TEST_P(DynamicCircuitEvalQFT, UnitaryTransformation) { - qc::CircuitOptimizer::reorderOperations(*qft); + qft->reorderOperations(); const auto start = std::chrono::steady_clock::now(); // transform dynamic circuit to unitary circuit by first eliminating reset // operations and afterwards deferring measurements to the end of the circuit @@ -624,7 +624,7 @@ TEST_P(DynamicCircuitEvalQFT, UnitaryTransformation) { // remove final measurements in order to just obtain the unitary functionality qc::CircuitOptimizer::removeFinalMeasurements(*dqft); - qc::CircuitOptimizer::reorderOperations(*dqft); + dqft->reorderOperations(); const auto finishedTransformation = std::chrono::steady_clock::now(); qc::MatrixDD e = dd->makeIdent(); diff --git a/test/algorithms/test_bernsteinvazirani.cpp b/test/algorithms/test_bernsteinvazirani.cpp index 012a0d2f9..9df8dc34a 100644 --- a/test/algorithms/test_bernsteinvazirani.cpp +++ b/test/algorithms/test_bernsteinvazirani.cpp @@ -1,6 +1,6 @@ -#include "CircuitOptimizer.hpp" #include "Definitions.hpp" #include "algorithms/BernsteinVazirani.hpp" +#include "circuit_optimizer/CircuitOptimizer.hpp" #include "dd/Benchmark.hpp" #include "dd/Package.hpp" #include "dd/Simulation.hpp" diff --git a/test/algorithms/test_grcs.cpp b/test/algorithms/test_grcs.cpp deleted file mode 100644 index d9889f8b5..000000000 --- a/test/algorithms/test_grcs.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "algorithms/GoogleRandomCircuitSampling.hpp" -#include "dd/Package.hpp" -#include "dd/Simulation.hpp" - -#include -#include -#include -#include -#include - -class GRCS : public testing::Test { -protected: - void TearDown() override {} - void SetUp() override {} -}; - -TEST_F(GRCS, import) { - auto qcBris = - qc::GoogleRandomCircuitSampling("./circuits/grcs/bris_4_40_9_v2.txt"); - qcBris.printStatistics(std::cout); - std::cout << qcBris << "\n"; - - auto qcInst = - qc::GoogleRandomCircuitSampling("./circuits/grcs/inst_4x4_80_9_v2.txt"); - qcInst.printStatistics(std::cout); - std::cout << qcInst << "\n"; -} - -TEST_F(GRCS, simulate) { - auto qcBris = - qc::GoogleRandomCircuitSampling("./circuits/grcs/bris_4_40_9_v2.txt"); - - auto dd = std::make_unique>(qcBris.getNqubits()); - auto in = dd->makeZeroState(qcBris.getNqubits()); - const std::optional ncycles = 4; - ASSERT_NO_THROW({ simulate(&qcBris, in, *dd, ncycles); }); - std::cout << qcBris << "\n"; - qcBris.printStatistics(std::cout); -} diff --git a/test/algorithms/test_qpe.cpp b/test/algorithms/test_qpe.cpp index 1f2745a92..8c1dc597a 100644 --- a/test/algorithms/test_qpe.cpp +++ b/test/algorithms/test_qpe.cpp @@ -1,6 +1,6 @@ -#include "CircuitOptimizer.hpp" #include "Definitions.hpp" #include "algorithms/QPE.hpp" +#include "circuit_optimizer/CircuitOptimizer.hpp" #include "dd/Benchmark.hpp" #include "dd/DDDefinitions.hpp" #include "dd/FunctionalityConstruction.hpp" diff --git a/test/circuit_optimizer/CMakeLists.txt b/test/circuit_optimizer/CMakeLists.txt new file mode 100644 index 000000000..72c34758f --- /dev/null +++ b/test/circuit_optimizer/CMakeLists.txt @@ -0,0 +1,6 @@ +if(TARGET MQT::CoreCircuitOptimizer) + file(GLOB_RECURSE CIRCUIT_OPTIMIZER_TEST_SOURCES *.cpp) + package_add_test(mqt-core-circuit-optimizer-test MQT::CoreCircuitOptimizer + ${CIRCUIT_OPTIMIZER_TEST_SOURCES}) + target_link_libraries(mqt-core-circuit-optimizer-test PRIVATE MQT::CoreAlgo) +endif() diff --git a/test/unittests/circuit_optimizer/test_backpropagate_output_permutation.cpp b/test/circuit_optimizer/test_backpropagate_output_permutation.cpp similarity index 98% rename from test/unittests/circuit_optimizer/test_backpropagate_output_permutation.cpp rename to test/circuit_optimizer/test_backpropagate_output_permutation.cpp index 636ffbc46..cee4e0907 100644 --- a/test/unittests/circuit_optimizer/test_backpropagate_output_permutation.cpp +++ b/test/circuit_optimizer/test_backpropagate_output_permutation.cpp @@ -1,5 +1,5 @@ -#include "CircuitOptimizer.hpp" -#include "QuantumComputation.hpp" +#include "circuit_optimizer/CircuitOptimizer.hpp" +#include "ir/QuantumComputation.hpp" #include diff --git a/test/circuit_optimizer/test_cancel_cnots.cpp b/test/circuit_optimizer/test_cancel_cnots.cpp new file mode 100644 index 000000000..e3489b5ab --- /dev/null +++ b/test/circuit_optimizer/test_cancel_cnots.cpp @@ -0,0 +1,75 @@ +#include "circuit_optimizer/CircuitOptimizer.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/OpType.hpp" + +#include + +namespace qc { +TEST(CancelCNOTs, CNOTCancellation1) { + QuantumComputation qc(2); + qc.cx(1, 0); + qc.cx(1, 0); + + CircuitOptimizer::cancelCNOTs(qc); + EXPECT_TRUE(qc.empty()); +} + +TEST(CancelCNOTs, CNOTCancellation2) { + QuantumComputation qc(2); + qc.swap(0, 1); + qc.swap(1, 0); + + CircuitOptimizer::cancelCNOTs(qc); + EXPECT_TRUE(qc.empty()); +} + +TEST(CancelCNOTs, CNOTCancellation3) { + QuantumComputation qc(2); + qc.swap(0, 1); + qc.cx(1, 0); + + CircuitOptimizer::cancelCNOTs(qc); + EXPECT_TRUE(qc.size() == 2U); + const auto& firstOperation = qc.front(); + EXPECT_EQ(firstOperation->getType(), qc::X); + EXPECT_EQ(firstOperation->getTargets().front(), 0U); + EXPECT_EQ(firstOperation->getControls().begin()->qubit, 1U); + + const auto& secondOperation = qc.back(); + EXPECT_EQ(secondOperation->getType(), qc::X); + EXPECT_EQ(secondOperation->getTargets().front(), 1U); + EXPECT_EQ(secondOperation->getControls().begin()->qubit, 0U); +} + +TEST(CancelCNOTs, CNOTCancellation4) { + QuantumComputation qc(2); + qc.cx(1, 0); + qc.swap(0, 1); + + CircuitOptimizer::cancelCNOTs(qc); + EXPECT_TRUE(qc.size() == 2U); + const auto& firstOperation = qc.front(); + EXPECT_EQ(firstOperation->getType(), qc::X); + EXPECT_EQ(firstOperation->getTargets().front(), 1U); + EXPECT_EQ(firstOperation->getControls().begin()->qubit, 0U); + + const auto& secondOperation = qc.back(); + EXPECT_EQ(secondOperation->getType(), qc::X); + EXPECT_EQ(secondOperation->getTargets().front(), 0U); + EXPECT_EQ(secondOperation->getControls().begin()->qubit, 1U); +} + +TEST(CancelCNOTs, CNOTCancellation5) { + QuantumComputation qc(2); + qc.cx(1, 0); + qc.cx(0, 1); + qc.cx(1, 0); + + CircuitOptimizer::cancelCNOTs(qc); + EXPECT_TRUE(qc.size() == 1U); + const auto& firstOperation = qc.front(); + EXPECT_EQ(firstOperation->getType(), qc::SWAP); + EXPECT_EQ(firstOperation->getTargets().front(), 0U); + EXPECT_EQ(firstOperation->getTargets().back(), 1U); +} +} // namespace qc diff --git a/test/unittests/circuit_optimizer/test_collect_blocks.cpp b/test/circuit_optimizer/test_collect_blocks.cpp similarity index 98% rename from test/unittests/circuit_optimizer/test_collect_blocks.cpp rename to test/circuit_optimizer/test_collect_blocks.cpp index f9c0adfd4..56a61cba8 100644 --- a/test/unittests/circuit_optimizer/test_collect_blocks.cpp +++ b/test/circuit_optimizer/test_collect_blocks.cpp @@ -1,5 +1,5 @@ -#include "CircuitOptimizer.hpp" -#include "QuantumComputation.hpp" +#include "circuit_optimizer/CircuitOptimizer.hpp" +#include "ir/QuantumComputation.hpp" #include #include diff --git a/test/circuit_optimizer/test_decompose_swap.cpp b/test/circuit_optimizer/test_decompose_swap.cpp new file mode 100644 index 000000000..5c19062c2 --- /dev/null +++ b/test/circuit_optimizer/test_decompose_swap.cpp @@ -0,0 +1,137 @@ +#include "circuit_optimizer/CircuitOptimizer.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/CompoundOperation.hpp" +#include "ir/operations/OpType.hpp" + +#include +#include +#include + +namespace qc { +TEST(DecomposeSwap, decomposeSWAPsUndirectedArchitecture) { + const std::size_t nqubits = 2; + QuantumComputation qc(nqubits, nqubits); + qc.swap(0, 1); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + CircuitOptimizer::decomposeSWAP(qc, false); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + auto it = qc.begin(); + const auto& op = *it; + EXPECT_TRUE(op->isStandardOperation()); + EXPECT_EQ(op->getType(), qc::X); + EXPECT_EQ(op->getControls().begin()->qubit, 0); + EXPECT_EQ(op->getTargets().at(0), 1); + ++it; + const auto& op2 = *it; + EXPECT_TRUE(op2->isStandardOperation()); + EXPECT_EQ(op2->getType(), qc::X); + EXPECT_EQ(op2->getControls().begin()->qubit, 1); + EXPECT_EQ(op2->getTargets().at(0), 0); + ++it; + const auto& op3 = *it; + EXPECT_TRUE(op3->isStandardOperation()); + EXPECT_EQ(op3->getType(), qc::X); + EXPECT_EQ(op3->getControls().begin()->qubit, 0); + EXPECT_EQ(op3->getTargets().at(0), 1); +} +TEST(DecomposeSwap, decomposeSWAPsDirectedArchitecture) { + const std::size_t nqubits = 2; + QuantumComputation qc(nqubits); + qc.swap(0, 1); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + CircuitOptimizer::decomposeSWAP(qc, true); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + auto it = qc.begin(); + const auto& op = *it; + EXPECT_TRUE(op->isStandardOperation()); + EXPECT_EQ(op->getType(), qc::X); + EXPECT_EQ(op->getControls().begin()->qubit, 0); + EXPECT_EQ(op->getTargets().at(0), 1); + + ++it; + const auto& op2 = *it; + EXPECT_TRUE(op2->isStandardOperation()); + EXPECT_EQ(op2->getType(), qc::H); + EXPECT_EQ(op2->getTargets().at(0), 1); + + ++it; + const auto& op3 = *it; + EXPECT_TRUE(op3->isStandardOperation()); + EXPECT_EQ(op3->getType(), qc::H); + EXPECT_EQ(op3->getTargets().at(0), 0); + + ++it; + const auto& op4 = *it; + EXPECT_TRUE(op4->isStandardOperation()); + EXPECT_EQ(op4->getType(), qc::X); + EXPECT_EQ(op4->getControls().begin()->qubit, 0); + EXPECT_EQ(op4->getTargets().at(0), 1); + + ++it; + const auto& op5 = *it; + EXPECT_TRUE(op5->isStandardOperation()); + EXPECT_EQ(op5->getType(), qc::H); + EXPECT_EQ(op5->getTargets().at(0), 1); + + ++it; + const auto& op6 = *it; + EXPECT_TRUE(op6->isStandardOperation()); + EXPECT_EQ(op6->getType(), qc::H); + EXPECT_EQ(op6->getTargets().at(0), 0); + + ++it; + const auto& op7 = *it; + EXPECT_TRUE(op7->isStandardOperation()); + EXPECT_EQ(op7->getType(), qc::X); + EXPECT_EQ(op7->getControls().begin()->qubit, 0); + EXPECT_EQ(op7->getTargets().at(0), 1); +} + +TEST(DecomposeSwap, decomposeSWAPsCompound) { + const std::size_t nqubits = 2; + QuantumComputation qc(nqubits); + QuantumComputation comp(nqubits); + comp.swap(0, 1); + comp.swap(0, 1); + comp.swap(0, 1); + qc.emplace_back(comp.asOperation()); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + qc::CircuitOptimizer::decomposeSWAP(qc, false); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + auto it = qc.begin(); + const auto& op = *it; + EXPECT_TRUE(op->isCompoundOperation()); + + const auto* cop = dynamic_cast(op.get()); + ASSERT_NE(cop, nullptr); + EXPECT_EQ(cop->size(), 9); +} + +TEST(DecomposeSwap, decomposeSWAPsCompoundDirected) { + const std::size_t nqubits = 2; + QuantumComputation qc(nqubits); + QuantumComputation comp(nqubits); + comp.swap(0, 1); + comp.swap(0, 1); + comp.swap(0, 1); + qc.emplace_back(comp.asOperation()); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + qc::CircuitOptimizer::decomposeSWAP(qc, true); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + auto it = qc.begin(); + const auto& op = *it; + EXPECT_TRUE(op->isCompoundOperation()); + + const auto* cop = dynamic_cast(op.get()); + ASSERT_NE(cop, nullptr); + EXPECT_EQ(cop->size(), 21); +} +} // namespace qc diff --git a/test/unittests/circuit_optimizer/test_defer_measurements.cpp b/test/circuit_optimizer/test_defer_measurements.cpp similarity index 98% rename from test/unittests/circuit_optimizer/test_defer_measurements.cpp rename to test/circuit_optimizer/test_defer_measurements.cpp index c9661644b..ce40cff8f 100644 --- a/test/unittests/circuit_optimizer/test_defer_measurements.cpp +++ b/test/circuit_optimizer/test_defer_measurements.cpp @@ -1,8 +1,8 @@ -#include "CircuitOptimizer.hpp" #include "Definitions.hpp" -#include "QuantumComputation.hpp" -#include "operations/NonUnitaryOperation.hpp" -#include "operations/OpType.hpp" +#include "circuit_optimizer/CircuitOptimizer.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/NonUnitaryOperation.hpp" +#include "ir/operations/OpType.hpp" #include #include diff --git a/test/unittests/circuit_optimizer/test_elide_permutations.cpp b/test/circuit_optimizer/test_elide_permutations.cpp similarity index 97% rename from test/unittests/circuit_optimizer/test_elide_permutations.cpp rename to test/circuit_optimizer/test_elide_permutations.cpp index 2ab85b4ef..c5a547451 100644 --- a/test/unittests/circuit_optimizer/test_elide_permutations.cpp +++ b/test/circuit_optimizer/test_elide_permutations.cpp @@ -1,6 +1,6 @@ -#include "CircuitOptimizer.hpp" -#include "QuantumComputation.hpp" -#include "operations/OpType.hpp" +#include "circuit_optimizer/CircuitOptimizer.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/OpType.hpp" #include #include diff --git a/test/circuit_optimizer/test_eliminate_resets.cpp b/test/circuit_optimizer/test_eliminate_resets.cpp new file mode 100644 index 000000000..983c1915a --- /dev/null +++ b/test/circuit_optimizer/test_eliminate_resets.cpp @@ -0,0 +1,227 @@ +#include "Definitions.hpp" +#include "circuit_optimizer/CircuitOptimizer.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/ClassicControlledOperation.hpp" +#include "ir/operations/CompoundOperation.hpp" +#include "ir/operations/NonUnitaryOperation.hpp" +#include "ir/operations/OpType.hpp" + +#include +#include + +namespace qc { +TEST(EliminateResets, eliminateResetsBasicTest) { + QuantumComputation qc{}; + qc.addQubitRegister(1); + qc.addClassicalRegister(2); + qc.h(0); + qc.measure(0, 0U); + qc.reset(0); + qc.h(0); + qc.measure(0, 1U); + + std::cout << qc << "\n"; + + EXPECT_TRUE(CircuitOptimizer::isDynamicCircuit(qc)); + + EXPECT_NO_THROW(CircuitOptimizer::eliminateResets(qc);); + + std::cout << qc << "\n"; + + ASSERT_EQ(qc.getNqubits(), 2); + ASSERT_EQ(qc.getNindividualOps(), 4); + const auto& op0 = qc.at(0); + const auto& op1 = qc.at(1); + const auto& op2 = qc.at(2); + const auto& op3 = qc.at(3); + + EXPECT_TRUE(op0->getType() == qc::H); + const auto& targets0 = op0->getTargets(); + EXPECT_EQ(targets0.size(), 1); + EXPECT_EQ(targets0.at(0), static_cast(0)); + EXPECT_TRUE(op0->getControls().empty()); + + EXPECT_TRUE(op1->getType() == qc::Measure); + const auto& targets1 = op1->getTargets(); + EXPECT_EQ(targets1.size(), 1); + EXPECT_EQ(targets1.at(0), static_cast(0)); + const auto* measure0 = dynamic_cast(op1.get()); + ASSERT_NE(measure0, nullptr); + const auto& classics0 = measure0->getClassics(); + EXPECT_EQ(classics0.size(), 1); + EXPECT_EQ(classics0.at(0), 0); + + EXPECT_TRUE(op2->getType() == qc::H); + const auto& targets2 = op2->getTargets(); + EXPECT_EQ(targets2.size(), 1); + EXPECT_EQ(targets2.at(0), static_cast(1)); + EXPECT_TRUE(op2->getControls().empty()); + + EXPECT_TRUE(op3->getType() == qc::Measure); + const auto& targets3 = op3->getTargets(); + EXPECT_EQ(targets3.size(), 1); + EXPECT_EQ(targets3.at(0), static_cast(1)); + auto* measure1 = dynamic_cast(op3.get()); + ASSERT_NE(measure1, nullptr); + const auto& classics1 = measure1->getClassics(); + EXPECT_EQ(classics1.size(), 1); + EXPECT_EQ(classics1.at(0), 1); +} + +TEST(EliminateResets, eliminateResetsClassicControlled) { + QuantumComputation qc{}; + qc.addQubitRegister(1); + qc.addClassicalRegister(2); + qc.h(0); + qc.measure(0, 0U); + qc.reset(0); + qc.classicControlled(qc::X, 0, {0, 1U}, 1U); + std::cout << qc << "\n"; + + EXPECT_TRUE(CircuitOptimizer::isDynamicCircuit(qc)); + + EXPECT_NO_THROW(CircuitOptimizer::eliminateResets(qc);); + + std::cout << qc << "\n"; + + ASSERT_EQ(qc.getNqubits(), 2); + ASSERT_EQ(qc.getNindividualOps(), 3); + const auto& op0 = qc.at(0); + const auto& op1 = qc.at(1); + const auto& op2 = qc.at(2); + + EXPECT_TRUE(op0->getType() == qc::H); + const auto& targets0 = op0->getTargets(); + EXPECT_EQ(targets0.size(), 1); + EXPECT_EQ(targets0.at(0), static_cast(0)); + EXPECT_TRUE(op0->getControls().empty()); + + EXPECT_TRUE(op1->getType() == qc::Measure); + const auto& targets1 = op1->getTargets(); + EXPECT_EQ(targets1.size(), 1); + EXPECT_EQ(targets1.at(0), static_cast(0)); + auto* measure0 = dynamic_cast(op1.get()); + ASSERT_NE(measure0, nullptr); + const auto& classics0 = measure0->getClassics(); + EXPECT_EQ(classics0.size(), 1); + EXPECT_EQ(classics0.at(0), 0); + + EXPECT_TRUE(op2->isClassicControlledOperation()); + auto* classicControlled = + dynamic_cast(op2.get()); + ASSERT_NE(classicControlled, nullptr); + const auto& operation = classicControlled->getOperation(); + EXPECT_TRUE(operation->getType() == qc::X); + EXPECT_EQ(classicControlled->getNtargets(), 1); + const auto& targets = classicControlled->getTargets(); + EXPECT_EQ(targets.at(0), 1); + EXPECT_EQ(classicControlled->getNcontrols(), 0); +} + +TEST(EliminateResets, eliminateResetsMultipleTargetReset) { + QuantumComputation qc{}; + qc.addQubitRegister(2); + qc.reset({0, 1}); + qc.x(0); + qc.z(1); + qc.cx(1, 0); + + std::cout << qc << "\n"; + + EXPECT_TRUE(CircuitOptimizer::isDynamicCircuit(qc)); + + EXPECT_NO_THROW(CircuitOptimizer::eliminateResets(qc);); + + std::cout << qc << "\n"; + + ASSERT_EQ(qc.getNqubits(), 4); + ASSERT_EQ(qc.getNindividualOps(), 3); + const auto& op0 = qc.at(0); + const auto& op1 = qc.at(1); + const auto& op2 = qc.at(2); + + EXPECT_TRUE(op0->getType() == qc::X); + const auto& targets0 = op0->getTargets(); + EXPECT_EQ(targets0.size(), 1); + EXPECT_EQ(targets0.at(0), static_cast(2)); + EXPECT_TRUE(op0->getControls().empty()); + + EXPECT_TRUE(op1->getType() == qc::Z); + const auto& targets1 = op1->getTargets(); + EXPECT_EQ(targets1.size(), 1); + EXPECT_EQ(targets1.at(0), static_cast(3)); + EXPECT_TRUE(op1->getControls().empty()); + + EXPECT_TRUE(op2->getType() == qc::X); + const auto& targets2 = op2->getTargets(); + EXPECT_EQ(targets2.size(), 1); + EXPECT_EQ(targets2.at(0), static_cast(2)); + const auto& controls2 = op2->getControls(); + EXPECT_EQ(controls2.size(), 1); + EXPECT_EQ(controls2.count(3), 1); +} + +TEST(EliminateResets, eliminateResetsCompoundOperation) { + QuantumComputation qc(2U, 2U); + + qc.reset(0); + qc.reset(1); + + QuantumComputation comp(2U, 2U); + comp.cx(1, 0); + comp.reset(0); + comp.measure(0, 0); + comp.classicControlled(qc::X, 0, {0, 1U}, 1U); + qc.emplace_back(comp.asOperation()); + + std::cout << qc << "\n"; + + EXPECT_TRUE(CircuitOptimizer::isDynamicCircuit(qc)); + + EXPECT_NO_THROW(CircuitOptimizer::eliminateResets(qc);); + + std::cout << qc << "\n"; + + ASSERT_EQ(qc.getNqubits(), 5); + ASSERT_EQ(qc.getNindividualOps(), 3); + + const auto& op = qc.at(0); + EXPECT_TRUE(op->isCompoundOperation()); + auto* compOp0 = dynamic_cast(op.get()); + ASSERT_NE(compOp0, nullptr); + EXPECT_EQ(compOp0->size(), 3); + + const auto& op0 = compOp0->at(0); + const auto& op1 = compOp0->at(1); + const auto& op2 = compOp0->at(2); + + EXPECT_TRUE(op0->getType() == qc::X); + const auto& targets0 = op0->getTargets(); + EXPECT_EQ(targets0.size(), 1); + EXPECT_EQ(targets0.at(0), static_cast(2)); + const auto& controls0 = op0->getControls(); + EXPECT_EQ(controls0.size(), 1); + EXPECT_EQ(controls0.count(3), 1); + + EXPECT_TRUE(op1->getType() == qc::Measure); + const auto& targets1 = op1->getTargets(); + EXPECT_EQ(targets1.size(), 1); + EXPECT_EQ(targets1.at(0), static_cast(4)); + auto* measure0 = dynamic_cast(op1.get()); + ASSERT_NE(measure0, nullptr); + const auto& classics0 = measure0->getClassics(); + EXPECT_EQ(classics0.size(), 1); + EXPECT_EQ(classics0.at(0), 0); + + EXPECT_TRUE(op2->isClassicControlledOperation()); + auto* classicControlled = + dynamic_cast(op2.get()); + ASSERT_NE(classicControlled, nullptr); + const auto& operation = classicControlled->getOperation(); + EXPECT_TRUE(operation->getType() == qc::X); + EXPECT_EQ(classicControlled->getNtargets(), 1); + const auto& targets = classicControlled->getTargets(); + EXPECT_EQ(targets.at(0), 4); + EXPECT_EQ(classicControlled->getNcontrols(), 0); +} +} // namespace qc diff --git a/test/circuit_optimizer/test_flatten_operations.cpp b/test/circuit_optimizer/test_flatten_operations.cpp new file mode 100644 index 000000000..b022d2bc4 --- /dev/null +++ b/test/circuit_optimizer/test_flatten_operations.cpp @@ -0,0 +1,102 @@ +#include "algorithms/RandomCliffordCircuit.hpp" +#include "circuit_optimizer/CircuitOptimizer.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/OpType.hpp" + +#include +#include +#include +#include +#include + +namespace qc { +TEST(FlattenOperations, FlattenRandomClifford) { + qc::RandomCliffordCircuit rcs(2U, 3U, 0U); + std::cout << rcs << "\n"; + const auto nops = rcs.getNindividualOps(); + + qc::CircuitOptimizer::flattenOperations(rcs); + std::cout << rcs << "\n"; + + for (const auto& op : rcs) { + EXPECT_FALSE(op->isCompoundOperation()); + } + EXPECT_EQ(nops, rcs.getNindividualOps()); +} + +TEST(FlattenOperations, FlattenRecursive) { + const std::size_t nqubits = 1U; + + // create a nested compound operation + QuantumComputation op(nqubits); + op.x(0); + op.z(0); + QuantumComputation op2(nqubits); + op2.emplace_back(op.asCompoundOperation()); + QuantumComputation qc(nqubits); + qc.emplace_back(op2.asCompoundOperation()); + std::cout << qc << "\n"; + + qc::CircuitOptimizer::flattenOperations(qc); + std::cout << qc << "\n"; + + for (const auto& g : qc) { + EXPECT_FALSE(g->isCompoundOperation()); + } + + ASSERT_EQ(qc.getNops(), 2U); + auto& gate = qc.at(0); + EXPECT_EQ(gate->getType(), qc::X); + EXPECT_EQ(gate->getTargets().at(0), 0U); + EXPECT_TRUE(gate->getControls().empty()); + auto& gate2 = qc.at(1); + EXPECT_EQ(gate2->getType(), qc::Z); + EXPECT_EQ(gate2->getTargets().at(0), 0U); + EXPECT_TRUE(gate2->getControls().empty()); +} + +TEST(FlattenOperations, FlattenCustomOnly) { + const std::size_t nqubits = 1U; + + // create a nested compound operation + QuantumComputation op(nqubits); + op.x(0); + op.z(0); + QuantumComputation op2(nqubits); + op2.emplace_back(op.asCompoundOperation()); + QuantumComputation qc(nqubits); + qc.emplace_back(op2.asCompoundOperation()); + std::cout << qc << "\n"; + + qc::CircuitOptimizer::flattenOperations(qc, true); + std::cout << qc << "\n"; + + ASSERT_EQ(qc.getNops(), 1U); + auto& gate = qc.at(0); + EXPECT_EQ(gate->getType(), qc::Compound); + + std::vector> opsCompound; + opsCompound.push_back(std::make_unique(0, qc::X)); + opsCompound.push_back(std::make_unique(0, qc::Z)); + QuantumComputation qc2(nqubits); + qc2.emplace_back(std::move(opsCompound), true); + std::cout << qc2 << "\n"; + + qc::CircuitOptimizer::flattenOperations(qc2, true); + std::cout << qc2 << "\n"; + + for (const auto& g : qc2) { + EXPECT_FALSE(g->isCompoundOperation()); + } + + ASSERT_EQ(qc2.getNops(), 2U); + auto& gate3 = qc2.at(0); + EXPECT_EQ(gate3->getType(), qc::X); + EXPECT_EQ(gate3->getTargets().at(0), 0U); + EXPECT_TRUE(gate3->getControls().empty()); + auto& gate4 = qc2.at(1); + EXPECT_EQ(gate4->getType(), qc::Z); + EXPECT_EQ(gate4->getTargets().at(0), 0U); + EXPECT_TRUE(gate4->getControls().empty()); +} +} // namespace qc diff --git a/test/circuit_optimizer/test_remove_diagonal_gates_before_measure.cpp b/test/circuit_optimizer/test_remove_diagonal_gates_before_measure.cpp new file mode 100644 index 000000000..5fd5d9542 --- /dev/null +++ b/test/circuit_optimizer/test_remove_diagonal_gates_before_measure.cpp @@ -0,0 +1,119 @@ +#include "circuit_optimizer/CircuitOptimizer.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/OpType.hpp" + +#include +#include +#include + +namespace qc { +TEST(RemoveDiagonalGateBeforeMeasure, removeDiagonalSingleQubitBeforeMeasure) { + const std::size_t nqubits = 1; + QuantumComputation qc(nqubits, nqubits); + qc.z(0); + qc.measure(0, 0); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + CircuitOptimizer::removeDiagonalGatesBeforeMeasure(qc); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + EXPECT_EQ(qc.getNops(), 1); + EXPECT_EQ(qc.begin()->get()->getType(), qc::Measure); +} + +TEST(RemoveDiagonalGateBeforeMeasure, removeDiagonalCompoundOpBeforeMeasure) { + const std::size_t nqubits = 1; + QuantumComputation qc(nqubits, nqubits); + qc.z(0); + qc.t(0); + qc.measure(0, 0); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + CircuitOptimizer::singleQubitGateFusion(qc); + CircuitOptimizer::removeDiagonalGatesBeforeMeasure(qc); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + EXPECT_EQ(qc.getNops(), 1); + EXPECT_EQ(qc.begin()->get()->getType(), qc::Measure); +} + +TEST(RemoveDiagonalGateBeforeMeasure, removeDiagonalTwoQubitGateBeforeMeasure) { + const std::size_t nqubits = 2; + QuantumComputation qc(nqubits, nqubits); + qc.cz(0, 1); + qc.measure({0, 1}, {0, 1}); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + CircuitOptimizer::removeDiagonalGatesBeforeMeasure(qc); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + EXPECT_EQ(qc.getNops(), 1); + EXPECT_EQ(qc.begin()->get()->getType(), qc::Measure); +} + +TEST(RemoveDiagonalGateBeforeMeasure, leaveGateBeforeMeasure) { + const std::size_t nqubits = 2; + QuantumComputation qc(nqubits, nqubits); + qc.cz(0, 1); + qc.x(0); + qc.measure({0, 1}, {0, 1}); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + CircuitOptimizer::removeDiagonalGatesBeforeMeasure(qc); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + EXPECT_EQ(qc.getNops(), 3); +} + +TEST(RemoveDiagonalGateBeforeMeasure, removeComplexGateBeforeMeasure) { + const std::size_t nqubits = 4; + QuantumComputation qc(nqubits, nqubits); + qc.cz(0, 1); + qc.x(0); + qc.cz(1, 2); + qc.cz(0, 1); + qc.z(0); + qc.cz(1, 2); + qc.x(3); + qc.t(3); + qc.mcz({0, 1, 2}, 3); + qc.measure({0, 1, 2, 3}, {0, 1, 2, 3}); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + CircuitOptimizer::removeDiagonalGatesBeforeMeasure(qc); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + EXPECT_EQ(qc.getNops(), 4); +} + +TEST(RemoveDiagonalGateBeforeMeasure, removeSimpleCompoundOpBeforeMeasure) { + const std::size_t nqubits = 1; + QuantumComputation qc(nqubits, nqubits); + qc.x(0); + qc.t(0); + qc.measure(0, 0); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + CircuitOptimizer::singleQubitGateFusion(qc); + CircuitOptimizer::removeDiagonalGatesBeforeMeasure(qc); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + EXPECT_EQ(qc.getNops(), 2); +} + +TEST(RemoveDiagonalGateBeforeMeasure, removePartOfCompoundOpBeforeMeasure) { + const std::size_t nqubits = 1; + QuantumComputation qc(nqubits, nqubits); + qc.t(0); + qc.x(0); + qc.t(0); + qc.measure(0, 0); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + CircuitOptimizer::singleQubitGateFusion(qc); + CircuitOptimizer::removeDiagonalGatesBeforeMeasure(qc); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + EXPECT_EQ(qc.getNops(), 2); +} +} // namespace qc diff --git a/test/circuit_optimizer/test_remove_final_measurements.cpp b/test/circuit_optimizer/test_remove_final_measurements.cpp new file mode 100644 index 000000000..b1591c176 --- /dev/null +++ b/test/circuit_optimizer/test_remove_final_measurements.cpp @@ -0,0 +1,163 @@ +#include "circuit_optimizer/CircuitOptimizer.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/OpType.hpp" + +#include +#include +#include + +namespace qc { +TEST(RemoveFinalMeasurements, removeFinalMeasurements) { + const std::size_t nqubits = 2; + QuantumComputation qc(nqubits, nqubits); + qc.h(0); + qc.h(1); + qc.measure(0, 0); + qc.measure(1, 1); + qc.h(1); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + CircuitOptimizer::removeFinalMeasurements(qc); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + auto it = qc.begin(); + ++it; + ++it; // skip first two H + const auto& op = *it; + EXPECT_TRUE(op->isNonUnitaryOperation()); + EXPECT_EQ(op->getType(), qc::Measure); + ++it; + const auto& op2 = *it; + EXPECT_TRUE(op2->isStandardOperation()); + EXPECT_EQ(op2->getType(), qc::H); + EXPECT_EQ(op2->getTargets().at(0), 1); +} + +TEST(RemoveFinalMeasurements, removeFinalMeasurementsTwoQubitMeasurement) { + const std::size_t nqubits = 2; + QuantumComputation qc(nqubits, nqubits); + qc.h(0); + qc.h(1); + qc.measure({0, 1}, {0, 1}); + qc.h(1); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + CircuitOptimizer::removeFinalMeasurements(qc); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + auto it = qc.begin(); + ++it; + ++it; // skip first two H + const auto& op = *it; + EXPECT_TRUE(op->isNonUnitaryOperation()); + EXPECT_EQ(op->getType(), qc::Measure); + ++it; + const auto& op2 = *it; + EXPECT_TRUE(op2->isStandardOperation()); + EXPECT_EQ(op2->getType(), qc::H); + EXPECT_EQ(op2->getTargets().at(0), 1); +} + +TEST(RemoveFinalMeasurements, removeFinalMeasurementsCompound) { + const std::size_t nqubits = 2; + QuantumComputation qc(nqubits, nqubits); + QuantumComputation comp(nqubits, nqubits); + comp.measure(0, 0); + comp.measure(1, 1); + comp.h(1); + qc.emplace_back(comp.asOperation()); + qc.h(1); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + CircuitOptimizer::removeFinalMeasurements(qc); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + auto it = qc.begin(); + const auto& op = *it; + EXPECT_TRUE(op->isCompoundOperation()); + + const auto* cop = dynamic_cast(op.get()); + ASSERT_NE(cop, nullptr); + EXPECT_EQ(cop->size(), 2); + ++it; + const auto& op2 = *it; + EXPECT_TRUE(op2->isStandardOperation()); + EXPECT_EQ(op2->getType(), qc::H); + EXPECT_EQ(op2->getTargets().at(0), 1); +} + +TEST(RemoveFinalMeasurements, removeFinalMeasurementsCompoundDegraded) { + const std::size_t nqubits = 2; + QuantumComputation qc(nqubits, nqubits); + QuantumComputation comp(nqubits, nqubits); + comp.measure(0, 0); + comp.h(1); + qc.emplace_back(comp.asOperation()); + qc.h(1); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + CircuitOptimizer::removeFinalMeasurements(qc); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + auto it = qc.begin(); + const auto& op = *it; + EXPECT_TRUE(op->isStandardOperation()); + EXPECT_EQ(op->getType(), qc::H); + EXPECT_EQ(op->getTargets().at(0), 1); + ++it; + const auto& op2 = *it; + EXPECT_TRUE(op2->isStandardOperation()); + EXPECT_EQ(op2->getType(), qc::H); + EXPECT_EQ(op2->getTargets().at(0), 1); +} + +TEST(RemoveFinalMeasurements, removeFinalMeasurementsCompoundEmpty) { + const std::size_t nqubits = 2; + QuantumComputation qc(nqubits, nqubits); + QuantumComputation comp(nqubits, nqubits); + comp.measure(0, 0); + qc.emplace_back(comp.asCompoundOperation()); + qc.h(1); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + CircuitOptimizer::removeFinalMeasurements(qc); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + auto it = qc.begin(); + const auto& op = *it; + EXPECT_TRUE(op->isStandardOperation()); + EXPECT_EQ(op->getType(), qc::H); + EXPECT_EQ(op->getTargets().at(0), 1); +} + +TEST(RemoveFinalMeasurements, removeFinalMeasurementsWithOperationsInFront) { + const std::string circ = + "OPENQASM 2.0;include \"qelib1.inc\";qreg q[3];qreg r[3];h q;cx q, " + "r;creg c[3];creg d[3];barrier q;measure q->c;measure r->d;\n"; + std::stringstream ss{}; + ss << circ; + QuantumComputation qc{}; + qc.import(ss, qc::Format::OpenQASM2); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + CircuitOptimizer::removeFinalMeasurements(qc); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + ASSERT_EQ(qc.getNops(), 2); + ASSERT_EQ(qc.getNindividualOps(), 6); +} + +TEST(RemoveFinalMeasurements, removeFinalMeasurementsWithBarrier) { + const std::size_t nqubits = 2; + QuantumComputation qc(nqubits, nqubits); + qc.barrier({0, 1}); + qc.measure(0, 0); + qc.measure(1, 1); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + CircuitOptimizer::removeFinalMeasurements(qc); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + EXPECT_TRUE(qc.empty()); +} +} // namespace qc diff --git a/test/circuit_optimizer/test_remove_operation.cpp b/test/circuit_optimizer/test_remove_operation.cpp new file mode 100644 index 000000000..dc3c053c8 --- /dev/null +++ b/test/circuit_optimizer/test_remove_operation.cpp @@ -0,0 +1,87 @@ +#include "circuit_optimizer/CircuitOptimizer.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/OpType.hpp" + +#include +#include +#include + +namespace qc { +TEST(RemoveOperation, removeIdentities) { + const std::size_t nqubits = 1; + QuantumComputation qc(nqubits); + qc.i(0); + qc.i(0); + qc.x(0); + qc.i(0); + qc.i(0); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + CircuitOptimizer::removeIdentities(qc); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + EXPECT_EQ(qc.getNops(), 1); +} + +TEST(RemoveOperation, removeSingleQubitGates) { + const std::size_t nqubits = 1; + QuantumComputation qc(nqubits); + qc.x(0); + qc.x(0); + qc.y(0); + qc.i(0); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + CircuitOptimizer::removeOperation(qc, {X, Y}, 1); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + EXPECT_EQ(qc.getNops(), 1); +} + +TEST(RemoveOperation, removeMultiQubitGates) { + const std::size_t nqubits = 2; + QuantumComputation qc(nqubits); + qc.x(0); + qc.cx(0, 1); + qc.cy(1, 1); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + CircuitOptimizer::removeOperation(qc, {X, Y}, 2); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + EXPECT_EQ(qc.getNops(), 2); +} + +TEST(RemoveOperation, removeMoves) { + const std::size_t nqubits = 2; + QuantumComputation qc(nqubits); + qc.x(0); + qc.move(0, 1); + qc.cy(1, 1); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + CircuitOptimizer::removeOperation(qc, {Move}, 0); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + EXPECT_EQ(qc.getNops(), 2); +} + +TEST(RemoveOperation, removeGateInCompoundOperation) { + const std::size_t nqubits = 1; + QuantumComputation qc(nqubits); + QuantumComputation compound(nqubits); + compound.x(0); + compound.y(0); + compound.z(0); + qc.emplace_back(compound.asOperation()); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + CircuitOptimizer::removeOperation(qc, {Y}, 1); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + EXPECT_EQ(qc.getNops(), 1); + EXPECT_EQ(qc.front()->getType(), Compound); + auto* compoundOp = dynamic_cast(qc.front().get()); + EXPECT_EQ(compoundOp->size(), 2); +} +} // namespace qc diff --git a/test/circuit_optimizer/test_replace_mcx_with_mcz.cpp b/test/circuit_optimizer/test_replace_mcx_with_mcz.cpp new file mode 100644 index 000000000..ea47b24c3 --- /dev/null +++ b/test/circuit_optimizer/test_replace_mcx_with_mcz.cpp @@ -0,0 +1,92 @@ +#include "Definitions.hpp" +#include "circuit_optimizer/CircuitOptimizer.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/Control.hpp" +#include "ir/operations/OpType.hpp" + +#include +#include +#include + +namespace qc { +TEST(ReplaceMCXwithMCZ, replaceCXwithCZ) { + qc::QuantumComputation qc(2U); + qc.cx(0, 1); + CircuitOptimizer::replaceMCXWithMCZ(qc); + std::cout << qc << "\n"; + EXPECT_EQ(qc.getNops(), 3U); + EXPECT_EQ(qc.at(0)->getType(), qc::H); + EXPECT_EQ(qc.at(0)->getTargets()[0], 1U); + EXPECT_EQ(qc.at(1)->getType(), qc::Z); + EXPECT_EQ(qc.at(1)->getTargets()[0], 1U); + EXPECT_EQ(*qc.at(1)->getControls().begin(), 0U); + EXPECT_EQ(qc.at(2)->getType(), qc::H); + EXPECT_EQ(qc.at(2)->getTargets()[0], 1U); +} + +TEST(ReplaceMCXwithMCZ, replaceCCXwithCCZ) { + std::size_t const nqubits = 3U; + qc::QuantumComputation qc(nqubits); + Controls const controls = {0, 1}; + Qubit const target = 2U; + qc.mcx(controls, target); + CircuitOptimizer::replaceMCXWithMCZ(qc); + std::cout << qc << "\n"; + EXPECT_EQ(qc.getNops(), 3U); + EXPECT_EQ(qc.at(0)->getType(), qc::H); + EXPECT_EQ(qc.at(0)->getTargets()[0], target); + EXPECT_EQ(qc.at(1)->getType(), qc::Z); + EXPECT_EQ(qc.at(1)->getTargets()[0], target); + EXPECT_EQ(qc.at(1)->getControls(), controls); + EXPECT_EQ(qc.at(2)->getType(), qc::H); + EXPECT_EQ(qc.at(2)->getTargets()[0], target); +} + +TEST(ReplaceMCXwithMCZ, replaceCXwithCZinCompoundOperation) { + std::size_t const nqubits = 2U; + qc::QuantumComputation op(nqubits); + op.cx(0, 1); + + qc::QuantumComputation qc(nqubits); + qc.emplace_back(op.asCompoundOperation()); + + CircuitOptimizer::replaceMCXWithMCZ(qc); + std::cout << qc << "\n"; + + CircuitOptimizer::flattenOperations(qc); + std::cout << qc << "\n"; + EXPECT_EQ(qc.getNops(), 3U); + EXPECT_EQ(qc.at(0)->getType(), qc::H); + EXPECT_EQ(qc.at(0)->getTargets()[0], 1U); + EXPECT_EQ(qc.at(1)->getType(), qc::Z); + EXPECT_EQ(qc.at(1)->getTargets()[0], 1U); + EXPECT_EQ(*qc.at(1)->getControls().begin(), 0U); + EXPECT_EQ(qc.at(2)->getType(), qc::H); + EXPECT_EQ(qc.at(2)->getTargets()[0], 1U); +} + +TEST(ReplaceMCXwithMCZ, testToffoliSequenceSimplification) { + std::size_t const nqubits = 3U; + qc::QuantumComputation qc(nqubits); + Controls const controls = {0, 1}; + Qubit const target = 2U; + qc.cx(0, target); + qc.mcx(controls, target); + CircuitOptimizer::replaceMCXWithMCZ(qc); + CircuitOptimizer::singleQubitGateFusion(qc); + CircuitOptimizer::flattenOperations(qc); + std::cout << qc << "\n"; + + qc::QuantumComputation reference(nqubits); + reference.h(target); + reference.cz(0, target); + reference.mcz(controls, target); + reference.h(target); + + for (std::size_t i = 0; i < reference.getNops(); ++i) { + EXPECT_EQ(qc.at(i)->getType(), reference.at(i)->getType()); + EXPECT_EQ(qc.at(i)->getTargets(), reference.at(i)->getTargets()); + EXPECT_EQ(qc.at(i)->getControls(), reference.at(i)->getControls()); + } +} +} // namespace qc diff --git a/test/circuit_optimizer/test_single_qubit_gate_fusion.cpp b/test/circuit_optimizer/test_single_qubit_gate_fusion.cpp new file mode 100644 index 000000000..3245fd22f --- /dev/null +++ b/test/circuit_optimizer/test_single_qubit_gate_fusion.cpp @@ -0,0 +1,115 @@ +#include "circuit_optimizer/CircuitOptimizer.hpp" +#include "ir/QuantumComputation.hpp" + +#include +#include +#include + +namespace qc { + +TEST(SingleQubitGateFusion, CollapseCompoundOperationToStandard) { + const std::size_t nqubits = 1; + QuantumComputation qc(nqubits); + qc.x(0); + qc.i(0); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + CircuitOptimizer::singleQubitGateFusion(qc); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + EXPECT_EQ(qc.getNops(), 1); + EXPECT_TRUE(qc.begin()->get()->isStandardOperation()); +} + +TEST(SingleQubitGateFusion, eliminateCompoundOperation) { + const std::size_t nqubits = 1; + QuantumComputation qc(nqubits); + qc.i(0); + qc.i(0); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + CircuitOptimizer::singleQubitGateFusion(qc); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + EXPECT_EQ(qc.getNops(), 0); + EXPECT_TRUE(qc.empty()); +} + +TEST(SingleQubitGateFusion, eliminateInverseInCompoundOperation) { + const std::size_t nqubits = 1; + QuantumComputation qc(nqubits); + qc.s(0); + qc.sdg(0); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + CircuitOptimizer::singleQubitGateFusion(qc); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + EXPECT_EQ(qc.getNops(), 0); + EXPECT_TRUE(qc.empty()); +} + +TEST(SingleQubitGateFusion, unknownInverseInCompoundOperation) { + const std::size_t nqubits = 1; + QuantumComputation qc(nqubits); + qc.p(1., 0); + qc.p(-1., 0); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + CircuitOptimizer::singleQubitGateFusion(qc); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + EXPECT_EQ(qc.getNops(), 1); +} + +TEST(SingleQubitGateFusion, repeatedCancellationInSingleQubitGateFusion) { + const std::size_t nqubits = 1U; + QuantumComputation qc(nqubits); + qc.x(0); + qc.h(0); // causes the creation of a CompoundOperation + qc.h(0); // cancels a gate in the compound operation + qc.x(0); // cancels the first gate, making the CompoundOperation empty + qc.z(0); // adds another gate to the CompoundOperation + std::cout << "-----------------------------\n"; + qc.print(std::cout); + CircuitOptimizer::singleQubitGateFusion(qc); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + EXPECT_EQ(qc.getNops(), 1U); +} + +TEST(SingleQubitGateFusion, emptyCompoundGatesRemovedInSingleQubitGateFusion) { + const std::size_t nqubits = 1U; + QuantumComputation qc(nqubits); + qc.x(0); + qc.h(0); // causes the creation of a CompoundOperation + qc.h(0); // cancels a gate in the compound operation + qc.x(0); // cancels the first gate, making the CompoundOperation empty + std::cout << "-----------------------------\n"; + qc.print(std::cout); + CircuitOptimizer::singleQubitGateFusion(qc); + std::cout << "-----------------------------\n"; + qc.print(std::cout); + EXPECT_EQ(qc.getNops(), 0U); +} + +TEST(SingleQubitGateFusion, SingleQubitGateCount) { + QuantumComputation qc(2U, 2U); + qc.x(0); + qc.h(0); + qc.cx(1, 0); + qc.z(0); + qc.measure(0, 0); + + EXPECT_EQ(qc.getNops(), 5U); + EXPECT_EQ(qc.getNindividualOps(), 5U); + EXPECT_EQ(qc.getNsingleQubitOps(), 3U); + + CircuitOptimizer::singleQubitGateFusion(qc); + + EXPECT_EQ(qc.getNops(), 4U); + EXPECT_EQ(qc.getNindividualOps(), 5U); + EXPECT_EQ(qc.getNsingleQubitOps(), 3U); +} + +} // namespace qc diff --git a/test/circuit_optimizer/test_swap_reconstruction.cpp b/test/circuit_optimizer/test_swap_reconstruction.cpp new file mode 100644 index 000000000..68cacbf5f --- /dev/null +++ b/test/circuit_optimizer/test_swap_reconstruction.cpp @@ -0,0 +1,64 @@ +#include "circuit_optimizer/CircuitOptimizer.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/OpType.hpp" + +#include +#include + +namespace qc { +TEST(SwapReconstruction, fuseCxToSwap) { + const std::size_t nqubits = 2; + QuantumComputation qc(nqubits); + qc.cx(0, 1); + qc.cx(1, 0); + qc.cx(0, 1); + CircuitOptimizer::swapReconstruction(qc); + const auto& op = qc.front(); + EXPECT_TRUE(op->isStandardOperation()); + EXPECT_EQ(op->getType(), SWAP); + EXPECT_EQ(op->getTargets().at(0), 0); + EXPECT_EQ(op->getTargets().at(1), 1); +} + +TEST(SwapReconstruction, replaceCxToSwapAtEnd) { + const std::size_t nqubits = 2; + QuantumComputation qc(nqubits); + qc.cx(0, 1); + qc.cx(1, 0); + CircuitOptimizer::swapReconstruction(qc); + auto it = qc.begin(); + const auto& op = *it; + EXPECT_TRUE(op->isStandardOperation()); + EXPECT_EQ(op->getType(), SWAP); + EXPECT_EQ(op->getTargets().at(0), 0); + EXPECT_EQ(op->getTargets().at(1), 1); + + ++it; + const auto& op2 = *it; + EXPECT_TRUE(op2->isStandardOperation()); + EXPECT_EQ(op2->getType(), X); + EXPECT_EQ(op2->getControls().begin()->qubit, 0); + EXPECT_EQ(op2->getTargets().at(0), 1); +} + +TEST(SwapReconstruction, replaceCxToSwap) { + const std::size_t nqubits = 2; + QuantumComputation qc(nqubits); + qc.cx(0, 1); + qc.cx(1, 0); + qc.h(0); + CircuitOptimizer::swapReconstruction(qc); + auto it = qc.begin(); + const auto& op = *it; + EXPECT_TRUE(op->isStandardOperation()); + EXPECT_EQ(op->getType(), SWAP); + EXPECT_EQ(op->getTargets().at(0), 0); + EXPECT_EQ(op->getTargets().at(1), 1); + ++it; + const auto& op2 = *it; + EXPECT_TRUE(op2->isStandardOperation()); + EXPECT_EQ(op2->getType(), X); + EXPECT_EQ(op2->getControls().begin()->qubit, 0); + EXPECT_EQ(op2->getTargets().at(0), 1); +} +} // namespace qc diff --git a/test/circuits/grcs/bris_4_40_9_v2.txt b/test/circuits/grcs/bris_4_40_9_v2.txt deleted file mode 100644 index d8ccf632c..000000000 --- a/test/circuits/grcs/bris_4_40_9_v2.txt +++ /dev/null @@ -1,295 +0,0 @@ -12 -0 h 0 -0 h 1 -0 h 2 -0 h 3 -0 h 4 -0 h 5 -0 h 6 -0 h 7 -0 h 8 -0 h 9 -0 h 10 -0 h 11 -1 t 0 -1 t 1 -1 t 2 -1 t 3 -1 cz 4 5 -1 cz 6 7 -1 t 8 -1 t 9 -1 t 10 -1 t 11 -2 cz 2 6 -2 cz 4 8 -2 x_1_2 5 -2 x_1_2 7 -3 cz 0 1 -3 x_1_2 2 -3 y_1_2 4 -3 t 5 -3 x_1_2 6 -3 cz 7 8 -4 y_1_2 0 -4 cz 1 4 -4 t 2 -4 t 6 -4 cz 7 10 -4 y_1_2 8 -5 t 0 -5 x_1_2 1 -5 cz 2 3 -5 y_1_2 4 -5 y_1_2 7 -5 cz 8 9 -5 x_1_2 10 -6 t 1 -6 x_1_2 2 -6 cz 3 7 -6 t 4 -6 cz 5 9 -6 y_1_2 8 -6 t 10 -7 t 2 -7 cz 3 4 -7 x_1_2 5 -7 y_1_2 7 -7 t 8 -7 x_1_2 9 -7 cz 10 11 -8 cz 0 3 -8 x_1_2 4 -8 t 5 -8 t 7 -8 cz 8 11 -8 t 9 -8 x_1_2 10 -9 y_1_2 0 -9 y_1_2 3 -9 cz 4 5 -9 cz 6 7 -9 y_1_2 8 -9 t 10 -9 y_1_2 11 -10 t 0 -10 cz 2 6 -10 t 3 -10 cz 4 8 -10 x_1_2 5 -10 y_1_2 7 -10 t 11 -11 cz 0 1 -11 x_1_2 2 -11 x_1_2 4 -11 t 5 -11 y_1_2 6 -11 cz 7 8 -12 y_1_2 0 -12 cz 1 4 -12 t 2 -12 t 6 -12 cz 7 10 -12 x_1_2 8 -13 t 0 -13 x_1_2 1 -13 cz 2 3 -13 x_1_2 4 -13 x_1_2 7 -13 cz 8 9 -13 x_1_2 10 -14 t 1 -14 y_1_2 2 -14 cz 3 7 -14 t 4 -14 cz 5 9 -14 x_1_2 8 -14 t 10 -15 t 2 -15 cz 3 4 -15 y_1_2 5 -15 y_1_2 7 -15 t 8 -15 x_1_2 9 -15 cz 10 11 -16 cz 0 3 -16 x_1_2 4 -16 t 5 -16 t 7 -16 cz 8 11 -16 t 9 -16 x_1_2 10 -17 x_1_2 0 -17 x_1_2 3 -17 cz 4 5 -17 cz 6 7 -17 y_1_2 8 -17 t 10 -17 x_1_2 11 -18 t 0 -18 cz 2 6 -18 t 3 -18 cz 4 8 -18 y_1_2 5 -18 x_1_2 7 -18 t 11 -19 cz 0 1 -19 y_1_2 2 -19 y_1_2 4 -19 t 5 -19 x_1_2 6 -19 cz 7 8 -20 x_1_2 0 -20 cz 1 4 -20 t 2 -20 t 6 -20 cz 7 10 -20 x_1_2 8 -21 t 0 -21 y_1_2 1 -21 cz 2 3 -21 x_1_2 4 -21 x_1_2 7 -21 cz 8 9 -21 x_1_2 10 -22 t 1 -22 y_1_2 2 -22 cz 3 7 -22 t 4 -22 cz 5 9 -22 x_1_2 8 -22 t 10 -23 t 2 -23 cz 3 4 -23 x_1_2 5 -23 y_1_2 7 -23 t 8 -23 x_1_2 9 -23 cz 10 11 -24 cz 0 3 -24 y_1_2 4 -24 t 5 -24 t 7 -24 cz 8 11 -24 t 9 -24 x_1_2 10 -25 y_1_2 0 -25 y_1_2 3 -25 cz 4 5 -25 cz 6 7 -25 x_1_2 8 -25 t 10 -25 y_1_2 11 -26 t 0 -26 cz 2 6 -26 t 3 -26 cz 4 8 -26 y_1_2 5 -26 x_1_2 7 -26 t 11 -27 cz 0 1 -27 x_1_2 2 -27 y_1_2 4 -27 t 5 -27 y_1_2 6 -27 cz 7 8 -28 x_1_2 0 -28 cz 1 4 -28 t 2 -28 t 6 -28 cz 7 10 -28 y_1_2 8 -29 t 0 -29 y_1_2 1 -29 cz 2 3 -29 x_1_2 4 -29 y_1_2 7 -29 cz 8 9 -29 x_1_2 10 -30 t 1 -30 x_1_2 2 -30 cz 3 7 -30 t 4 -30 cz 5 9 -30 y_1_2 8 -30 t 10 -31 t 2 -31 cz 3 4 -31 y_1_2 5 -31 y_1_2 7 -31 t 8 -31 x_1_2 9 -31 cz 10 11 -32 cz 0 3 -32 x_1_2 4 -32 t 5 -32 t 7 -32 cz 8 11 -32 t 9 -32 y_1_2 10 -33 y_1_2 0 -33 x_1_2 3 -33 cz 4 5 -33 cz 6 7 -33 x_1_2 8 -33 t 10 -33 y_1_2 11 -34 t 0 -34 cz 2 6 -34 t 3 -34 cz 4 8 -34 y_1_2 5 -34 x_1_2 7 -34 t 11 -35 cz 0 1 -35 y_1_2 2 -35 x_1_2 4 -35 t 5 -35 x_1_2 6 -35 cz 7 8 -36 x_1_2 0 -36 cz 1 4 -36 t 2 -36 t 6 -36 cz 7 10 -36 x_1_2 8 -37 t 0 -37 x_1_2 1 -37 cz 2 3 -37 x_1_2 4 -37 y_1_2 7 -37 cz 8 9 -37 x_1_2 10 -38 t 1 -38 y_1_2 2 -38 cz 3 7 -38 t 4 -38 cz 5 9 -38 x_1_2 8 -38 t 10 -39 t 2 -39 cz 3 4 -39 y_1_2 5 -39 y_1_2 7 -39 t 8 -39 x_1_2 9 -39 cz 10 11 -40 cz 0 3 -40 y_1_2 4 -40 t 5 -40 t 7 -40 cz 8 11 -40 t 9 -40 x_1_2 10 -41 h 0 -41 h 1 -41 h 2 -41 h 3 -41 h 4 -41 h 5 -41 h 6 -41 h 7 -41 h 8 -41 h 9 -41 h 10 -41 h 11 diff --git a/test/circuits/grcs/bris_7_40_9_v2.txt b/test/circuits/grcs/bris_7_40_9_v2.txt deleted file mode 100644 index 0dcb86f42..000000000 --- a/test/circuits/grcs/bris_7_40_9_v2.txt +++ /dev/null @@ -1,752 +0,0 @@ -30 -0 h 0 -0 h 1 -0 h 2 -0 h 3 -0 h 4 -0 h 5 -0 h 6 -0 h 7 -0 h 8 -0 h 9 -0 h 10 -0 h 11 -0 h 12 -0 h 13 -0 h 14 -0 h 15 -0 h 16 -0 h 17 -0 h 18 -0 h 19 -0 h 20 -0 h 21 -0 h 22 -0 h 23 -0 h 24 -0 h 25 -0 h 26 -0 h 27 -0 h 28 -0 h 29 -1 t 0 -1 t 1 -1 t 2 -1 t 3 -1 cz 4 5 -1 t 6 -1 cz 7 8 -1 t 9 -1 t 10 -1 t 11 -1 t 12 -1 t 13 -1 t 14 -1 cz 15 16 -1 t 17 -1 t 18 -1 cz 19 20 -1 t 21 -1 t 22 -1 t 23 -1 t 24 -1 t 25 -1 cz 26 27 -1 t 28 -1 t 29 -2 cz 2 7 -2 cz 4 9 -2 x_1_2 5 -2 x_1_2 8 -2 cz 12 18 -2 cz 14 20 -2 x_1_2 15 -2 cz 16 22 -2 y_1_2 19 -2 cz 26 29 -2 x_1_2 27 -3 cz 0 1 -3 y_1_2 2 -3 y_1_2 4 -3 t 5 -3 x_1_2 7 -3 cz 8 9 -3 cz 12 13 -3 y_1_2 14 -3 t 15 -3 cz 16 17 -3 y_1_2 18 -3 t 19 -3 cz 20 21 -3 x_1_2 22 -3 x_1_2 26 -3 t 27 -3 cz 28 29 -4 y_1_2 0 -4 cz 1 4 -4 t 2 -4 cz 6 12 -4 t 7 -4 cz 8 14 -4 x_1_2 9 -4 cz 10 16 -4 y_1_2 13 -4 x_1_2 17 -4 t 18 -4 cz 19 24 -4 x_1_2 20 -4 cz 21 26 -4 t 22 -4 x_1_2 28 -4 y_1_2 29 -5 t 0 -5 y_1_2 1 -5 cz 2 3 -5 y_1_2 4 -5 y_1_2 6 -5 x_1_2 8 -5 cz 9 10 -5 y_1_2 12 -5 cz 13 14 -5 x_1_2 16 -5 t 17 -5 x_1_2 19 -5 t 20 -5 cz 21 22 -5 cz 24 25 -5 y_1_2 26 -5 t 28 -5 t 29 -6 t 1 -6 y_1_2 2 -6 cz 3 8 -6 t 4 -6 cz 5 10 -6 t 6 -6 x_1_2 9 -6 t 12 -6 cz 13 19 -6 x_1_2 14 -6 cz 15 21 -6 t 16 -6 cz 17 23 -6 x_1_2 22 -6 x_1_2 24 -6 cz 25 28 -6 t 26 -7 t 2 -7 cz 3 4 -7 x_1_2 5 -7 cz 6 7 -7 y_1_2 8 -7 t 9 -7 cz 10 11 -7 x_1_2 13 -7 cz 14 15 -7 y_1_2 17 -7 cz 18 19 -7 y_1_2 21 -7 cz 22 23 -7 t 24 -7 cz 25 26 -7 x_1_2 28 -8 cz 0 3 -8 x_1_2 4 -8 t 5 -8 x_1_2 6 -8 cz 7 13 -8 t 8 -8 cz 9 15 -8 x_1_2 10 -8 cz 11 17 -8 x_1_2 14 -8 y_1_2 18 -8 x_1_2 19 -8 cz 20 25 -8 t 21 -8 cz 22 27 -8 y_1_2 23 -8 x_1_2 26 -8 t 28 -9 y_1_2 0 -9 y_1_2 3 -9 cz 4 5 -9 t 6 -9 cz 7 8 -9 x_1_2 9 -9 t 10 -9 x_1_2 11 -9 x_1_2 13 -9 t 14 -9 cz 15 16 -9 y_1_2 17 -9 t 18 -9 cz 19 20 -9 x_1_2 22 -9 t 23 -9 x_1_2 25 -9 cz 26 27 -10 t 0 -10 cz 2 7 -10 t 3 -10 cz 4 9 -10 x_1_2 5 -10 y_1_2 8 -10 t 11 -10 cz 12 18 -10 t 13 -10 cz 14 20 -10 x_1_2 15 -10 cz 16 22 -10 t 17 -10 x_1_2 19 -10 t 25 -10 cz 26 29 -10 y_1_2 27 -11 cz 0 1 -11 x_1_2 2 -11 y_1_2 4 -11 t 5 -11 x_1_2 7 -11 cz 8 9 -11 cz 12 13 -11 y_1_2 14 -11 t 15 -11 cz 16 17 -11 y_1_2 18 -11 t 19 -11 cz 20 21 -11 x_1_2 22 -11 y_1_2 26 -11 t 27 -11 cz 28 29 -12 y_1_2 0 -12 cz 1 4 -12 t 2 -12 cz 6 12 -12 t 7 -12 cz 8 14 -12 x_1_2 9 -12 cz 10 16 -12 x_1_2 13 -12 y_1_2 17 -12 t 18 -12 cz 19 24 -12 y_1_2 20 -12 cz 21 26 -12 t 22 -12 x_1_2 28 -12 y_1_2 29 -13 t 0 -13 y_1_2 1 -13 cz 2 3 -13 x_1_2 4 -13 y_1_2 6 -13 x_1_2 8 -13 cz 9 10 -13 x_1_2 12 -13 cz 13 14 -13 y_1_2 16 -13 t 17 -13 y_1_2 19 -13 t 20 -13 cz 21 22 -13 cz 24 25 -13 y_1_2 26 -13 t 28 -13 t 29 -14 t 1 -14 x_1_2 2 -14 cz 3 8 -14 t 4 -14 cz 5 10 -14 t 6 -14 x_1_2 9 -14 t 12 -14 cz 13 19 -14 y_1_2 14 -14 cz 15 21 -14 t 16 -14 cz 17 23 -14 y_1_2 22 -14 x_1_2 24 -14 cz 25 28 -14 t 26 -15 t 2 -15 cz 3 4 -15 x_1_2 5 -15 cz 6 7 -15 y_1_2 8 -15 t 9 -15 cz 10 11 -15 y_1_2 13 -15 cz 14 15 -15 x_1_2 17 -15 cz 18 19 -15 y_1_2 21 -15 cz 22 23 -15 t 24 -15 cz 25 26 -15 x_1_2 28 -16 cz 0 3 -16 x_1_2 4 -16 t 5 -16 x_1_2 6 -16 cz 7 13 -16 t 8 -16 cz 9 15 -16 x_1_2 10 -16 cz 11 17 -16 x_1_2 14 -16 x_1_2 18 -16 y_1_2 19 -16 cz 20 25 -16 t 21 -16 cz 22 27 -16 x_1_2 23 -16 y_1_2 26 -16 t 28 -17 x_1_2 0 -17 y_1_2 3 -17 cz 4 5 -17 t 6 -17 cz 7 8 -17 y_1_2 9 -17 t 10 -17 x_1_2 11 -17 y_1_2 13 -17 t 14 -17 cz 15 16 -17 x_1_2 17 -17 t 18 -17 cz 19 20 -17 y_1_2 22 -17 t 23 -17 x_1_2 25 -17 cz 26 27 -18 t 0 -18 cz 2 7 -18 t 3 -18 cz 4 9 -18 x_1_2 5 -18 y_1_2 8 -18 t 11 -18 cz 12 18 -18 t 13 -18 cz 14 20 -18 x_1_2 15 -18 cz 16 22 -18 t 17 -18 x_1_2 19 -18 t 25 -18 cz 26 29 -18 y_1_2 27 -19 cz 0 1 -19 x_1_2 2 -19 y_1_2 4 -19 t 5 -19 x_1_2 7 -19 cz 8 9 -19 cz 12 13 -19 y_1_2 14 -19 t 15 -19 cz 16 17 -19 x_1_2 18 -19 t 19 -19 cz 20 21 -19 x_1_2 22 -19 y_1_2 26 -19 t 27 -19 cz 28 29 -20 x_1_2 0 -20 cz 1 4 -20 t 2 -20 cz 6 12 -20 t 7 -20 cz 8 14 -20 y_1_2 9 -20 cz 10 16 -20 y_1_2 13 -20 y_1_2 17 -20 t 18 -20 cz 19 24 -20 x_1_2 20 -20 cz 21 26 -20 t 22 -20 x_1_2 28 -20 x_1_2 29 -21 t 0 -21 x_1_2 1 -21 cz 2 3 -21 y_1_2 4 -21 y_1_2 6 -21 x_1_2 8 -21 cz 9 10 -21 x_1_2 12 -21 cz 13 14 -21 y_1_2 16 -21 t 17 -21 x_1_2 19 -21 t 20 -21 cz 21 22 -21 cz 24 25 -21 x_1_2 26 -21 t 28 -21 t 29 -22 t 1 -22 y_1_2 2 -22 cz 3 8 -22 t 4 -22 cz 5 10 -22 t 6 -22 y_1_2 9 -22 t 12 -22 cz 13 19 -22 x_1_2 14 -22 cz 15 21 -22 t 16 -22 cz 17 23 -22 x_1_2 22 -22 y_1_2 24 -22 cz 25 28 -22 t 26 -23 t 2 -23 cz 3 4 -23 y_1_2 5 -23 cz 6 7 -23 x_1_2 8 -23 t 9 -23 cz 10 11 -23 y_1_2 13 -23 cz 14 15 -23 x_1_2 17 -23 cz 18 19 -23 y_1_2 21 -23 cz 22 23 -23 t 24 -23 cz 25 26 -23 y_1_2 28 -24 cz 0 3 -24 y_1_2 4 -24 t 5 -24 x_1_2 6 -24 cz 7 13 -24 t 8 -24 cz 9 15 -24 x_1_2 10 -24 cz 11 17 -24 x_1_2 14 -24 y_1_2 18 -24 x_1_2 19 -24 cz 20 25 -24 t 21 -24 cz 22 27 -24 y_1_2 23 -24 x_1_2 26 -24 t 28 -25 y_1_2 0 -25 x_1_2 3 -25 cz 4 5 -25 t 6 -25 cz 7 8 -25 x_1_2 9 -25 t 10 -25 x_1_2 11 -25 x_1_2 13 -25 t 14 -25 cz 15 16 -25 y_1_2 17 -25 t 18 -25 cz 19 20 -25 x_1_2 22 -25 t 23 -25 x_1_2 25 -25 cz 26 27 -26 t 0 -26 cz 2 7 -26 t 3 -26 cz 4 9 -26 x_1_2 5 -26 y_1_2 8 -26 t 11 -26 cz 12 18 -26 t 13 -26 cz 14 20 -26 y_1_2 15 -26 cz 16 22 -26 t 17 -26 y_1_2 19 -26 t 25 -26 cz 26 29 -26 x_1_2 27 -27 cz 0 1 -27 y_1_2 2 -27 y_1_2 4 -27 t 5 -27 y_1_2 7 -27 cz 8 9 -27 cz 12 13 -27 y_1_2 14 -27 t 15 -27 cz 16 17 -27 y_1_2 18 -27 t 19 -27 cz 20 21 -27 y_1_2 22 -27 x_1_2 26 -27 t 27 -27 cz 28 29 -28 y_1_2 0 -28 cz 1 4 -28 t 2 -28 cz 6 12 -28 t 7 -28 cz 8 14 -28 y_1_2 9 -28 cz 10 16 -28 x_1_2 13 -28 y_1_2 17 -28 t 18 -28 cz 19 24 -28 y_1_2 20 -28 cz 21 26 -28 t 22 -28 x_1_2 28 -28 y_1_2 29 -29 t 0 -29 x_1_2 1 -29 cz 2 3 -29 x_1_2 4 -29 y_1_2 6 -29 x_1_2 8 -29 cz 9 10 -29 y_1_2 12 -29 cz 13 14 -29 x_1_2 16 -29 t 17 -29 y_1_2 19 -29 t 20 -29 cz 21 22 -29 cz 24 25 -29 x_1_2 26 -29 t 28 -29 t 29 -30 t 1 -30 y_1_2 2 -30 cz 3 8 -30 t 4 -30 cz 5 10 -30 t 6 -30 y_1_2 9 -30 t 12 -30 cz 13 19 -30 y_1_2 14 -30 cz 15 21 -30 t 16 -30 cz 17 23 -30 y_1_2 22 -30 x_1_2 24 -30 cz 25 28 -30 t 26 -31 t 2 -31 cz 3 4 -31 y_1_2 5 -31 cz 6 7 -31 y_1_2 8 -31 t 9 -31 cz 10 11 -31 y_1_2 13 -31 cz 14 15 -31 x_1_2 17 -31 cz 18 19 -31 x_1_2 21 -31 cz 22 23 -31 t 24 -31 cz 25 26 -31 x_1_2 28 -32 cz 0 3 -32 y_1_2 4 -32 t 5 -32 x_1_2 6 -32 cz 7 13 -32 t 8 -32 cz 9 15 -32 x_1_2 10 -32 cz 11 17 -32 x_1_2 14 -32 x_1_2 18 -32 y_1_2 19 -32 cz 20 25 -32 t 21 -32 cz 22 27 -32 x_1_2 23 -32 y_1_2 26 -32 t 28 -33 x_1_2 0 -33 y_1_2 3 -33 cz 4 5 -33 t 6 -33 cz 7 8 -33 x_1_2 9 -33 t 10 -33 y_1_2 11 -33 y_1_2 13 -33 t 14 -33 cz 15 16 -33 y_1_2 17 -33 t 18 -33 cz 19 20 -33 y_1_2 22 -33 t 23 -33 y_1_2 25 -33 cz 26 27 -34 t 0 -34 cz 2 7 -34 t 3 -34 cz 4 9 -34 x_1_2 5 -34 x_1_2 8 -34 t 11 -34 cz 12 18 -34 t 13 -34 cz 14 20 -34 x_1_2 15 -34 cz 16 22 -34 t 17 -34 y_1_2 19 -34 t 25 -34 cz 26 29 -34 x_1_2 27 -35 cz 0 1 -35 x_1_2 2 -35 x_1_2 4 -35 t 5 -35 x_1_2 7 -35 cz 8 9 -35 cz 12 13 -35 y_1_2 14 -35 t 15 -35 cz 16 17 -35 y_1_2 18 -35 t 19 -35 cz 20 21 -35 x_1_2 22 -35 y_1_2 26 -35 t 27 -35 cz 28 29 -36 x_1_2 0 -36 cz 1 4 -36 t 2 -36 cz 6 12 -36 t 7 -36 cz 8 14 -36 y_1_2 9 -36 cz 10 16 -36 x_1_2 13 -36 y_1_2 17 -36 t 18 -36 cz 19 24 -36 x_1_2 20 -36 cz 21 26 -36 t 22 -36 x_1_2 28 -36 y_1_2 29 -37 t 0 -37 x_1_2 1 -37 cz 2 3 -37 x_1_2 4 -37 y_1_2 6 -37 x_1_2 8 -37 cz 9 10 -37 x_1_2 12 -37 cz 13 14 -37 y_1_2 16 -37 t 17 -37 x_1_2 19 -37 t 20 -37 cz 21 22 -37 cz 24 25 -37 x_1_2 26 -37 t 28 -37 t 29 -38 t 1 -38 y_1_2 2 -38 cz 3 8 -38 t 4 -38 cz 5 10 -38 t 6 -38 y_1_2 9 -38 t 12 -38 cz 13 19 -38 x_1_2 14 -38 cz 15 21 -38 t 16 -38 cz 17 23 -38 x_1_2 22 -38 x_1_2 24 -38 cz 25 28 -38 t 26 -39 t 2 -39 cz 3 4 -39 x_1_2 5 -39 cz 6 7 -39 y_1_2 8 -39 t 9 -39 cz 10 11 -39 y_1_2 13 -39 cz 14 15 -39 y_1_2 17 -39 cz 18 19 -39 y_1_2 21 -39 cz 22 23 -39 t 24 -39 cz 25 26 -39 y_1_2 28 -40 cz 0 3 -40 y_1_2 4 -40 t 5 -40 y_1_2 6 -40 cz 7 13 -40 t 8 -40 cz 9 15 -40 y_1_2 10 -40 cz 11 17 -40 x_1_2 14 -40 x_1_2 18 -40 x_1_2 19 -40 cz 20 25 -40 t 21 -40 cz 22 27 -40 y_1_2 23 -40 x_1_2 26 -40 t 28 -41 h 0 -41 h 1 -41 h 2 -41 h 3 -41 h 4 -41 h 5 -41 h 6 -41 h 7 -41 h 8 -41 h 9 -41 h 10 -41 h 11 -41 h 12 -41 h 13 -41 h 14 -41 h 15 -41 h 16 -41 h 17 -41 h 18 -41 h 19 -41 h 20 -41 h 21 -41 h 22 -41 h 23 -41 h 24 -41 h 25 -41 h 26 -41 h 27 -41 h 28 -41 h 29 diff --git a/test/circuits/grcs/inst_4x4_80_9_v2.txt b/test/circuits/grcs/inst_4x4_80_9_v2.txt deleted file mode 100644 index 7569571d7..000000000 --- a/test/circuits/grcs/inst_4x4_80_9_v2.txt +++ /dev/null @@ -1,765 +0,0 @@ -16 -0 h 0 -0 h 1 -0 h 2 -0 h 3 -0 h 4 -0 h 5 -0 h 6 -0 h 7 -0 h 8 -0 h 9 -0 h 10 -0 h 11 -0 h 12 -0 h 13 -0 h 14 -0 h 15 -1 cz 0 1 -1 cz 6 7 -1 cz 8 9 -1 cz 14 15 -1 t 2 -1 t 3 -1 t 4 -1 t 5 -1 t 10 -1 t 11 -1 t 12 -1 t 13 -2 cz 4 8 -2 cz 6 10 -2 x_1_2 0 -2 x_1_2 1 -2 x_1_2 7 -2 y_1_2 9 -2 x_1_2 14 -2 y_1_2 15 -3 cz 1 2 -3 cz 9 10 -3 t 0 -3 y_1_2 4 -3 x_1_2 6 -3 t 7 -3 y_1_2 8 -3 t 14 -3 t 15 -4 cz 0 4 -4 cz 9 13 -4 cz 2 6 -4 cz 11 15 -4 y_1_2 1 -4 t 8 -4 x_1_2 10 -5 cz 2 3 -5 cz 4 5 -5 cz 10 11 -5 cz 12 13 -5 x_1_2 0 -5 t 1 -5 y_1_2 6 -5 x_1_2 9 -5 y_1_2 15 -6 cz 5 9 -6 cz 7 11 -6 t 0 -6 x_1_2 2 -6 x_1_2 3 -6 x_1_2 4 -6 t 6 -6 y_1_2 10 -6 y_1_2 12 -6 y_1_2 13 -6 t 15 -7 cz 5 6 -7 cz 13 14 -7 t 2 -7 t 3 -7 t 4 -7 y_1_2 7 -7 x_1_2 9 -7 t 10 -7 y_1_2 11 -7 t 12 -8 cz 8 12 -8 cz 1 5 -8 cz 10 14 -8 cz 3 7 -8 x_1_2 6 -8 t 9 -8 t 11 -8 x_1_2 13 -9 cz 0 1 -9 cz 6 7 -9 cz 8 9 -9 cz 14 15 -9 y_1_2 3 -9 y_1_2 5 -9 x_1_2 10 -9 x_1_2 12 -9 t 13 -10 cz 4 8 -10 cz 6 10 -10 x_1_2 0 -10 x_1_2 1 -10 t 3 -10 t 5 -10 x_1_2 7 -10 y_1_2 9 -10 t 12 -10 x_1_2 14 -10 y_1_2 15 -11 cz 1 2 -11 cz 9 10 -11 t 0 -11 y_1_2 4 -11 x_1_2 6 -11 t 7 -11 x_1_2 8 -11 t 14 -11 t 15 -12 cz 0 4 -12 cz 9 13 -12 cz 2 6 -12 cz 11 15 -12 x_1_2 1 -12 t 8 -12 x_1_2 10 -13 cz 2 3 -13 cz 4 5 -13 cz 10 11 -13 cz 12 13 -13 x_1_2 0 -13 t 1 -13 y_1_2 6 -13 x_1_2 9 -13 y_1_2 15 -14 cz 5 9 -14 cz 7 11 -14 t 0 -14 x_1_2 2 -14 y_1_2 3 -14 y_1_2 4 -14 t 6 -14 x_1_2 10 -14 x_1_2 12 -14 x_1_2 13 -14 t 15 -15 cz 5 6 -15 cz 13 14 -15 t 2 -15 t 3 -15 t 4 -15 y_1_2 7 -15 x_1_2 9 -15 t 10 -15 x_1_2 11 -15 t 12 -16 cz 8 12 -16 cz 1 5 -16 cz 10 14 -16 cz 3 7 -16 x_1_2 6 -16 t 9 -16 t 11 -16 y_1_2 13 -17 cz 0 1 -17 cz 6 7 -17 cz 8 9 -17 cz 14 15 -17 x_1_2 3 -17 x_1_2 5 -17 y_1_2 10 -17 x_1_2 12 -17 t 13 -18 cz 4 8 -18 cz 6 10 -18 y_1_2 0 -18 x_1_2 1 -18 t 3 -18 t 5 -18 y_1_2 7 -18 y_1_2 9 -18 t 12 -18 x_1_2 14 -18 y_1_2 15 -19 cz 1 2 -19 cz 9 10 -19 t 0 -19 y_1_2 4 -19 x_1_2 6 -19 t 7 -19 x_1_2 8 -19 t 14 -19 t 15 -20 cz 0 4 -20 cz 9 13 -20 cz 2 6 -20 cz 11 15 -20 y_1_2 1 -20 t 8 -20 y_1_2 10 -21 cz 2 3 -21 cz 4 5 -21 cz 10 11 -21 cz 12 13 -21 x_1_2 0 -21 t 1 -21 y_1_2 6 -21 y_1_2 9 -21 x_1_2 15 -22 cz 5 9 -22 cz 7 11 -22 t 0 -22 y_1_2 2 -22 x_1_2 3 -22 x_1_2 4 -22 t 6 -22 y_1_2 10 -22 y_1_2 12 -22 y_1_2 13 -22 t 15 -23 cz 5 6 -23 cz 13 14 -23 t 2 -23 t 3 -23 t 4 -23 x_1_2 7 -23 x_1_2 9 -23 t 10 -23 y_1_2 11 -23 t 12 -24 cz 8 12 -24 cz 1 5 -24 cz 10 14 -24 cz 3 7 -24 y_1_2 6 -24 t 9 -24 t 11 -24 x_1_2 13 -25 cz 0 1 -25 cz 6 7 -25 cz 8 9 -25 cz 14 15 -25 x_1_2 3 -25 y_1_2 5 -25 y_1_2 10 -25 x_1_2 12 -25 t 13 -26 cz 4 8 -26 cz 6 10 -26 y_1_2 0 -26 x_1_2 1 -26 t 3 -26 t 5 -26 x_1_2 7 -26 x_1_2 9 -26 t 12 -26 x_1_2 14 -26 x_1_2 15 -27 cz 1 2 -27 cz 9 10 -27 t 0 -27 x_1_2 4 -27 y_1_2 6 -27 t 7 -27 x_1_2 8 -27 t 14 -27 t 15 -28 cz 0 4 -28 cz 9 13 -28 cz 2 6 -28 cz 11 15 -28 y_1_2 1 -28 t 8 -28 x_1_2 10 -29 cz 2 3 -29 cz 4 5 -29 cz 10 11 -29 cz 12 13 -29 y_1_2 0 -29 t 1 -29 y_1_2 6 -29 x_1_2 9 -29 y_1_2 15 -30 cz 5 9 -30 cz 7 11 -30 t 0 -30 x_1_2 2 -30 y_1_2 3 -30 x_1_2 4 -30 t 6 -30 x_1_2 10 -30 y_1_2 12 -30 x_1_2 13 -30 t 15 -31 cz 5 6 -31 cz 13 14 -31 t 2 -31 t 3 -31 t 4 -31 x_1_2 7 -31 y_1_2 9 -31 t 10 -31 x_1_2 11 -31 t 12 -32 cz 8 12 -32 cz 1 5 -32 cz 10 14 -32 cz 3 7 -32 y_1_2 6 -32 t 9 -32 t 11 -32 x_1_2 13 -33 cz 0 1 -33 cz 6 7 -33 cz 8 9 -33 cz 14 15 -33 y_1_2 3 -33 x_1_2 5 -33 x_1_2 10 -33 y_1_2 12 -33 t 13 -34 cz 4 8 -34 cz 6 10 -34 x_1_2 0 -34 y_1_2 1 -34 t 3 -34 t 5 -34 y_1_2 7 -34 y_1_2 9 -34 t 12 -34 x_1_2 14 -34 x_1_2 15 -35 cz 1 2 -35 cz 9 10 -35 t 0 -35 x_1_2 4 -35 x_1_2 6 -35 t 7 -35 y_1_2 8 -35 t 14 -35 t 15 -36 cz 0 4 -36 cz 9 13 -36 cz 2 6 -36 cz 11 15 -36 y_1_2 1 -36 t 8 -36 x_1_2 10 -37 cz 2 3 -37 cz 4 5 -37 cz 10 11 -37 cz 12 13 -37 x_1_2 0 -37 t 1 -37 y_1_2 6 -37 x_1_2 9 -37 x_1_2 15 -38 cz 5 9 -38 cz 7 11 -38 t 0 -38 y_1_2 2 -38 y_1_2 3 -38 x_1_2 4 -38 t 6 -38 x_1_2 10 -38 y_1_2 12 -38 y_1_2 13 -38 t 15 -39 cz 5 6 -39 cz 13 14 -39 t 2 -39 t 3 -39 t 4 -39 x_1_2 7 -39 y_1_2 9 -39 t 10 -39 x_1_2 11 -39 t 12 -40 cz 8 12 -40 cz 1 5 -40 cz 10 14 -40 cz 3 7 -40 y_1_2 6 -40 t 9 -40 t 11 -40 y_1_2 13 -41 cz 0 1 -41 cz 6 7 -41 cz 8 9 -41 cz 14 15 -41 y_1_2 3 -41 x_1_2 5 -41 x_1_2 10 -41 x_1_2 12 -41 t 13 -42 cz 4 8 -42 cz 6 10 -42 y_1_2 0 -42 x_1_2 1 -42 t 3 -42 t 5 -42 y_1_2 7 -42 x_1_2 9 -42 t 12 -42 y_1_2 14 -42 x_1_2 15 -43 cz 1 2 -43 cz 9 10 -43 t 0 -43 x_1_2 4 -43 x_1_2 6 -43 t 7 -43 x_1_2 8 -43 t 14 -43 t 15 -44 cz 0 4 -44 cz 9 13 -44 cz 2 6 -44 cz 11 15 -44 y_1_2 1 -44 t 8 -44 x_1_2 10 -45 cz 2 3 -45 cz 4 5 -45 cz 10 11 -45 cz 12 13 -45 x_1_2 0 -45 t 1 -45 x_1_2 6 -45 y_1_2 9 -45 y_1_2 15 -46 cz 5 9 -46 cz 7 11 -46 t 0 -46 y_1_2 2 -46 x_1_2 3 -46 y_1_2 4 -46 t 6 -46 y_1_2 10 -46 y_1_2 12 -46 y_1_2 13 -46 t 15 -47 cz 5 6 -47 cz 13 14 -47 t 2 -47 t 3 -47 t 4 -47 y_1_2 7 -47 y_1_2 9 -47 t 10 -47 x_1_2 11 -47 t 12 -48 cz 8 12 -48 cz 1 5 -48 cz 10 14 -48 cz 3 7 -48 y_1_2 6 -48 t 9 -48 t 11 -48 y_1_2 13 -49 cz 0 1 -49 cz 6 7 -49 cz 8 9 -49 cz 14 15 -49 x_1_2 3 -49 y_1_2 5 -49 y_1_2 10 -49 x_1_2 12 -49 t 13 -50 cz 4 8 -50 cz 6 10 -50 y_1_2 0 -50 x_1_2 1 -50 t 3 -50 t 5 -50 x_1_2 7 -50 y_1_2 9 -50 t 12 -50 x_1_2 14 -50 y_1_2 15 -51 cz 1 2 -51 cz 9 10 -51 t 0 -51 x_1_2 4 -51 y_1_2 6 -51 t 7 -51 x_1_2 8 -51 t 14 -51 t 15 -52 cz 0 4 -52 cz 9 13 -52 cz 2 6 -52 cz 11 15 -52 y_1_2 1 -52 t 8 -52 y_1_2 10 -53 cz 2 3 -53 cz 4 5 -53 cz 10 11 -53 cz 12 13 -53 y_1_2 0 -53 t 1 -53 y_1_2 6 -53 x_1_2 9 -53 y_1_2 15 -54 cz 5 9 -54 cz 7 11 -54 t 0 -54 y_1_2 2 -54 y_1_2 3 -54 x_1_2 4 -54 t 6 -54 x_1_2 10 -54 x_1_2 12 -54 y_1_2 13 -54 t 15 -55 cz 5 6 -55 cz 13 14 -55 t 2 -55 t 3 -55 t 4 -55 x_1_2 7 -55 x_1_2 9 -55 t 10 -55 x_1_2 11 -55 t 12 -56 cz 8 12 -56 cz 1 5 -56 cz 10 14 -56 cz 3 7 -56 x_1_2 6 -56 t 9 -56 t 11 -56 y_1_2 13 -57 cz 0 1 -57 cz 6 7 -57 cz 8 9 -57 cz 14 15 -57 x_1_2 3 -57 y_1_2 5 -57 x_1_2 10 -57 y_1_2 12 -57 t 13 -58 cz 4 8 -58 cz 6 10 -58 x_1_2 0 -58 y_1_2 1 -58 t 3 -58 t 5 -58 y_1_2 7 -58 y_1_2 9 -58 t 12 -58 y_1_2 14 -58 y_1_2 15 -59 cz 1 2 -59 cz 9 10 -59 t 0 -59 x_1_2 4 -59 x_1_2 6 -59 t 7 -59 x_1_2 8 -59 t 14 -59 t 15 -60 cz 0 4 -60 cz 9 13 -60 cz 2 6 -60 cz 11 15 -60 y_1_2 1 -60 t 8 -60 x_1_2 10 -61 cz 2 3 -61 cz 4 5 -61 cz 10 11 -61 cz 12 13 -61 x_1_2 0 -61 t 1 -61 x_1_2 6 -61 x_1_2 9 -61 y_1_2 15 -62 cz 5 9 -62 cz 7 11 -62 t 0 -62 y_1_2 2 -62 x_1_2 3 -62 y_1_2 4 -62 t 6 -62 x_1_2 10 -62 y_1_2 12 -62 x_1_2 13 -62 t 15 -63 cz 5 6 -63 cz 13 14 -63 t 2 -63 t 3 -63 t 4 -63 y_1_2 7 -63 x_1_2 9 -63 t 10 -63 x_1_2 11 -63 t 12 -64 cz 8 12 -64 cz 1 5 -64 cz 10 14 -64 cz 3 7 -64 y_1_2 6 -64 t 9 -64 t 11 -64 x_1_2 13 -65 cz 0 1 -65 cz 6 7 -65 cz 8 9 -65 cz 14 15 -65 x_1_2 3 -65 y_1_2 5 -65 x_1_2 10 -65 x_1_2 12 -65 t 13 -66 cz 4 8 -66 cz 6 10 -66 y_1_2 0 -66 x_1_2 1 -66 t 3 -66 t 5 -66 x_1_2 7 -66 y_1_2 9 -66 t 12 -66 y_1_2 14 -66 x_1_2 15 -67 cz 1 2 -67 cz 9 10 -67 t 0 -67 x_1_2 4 -67 x_1_2 6 -67 t 7 -67 x_1_2 8 -67 t 14 -67 t 15 -68 cz 0 4 -68 cz 9 13 -68 cz 2 6 -68 cz 11 15 -68 y_1_2 1 -68 t 8 -68 y_1_2 10 -69 cz 2 3 -69 cz 4 5 -69 cz 10 11 -69 cz 12 13 -69 y_1_2 0 -69 t 1 -69 y_1_2 6 -69 y_1_2 9 -69 y_1_2 15 -70 cz 5 9 -70 cz 7 11 -70 t 0 -70 y_1_2 2 -70 y_1_2 3 -70 x_1_2 4 -70 t 6 -70 x_1_2 10 -70 x_1_2 12 -70 y_1_2 13 -70 t 15 -71 cz 5 6 -71 cz 13 14 -71 t 2 -71 t 3 -71 t 4 -71 x_1_2 7 -71 x_1_2 9 -71 t 10 -71 y_1_2 11 -71 t 12 -72 cz 8 12 -72 cz 1 5 -72 cz 10 14 -72 cz 3 7 -72 x_1_2 6 -72 t 9 -72 t 11 -72 x_1_2 13 -73 cz 0 1 -73 cz 6 7 -73 cz 8 9 -73 cz 14 15 -73 x_1_2 3 -73 x_1_2 5 -73 y_1_2 10 -73 y_1_2 12 -73 t 13 -74 cz 4 8 -74 cz 6 10 -74 x_1_2 0 -74 x_1_2 1 -74 t 3 -74 t 5 -74 x_1_2 7 -74 x_1_2 9 -74 t 12 -74 x_1_2 14 -74 y_1_2 15 -75 cz 1 2 -75 cz 9 10 -75 t 0 -75 x_1_2 4 -75 y_1_2 6 -75 t 7 -75 y_1_2 8 -75 t 14 -75 t 15 -76 cz 0 4 -76 cz 9 13 -76 cz 2 6 -76 cz 11 15 -76 x_1_2 1 -76 t 8 -76 y_1_2 10 -77 cz 2 3 -77 cz 4 5 -77 cz 10 11 -77 cz 12 13 -77 x_1_2 0 -77 t 1 -77 x_1_2 6 -77 y_1_2 9 -77 y_1_2 15 -78 cz 5 9 -78 cz 7 11 -78 t 0 -78 y_1_2 2 -78 y_1_2 3 -78 x_1_2 4 -78 t 6 -78 y_1_2 10 -78 x_1_2 12 -78 x_1_2 13 -78 t 15 -79 cz 5 6 -79 cz 13 14 -79 t 2 -79 t 3 -79 t 4 -79 y_1_2 7 -79 x_1_2 9 -79 t 10 -79 y_1_2 11 -79 t 12 -80 h 0 -80 h 1 -80 h 2 -80 h 3 -80 h 4 -80 h 5 -80 h 6 -80 h 7 -80 h 8 -80 h 9 -80 h 10 -80 h 11 -80 h 12 -80 h 13 -80 h 14 -80 h 15 diff --git a/test/circuits/grcs/inst_5x6_80_9_v2.txt b/test/circuits/grcs/inst_5x6_80_9_v2.txt deleted file mode 100644 index 4602fa450..000000000 --- a/test/circuits/grcs/inst_5x6_80_9_v2.txt +++ /dev/null @@ -1,1465 +0,0 @@ -30 -0 h 0 -0 h 1 -0 h 2 -0 h 3 -0 h 4 -0 h 5 -0 h 6 -0 h 7 -0 h 8 -0 h 9 -0 h 10 -0 h 11 -0 h 12 -0 h 13 -0 h 14 -0 h 15 -0 h 16 -0 h 17 -0 h 18 -0 h 19 -0 h 20 -0 h 21 -0 h 22 -0 h 23 -0 h 24 -0 h 25 -0 h 26 -0 h 27 -0 h 28 -0 h 29 -1 cz 0 1 -1 cz 4 5 -1 cz 8 9 -1 cz 12 13 -1 cz 16 17 -1 cz 20 21 -1 cz 24 25 -1 cz 28 29 -1 t 2 -1 t 3 -1 t 6 -1 t 7 -1 t 10 -1 t 11 -1 t 14 -1 t 15 -1 t 18 -1 t 19 -1 t 22 -1 t 23 -1 t 26 -1 t 27 -2 cz 6 12 -2 cz 19 25 -2 cz 8 14 -2 cz 21 27 -2 cz 10 16 -2 cz 23 29 -2 x_1_2 0 -2 x_1_2 1 -2 x_1_2 4 -2 y_1_2 5 -2 x_1_2 9 -2 y_1_2 13 -2 y_1_2 17 -2 x_1_2 20 -2 y_1_2 24 -2 y_1_2 28 -3 cz 1 2 -3 cz 9 10 -3 cz 13 14 -3 cz 21 22 -3 cz 25 26 -3 t 0 -3 t 4 -3 t 5 -3 x_1_2 6 -3 x_1_2 8 -3 y_1_2 12 -3 x_1_2 16 -3 t 17 -3 y_1_2 19 -3 t 20 -3 x_1_2 23 -3 t 24 -3 x_1_2 27 -3 t 28 -3 x_1_2 29 -4 cz 0 6 -4 cz 13 19 -4 cz 2 8 -4 cz 15 21 -4 cz 4 10 -4 cz 17 23 -4 y_1_2 1 -4 y_1_2 9 -4 t 12 -4 y_1_2 14 -4 t 16 -4 y_1_2 22 -4 x_1_2 25 -4 y_1_2 26 -4 t 27 -4 t 29 -5 cz 2 3 -5 cz 6 7 -5 cz 10 11 -5 cz 14 15 -5 cz 18 19 -5 cz 22 23 -5 cz 26 27 -5 x_1_2 0 -5 t 1 -5 x_1_2 4 -5 y_1_2 8 -5 t 9 -5 y_1_2 13 -5 x_1_2 17 -5 x_1_2 21 -5 t 25 -6 cz 18 24 -6 cz 7 13 -6 cz 20 26 -6 cz 9 15 -6 cz 22 28 -6 cz 11 17 -6 t 0 -6 x_1_2 2 -6 x_1_2 3 -6 t 4 -6 x_1_2 6 -6 t 8 -6 y_1_2 10 -6 x_1_2 14 -6 y_1_2 19 -6 t 21 -6 y_1_2 23 -6 x_1_2 27 -7 cz 3 4 -7 cz 7 8 -7 cz 15 16 -7 cz 19 20 -7 cz 27 28 -7 t 2 -7 t 6 -7 x_1_2 9 -7 t 10 -7 x_1_2 11 -7 x_1_2 13 -7 t 14 -7 x_1_2 17 -7 y_1_2 18 -7 x_1_2 22 -7 t 23 -7 y_1_2 24 -7 x_1_2 26 -8 cz 12 18 -8 cz 1 7 -8 cz 14 20 -8 cz 3 9 -8 cz 16 22 -8 cz 5 11 -8 y_1_2 4 -8 y_1_2 8 -8 t 13 -8 x_1_2 15 -8 t 17 -8 x_1_2 19 -8 t 24 -8 t 26 -8 x_1_2 27 -8 y_1_2 28 -9 cz 0 1 -9 cz 4 5 -9 cz 8 9 -9 cz 12 13 -9 cz 16 17 -9 cz 20 21 -9 cz 24 25 -9 cz 28 29 -9 x_1_2 3 -9 x_1_2 7 -9 x_1_2 11 -9 y_1_2 14 -9 t 15 -9 x_1_2 18 -9 t 19 -9 x_1_2 22 -9 t 27 -10 cz 6 12 -10 cz 19 25 -10 cz 8 14 -10 cz 21 27 -10 cz 10 16 -10 cz 23 29 -10 y_1_2 0 -10 x_1_2 1 -10 t 3 -10 y_1_2 4 -10 x_1_2 5 -10 t 7 -10 y_1_2 9 -10 t 11 -10 y_1_2 13 -10 x_1_2 17 -10 t 18 -10 y_1_2 20 -10 t 22 -10 y_1_2 24 -10 x_1_2 28 -11 cz 1 2 -11 cz 9 10 -11 cz 13 14 -11 cz 21 22 -11 cz 25 26 -11 t 0 -11 t 4 -11 t 5 -11 x_1_2 6 -11 y_1_2 8 -11 y_1_2 12 -11 x_1_2 16 -11 t 17 -11 y_1_2 19 -11 t 20 -11 y_1_2 23 -11 t 24 -11 x_1_2 27 -11 t 28 -11 y_1_2 29 -12 cz 0 6 -12 cz 13 19 -12 cz 2 8 -12 cz 15 21 -12 cz 4 10 -12 cz 17 23 -12 x_1_2 1 -12 x_1_2 9 -12 t 12 -12 y_1_2 14 -12 t 16 -12 y_1_2 22 -12 y_1_2 25 -12 x_1_2 26 -12 t 27 -12 t 29 -13 cz 2 3 -13 cz 6 7 -13 cz 10 11 -13 cz 14 15 -13 cz 18 19 -13 cz 22 23 -13 cz 26 27 -13 x_1_2 0 -13 t 1 -13 y_1_2 4 -13 y_1_2 8 -13 t 9 -13 x_1_2 13 -13 x_1_2 17 -13 y_1_2 21 -13 t 25 -14 cz 18 24 -14 cz 7 13 -14 cz 20 26 -14 cz 9 15 -14 cz 22 28 -14 cz 11 17 -14 t 0 -14 y_1_2 2 -14 x_1_2 3 -14 t 4 -14 y_1_2 6 -14 t 8 -14 x_1_2 10 -14 x_1_2 14 -14 x_1_2 19 -14 t 21 -14 x_1_2 23 -14 x_1_2 27 -15 cz 3 4 -15 cz 7 8 -15 cz 15 16 -15 cz 19 20 -15 cz 27 28 -15 t 2 -15 t 6 -15 x_1_2 9 -15 t 10 -15 y_1_2 11 -15 x_1_2 13 -15 t 14 -15 y_1_2 17 -15 x_1_2 18 -15 y_1_2 22 -15 t 23 -15 y_1_2 24 -15 x_1_2 26 -16 cz 12 18 -16 cz 1 7 -16 cz 14 20 -16 cz 3 9 -16 cz 16 22 -16 cz 5 11 -16 y_1_2 4 -16 x_1_2 8 -16 t 13 -16 y_1_2 15 -16 t 17 -16 x_1_2 19 -16 t 24 -16 t 26 -16 x_1_2 27 -16 y_1_2 28 -17 cz 0 1 -17 cz 4 5 -17 cz 8 9 -17 cz 12 13 -17 cz 16 17 -17 cz 20 21 -17 cz 24 25 -17 cz 28 29 -17 x_1_2 3 -17 x_1_2 7 -17 y_1_2 11 -17 x_1_2 14 -17 t 15 -17 y_1_2 18 -17 t 19 -17 x_1_2 22 -17 t 27 -18 cz 6 12 -18 cz 19 25 -18 cz 8 14 -18 cz 21 27 -18 cz 10 16 -18 cz 23 29 -18 y_1_2 0 -18 x_1_2 1 -18 t 3 -18 x_1_2 4 -18 y_1_2 5 -18 t 7 -18 x_1_2 9 -18 t 11 -18 y_1_2 13 -18 y_1_2 17 -18 t 18 -18 y_1_2 20 -18 t 22 -18 x_1_2 24 -18 x_1_2 28 -19 cz 1 2 -19 cz 9 10 -19 cz 13 14 -19 cz 21 22 -19 cz 25 26 -19 t 0 -19 t 4 -19 t 5 -19 x_1_2 6 -19 x_1_2 8 -19 y_1_2 12 -19 y_1_2 16 -19 t 17 -19 x_1_2 19 -19 t 20 -19 x_1_2 23 -19 t 24 -19 y_1_2 27 -19 t 28 -19 x_1_2 29 -20 cz 0 6 -20 cz 13 19 -20 cz 2 8 -20 cz 15 21 -20 cz 4 10 -20 cz 17 23 -20 x_1_2 1 -20 y_1_2 9 -20 t 12 -20 y_1_2 14 -20 t 16 -20 x_1_2 22 -20 x_1_2 25 -20 y_1_2 26 -20 t 27 -20 t 29 -21 cz 2 3 -21 cz 6 7 -21 cz 10 11 -21 cz 14 15 -21 cz 18 19 -21 cz 22 23 -21 cz 26 27 -21 y_1_2 0 -21 t 1 -21 x_1_2 4 -21 y_1_2 8 -21 t 9 -21 x_1_2 13 -21 y_1_2 17 -21 y_1_2 21 -21 t 25 -22 cz 18 24 -22 cz 7 13 -22 cz 20 26 -22 cz 9 15 -22 cz 22 28 -22 cz 11 17 -22 t 0 -22 y_1_2 2 -22 x_1_2 3 -22 t 4 -22 x_1_2 6 -22 t 8 -22 x_1_2 10 -22 y_1_2 14 -22 x_1_2 19 -22 t 21 -22 y_1_2 23 -22 x_1_2 27 -23 cz 3 4 -23 cz 7 8 -23 cz 15 16 -23 cz 19 20 -23 cz 27 28 -23 t 2 -23 t 6 -23 y_1_2 9 -23 t 10 -23 x_1_2 11 -23 x_1_2 13 -23 t 14 -23 x_1_2 17 -23 x_1_2 18 -23 y_1_2 22 -23 t 23 -23 x_1_2 24 -23 x_1_2 26 -24 cz 12 18 -24 cz 1 7 -24 cz 14 20 -24 cz 3 9 -24 cz 16 22 -24 cz 5 11 -24 x_1_2 4 -24 y_1_2 8 -24 t 13 -24 y_1_2 15 -24 t 17 -24 y_1_2 19 -24 t 24 -24 t 26 -24 x_1_2 27 -24 y_1_2 28 -25 cz 0 1 -25 cz 4 5 -25 cz 8 9 -25 cz 12 13 -25 cz 16 17 -25 cz 20 21 -25 cz 24 25 -25 cz 28 29 -25 y_1_2 3 -25 y_1_2 7 -25 y_1_2 11 -25 y_1_2 14 -25 t 15 -25 y_1_2 18 -25 t 19 -25 x_1_2 22 -25 t 27 -26 cz 6 12 -26 cz 19 25 -26 cz 8 14 -26 cz 21 27 -26 cz 10 16 -26 cz 23 29 -26 y_1_2 0 -26 y_1_2 1 -26 t 3 -26 x_1_2 4 -26 y_1_2 5 -26 t 7 -26 y_1_2 9 -26 t 11 -26 x_1_2 13 -26 y_1_2 17 -26 t 18 -26 x_1_2 20 -26 t 22 -26 x_1_2 24 -26 y_1_2 28 -27 cz 1 2 -27 cz 9 10 -27 cz 13 14 -27 cz 21 22 -27 cz 25 26 -27 t 0 -27 t 4 -27 t 5 -27 x_1_2 6 -27 y_1_2 8 -27 x_1_2 12 -27 y_1_2 16 -27 t 17 -27 x_1_2 19 -27 t 20 -27 y_1_2 23 -27 t 24 -27 y_1_2 27 -27 t 28 -27 y_1_2 29 -28 cz 0 6 -28 cz 13 19 -28 cz 2 8 -28 cz 15 21 -28 cz 4 10 -28 cz 17 23 -28 y_1_2 1 -28 x_1_2 9 -28 t 12 -28 y_1_2 14 -28 t 16 -28 y_1_2 22 -28 y_1_2 25 -28 x_1_2 26 -28 t 27 -28 t 29 -29 cz 2 3 -29 cz 6 7 -29 cz 10 11 -29 cz 14 15 -29 cz 18 19 -29 cz 22 23 -29 cz 26 27 -29 x_1_2 0 -29 t 1 -29 x_1_2 4 -29 y_1_2 8 -29 t 9 -29 x_1_2 13 -29 x_1_2 17 -29 x_1_2 21 -29 t 25 -30 cz 18 24 -30 cz 7 13 -30 cz 20 26 -30 cz 9 15 -30 cz 22 28 -30 cz 11 17 -30 t 0 -30 x_1_2 2 -30 y_1_2 3 -30 t 4 -30 x_1_2 6 -30 t 8 -30 y_1_2 10 -30 x_1_2 14 -30 y_1_2 19 -30 t 21 -30 x_1_2 23 -30 y_1_2 27 -31 cz 3 4 -31 cz 7 8 -31 cz 15 16 -31 cz 19 20 -31 cz 27 28 -31 t 2 -31 t 6 -31 y_1_2 9 -31 t 10 -31 y_1_2 11 -31 y_1_2 13 -31 t 14 -31 y_1_2 17 -31 x_1_2 18 -31 x_1_2 22 -31 t 23 -31 x_1_2 24 -31 y_1_2 26 -32 cz 12 18 -32 cz 1 7 -32 cz 14 20 -32 cz 3 9 -32 cz 16 22 -32 cz 5 11 -32 x_1_2 4 -32 x_1_2 8 -32 t 13 -32 x_1_2 15 -32 t 17 -32 x_1_2 19 -32 t 24 -32 t 26 -32 y_1_2 27 -32 y_1_2 28 -33 cz 0 1 -33 cz 4 5 -33 cz 8 9 -33 cz 12 13 -33 cz 16 17 -33 cz 20 21 -33 cz 24 25 -33 cz 28 29 -33 x_1_2 3 -33 y_1_2 7 -33 x_1_2 11 -33 y_1_2 14 -33 t 15 -33 x_1_2 18 -33 t 19 -33 y_1_2 22 -33 t 27 -34 cz 6 12 -34 cz 19 25 -34 cz 8 14 -34 cz 21 27 -34 cz 10 16 -34 cz 23 29 -34 x_1_2 0 -34 x_1_2 1 -34 t 3 -34 y_1_2 4 -34 x_1_2 5 -34 t 7 -34 x_1_2 9 -34 t 11 -34 y_1_2 13 -34 x_1_2 17 -34 t 18 -34 x_1_2 20 -34 t 22 -34 y_1_2 24 -34 x_1_2 28 -35 cz 1 2 -35 cz 9 10 -35 cz 13 14 -35 cz 21 22 -35 cz 25 26 -35 t 0 -35 t 4 -35 t 5 -35 x_1_2 6 -35 y_1_2 8 -35 y_1_2 12 -35 x_1_2 16 -35 t 17 -35 x_1_2 19 -35 t 20 -35 x_1_2 23 -35 t 24 -35 x_1_2 27 -35 t 28 -35 y_1_2 29 -36 cz 0 6 -36 cz 13 19 -36 cz 2 8 -36 cz 15 21 -36 cz 4 10 -36 cz 17 23 -36 y_1_2 1 -36 y_1_2 9 -36 t 12 -36 y_1_2 14 -36 t 16 -36 y_1_2 22 -36 y_1_2 25 -36 y_1_2 26 -36 t 27 -36 t 29 -37 cz 2 3 -37 cz 6 7 -37 cz 10 11 -37 cz 14 15 -37 cz 18 19 -37 cz 22 23 -37 cz 26 27 -37 y_1_2 0 -37 t 1 -37 x_1_2 4 -37 x_1_2 8 -37 t 9 -37 x_1_2 13 -37 y_1_2 17 -37 x_1_2 21 -37 t 25 -38 cz 18 24 -38 cz 7 13 -38 cz 20 26 -38 cz 9 15 -38 cz 22 28 -38 cz 11 17 -38 t 0 -38 x_1_2 2 -38 y_1_2 3 -38 t 4 -38 x_1_2 6 -38 t 8 -38 x_1_2 10 -38 x_1_2 14 -38 x_1_2 19 -38 t 21 -38 y_1_2 23 -38 y_1_2 27 -39 cz 3 4 -39 cz 7 8 -39 cz 15 16 -39 cz 19 20 -39 cz 27 28 -39 t 2 -39 t 6 -39 x_1_2 9 -39 t 10 -39 x_1_2 11 -39 x_1_2 13 -39 t 14 -39 x_1_2 17 -39 x_1_2 18 -39 y_1_2 22 -39 t 23 -39 x_1_2 24 -39 y_1_2 26 -40 cz 12 18 -40 cz 1 7 -40 cz 14 20 -40 cz 3 9 -40 cz 16 22 -40 cz 5 11 -40 y_1_2 4 -40 x_1_2 8 -40 t 13 -40 y_1_2 15 -40 t 17 -40 x_1_2 19 -40 t 24 -40 t 26 -40 x_1_2 27 -40 y_1_2 28 -41 cz 0 1 -41 cz 4 5 -41 cz 8 9 -41 cz 12 13 -41 cz 16 17 -41 cz 20 21 -41 cz 24 25 -41 cz 28 29 -41 y_1_2 3 -41 y_1_2 7 -41 y_1_2 11 -41 x_1_2 14 -41 t 15 -41 y_1_2 18 -41 t 19 -41 x_1_2 22 -41 t 27 -42 cz 6 12 -42 cz 19 25 -42 cz 8 14 -42 cz 21 27 -42 cz 10 16 -42 cz 23 29 -42 x_1_2 0 -42 y_1_2 1 -42 t 3 -42 x_1_2 4 -42 y_1_2 5 -42 t 7 -42 x_1_2 9 -42 t 11 -42 y_1_2 13 -42 y_1_2 17 -42 t 18 -42 x_1_2 20 -42 t 22 -42 y_1_2 24 -42 x_1_2 28 -43 cz 1 2 -43 cz 9 10 -43 cz 13 14 -43 cz 21 22 -43 cz 25 26 -43 t 0 -43 t 4 -43 t 5 -43 y_1_2 6 -43 x_1_2 8 -43 x_1_2 12 -43 y_1_2 16 -43 t 17 -43 x_1_2 19 -43 t 20 -43 x_1_2 23 -43 t 24 -43 x_1_2 27 -43 t 28 -43 x_1_2 29 -44 cz 0 6 -44 cz 13 19 -44 cz 2 8 -44 cz 15 21 -44 cz 4 10 -44 cz 17 23 -44 y_1_2 1 -44 y_1_2 9 -44 t 12 -44 y_1_2 14 -44 t 16 -44 x_1_2 22 -44 y_1_2 25 -44 y_1_2 26 -44 t 27 -44 t 29 -45 cz 2 3 -45 cz 6 7 -45 cz 10 11 -45 cz 14 15 -45 cz 18 19 -45 cz 22 23 -45 cz 26 27 -45 x_1_2 0 -45 t 1 -45 y_1_2 4 -45 x_1_2 8 -45 t 9 -45 x_1_2 13 -45 x_1_2 17 -45 x_1_2 21 -45 t 25 -46 cz 18 24 -46 cz 7 13 -46 cz 20 26 -46 cz 9 15 -46 cz 22 28 -46 cz 11 17 -46 t 0 -46 x_1_2 2 -46 y_1_2 3 -46 t 4 -46 y_1_2 6 -46 t 8 -46 y_1_2 10 -46 x_1_2 14 -46 y_1_2 19 -46 t 21 -46 x_1_2 23 -46 x_1_2 27 -47 cz 3 4 -47 cz 7 8 -47 cz 15 16 -47 cz 19 20 -47 cz 27 28 -47 t 2 -47 t 6 -47 y_1_2 9 -47 t 10 -47 y_1_2 11 -47 y_1_2 13 -47 t 14 -47 y_1_2 17 -47 x_1_2 18 -47 x_1_2 22 -47 t 23 -47 x_1_2 24 -47 y_1_2 26 -48 cz 12 18 -48 cz 1 7 -48 cz 14 20 -48 cz 3 9 -48 cz 16 22 -48 cz 5 11 -48 x_1_2 4 -48 x_1_2 8 -48 t 13 -48 y_1_2 15 -48 t 17 -48 x_1_2 19 -48 t 24 -48 t 26 -48 y_1_2 27 -48 y_1_2 28 -49 cz 0 1 -49 cz 4 5 -49 cz 8 9 -49 cz 12 13 -49 cz 16 17 -49 cz 20 21 -49 cz 24 25 -49 cz 28 29 -49 y_1_2 3 -49 x_1_2 7 -49 x_1_2 11 -49 y_1_2 14 -49 t 15 -49 y_1_2 18 -49 t 19 -49 x_1_2 22 -49 t 27 -50 cz 6 12 -50 cz 19 25 -50 cz 8 14 -50 cz 21 27 -50 cz 10 16 -50 cz 23 29 -50 x_1_2 0 -50 x_1_2 1 -50 t 3 -50 y_1_2 4 -50 y_1_2 5 -50 t 7 -50 x_1_2 9 -50 t 11 -50 x_1_2 13 -50 y_1_2 17 -50 t 18 -50 x_1_2 20 -50 t 22 -50 y_1_2 24 -50 y_1_2 28 -51 cz 1 2 -51 cz 9 10 -51 cz 13 14 -51 cz 21 22 -51 cz 25 26 -51 t 0 -51 t 4 -51 t 5 -51 y_1_2 6 -51 y_1_2 8 -51 x_1_2 12 -51 x_1_2 16 -51 t 17 -51 y_1_2 19 -51 t 20 -51 x_1_2 23 -51 t 24 -51 x_1_2 27 -51 t 28 -51 y_1_2 29 -52 cz 0 6 -52 cz 13 19 -52 cz 2 8 -52 cz 15 21 -52 cz 4 10 -52 cz 17 23 -52 y_1_2 1 -52 y_1_2 9 -52 t 12 -52 y_1_2 14 -52 t 16 -52 y_1_2 22 -52 x_1_2 25 -52 x_1_2 26 -52 t 27 -52 t 29 -53 cz 2 3 -53 cz 6 7 -53 cz 10 11 -53 cz 14 15 -53 cz 18 19 -53 cz 22 23 -53 cz 26 27 -53 y_1_2 0 -53 t 1 -53 y_1_2 4 -53 y_1_2 8 -53 t 9 -53 x_1_2 13 -53 y_1_2 17 -53 y_1_2 21 -53 t 25 -54 cz 18 24 -54 cz 7 13 -54 cz 20 26 -54 cz 9 15 -54 cz 22 28 -54 cz 11 17 -54 t 0 -54 y_1_2 2 -54 y_1_2 3 -54 t 4 -54 y_1_2 6 -54 t 8 -54 x_1_2 10 -54 x_1_2 14 -54 y_1_2 19 -54 t 21 -54 y_1_2 23 -54 x_1_2 27 -55 cz 3 4 -55 cz 7 8 -55 cz 15 16 -55 cz 19 20 -55 cz 27 28 -55 t 2 -55 t 6 -55 y_1_2 9 -55 t 10 -55 x_1_2 11 -55 x_1_2 13 -55 t 14 -55 x_1_2 17 -55 x_1_2 18 -55 x_1_2 22 -55 t 23 -55 y_1_2 24 -55 x_1_2 26 -56 cz 12 18 -56 cz 1 7 -56 cz 14 20 -56 cz 3 9 -56 cz 16 22 -56 cz 5 11 -56 y_1_2 4 -56 x_1_2 8 -56 t 13 -56 x_1_2 15 -56 t 17 -56 x_1_2 19 -56 t 24 -56 t 26 -56 y_1_2 27 -56 x_1_2 28 -57 cz 0 1 -57 cz 4 5 -57 cz 8 9 -57 cz 12 13 -57 cz 16 17 -57 cz 20 21 -57 cz 24 25 -57 cz 28 29 -57 y_1_2 3 -57 y_1_2 7 -57 y_1_2 11 -57 y_1_2 14 -57 t 15 -57 y_1_2 18 -57 t 19 -57 y_1_2 22 -57 t 27 -58 cz 6 12 -58 cz 19 25 -58 cz 8 14 -58 cz 21 27 -58 cz 10 16 -58 cz 23 29 -58 x_1_2 0 -58 x_1_2 1 -58 t 3 -58 y_1_2 4 -58 x_1_2 5 -58 t 7 -58 x_1_2 9 -58 t 11 -58 x_1_2 13 -58 x_1_2 17 -58 t 18 -58 y_1_2 20 -58 t 22 -58 y_1_2 24 -58 x_1_2 28 -59 cz 1 2 -59 cz 9 10 -59 cz 13 14 -59 cz 21 22 -59 cz 25 26 -59 t 0 -59 t 4 -59 t 5 -59 y_1_2 6 -59 y_1_2 8 -59 x_1_2 12 -59 y_1_2 16 -59 t 17 -59 y_1_2 19 -59 t 20 -59 x_1_2 23 -59 t 24 -59 x_1_2 27 -59 t 28 -59 x_1_2 29 -60 cz 0 6 -60 cz 13 19 -60 cz 2 8 -60 cz 15 21 -60 cz 4 10 -60 cz 17 23 -60 x_1_2 1 -60 y_1_2 9 -60 t 12 -60 x_1_2 14 -60 t 16 -60 y_1_2 22 -60 x_1_2 25 -60 x_1_2 26 -60 t 27 -60 t 29 -61 cz 2 3 -61 cz 6 7 -61 cz 10 11 -61 cz 14 15 -61 cz 18 19 -61 cz 22 23 -61 cz 26 27 -61 x_1_2 0 -61 t 1 -61 x_1_2 4 -61 x_1_2 8 -61 t 9 -61 x_1_2 13 -61 x_1_2 17 -61 y_1_2 21 -61 t 25 -62 cz 18 24 -62 cz 7 13 -62 cz 20 26 -62 cz 9 15 -62 cz 22 28 -62 cz 11 17 -62 t 0 -62 y_1_2 2 -62 x_1_2 3 -62 t 4 -62 y_1_2 6 -62 t 8 -62 x_1_2 10 -62 y_1_2 14 -62 y_1_2 19 -62 t 21 -62 x_1_2 23 -62 y_1_2 27 -63 cz 3 4 -63 cz 7 8 -63 cz 15 16 -63 cz 19 20 -63 cz 27 28 -63 t 2 -63 t 6 -63 x_1_2 9 -63 t 10 -63 x_1_2 11 -63 x_1_2 13 -63 t 14 -63 y_1_2 17 -63 y_1_2 18 -63 x_1_2 22 -63 t 23 -63 y_1_2 24 -63 y_1_2 26 -64 cz 12 18 -64 cz 1 7 -64 cz 14 20 -64 cz 3 9 -64 cz 16 22 -64 cz 5 11 -64 x_1_2 4 -64 y_1_2 8 -64 t 13 -64 y_1_2 15 -64 t 17 -64 y_1_2 19 -64 t 24 -64 t 26 -64 x_1_2 27 -64 y_1_2 28 -65 cz 0 1 -65 cz 4 5 -65 cz 8 9 -65 cz 12 13 -65 cz 16 17 -65 cz 20 21 -65 cz 24 25 -65 cz 28 29 -65 y_1_2 3 -65 y_1_2 7 -65 x_1_2 11 -65 y_1_2 14 -65 t 15 -65 y_1_2 18 -65 t 19 -65 x_1_2 22 -65 t 27 -66 cz 6 12 -66 cz 19 25 -66 cz 8 14 -66 cz 21 27 -66 cz 10 16 -66 cz 23 29 -66 y_1_2 0 -66 y_1_2 1 -66 t 3 -66 x_1_2 4 -66 y_1_2 5 -66 t 7 -66 x_1_2 9 -66 t 11 -66 x_1_2 13 -66 x_1_2 17 -66 t 18 -66 y_1_2 20 -66 t 22 -66 y_1_2 24 -66 y_1_2 28 -67 cz 1 2 -67 cz 9 10 -67 cz 13 14 -67 cz 21 22 -67 cz 25 26 -67 t 0 -67 t 4 -67 t 5 -67 x_1_2 6 -67 y_1_2 8 -67 y_1_2 12 -67 y_1_2 16 -67 t 17 -67 x_1_2 19 -67 t 20 -67 x_1_2 23 -67 t 24 -67 x_1_2 27 -67 t 28 -67 x_1_2 29 -68 cz 0 6 -68 cz 13 19 -68 cz 2 8 -68 cz 15 21 -68 cz 4 10 -68 cz 17 23 -68 y_1_2 1 -68 x_1_2 9 -68 t 12 -68 y_1_2 14 -68 t 16 -68 x_1_2 22 -68 y_1_2 25 -68 y_1_2 26 -68 t 27 -68 t 29 -69 cz 2 3 -69 cz 6 7 -69 cz 10 11 -69 cz 14 15 -69 cz 18 19 -69 cz 22 23 -69 cz 26 27 -69 y_1_2 0 -69 t 1 -69 x_1_2 4 -69 x_1_2 8 -69 t 9 -69 x_1_2 13 -69 x_1_2 17 -69 y_1_2 21 -69 t 25 -70 cz 18 24 -70 cz 7 13 -70 cz 20 26 -70 cz 9 15 -70 cz 22 28 -70 cz 11 17 -70 t 0 -70 y_1_2 2 -70 y_1_2 3 -70 t 4 -70 y_1_2 6 -70 t 8 -70 x_1_2 10 -70 x_1_2 14 -70 x_1_2 19 -70 t 21 -70 x_1_2 23 -70 x_1_2 27 -71 cz 3 4 -71 cz 7 8 -71 cz 15 16 -71 cz 19 20 -71 cz 27 28 -71 t 2 -71 t 6 -71 y_1_2 9 -71 t 10 -71 x_1_2 11 -71 y_1_2 13 -71 t 14 -71 x_1_2 17 -71 x_1_2 18 -71 y_1_2 22 -71 t 23 -71 x_1_2 24 -71 y_1_2 26 -72 cz 12 18 -72 cz 1 7 -72 cz 14 20 -72 cz 3 9 -72 cz 16 22 -72 cz 5 11 -72 y_1_2 4 -72 y_1_2 8 -72 t 13 -72 x_1_2 15 -72 t 17 -72 y_1_2 19 -72 t 24 -72 t 26 -72 y_1_2 27 -72 x_1_2 28 -73 cz 0 1 -73 cz 4 5 -73 cz 8 9 -73 cz 12 13 -73 cz 16 17 -73 cz 20 21 -73 cz 24 25 -73 cz 28 29 -73 x_1_2 3 -73 y_1_2 7 -73 x_1_2 11 -73 y_1_2 14 -73 t 15 -73 y_1_2 18 -73 t 19 -73 x_1_2 22 -73 t 27 -74 cz 6 12 -74 cz 19 25 -74 cz 8 14 -74 cz 21 27 -74 cz 10 16 -74 cz 23 29 -74 y_1_2 0 -74 y_1_2 1 -74 t 3 -74 x_1_2 4 -74 y_1_2 5 -74 t 7 -74 y_1_2 9 -74 t 11 -74 x_1_2 13 -74 x_1_2 17 -74 t 18 -74 x_1_2 20 -74 t 22 -74 y_1_2 24 -74 y_1_2 28 -75 cz 1 2 -75 cz 9 10 -75 cz 13 14 -75 cz 21 22 -75 cz 25 26 -75 t 0 -75 t 4 -75 t 5 -75 x_1_2 6 -75 x_1_2 8 -75 y_1_2 12 -75 y_1_2 16 -75 t 17 -75 x_1_2 19 -75 t 20 -75 y_1_2 23 -75 t 24 -75 y_1_2 27 -75 t 28 -75 y_1_2 29 -76 cz 0 6 -76 cz 13 19 -76 cz 2 8 -76 cz 15 21 -76 cz 4 10 -76 cz 17 23 -76 y_1_2 1 -76 y_1_2 9 -76 t 12 -76 x_1_2 14 -76 t 16 -76 x_1_2 22 -76 y_1_2 25 -76 x_1_2 26 -76 t 27 -76 t 29 -77 cz 2 3 -77 cz 6 7 -77 cz 10 11 -77 cz 14 15 -77 cz 18 19 -77 cz 22 23 -77 cz 26 27 -77 y_1_2 0 -77 t 1 -77 y_1_2 4 -77 y_1_2 8 -77 t 9 -77 x_1_2 13 -77 x_1_2 17 -77 y_1_2 21 -77 t 25 -78 cz 18 24 -78 cz 7 13 -78 cz 20 26 -78 cz 9 15 -78 cz 22 28 -78 cz 11 17 -78 t 0 -78 y_1_2 2 -78 x_1_2 3 -78 t 4 -78 y_1_2 6 -78 t 8 -78 y_1_2 10 -78 x_1_2 14 -78 y_1_2 19 -78 t 21 -78 x_1_2 23 -78 y_1_2 27 -79 cz 3 4 -79 cz 7 8 -79 cz 15 16 -79 cz 19 20 -79 cz 27 28 -79 t 2 -79 t 6 -79 y_1_2 9 -79 t 10 -79 x_1_2 11 -79 x_1_2 13 -79 t 14 -79 y_1_2 17 -79 x_1_2 18 -79 y_1_2 22 -79 t 23 -79 y_1_2 24 -79 y_1_2 26 -80 h 0 -80 h 1 -80 h 2 -80 h 3 -80 h 4 -80 h 5 -80 h 6 -80 h 7 -80 h 8 -80 h 9 -80 h 10 -80 h 11 -80 h 12 -80 h 13 -80 h 14 -80 h 15 -80 h 16 -80 h 17 -80 h 18 -80 h 19 -80 h 20 -80 h 21 -80 h 22 -80 h 23 -80 h 24 -80 h 25 -80 h 26 -80 h 27 -80 h 28 -80 h 29 diff --git a/test/circuits/grcs/inst_7x7_80_9_v2.txt b/test/circuits/grcs/inst_7x7_80_9_v2.txt deleted file mode 100644 index c7aa55480..000000000 --- a/test/circuits/grcs/inst_7x7_80_9_v2.txt +++ /dev/null @@ -1,2433 +0,0 @@ -49 -0 h 0 -0 h 1 -0 h 2 -0 h 3 -0 h 4 -0 h 5 -0 h 6 -0 h 7 -0 h 8 -0 h 9 -0 h 10 -0 h 11 -0 h 12 -0 h 13 -0 h 14 -0 h 15 -0 h 16 -0 h 17 -0 h 18 -0 h 19 -0 h 20 -0 h 21 -0 h 22 -0 h 23 -0 h 24 -0 h 25 -0 h 26 -0 h 27 -0 h 28 -0 h 29 -0 h 30 -0 h 31 -0 h 32 -0 h 33 -0 h 34 -0 h 35 -0 h 36 -0 h 37 -0 h 38 -0 h 39 -0 h 40 -0 h 41 -0 h 42 -0 h 43 -0 h 44 -0 h 45 -0 h 46 -0 h 47 -0 h 48 -1 cz 0 1 -1 cz 4 5 -1 cz 9 10 -1 cz 14 15 -1 cz 18 19 -1 cz 23 24 -1 cz 28 29 -1 cz 32 33 -1 cz 37 38 -1 cz 42 43 -1 cz 46 47 -1 t 2 -1 t 3 -1 t 6 -1 t 7 -1 t 8 -1 t 11 -1 t 12 -1 t 13 -1 t 16 -1 t 17 -1 t 20 -1 t 21 -1 t 22 -1 t 25 -1 t 26 -1 t 27 -1 t 30 -1 t 31 -1 t 34 -1 t 35 -1 t 36 -1 t 39 -1 t 40 -1 t 41 -1 t 44 -1 t 45 -1 t 48 -2 cz 7 14 -2 cz 35 42 -2 cz 22 29 -2 cz 9 16 -2 cz 37 44 -2 cz 24 31 -2 cz 11 18 -2 cz 39 46 -2 cz 26 33 -2 cz 13 20 -2 cz 41 48 -2 x_1_2 0 -2 x_1_2 1 -2 x_1_2 4 -2 y_1_2 5 -2 x_1_2 10 -2 y_1_2 15 -2 y_1_2 19 -2 x_1_2 23 -2 y_1_2 28 -2 y_1_2 32 -2 x_1_2 38 -2 x_1_2 43 -2 y_1_2 47 -3 cz 1 2 -3 cz 5 6 -3 cz 10 11 -3 cz 15 16 -3 cz 19 20 -3 cz 24 25 -3 cz 29 30 -3 cz 33 34 -3 cz 38 39 -3 cz 43 44 -3 cz 47 48 -3 t 0 -3 t 4 -3 x_1_2 7 -3 y_1_2 9 -3 x_1_2 13 -3 x_1_2 14 -3 x_1_2 18 -3 y_1_2 22 -3 t 23 -3 y_1_2 26 -3 t 28 -3 y_1_2 31 -3 t 32 -3 y_1_2 35 -3 x_1_2 37 -3 y_1_2 41 -3 x_1_2 42 -3 x_1_2 46 -4 cz 0 7 -4 cz 28 35 -4 cz 15 22 -4 cz 2 9 -4 cz 30 37 -4 cz 17 24 -4 cz 4 11 -4 cz 32 39 -4 cz 19 26 -4 cz 6 13 -4 cz 34 41 -4 y_1_2 1 -4 y_1_2 5 -4 x_1_2 10 -4 t 14 -4 x_1_2 16 -4 t 18 -4 x_1_2 20 -4 x_1_2 25 -4 x_1_2 29 -4 t 31 -4 y_1_2 33 -4 x_1_2 38 -4 t 42 -4 y_1_2 43 -4 y_1_2 44 -4 t 46 -4 x_1_2 47 -4 x_1_2 48 -5 cz 2 3 -5 cz 7 8 -5 cz 11 12 -5 cz 16 17 -5 cz 21 22 -5 cz 25 26 -5 cz 30 31 -5 cz 35 36 -5 cz 39 40 -5 cz 44 45 -5 x_1_2 0 -5 t 1 -5 x_1_2 4 -5 t 5 -5 x_1_2 6 -5 y_1_2 9 -5 t 10 -5 x_1_2 13 -5 y_1_2 15 -5 x_1_2 19 -5 t 20 -5 y_1_2 24 -5 y_1_2 28 -5 t 29 -5 x_1_2 32 -5 t 33 -5 x_1_2 34 -5 x_1_2 37 -5 t 38 -5 y_1_2 41 -5 t 43 -5 t 47 -5 t 48 -6 cz 21 28 -6 cz 8 15 -6 cz 36 43 -6 cz 23 30 -6 cz 10 17 -6 cz 38 45 -6 cz 25 32 -6 cz 12 19 -6 cz 40 47 -6 cz 27 34 -6 t 0 -6 x_1_2 2 -6 x_1_2 3 -6 t 4 -6 t 6 -6 x_1_2 7 -6 t 9 -6 y_1_2 11 -6 t 13 -6 x_1_2 16 -6 x_1_2 22 -6 t 24 -6 y_1_2 26 -6 x_1_2 31 -6 y_1_2 35 -6 t 37 -6 x_1_2 39 -6 t 41 -6 y_1_2 44 -7 cz 3 4 -7 cz 8 9 -7 cz 12 13 -7 cz 17 18 -7 cz 22 23 -7 cz 26 27 -7 cz 31 32 -7 cz 36 37 -7 cz 40 41 -7 cz 45 46 -7 t 2 -7 t 7 -7 y_1_2 10 -7 t 11 -7 x_1_2 15 -7 t 16 -7 y_1_2 19 -7 y_1_2 21 -7 x_1_2 25 -7 x_1_2 28 -7 y_1_2 30 -7 y_1_2 34 -7 t 35 -7 x_1_2 38 -7 t 39 -7 y_1_2 43 -7 t 44 -7 y_1_2 47 -8 cz 14 21 -8 cz 1 8 -8 cz 29 36 -8 cz 16 23 -8 cz 3 10 -8 cz 31 38 -8 cz 18 25 -8 cz 5 12 -8 cz 33 40 -8 cz 20 27 -8 x_1_2 4 -8 y_1_2 9 -8 x_1_2 13 -8 t 15 -8 x_1_2 17 -8 t 19 -8 y_1_2 22 -8 y_1_2 26 -8 t 28 -8 t 30 -8 y_1_2 32 -8 t 34 -8 x_1_2 37 -8 x_1_2 41 -8 t 43 -8 y_1_2 45 -8 y_1_2 46 -8 t 47 -9 cz 0 1 -9 cz 4 5 -9 cz 9 10 -9 cz 14 15 -9 cz 18 19 -9 cz 23 24 -9 cz 28 29 -9 cz 32 33 -9 cz 37 38 -9 cz 42 43 -9 cz 46 47 -9 x_1_2 3 -9 x_1_2 8 -9 y_1_2 12 -9 t 13 -9 y_1_2 16 -9 t 17 -9 x_1_2 20 -9 y_1_2 21 -9 t 22 -9 x_1_2 25 -9 t 26 -9 x_1_2 27 -9 x_1_2 31 -9 x_1_2 36 -9 x_1_2 40 -9 t 41 -9 t 45 -10 cz 7 14 -10 cz 35 42 -10 cz 22 29 -10 cz 9 16 -10 cz 37 44 -10 cz 24 31 -10 cz 11 18 -10 cz 39 46 -10 cz 26 33 -10 cz 13 20 -10 cz 41 48 -10 x_1_2 0 -10 y_1_2 1 -10 t 3 -10 x_1_2 4 -10 y_1_2 5 -10 t 8 -10 x_1_2 10 -10 t 12 -10 y_1_2 15 -10 y_1_2 19 -10 t 21 -10 x_1_2 23 -10 t 25 -10 t 27 -10 y_1_2 28 -10 x_1_2 32 -10 t 36 -10 y_1_2 38 -10 t 40 -10 x_1_2 43 -10 x_1_2 47 -11 cz 1 2 -11 cz 5 6 -11 cz 10 11 -11 cz 15 16 -11 cz 19 20 -11 cz 24 25 -11 cz 29 30 -11 cz 33 34 -11 cz 38 39 -11 cz 43 44 -11 cz 47 48 -11 t 0 -11 t 4 -11 y_1_2 7 -11 x_1_2 9 -11 x_1_2 13 -11 y_1_2 14 -11 x_1_2 18 -11 y_1_2 22 -11 t 23 -11 x_1_2 26 -11 t 28 -11 y_1_2 31 -11 t 32 -11 x_1_2 35 -11 x_1_2 37 -11 y_1_2 41 -11 x_1_2 42 -11 y_1_2 46 -12 cz 0 7 -12 cz 28 35 -12 cz 15 22 -12 cz 2 9 -12 cz 30 37 -12 cz 17 24 -12 cz 4 11 -12 cz 32 39 -12 cz 19 26 -12 cz 6 13 -12 cz 34 41 -12 y_1_2 1 -12 y_1_2 5 -12 x_1_2 10 -12 t 14 -12 x_1_2 16 -12 t 18 -12 x_1_2 20 -12 x_1_2 25 -12 y_1_2 29 -12 t 31 -12 y_1_2 33 -12 x_1_2 38 -12 t 42 -12 x_1_2 43 -12 y_1_2 44 -12 t 46 -12 x_1_2 47 -12 x_1_2 48 -13 cz 2 3 -13 cz 7 8 -13 cz 11 12 -13 cz 16 17 -13 cz 21 22 -13 cz 25 26 -13 cz 30 31 -13 cz 35 36 -13 cz 39 40 -13 cz 44 45 -13 y_1_2 0 -13 t 1 -13 y_1_2 4 -13 t 5 -13 x_1_2 6 -13 x_1_2 9 -13 t 10 -13 y_1_2 13 -13 y_1_2 15 -13 x_1_2 19 -13 t 20 -13 y_1_2 24 -13 x_1_2 28 -13 t 29 -13 y_1_2 32 -13 t 33 -13 y_1_2 34 -13 y_1_2 37 -13 t 38 -13 x_1_2 41 -13 t 43 -13 t 47 -13 t 48 -14 cz 21 28 -14 cz 8 15 -14 cz 36 43 -14 cz 23 30 -14 cz 10 17 -14 cz 38 45 -14 cz 25 32 -14 cz 12 19 -14 cz 40 47 -14 cz 27 34 -14 t 0 -14 x_1_2 2 -14 x_1_2 3 -14 t 4 -14 t 6 -14 y_1_2 7 -14 t 9 -14 x_1_2 11 -14 t 13 -14 y_1_2 16 -14 x_1_2 22 -14 t 24 -14 y_1_2 26 -14 x_1_2 31 -14 x_1_2 35 -14 t 37 -14 x_1_2 39 -14 t 41 -14 x_1_2 44 -15 cz 3 4 -15 cz 8 9 -15 cz 12 13 -15 cz 17 18 -15 cz 22 23 -15 cz 26 27 -15 cz 31 32 -15 cz 36 37 -15 cz 40 41 -15 cz 45 46 -15 t 2 -15 t 7 -15 y_1_2 10 -15 t 11 -15 x_1_2 15 -15 t 16 -15 x_1_2 19 -15 x_1_2 21 -15 y_1_2 25 -15 y_1_2 28 -15 y_1_2 30 -15 x_1_2 34 -15 t 35 -15 y_1_2 38 -15 t 39 -15 y_1_2 43 -15 t 44 -15 y_1_2 47 -16 cz 14 21 -16 cz 1 8 -16 cz 29 36 -16 cz 16 23 -16 cz 3 10 -16 cz 31 38 -16 cz 18 25 -16 cz 5 12 -16 cz 33 40 -16 cz 20 27 -16 y_1_2 4 -16 y_1_2 9 -16 y_1_2 13 -16 t 15 -16 x_1_2 17 -16 t 19 -16 y_1_2 22 -16 y_1_2 26 -16 t 28 -16 t 30 -16 x_1_2 32 -16 t 34 -16 y_1_2 37 -16 y_1_2 41 -16 t 43 -16 x_1_2 45 -16 y_1_2 46 -16 t 47 -17 cz 0 1 -17 cz 4 5 -17 cz 9 10 -17 cz 14 15 -17 cz 18 19 -17 cz 23 24 -17 cz 28 29 -17 cz 32 33 -17 cz 37 38 -17 cz 42 43 -17 cz 46 47 -17 x_1_2 3 -17 x_1_2 8 -17 y_1_2 12 -17 t 13 -17 x_1_2 16 -17 t 17 -17 y_1_2 20 -17 x_1_2 21 -17 t 22 -17 y_1_2 25 -17 t 26 -17 x_1_2 27 -17 y_1_2 31 -17 y_1_2 36 -17 y_1_2 40 -17 t 41 -17 t 45 -18 cz 7 14 -18 cz 35 42 -18 cz 22 29 -18 cz 9 16 -18 cz 37 44 -18 cz 24 31 -18 cz 11 18 -18 cz 39 46 -18 cz 26 33 -18 cz 13 20 -18 cz 41 48 -18 y_1_2 0 -18 x_1_2 1 -18 t 3 -18 y_1_2 4 -18 y_1_2 5 -18 t 8 -18 y_1_2 10 -18 t 12 -18 x_1_2 15 -18 x_1_2 19 -18 t 21 -18 x_1_2 23 -18 t 25 -18 t 27 -18 y_1_2 28 -18 x_1_2 32 -18 t 36 -18 x_1_2 38 -18 t 40 -18 x_1_2 43 -18 x_1_2 47 -19 cz 1 2 -19 cz 5 6 -19 cz 10 11 -19 cz 15 16 -19 cz 19 20 -19 cz 24 25 -19 cz 29 30 -19 cz 33 34 -19 cz 38 39 -19 cz 43 44 -19 cz 47 48 -19 t 0 -19 t 4 -19 y_1_2 7 -19 x_1_2 9 -19 y_1_2 13 -19 x_1_2 14 -19 y_1_2 18 -19 x_1_2 22 -19 t 23 -19 y_1_2 26 -19 t 28 -19 y_1_2 31 -19 t 32 -19 y_1_2 35 -19 y_1_2 37 -19 y_1_2 41 -19 x_1_2 42 -19 x_1_2 46 -20 cz 0 7 -20 cz 28 35 -20 cz 15 22 -20 cz 2 9 -20 cz 30 37 -20 cz 17 24 -20 cz 4 11 -20 cz 32 39 -20 cz 19 26 -20 cz 6 13 -20 cz 34 41 -20 x_1_2 1 -20 y_1_2 5 -20 x_1_2 10 -20 t 14 -20 x_1_2 16 -20 t 18 -20 x_1_2 20 -20 x_1_2 25 -20 y_1_2 29 -20 t 31 -20 y_1_2 33 -20 x_1_2 38 -20 t 42 -20 y_1_2 43 -20 x_1_2 44 -20 t 46 -20 y_1_2 47 -20 x_1_2 48 -21 cz 2 3 -21 cz 7 8 -21 cz 11 12 -21 cz 16 17 -21 cz 21 22 -21 cz 25 26 -21 cz 30 31 -21 cz 35 36 -21 cz 39 40 -21 cz 44 45 -21 y_1_2 0 -21 t 1 -21 x_1_2 4 -21 t 5 -21 x_1_2 6 -21 y_1_2 9 -21 t 10 -21 x_1_2 13 -21 x_1_2 15 -21 y_1_2 19 -21 t 20 -21 x_1_2 24 -21 x_1_2 28 -21 t 29 -21 y_1_2 32 -21 t 33 -21 x_1_2 34 -21 x_1_2 37 -21 t 38 -21 y_1_2 41 -21 t 43 -21 t 47 -21 t 48 -22 cz 21 28 -22 cz 8 15 -22 cz 36 43 -22 cz 23 30 -22 cz 10 17 -22 cz 38 45 -22 cz 25 32 -22 cz 12 19 -22 cz 40 47 -22 cz 27 34 -22 t 0 -22 y_1_2 2 -22 x_1_2 3 -22 t 4 -22 t 6 -22 x_1_2 7 -22 t 9 -22 x_1_2 11 -22 t 13 -22 x_1_2 16 -22 y_1_2 22 -22 t 24 -22 y_1_2 26 -22 y_1_2 31 -22 y_1_2 35 -22 t 37 -22 y_1_2 39 -22 t 41 -22 y_1_2 44 -23 cz 3 4 -23 cz 8 9 -23 cz 12 13 -23 cz 17 18 -23 cz 22 23 -23 cz 26 27 -23 cz 31 32 -23 cz 36 37 -23 cz 40 41 -23 cz 45 46 -23 t 2 -23 t 7 -23 y_1_2 10 -23 t 11 -23 y_1_2 15 -23 t 16 -23 x_1_2 19 -23 x_1_2 21 -23 x_1_2 25 -23 y_1_2 28 -23 x_1_2 30 -23 x_1_2 34 -23 t 35 -23 y_1_2 38 -23 t 39 -23 x_1_2 43 -23 t 44 -23 x_1_2 47 -24 cz 14 21 -24 cz 1 8 -24 cz 29 36 -24 cz 16 23 -24 cz 3 10 -24 cz 31 38 -24 cz 18 25 -24 cz 5 12 -24 cz 33 40 -24 cz 20 27 -24 x_1_2 4 -24 x_1_2 9 -24 y_1_2 13 -24 t 15 -24 y_1_2 17 -24 t 19 -24 x_1_2 22 -24 x_1_2 26 -24 t 28 -24 t 30 -24 x_1_2 32 -24 t 34 -24 x_1_2 37 -24 x_1_2 41 -24 t 43 -24 y_1_2 45 -24 x_1_2 46 -24 t 47 -25 cz 0 1 -25 cz 4 5 -25 cz 9 10 -25 cz 14 15 -25 cz 18 19 -25 cz 23 24 -25 cz 28 29 -25 cz 32 33 -25 cz 37 38 -25 cz 42 43 -25 cz 46 47 -25 y_1_2 3 -25 y_1_2 8 -25 x_1_2 12 -25 t 13 -25 y_1_2 16 -25 t 17 -25 x_1_2 20 -25 x_1_2 21 -25 t 22 -25 y_1_2 25 -25 t 26 -25 y_1_2 27 -25 y_1_2 31 -25 y_1_2 36 -25 x_1_2 40 -25 t 41 -25 t 45 -26 cz 7 14 -26 cz 35 42 -26 cz 22 29 -26 cz 9 16 -26 cz 37 44 -26 cz 24 31 -26 cz 11 18 -26 cz 39 46 -26 cz 26 33 -26 cz 13 20 -26 cz 41 48 -26 y_1_2 0 -26 x_1_2 1 -26 t 3 -26 x_1_2 4 -26 y_1_2 5 -26 t 8 -26 x_1_2 10 -26 t 12 -26 y_1_2 15 -26 x_1_2 19 -26 t 21 -26 y_1_2 23 -26 t 25 -26 t 27 -26 y_1_2 28 -26 x_1_2 32 -26 t 36 -26 y_1_2 38 -26 t 40 -26 x_1_2 43 -26 y_1_2 47 -27 cz 1 2 -27 cz 5 6 -27 cz 10 11 -27 cz 15 16 -27 cz 19 20 -27 cz 24 25 -27 cz 29 30 -27 cz 33 34 -27 cz 38 39 -27 cz 43 44 -27 cz 47 48 -27 t 0 -27 t 4 -27 x_1_2 7 -27 x_1_2 9 -27 y_1_2 13 -27 x_1_2 14 -27 x_1_2 18 -27 x_1_2 22 -27 t 23 -27 x_1_2 26 -27 t 28 -27 y_1_2 31 -27 t 32 -27 y_1_2 35 -27 y_1_2 37 -27 x_1_2 41 -27 y_1_2 42 -27 y_1_2 46 -28 cz 0 7 -28 cz 28 35 -28 cz 15 22 -28 cz 2 9 -28 cz 30 37 -28 cz 17 24 -28 cz 4 11 -28 cz 32 39 -28 cz 19 26 -28 cz 6 13 -28 cz 34 41 -28 x_1_2 1 -28 y_1_2 5 -28 x_1_2 10 -28 t 14 -28 x_1_2 16 -28 t 18 -28 x_1_2 20 -28 x_1_2 25 -28 x_1_2 29 -28 t 31 -28 y_1_2 33 -28 y_1_2 38 -28 t 42 -28 y_1_2 43 -28 x_1_2 44 -28 t 46 -28 y_1_2 47 -28 x_1_2 48 -29 cz 2 3 -29 cz 7 8 -29 cz 11 12 -29 cz 16 17 -29 cz 21 22 -29 cz 25 26 -29 cz 30 31 -29 cz 35 36 -29 cz 39 40 -29 cz 44 45 -29 x_1_2 0 -29 t 1 -29 y_1_2 4 -29 t 5 -29 y_1_2 6 -29 y_1_2 9 -29 t 10 -29 y_1_2 13 -29 x_1_2 15 -29 x_1_2 19 -29 t 20 -29 x_1_2 24 -29 y_1_2 28 -29 t 29 -29 x_1_2 32 -29 t 33 -29 x_1_2 34 -29 y_1_2 37 -29 t 38 -29 x_1_2 41 -29 t 43 -29 t 47 -29 t 48 -30 cz 21 28 -30 cz 8 15 -30 cz 36 43 -30 cz 23 30 -30 cz 10 17 -30 cz 38 45 -30 cz 25 32 -30 cz 12 19 -30 cz 40 47 -30 cz 27 34 -30 t 0 -30 y_1_2 2 -30 y_1_2 3 -30 t 4 -30 t 6 -30 y_1_2 7 -30 t 9 -30 x_1_2 11 -30 t 13 -30 x_1_2 16 -30 y_1_2 22 -30 t 24 -30 y_1_2 26 -30 x_1_2 31 -30 x_1_2 35 -30 t 37 -30 x_1_2 39 -30 t 41 -30 y_1_2 44 -31 cz 3 4 -31 cz 8 9 -31 cz 12 13 -31 cz 17 18 -31 cz 22 23 -31 cz 26 27 -31 cz 31 32 -31 cz 36 37 -31 cz 40 41 -31 cz 45 46 -31 t 2 -31 t 7 -31 y_1_2 10 -31 t 11 -31 x_1_2 15 -31 t 16 -31 x_1_2 19 -31 y_1_2 21 -31 x_1_2 25 -31 y_1_2 28 -31 y_1_2 30 -31 y_1_2 34 -31 t 35 -31 y_1_2 38 -31 t 39 -31 x_1_2 43 -31 t 44 -31 x_1_2 47 -32 cz 14 21 -32 cz 1 8 -32 cz 29 36 -32 cz 16 23 -32 cz 3 10 -32 cz 31 38 -32 cz 18 25 -32 cz 5 12 -32 cz 33 40 -32 cz 20 27 -32 y_1_2 4 -32 x_1_2 9 -32 x_1_2 13 -32 t 15 -32 y_1_2 17 -32 t 19 -32 y_1_2 22 -32 y_1_2 26 -32 t 28 -32 t 30 -32 y_1_2 32 -32 t 34 -32 y_1_2 37 -32 x_1_2 41 -32 t 43 -32 x_1_2 45 -32 y_1_2 46 -32 t 47 -33 cz 0 1 -33 cz 4 5 -33 cz 9 10 -33 cz 14 15 -33 cz 18 19 -33 cz 23 24 -33 cz 28 29 -33 cz 32 33 -33 cz 37 38 -33 cz 42 43 -33 cz 46 47 -33 y_1_2 3 -33 y_1_2 8 -33 x_1_2 12 -33 t 13 -33 y_1_2 16 -33 t 17 -33 y_1_2 20 -33 y_1_2 21 -33 t 22 -33 y_1_2 25 -33 t 26 -33 y_1_2 27 -33 x_1_2 31 -33 x_1_2 36 -33 y_1_2 40 -33 t 41 -33 t 45 -34 cz 7 14 -34 cz 35 42 -34 cz 22 29 -34 cz 9 16 -34 cz 37 44 -34 cz 24 31 -34 cz 11 18 -34 cz 39 46 -34 cz 26 33 -34 cz 13 20 -34 cz 41 48 -34 y_1_2 0 -34 x_1_2 1 -34 t 3 -34 y_1_2 4 -34 x_1_2 5 -34 t 8 -34 x_1_2 10 -34 t 12 -34 x_1_2 15 -34 x_1_2 19 -34 t 21 -34 x_1_2 23 -34 t 25 -34 t 27 -34 y_1_2 28 -34 x_1_2 32 -34 t 36 -34 y_1_2 38 -34 t 40 -34 x_1_2 43 -34 x_1_2 47 -35 cz 1 2 -35 cz 5 6 -35 cz 10 11 -35 cz 15 16 -35 cz 19 20 -35 cz 24 25 -35 cz 29 30 -35 cz 33 34 -35 cz 38 39 -35 cz 43 44 -35 cz 47 48 -35 t 0 -35 t 4 -35 x_1_2 7 -35 y_1_2 9 -35 x_1_2 13 -35 y_1_2 14 -35 y_1_2 18 -35 y_1_2 22 -35 t 23 -35 y_1_2 26 -35 t 28 -35 y_1_2 31 -35 t 32 -35 y_1_2 35 -35 x_1_2 37 -35 x_1_2 41 -35 y_1_2 42 -35 x_1_2 46 -36 cz 0 7 -36 cz 28 35 -36 cz 15 22 -36 cz 2 9 -36 cz 30 37 -36 cz 17 24 -36 cz 4 11 -36 cz 32 39 -36 cz 19 26 -36 cz 6 13 -36 cz 34 41 -36 x_1_2 1 -36 x_1_2 5 -36 x_1_2 10 -36 t 14 -36 y_1_2 16 -36 t 18 -36 y_1_2 20 -36 x_1_2 25 -36 y_1_2 29 -36 t 31 -36 y_1_2 33 -36 x_1_2 38 -36 t 42 -36 y_1_2 43 -36 y_1_2 44 -36 t 46 -36 x_1_2 47 -36 x_1_2 48 -37 cz 2 3 -37 cz 7 8 -37 cz 11 12 -37 cz 16 17 -37 cz 21 22 -37 cz 25 26 -37 cz 30 31 -37 cz 35 36 -37 cz 39 40 -37 cz 44 45 -37 x_1_2 0 -37 t 1 -37 x_1_2 4 -37 t 5 -37 y_1_2 6 -37 x_1_2 9 -37 t 10 -37 y_1_2 13 -37 x_1_2 15 -37 x_1_2 19 -37 t 20 -37 x_1_2 24 -37 x_1_2 28 -37 t 29 -37 x_1_2 32 -37 t 33 -37 x_1_2 34 -37 x_1_2 37 -37 t 38 -37 y_1_2 41 -37 t 43 -37 t 47 -37 t 48 -38 cz 21 28 -38 cz 8 15 -38 cz 36 43 -38 cz 23 30 -38 cz 10 17 -38 cz 38 45 -38 cz 25 32 -38 cz 12 19 -38 cz 40 47 -38 cz 27 34 -38 t 0 -38 y_1_2 2 -38 x_1_2 3 -38 t 4 -38 t 6 -38 y_1_2 7 -38 t 9 -38 x_1_2 11 -38 t 13 -38 y_1_2 16 -38 y_1_2 22 -38 t 24 -38 x_1_2 26 -38 y_1_2 31 -38 x_1_2 35 -38 t 37 -38 x_1_2 39 -38 t 41 -38 x_1_2 44 -39 cz 3 4 -39 cz 8 9 -39 cz 12 13 -39 cz 17 18 -39 cz 22 23 -39 cz 26 27 -39 cz 31 32 -39 cz 36 37 -39 cz 40 41 -39 cz 45 46 -39 t 2 -39 t 7 -39 y_1_2 10 -39 t 11 -39 y_1_2 15 -39 t 16 -39 x_1_2 19 -39 y_1_2 21 -39 y_1_2 25 -39 x_1_2 28 -39 y_1_2 30 -39 y_1_2 34 -39 t 35 -39 y_1_2 38 -39 t 39 -39 x_1_2 43 -39 t 44 -39 y_1_2 47 -40 cz 14 21 -40 cz 1 8 -40 cz 29 36 -40 cz 16 23 -40 cz 3 10 -40 cz 31 38 -40 cz 18 25 -40 cz 5 12 -40 cz 33 40 -40 cz 20 27 -40 y_1_2 4 -40 y_1_2 9 -40 x_1_2 13 -40 t 15 -40 y_1_2 17 -40 t 19 -40 y_1_2 22 -40 x_1_2 26 -40 t 28 -40 t 30 -40 y_1_2 32 -40 t 34 -40 y_1_2 37 -40 x_1_2 41 -40 t 43 -40 y_1_2 45 -40 x_1_2 46 -40 t 47 -41 cz 0 1 -41 cz 4 5 -41 cz 9 10 -41 cz 14 15 -41 cz 18 19 -41 cz 23 24 -41 cz 28 29 -41 cz 32 33 -41 cz 37 38 -41 cz 42 43 -41 cz 46 47 -41 x_1_2 3 -41 x_1_2 8 -41 y_1_2 12 -41 t 13 -41 y_1_2 16 -41 t 17 -41 y_1_2 20 -41 x_1_2 21 -41 t 22 -41 y_1_2 25 -41 t 26 -41 y_1_2 27 -41 y_1_2 31 -41 x_1_2 36 -41 x_1_2 40 -41 t 41 -41 t 45 -42 cz 7 14 -42 cz 35 42 -42 cz 22 29 -42 cz 9 16 -42 cz 37 44 -42 cz 24 31 -42 cz 11 18 -42 cz 39 46 -42 cz 26 33 -42 cz 13 20 -42 cz 41 48 -42 x_1_2 0 -42 x_1_2 1 -42 t 3 -42 y_1_2 4 -42 x_1_2 5 -42 t 8 -42 y_1_2 10 -42 t 12 -42 x_1_2 15 -42 y_1_2 19 -42 t 21 -42 y_1_2 23 -42 t 25 -42 t 27 -42 y_1_2 28 -42 x_1_2 32 -42 t 36 -42 x_1_2 38 -42 t 40 -42 x_1_2 43 -42 x_1_2 47 -43 cz 1 2 -43 cz 5 6 -43 cz 10 11 -43 cz 15 16 -43 cz 19 20 -43 cz 24 25 -43 cz 29 30 -43 cz 33 34 -43 cz 38 39 -43 cz 43 44 -43 cz 47 48 -43 t 0 -43 t 4 -43 y_1_2 7 -43 y_1_2 9 -43 y_1_2 13 -43 y_1_2 14 -43 x_1_2 18 -43 x_1_2 22 -43 t 23 -43 x_1_2 26 -43 t 28 -43 x_1_2 31 -43 t 32 -43 x_1_2 35 -43 y_1_2 37 -43 x_1_2 41 -43 y_1_2 42 -43 x_1_2 46 -44 cz 0 7 -44 cz 28 35 -44 cz 15 22 -44 cz 2 9 -44 cz 30 37 -44 cz 17 24 -44 cz 4 11 -44 cz 32 39 -44 cz 19 26 -44 cz 6 13 -44 cz 34 41 -44 x_1_2 1 -44 y_1_2 5 -44 x_1_2 10 -44 t 14 -44 y_1_2 16 -44 t 18 -44 y_1_2 20 -44 y_1_2 25 -44 x_1_2 29 -44 t 31 -44 y_1_2 33 -44 y_1_2 38 -44 t 42 -44 x_1_2 43 -44 x_1_2 44 -44 t 46 -44 y_1_2 47 -44 x_1_2 48 -45 cz 2 3 -45 cz 7 8 -45 cz 11 12 -45 cz 16 17 -45 cz 21 22 -45 cz 25 26 -45 cz 30 31 -45 cz 35 36 -45 cz 39 40 -45 cz 44 45 -45 y_1_2 0 -45 t 1 -45 y_1_2 4 -45 t 5 -45 x_1_2 6 -45 y_1_2 9 -45 t 10 -45 y_1_2 13 -45 x_1_2 15 -45 y_1_2 19 -45 t 20 -45 y_1_2 24 -45 x_1_2 28 -45 t 29 -45 x_1_2 32 -45 t 33 -45 x_1_2 34 -45 y_1_2 37 -45 t 38 -45 y_1_2 41 -45 t 43 -45 t 47 -45 t 48 -46 cz 21 28 -46 cz 8 15 -46 cz 36 43 -46 cz 23 30 -46 cz 10 17 -46 cz 38 45 -46 cz 25 32 -46 cz 12 19 -46 cz 40 47 -46 cz 27 34 -46 t 0 -46 x_1_2 2 -46 x_1_2 3 -46 t 4 -46 t 6 -46 y_1_2 7 -46 t 9 -46 y_1_2 11 -46 t 13 -46 x_1_2 16 -46 y_1_2 22 -46 t 24 -46 y_1_2 26 -46 y_1_2 31 -46 y_1_2 35 -46 t 37 -46 y_1_2 39 -46 t 41 -46 x_1_2 44 -47 cz 3 4 -47 cz 8 9 -47 cz 12 13 -47 cz 17 18 -47 cz 22 23 -47 cz 26 27 -47 cz 31 32 -47 cz 36 37 -47 cz 40 41 -47 cz 45 46 -47 t 2 -47 t 7 -47 x_1_2 10 -47 t 11 -47 y_1_2 15 -47 t 16 -47 x_1_2 19 -47 y_1_2 21 -47 y_1_2 25 -47 y_1_2 28 -47 x_1_2 30 -47 x_1_2 34 -47 t 35 -47 y_1_2 38 -47 t 39 -47 y_1_2 43 -47 t 44 -47 x_1_2 47 -48 cz 14 21 -48 cz 1 8 -48 cz 29 36 -48 cz 16 23 -48 cz 3 10 -48 cz 31 38 -48 cz 18 25 -48 cz 5 12 -48 cz 33 40 -48 cz 20 27 -48 y_1_2 4 -48 y_1_2 9 -48 x_1_2 13 -48 t 15 -48 y_1_2 17 -48 t 19 -48 x_1_2 22 -48 y_1_2 26 -48 t 28 -48 t 30 -48 y_1_2 32 -48 t 34 -48 x_1_2 37 -48 x_1_2 41 -48 t 43 -48 y_1_2 45 -48 x_1_2 46 -48 t 47 -49 cz 0 1 -49 cz 4 5 -49 cz 9 10 -49 cz 14 15 -49 cz 18 19 -49 cz 23 24 -49 cz 28 29 -49 cz 32 33 -49 cz 37 38 -49 cz 42 43 -49 cz 46 47 -49 y_1_2 3 -49 y_1_2 8 -49 y_1_2 12 -49 t 13 -49 x_1_2 16 -49 t 17 -49 y_1_2 20 -49 y_1_2 21 -49 t 22 -49 y_1_2 25 -49 t 26 -49 x_1_2 27 -49 x_1_2 31 -49 x_1_2 36 -49 y_1_2 40 -49 t 41 -49 t 45 -50 cz 7 14 -50 cz 35 42 -50 cz 22 29 -50 cz 9 16 -50 cz 37 44 -50 cz 24 31 -50 cz 11 18 -50 cz 39 46 -50 cz 26 33 -50 cz 13 20 -50 cz 41 48 -50 x_1_2 0 -50 x_1_2 1 -50 t 3 -50 x_1_2 4 -50 y_1_2 5 -50 t 8 -50 y_1_2 10 -50 t 12 -50 y_1_2 15 -50 x_1_2 19 -50 t 21 -50 y_1_2 23 -50 t 25 -50 t 27 -50 y_1_2 28 -50 x_1_2 32 -50 t 36 -50 x_1_2 38 -50 t 40 -50 x_1_2 43 -50 x_1_2 47 -51 cz 1 2 -51 cz 5 6 -51 cz 10 11 -51 cz 15 16 -51 cz 19 20 -51 cz 24 25 -51 cz 29 30 -51 cz 33 34 -51 cz 38 39 -51 cz 43 44 -51 cz 47 48 -51 t 0 -51 t 4 -51 y_1_2 7 -51 x_1_2 9 -51 x_1_2 13 -51 y_1_2 14 -51 x_1_2 18 -51 y_1_2 22 -51 t 23 -51 y_1_2 26 -51 t 28 -51 x_1_2 31 -51 t 32 -51 x_1_2 35 -51 x_1_2 37 -51 y_1_2 41 -51 y_1_2 42 -51 y_1_2 46 -52 cz 0 7 -52 cz 28 35 -52 cz 15 22 -52 cz 2 9 -52 cz 30 37 -52 cz 17 24 -52 cz 4 11 -52 cz 32 39 -52 cz 19 26 -52 cz 6 13 -52 cz 34 41 -52 x_1_2 1 -52 y_1_2 5 -52 x_1_2 10 -52 t 14 -52 y_1_2 16 -52 t 18 -52 x_1_2 20 -52 x_1_2 25 -52 y_1_2 29 -52 t 31 -52 x_1_2 33 -52 y_1_2 38 -52 t 42 -52 y_1_2 43 -52 x_1_2 44 -52 t 46 -52 x_1_2 47 -52 y_1_2 48 -53 cz 2 3 -53 cz 7 8 -53 cz 11 12 -53 cz 16 17 -53 cz 21 22 -53 cz 25 26 -53 cz 30 31 -53 cz 35 36 -53 cz 39 40 -53 cz 44 45 -53 x_1_2 0 -53 t 1 -53 x_1_2 4 -53 t 5 -53 y_1_2 6 -53 y_1_2 9 -53 t 10 -53 x_1_2 13 -53 y_1_2 15 -53 y_1_2 19 -53 t 20 -53 x_1_2 24 -53 x_1_2 28 -53 t 29 -53 y_1_2 32 -53 t 33 -53 x_1_2 34 -53 y_1_2 37 -53 t 38 -53 x_1_2 41 -53 t 43 -53 t 47 -53 t 48 -54 cz 21 28 -54 cz 8 15 -54 cz 36 43 -54 cz 23 30 -54 cz 10 17 -54 cz 38 45 -54 cz 25 32 -54 cz 12 19 -54 cz 40 47 -54 cz 27 34 -54 t 0 -54 x_1_2 2 -54 x_1_2 3 -54 t 4 -54 t 6 -54 x_1_2 7 -54 t 9 -54 x_1_2 11 -54 t 13 -54 x_1_2 16 -54 x_1_2 22 -54 t 24 -54 y_1_2 26 -54 y_1_2 31 -54 y_1_2 35 -54 t 37 -54 x_1_2 39 -54 t 41 -54 y_1_2 44 -55 cz 3 4 -55 cz 8 9 -55 cz 12 13 -55 cz 17 18 -55 cz 22 23 -55 cz 26 27 -55 cz 31 32 -55 cz 36 37 -55 cz 40 41 -55 cz 45 46 -55 t 2 -55 t 7 -55 x_1_2 10 -55 t 11 -55 x_1_2 15 -55 t 16 -55 y_1_2 19 -55 x_1_2 21 -55 x_1_2 25 -55 y_1_2 28 -55 x_1_2 30 -55 x_1_2 34 -55 t 35 -55 x_1_2 38 -55 t 39 -55 y_1_2 43 -55 t 44 -55 y_1_2 47 -56 cz 14 21 -56 cz 1 8 -56 cz 29 36 -56 cz 16 23 -56 cz 3 10 -56 cz 31 38 -56 cz 18 25 -56 cz 5 12 -56 cz 33 40 -56 cz 20 27 -56 x_1_2 4 -56 x_1_2 9 -56 y_1_2 13 -56 t 15 -56 x_1_2 17 -56 t 19 -56 y_1_2 22 -56 y_1_2 26 -56 t 28 -56 t 30 -56 y_1_2 32 -56 t 34 -56 x_1_2 37 -56 x_1_2 41 -56 t 43 -56 x_1_2 45 -56 y_1_2 46 -56 t 47 -57 cz 0 1 -57 cz 4 5 -57 cz 9 10 -57 cz 14 15 -57 cz 18 19 -57 cz 23 24 -57 cz 28 29 -57 cz 32 33 -57 cz 37 38 -57 cz 42 43 -57 cz 46 47 -57 x_1_2 3 -57 x_1_2 8 -57 x_1_2 12 -57 t 13 -57 x_1_2 16 -57 t 17 -57 y_1_2 20 -57 y_1_2 21 -57 t 22 -57 y_1_2 25 -57 t 26 -57 y_1_2 27 -57 x_1_2 31 -57 y_1_2 36 -57 y_1_2 40 -57 t 41 -57 t 45 -58 cz 7 14 -58 cz 35 42 -58 cz 22 29 -58 cz 9 16 -58 cz 37 44 -58 cz 24 31 -58 cz 11 18 -58 cz 39 46 -58 cz 26 33 -58 cz 13 20 -58 cz 41 48 -58 y_1_2 0 -58 y_1_2 1 -58 t 3 -58 y_1_2 4 -58 y_1_2 5 -58 t 8 -58 x_1_2 10 -58 t 12 -58 x_1_2 15 -58 x_1_2 19 -58 t 21 -58 x_1_2 23 -58 t 25 -58 t 27 -58 x_1_2 28 -58 x_1_2 32 -58 t 36 -58 x_1_2 38 -58 t 40 -58 x_1_2 43 -58 x_1_2 47 -59 cz 1 2 -59 cz 5 6 -59 cz 10 11 -59 cz 15 16 -59 cz 19 20 -59 cz 24 25 -59 cz 29 30 -59 cz 33 34 -59 cz 38 39 -59 cz 43 44 -59 cz 47 48 -59 t 0 -59 t 4 -59 x_1_2 7 -59 y_1_2 9 -59 y_1_2 13 -59 x_1_2 14 -59 y_1_2 18 -59 x_1_2 22 -59 t 23 -59 y_1_2 26 -59 t 28 -59 y_1_2 31 -59 t 32 -59 y_1_2 35 -59 x_1_2 37 -59 y_1_2 41 -59 x_1_2 42 -59 y_1_2 46 -60 cz 0 7 -60 cz 28 35 -60 cz 15 22 -60 cz 2 9 -60 cz 30 37 -60 cz 17 24 -60 cz 4 11 -60 cz 32 39 -60 cz 19 26 -60 cz 6 13 -60 cz 34 41 -60 x_1_2 1 -60 x_1_2 5 -60 x_1_2 10 -60 t 14 -60 x_1_2 16 -60 t 18 -60 y_1_2 20 -60 x_1_2 25 -60 y_1_2 29 -60 t 31 -60 x_1_2 33 -60 x_1_2 38 -60 t 42 -60 y_1_2 43 -60 y_1_2 44 -60 t 46 -60 x_1_2 47 -60 y_1_2 48 -61 cz 2 3 -61 cz 7 8 -61 cz 11 12 -61 cz 16 17 -61 cz 21 22 -61 cz 25 26 -61 cz 30 31 -61 cz 35 36 -61 cz 39 40 -61 cz 44 45 -61 x_1_2 0 -61 t 1 -61 x_1_2 4 -61 t 5 -61 y_1_2 6 -61 y_1_2 9 -61 t 10 -61 y_1_2 13 -61 y_1_2 15 -61 y_1_2 19 -61 t 20 -61 y_1_2 24 -61 y_1_2 28 -61 t 29 -61 x_1_2 32 -61 t 33 -61 y_1_2 34 -61 x_1_2 37 -61 t 38 -61 y_1_2 41 -61 t 43 -61 t 47 -61 t 48 -62 cz 21 28 -62 cz 8 15 -62 cz 36 43 -62 cz 23 30 -62 cz 10 17 -62 cz 38 45 -62 cz 25 32 -62 cz 12 19 -62 cz 40 47 -62 cz 27 34 -62 t 0 -62 x_1_2 2 -62 x_1_2 3 -62 t 4 -62 t 6 -62 x_1_2 7 -62 t 9 -62 x_1_2 11 -62 t 13 -62 y_1_2 16 -62 y_1_2 22 -62 t 24 -62 y_1_2 26 -62 x_1_2 31 -62 y_1_2 35 -62 t 37 -62 x_1_2 39 -62 t 41 -62 x_1_2 44 -63 cz 3 4 -63 cz 8 9 -63 cz 12 13 -63 cz 17 18 -63 cz 22 23 -63 cz 26 27 -63 cz 31 32 -63 cz 36 37 -63 cz 40 41 -63 cz 45 46 -63 t 2 -63 t 7 -63 x_1_2 10 -63 t 11 -63 y_1_2 15 -63 t 16 -63 x_1_2 19 -63 x_1_2 21 -63 x_1_2 25 -63 x_1_2 28 -63 x_1_2 30 -63 x_1_2 34 -63 t 35 -63 y_1_2 38 -63 t 39 -63 x_1_2 43 -63 t 44 -63 y_1_2 47 -64 cz 14 21 -64 cz 1 8 -64 cz 29 36 -64 cz 16 23 -64 cz 3 10 -64 cz 31 38 -64 cz 18 25 -64 cz 5 12 -64 cz 33 40 -64 cz 20 27 -64 y_1_2 4 -64 x_1_2 9 -64 y_1_2 13 -64 t 15 -64 x_1_2 17 -64 t 19 -64 x_1_2 22 -64 y_1_2 26 -64 t 28 -64 t 30 -64 x_1_2 32 -64 t 34 -64 x_1_2 37 -64 x_1_2 41 -64 t 43 -64 y_1_2 45 -64 y_1_2 46 -64 t 47 -65 cz 0 1 -65 cz 4 5 -65 cz 9 10 -65 cz 14 15 -65 cz 18 19 -65 cz 23 24 -65 cz 28 29 -65 cz 32 33 -65 cz 37 38 -65 cz 42 43 -65 cz 46 47 -65 x_1_2 3 -65 y_1_2 8 -65 y_1_2 12 -65 t 13 -65 y_1_2 16 -65 t 17 -65 x_1_2 20 -65 x_1_2 21 -65 t 22 -65 x_1_2 25 -65 t 26 -65 x_1_2 27 -65 x_1_2 31 -65 y_1_2 36 -65 y_1_2 40 -65 t 41 -65 t 45 -66 cz 7 14 -66 cz 35 42 -66 cz 22 29 -66 cz 9 16 -66 cz 37 44 -66 cz 24 31 -66 cz 11 18 -66 cz 39 46 -66 cz 26 33 -66 cz 13 20 -66 cz 41 48 -66 x_1_2 0 -66 y_1_2 1 -66 t 3 -66 y_1_2 4 -66 x_1_2 5 -66 t 8 -66 x_1_2 10 -66 t 12 -66 y_1_2 15 -66 y_1_2 19 -66 t 21 -66 y_1_2 23 -66 t 25 -66 t 27 -66 x_1_2 28 -66 y_1_2 32 -66 t 36 -66 x_1_2 38 -66 t 40 -66 x_1_2 43 -66 x_1_2 47 -67 cz 1 2 -67 cz 5 6 -67 cz 10 11 -67 cz 15 16 -67 cz 19 20 -67 cz 24 25 -67 cz 29 30 -67 cz 33 34 -67 cz 38 39 -67 cz 43 44 -67 cz 47 48 -67 t 0 -67 t 4 -67 x_1_2 7 -67 x_1_2 9 -67 x_1_2 13 -67 y_1_2 14 -67 x_1_2 18 -67 x_1_2 22 -67 t 23 -67 x_1_2 26 -67 t 28 -67 x_1_2 31 -67 t 32 -67 x_1_2 35 -67 x_1_2 37 -67 x_1_2 41 -67 y_1_2 42 -67 x_1_2 46 -68 cz 0 7 -68 cz 28 35 -68 cz 15 22 -68 cz 2 9 -68 cz 30 37 -68 cz 17 24 -68 cz 4 11 -68 cz 32 39 -68 cz 19 26 -68 cz 6 13 -68 cz 34 41 -68 x_1_2 1 -68 x_1_2 5 -68 x_1_2 10 -68 t 14 -68 x_1_2 16 -68 t 18 -68 y_1_2 20 -68 x_1_2 25 -68 x_1_2 29 -68 t 31 -68 y_1_2 33 -68 y_1_2 38 -68 t 42 -68 y_1_2 43 -68 y_1_2 44 -68 t 46 -68 y_1_2 47 -68 x_1_2 48 -69 cz 2 3 -69 cz 7 8 -69 cz 11 12 -69 cz 16 17 -69 cz 21 22 -69 cz 25 26 -69 cz 30 31 -69 cz 35 36 -69 cz 39 40 -69 cz 44 45 -69 y_1_2 0 -69 t 1 -69 x_1_2 4 -69 t 5 -69 x_1_2 6 -69 x_1_2 9 -69 t 10 -69 x_1_2 13 -69 x_1_2 15 -69 x_1_2 19 -69 t 20 -69 y_1_2 24 -69 x_1_2 28 -69 t 29 -69 x_1_2 32 -69 t 33 -69 y_1_2 34 -69 y_1_2 37 -69 t 38 -69 y_1_2 41 -69 t 43 -69 t 47 -69 t 48 -70 cz 21 28 -70 cz 8 15 -70 cz 36 43 -70 cz 23 30 -70 cz 10 17 -70 cz 38 45 -70 cz 25 32 -70 cz 12 19 -70 cz 40 47 -70 cz 27 34 -70 t 0 -70 x_1_2 2 -70 x_1_2 3 -70 t 4 -70 t 6 -70 y_1_2 7 -70 t 9 -70 y_1_2 11 -70 t 13 -70 y_1_2 16 -70 x_1_2 22 -70 t 24 -70 x_1_2 26 -70 x_1_2 31 -70 x_1_2 35 -70 t 37 -70 x_1_2 39 -70 t 41 -70 y_1_2 44 -71 cz 3 4 -71 cz 8 9 -71 cz 12 13 -71 cz 17 18 -71 cz 22 23 -71 cz 26 27 -71 cz 31 32 -71 cz 36 37 -71 cz 40 41 -71 cz 45 46 -71 t 2 -71 t 7 -71 x_1_2 10 -71 t 11 -71 y_1_2 15 -71 t 16 -71 x_1_2 19 -71 y_1_2 21 -71 y_1_2 25 -71 x_1_2 28 -71 x_1_2 30 -71 y_1_2 34 -71 t 35 -71 y_1_2 38 -71 t 39 -71 x_1_2 43 -71 t 44 -71 x_1_2 47 -72 cz 14 21 -72 cz 1 8 -72 cz 29 36 -72 cz 16 23 -72 cz 3 10 -72 cz 31 38 -72 cz 18 25 -72 cz 5 12 -72 cz 33 40 -72 cz 20 27 -72 x_1_2 4 -72 y_1_2 9 -72 y_1_2 13 -72 t 15 -72 y_1_2 17 -72 t 19 -72 y_1_2 22 -72 y_1_2 26 -72 t 28 -72 t 30 -72 y_1_2 32 -72 t 34 -72 y_1_2 37 -72 y_1_2 41 -72 t 43 -72 x_1_2 45 -72 x_1_2 46 -72 t 47 -73 cz 0 1 -73 cz 4 5 -73 cz 9 10 -73 cz 14 15 -73 cz 18 19 -73 cz 23 24 -73 cz 28 29 -73 cz 32 33 -73 cz 37 38 -73 cz 42 43 -73 cz 46 47 -73 x_1_2 3 -73 x_1_2 8 -73 y_1_2 12 -73 t 13 -73 y_1_2 16 -73 t 17 -73 y_1_2 20 -73 y_1_2 21 -73 t 22 -73 y_1_2 25 -73 t 26 -73 y_1_2 27 -73 x_1_2 31 -73 y_1_2 36 -73 x_1_2 40 -73 t 41 -73 t 45 -74 cz 7 14 -74 cz 35 42 -74 cz 22 29 -74 cz 9 16 -74 cz 37 44 -74 cz 24 31 -74 cz 11 18 -74 cz 39 46 -74 cz 26 33 -74 cz 13 20 -74 cz 41 48 -74 x_1_2 0 -74 x_1_2 1 -74 t 3 -74 y_1_2 4 -74 y_1_2 5 -74 t 8 -74 y_1_2 10 -74 t 12 -74 y_1_2 15 -74 x_1_2 19 -74 t 21 -74 x_1_2 23 -74 t 25 -74 t 27 -74 x_1_2 28 -74 y_1_2 32 -74 t 36 -74 x_1_2 38 -74 t 40 -74 x_1_2 43 -74 y_1_2 47 -75 cz 1 2 -75 cz 5 6 -75 cz 10 11 -75 cz 15 16 -75 cz 19 20 -75 cz 24 25 -75 cz 29 30 -75 cz 33 34 -75 cz 38 39 -75 cz 43 44 -75 cz 47 48 -75 t 0 -75 t 4 -75 y_1_2 7 -75 x_1_2 9 -75 x_1_2 13 -75 x_1_2 14 -75 x_1_2 18 -75 y_1_2 22 -75 t 23 -75 x_1_2 26 -75 t 28 -75 y_1_2 31 -75 t 32 -75 x_1_2 35 -75 y_1_2 37 -75 x_1_2 41 -75 y_1_2 42 -75 x_1_2 46 -76 cz 0 7 -76 cz 28 35 -76 cz 15 22 -76 cz 2 9 -76 cz 30 37 -76 cz 17 24 -76 cz 4 11 -76 cz 32 39 -76 cz 19 26 -76 cz 6 13 -76 cz 34 41 -76 y_1_2 1 -76 x_1_2 5 -76 y_1_2 10 -76 t 14 -76 y_1_2 16 -76 t 18 -76 y_1_2 20 -76 y_1_2 25 -76 y_1_2 29 -76 t 31 -76 x_1_2 33 -76 y_1_2 38 -76 t 42 -76 y_1_2 43 -76 y_1_2 44 -76 t 46 -76 x_1_2 47 -76 y_1_2 48 -77 cz 2 3 -77 cz 7 8 -77 cz 11 12 -77 cz 16 17 -77 cz 21 22 -77 cz 25 26 -77 cz 30 31 -77 cz 35 36 -77 cz 39 40 -77 cz 44 45 -77 x_1_2 0 -77 t 1 -77 x_1_2 4 -77 t 5 -77 x_1_2 6 -77 y_1_2 9 -77 t 10 -77 x_1_2 13 -77 y_1_2 15 -77 x_1_2 19 -77 t 20 -77 y_1_2 24 -77 x_1_2 28 -77 t 29 -77 y_1_2 32 -77 t 33 -77 y_1_2 34 -77 y_1_2 37 -77 t 38 -77 y_1_2 41 -77 t 43 -77 t 47 -77 t 48 -78 cz 21 28 -78 cz 8 15 -78 cz 36 43 -78 cz 23 30 -78 cz 10 17 -78 cz 38 45 -78 cz 25 32 -78 cz 12 19 -78 cz 40 47 -78 cz 27 34 -78 t 0 -78 y_1_2 2 -78 x_1_2 3 -78 t 4 -78 t 6 -78 x_1_2 7 -78 t 9 -78 x_1_2 11 -78 t 13 -78 x_1_2 16 -78 y_1_2 22 -78 t 24 -78 x_1_2 26 -78 x_1_2 31 -78 y_1_2 35 -78 t 37 -78 x_1_2 39 -78 t 41 -78 x_1_2 44 -79 cz 3 4 -79 cz 8 9 -79 cz 12 13 -79 cz 17 18 -79 cz 22 23 -79 cz 26 27 -79 cz 31 32 -79 cz 36 37 -79 cz 40 41 -79 cz 45 46 -79 t 2 -79 t 7 -79 x_1_2 10 -79 t 11 -79 x_1_2 15 -79 t 16 -79 x_1_2 19 -79 y_1_2 21 -79 x_1_2 25 -79 y_1_2 28 -79 x_1_2 30 -79 y_1_2 34 -79 t 35 -79 y_1_2 38 -79 t 39 -79 x_1_2 43 -79 t 44 -79 y_1_2 47 -80 h 0 -80 h 1 -80 h 2 -80 h 3 -80 h 4 -80 h 5 -80 h 6 -80 h 7 -80 h 8 -80 h 9 -80 h 10 -80 h 11 -80 h 12 -80 h 13 -80 h 14 -80 h 15 -80 h 16 -80 h 17 -80 h 18 -80 h 19 -80 h 20 -80 h 21 -80 h 22 -80 h 23 -80 h 24 -80 h 25 -80 h 26 -80 h 27 -80 h 28 -80 h 29 -80 h 30 -80 h 31 -80 h 32 -80 h 33 -80 h 34 -80 h 35 -80 h 36 -80 h 37 -80 h 38 -80 h 39 -80 h 40 -80 h 41 -80 h 42 -80 h 43 -80 h 44 -80 h 45 -80 h 46 -80 h 47 -80 h 48 diff --git a/test/datastructures/test_layer.cpp b/test/datastructures/test_layer.cpp index 4fcaabbfd..a105b8e38 100644 --- a/test/datastructures/test_layer.cpp +++ b/test/datastructures/test_layer.cpp @@ -1,8 +1,8 @@ #include "Definitions.hpp" -#include "QuantumComputation.hpp" #include "datastructures/Layer.hpp" -#include "operations/OpType.hpp" -#include "operations/StandardOperation.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/OpType.hpp" +#include "ir/operations/StandardOperation.hpp" #include #include diff --git a/test/dd/CMakeLists.txt b/test/dd/CMakeLists.txt new file mode 100644 index 000000000..04868d190 --- /dev/null +++ b/test/dd/CMakeLists.txt @@ -0,0 +1,5 @@ +if(TARGET MQT::CoreDD) + file(GLOB_RECURSE DD_TEST_SOURCES *.cpp) + package_add_test(mqt-core-dd-test MQT::CoreDD ${DD_TEST_SOURCES}) + target_link_libraries(mqt-core-dd-test PRIVATE MQT::CoreCircuitOptimizer) +endif() diff --git a/test/dd/test_dd_functionality.cpp b/test/dd/test_dd_functionality.cpp index 657d9597c..9c05c204b 100644 --- a/test/dd/test_dd_functionality.cpp +++ b/test/dd/test_dd_functionality.cpp @@ -1,15 +1,15 @@ -#include "CircuitOptimizer.hpp" #include "Definitions.hpp" -#include "Permutation.hpp" -#include "QuantumComputation.hpp" +#include "circuit_optimizer/CircuitOptimizer.hpp" #include "dd/DDDefinitions.hpp" #include "dd/FunctionalityConstruction.hpp" #include "dd/Operations.hpp" #include "dd/Package.hpp" #include "dd/Simulation.hpp" -#include "operations/Control.hpp" -#include "operations/OpType.hpp" -#include "operations/StandardOperation.hpp" +#include "ir/Permutation.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/Control.hpp" +#include "ir/operations/OpType.hpp" +#include "ir/operations/StandardOperation.hpp" #include #include diff --git a/test/dd/test_dd_noise_functionality.cpp b/test/dd/test_dd_noise_functionality.cpp index 68292fa79..6d27fadd0 100644 --- a/test/dd/test_dd_noise_functionality.cpp +++ b/test/dd/test_dd_noise_functionality.cpp @@ -1,11 +1,11 @@ #include "Definitions.hpp" -#include "QuantumComputation.hpp" #include "dd/DDDefinitions.hpp" #include "dd/DDpackageConfig.hpp" #include "dd/NoiseFunctionality.hpp" #include "dd/Operations.hpp" #include "dd/Package.hpp" -#include "operations/OpType.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/OpType.hpp" #include #include diff --git a/test/dd/test_package.cpp b/test/dd/test_package.cpp index dbe38c1f1..a5762e7d2 100644 --- a/test/dd/test_package.cpp +++ b/test/dd/test_package.cpp @@ -8,7 +8,7 @@ #include "dd/Package.hpp" #include "dd/RealNumber.hpp" #include "dd/statistics/PackageStatistics.hpp" -#include "operations/Control.hpp" +#include "ir/operations/Control.hpp" #include #include diff --git a/test/ir/CMakeLists.txt b/test/ir/CMakeLists.txt new file mode 100644 index 000000000..b6102d1a7 --- /dev/null +++ b/test/ir/CMakeLists.txt @@ -0,0 +1,4 @@ +if(TARGET MQT::CoreIR) + file(GLOB_RECURSE IR_TEST_SOURCES *.cpp) + package_add_test(mqt-core-ir-test MQT::CoreIR ${IR_TEST_SOURCES}) +endif() diff --git a/test/unittests/test_io.cpp b/test/ir/test_io.cpp similarity index 97% rename from test/unittests/test_io.cpp rename to test/ir/test_io.cpp index 64f09f902..17fda0387 100644 --- a/test/unittests/test_io.cpp +++ b/test/ir/test_io.cpp @@ -1,10 +1,10 @@ #include "Definitions.hpp" -#include "QuantumComputation.hpp" -#include "operations/CompoundOperation.hpp" -#include "operations/NonUnitaryOperation.hpp" -#include "operations/OpType.hpp" -#include "operations/StandardOperation.hpp" -#include "parsers/qasm3_parser/Exception.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/CompoundOperation.hpp" +#include "ir/operations/NonUnitaryOperation.hpp" +#include "ir/operations/OpType.hpp" +#include "ir/operations/StandardOperation.hpp" +#include "ir/parsers/qasm3_parser/Exception.hpp" #include #include @@ -56,7 +56,7 @@ void compareFiles(const std::string& file1, const std::string& file2, INSTANTIATE_TEST_SUITE_P( IO, IO, testing::Values(std::make_tuple( - "./circuits/test.qasm", + "../circuits/test.qasm", qc::Format::OpenQASM3)), // std::make_tuple("circuits/test.real", // qc::Format::Real [](const testing::TestParamInfo& inf) { @@ -68,8 +68,6 @@ INSTANTIATE_TEST_SUITE_P( case qc::Format::OpenQASM2: case qc::Format::OpenQASM3: return "OpenQasm"; - case qc::Format::GRCS: - return "GRCS"; default: return "Unknown format"; } @@ -348,24 +346,17 @@ TEST_F(IO, CommentInDeclaration) { } TEST_F(IO, realInput) { - qc->import("./circuits/test.real"); + qc->import("../circuits/test.real"); std::cout << *qc << "\n"; } TEST_F(IO, tfcInput) { - qc->import("./circuits/test.tfc"); + qc->import("../circuits/test.tfc"); std::cout << *qc << "\n"; } TEST_F(IO, qcInput) { - qc->import("./circuits/test.qc"); - std::cout << *qc << "\n"; -} - -TEST_F(IO, grcsInput) { - qc->import("./circuits/grcs/bris_4_40_9_v2.txt"); - std::cout << *qc << "\n"; - qc->import("./circuits/grcs/inst_4x4_80_9_v2.txt"); + qc->import("../circuits/test.qc"); std::cout << *qc << "\n"; } diff --git a/test/test_operation.cpp b/test/ir/test_operation.cpp similarity index 96% rename from test/test_operation.cpp rename to test/ir/test_operation.cpp index baa6e9788..81eec343f 100644 --- a/test/test_operation.cpp +++ b/test/ir/test_operation.cpp @@ -1,12 +1,12 @@ #include "Definitions.hpp" -#include "Permutation.hpp" -#include "operations/AodOperation.hpp" -#include "operations/CompoundOperation.hpp" -#include "operations/Expression.hpp" -#include "operations/NonUnitaryOperation.hpp" -#include "operations/OpType.hpp" -#include "operations/StandardOperation.hpp" -#include "operations/SymbolicOperation.hpp" +#include "ir/Permutation.hpp" +#include "ir/operations/AodOperation.hpp" +#include "ir/operations/CompoundOperation.hpp" +#include "ir/operations/Expression.hpp" +#include "ir/operations/NonUnitaryOperation.hpp" +#include "ir/operations/OpType.hpp" +#include "ir/operations/StandardOperation.hpp" +#include "ir/operations/SymbolicOperation.hpp" #include #include diff --git a/test/unittests/test_qasm3_parser.cpp b/test/ir/test_qasm3_parser.cpp similarity index 99% rename from test/unittests/test_qasm3_parser.cpp rename to test/ir/test_qasm3_parser.cpp index 497ac48fd..5877ef101 100644 --- a/test/unittests/test_qasm3_parser.cpp +++ b/test/ir/test_qasm3_parser.cpp @@ -1,13 +1,13 @@ #include "Definitions.hpp" -#include "QuantumComputation.hpp" -#include "operations/ClassicControlledOperation.hpp" -#include "operations/OpType.hpp" -#include "parsers/qasm3_parser/Exception.hpp" -#include "parsers/qasm3_parser/Parser.hpp" -#include "parsers/qasm3_parser/Scanner.hpp" -#include "parsers/qasm3_parser/Statement.hpp" -#include "parsers/qasm3_parser/Token.hpp" -#include "parsers/qasm3_parser/passes/ConstEvalPass.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/ClassicControlledOperation.hpp" +#include "ir/operations/OpType.hpp" +#include "ir/parsers/qasm3_parser/Exception.hpp" +#include "ir/parsers/qasm3_parser/Parser.hpp" +#include "ir/parsers/qasm3_parser/Scanner.hpp" +#include "ir/parsers/qasm3_parser/Statement.hpp" +#include "ir/parsers/qasm3_parser/Token.hpp" +#include "ir/parsers/qasm3_parser/passes/ConstEvalPass.hpp" #include #include diff --git a/test/unittests/test_qfr_functionality.cpp b/test/ir/test_qfr_functionality.cpp similarity index 51% rename from test/unittests/test_qfr_functionality.cpp rename to test/ir/test_qfr_functionality.cpp index 7e5994693..bf073fa35 100644 --- a/test/unittests/test_qfr_functionality.cpp +++ b/test/ir/test_qfr_functionality.cpp @@ -1,14 +1,14 @@ -#include "CircuitOptimizer.hpp" #include "Definitions.hpp" -#include "QuantumComputation.hpp" #include "algorithms/RandomCliffordCircuit.hpp" -#include "operations/ClassicControlledOperation.hpp" -#include "operations/CompoundOperation.hpp" -#include "operations/Control.hpp" -#include "operations/Expression.hpp" -#include "operations/NonUnitaryOperation.hpp" -#include "operations/OpType.hpp" -#include "operations/StandardOperation.hpp" +// #include "circuit_optimizer/CircuitOptimizer.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/ClassicControlledOperation.hpp" +#include "ir/operations/CompoundOperation.hpp" +#include "ir/operations/Control.hpp" +#include "ir/operations/Expression.hpp" +#include "ir/operations/NonUnitaryOperation.hpp" +#include "ir/operations/OpType.hpp" +#include "ir/operations/StandardOperation.hpp" #include #include @@ -43,62 +43,6 @@ class QFRFunctionality : public testing::TestWithParam { std::uniform_real_distribution dist; }; -TEST_F(QFRFunctionality, fuseCxToSwap) { - const std::size_t nqubits = 2; - QuantumComputation qc(nqubits); - qc.cx(0, 1); - qc.cx(1, 0); - qc.cx(0, 1); - CircuitOptimizer::swapReconstruction(qc); - const auto& op = qc.front(); - EXPECT_TRUE(op->isStandardOperation()); - EXPECT_EQ(op->getType(), SWAP); - EXPECT_EQ(op->getTargets().at(0), 0); - EXPECT_EQ(op->getTargets().at(1), 1); -} - -TEST_F(QFRFunctionality, replaceCxToSwapAtEnd) { - const std::size_t nqubits = 2; - QuantumComputation qc(nqubits); - qc.cx(0, 1); - qc.cx(1, 0); - CircuitOptimizer::swapReconstruction(qc); - auto it = qc.begin(); - const auto& op = *it; - EXPECT_TRUE(op->isStandardOperation()); - EXPECT_EQ(op->getType(), SWAP); - EXPECT_EQ(op->getTargets().at(0), 0); - EXPECT_EQ(op->getTargets().at(1), 1); - - ++it; - const auto& op2 = *it; - EXPECT_TRUE(op2->isStandardOperation()); - EXPECT_EQ(op2->getType(), X); - EXPECT_EQ(op2->getControls().begin()->qubit, 0); - EXPECT_EQ(op2->getTargets().at(0), 1); -} - -TEST_F(QFRFunctionality, replaceCxToSwap) { - const std::size_t nqubits = 2; - QuantumComputation qc(nqubits); - qc.cx(0, 1); - qc.cx(1, 0); - qc.h(0); - CircuitOptimizer::swapReconstruction(qc); - auto it = qc.begin(); - const auto& op = *it; - EXPECT_TRUE(op->isStandardOperation()); - EXPECT_EQ(op->getType(), SWAP); - EXPECT_EQ(op->getTargets().at(0), 0); - EXPECT_EQ(op->getTargets().at(1), 1); - ++it; - const auto& op2 = *it; - EXPECT_TRUE(op2->isStandardOperation()); - EXPECT_EQ(op2->getType(), X); - EXPECT_EQ(op2->getControls().begin()->qubit, 0); - EXPECT_EQ(op2->getTargets().at(0), 1); -} - TEST_F(QFRFunctionality, removeTrailingIdleQubits) { const std::size_t nqubits = 4; QuantumComputation qc(nqubits, nqubits); @@ -239,561 +183,6 @@ TEST_F(QFRFunctionality, StripIdleAndDump) { EXPECT_EQ(goal.str(), actual.str()); } -TEST_F(QFRFunctionality, CollapseCompoundOperationToStandard) { - const std::size_t nqubits = 1; - QuantumComputation qc(nqubits); - qc.x(0); - qc.i(0); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - CircuitOptimizer::singleQubitGateFusion(qc); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - EXPECT_EQ(qc.getNops(), 1); - EXPECT_TRUE(qc.begin()->get()->isStandardOperation()); -} - -TEST_F(QFRFunctionality, eliminateCompoundOperation) { - const std::size_t nqubits = 1; - QuantumComputation qc(nqubits); - qc.i(0); - qc.i(0); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - CircuitOptimizer::singleQubitGateFusion(qc); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - EXPECT_EQ(qc.getNops(), 0); - EXPECT_TRUE(qc.empty()); -} - -TEST_F(QFRFunctionality, removeIdentities) { - const std::size_t nqubits = 1; - QuantumComputation qc(nqubits); - qc.i(0); - qc.i(0); - qc.x(0); - qc.i(0); - qc.i(0); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - CircuitOptimizer::removeIdentities(qc); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - EXPECT_EQ(qc.getNops(), 1); -} - -TEST_F(QFRFunctionality, removeSingleQubitGates) { - const std::size_t nqubits = 1; - QuantumComputation qc(nqubits); - qc.x(0); - qc.x(0); - qc.y(0); - qc.i(0); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - CircuitOptimizer::removeOperation(qc, {X, Y}, 1); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - EXPECT_EQ(qc.getNops(), 1); -} - -TEST_F(QFRFunctionality, removeMultiQubitGates) { - const std::size_t nqubits = 2; - QuantumComputation qc(nqubits); - qc.x(0); - qc.cx(0, 1); - qc.cy(1, 1); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - CircuitOptimizer::removeOperation(qc, {X, Y}, 2); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - EXPECT_EQ(qc.getNops(), 2); -} - -TEST_F(QFRFunctionality, removeMoves) { - const std::size_t nqubits = 2; - QuantumComputation qc(nqubits); - qc.x(0); - qc.move(0, 1); - qc.cy(1, 1); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - CircuitOptimizer::removeOperation(qc, {Move}, 0); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - EXPECT_EQ(qc.getNops(), 2); -} - -TEST_F(QFRFunctionality, removeGateInCompoundOperation) { - const std::size_t nqubits = 1; - QuantumComputation qc(nqubits); - QuantumComputation compound(nqubits); - compound.x(0); - compound.y(0); - compound.z(0); - qc.emplace_back(compound.asOperation()); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - CircuitOptimizer::removeOperation(qc, {Y}, 1); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - EXPECT_EQ(qc.getNops(), 1); - EXPECT_EQ(qc.front()->getType(), Compound); - auto* compoundOp = dynamic_cast(qc.front().get()); - EXPECT_EQ(compoundOp->size(), 2); -} - -TEST_F(QFRFunctionality, eliminateInverseInCompoundOperation) { - const std::size_t nqubits = 1; - QuantumComputation qc(nqubits); - qc.s(0); - qc.sdg(0); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - CircuitOptimizer::singleQubitGateFusion(qc); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - EXPECT_EQ(qc.getNops(), 0); - EXPECT_TRUE(qc.empty()); -} - -TEST_F(QFRFunctionality, unknownInverseInCompoundOperation) { - const std::size_t nqubits = 1; - QuantumComputation qc(nqubits); - qc.p(1., 0); - qc.p(-1., 0); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - CircuitOptimizer::singleQubitGateFusion(qc); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - EXPECT_EQ(qc.getNops(), 1); -} - -TEST_F(QFRFunctionality, repeatedCancellationInSingleQubitGateFusion) { - const std::size_t nqubits = 1U; - QuantumComputation qc(nqubits); - qc.x(0); - qc.h(0); // causes the creation of a CompoundOperation - qc.h(0); // cancels a gate in the compound operation - qc.x(0); // cancels the first gate, making the CompoundOperation empty - qc.z(0); // adds another gate to the CompoundOperation - std::cout << "-----------------------------\n"; - qc.print(std::cout); - CircuitOptimizer::singleQubitGateFusion(qc); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - EXPECT_EQ(qc.getNops(), 1U); -} - -TEST_F(QFRFunctionality, emptyCompoundGatesRemovedInSingleQubitGateFusion) { - const std::size_t nqubits = 1U; - QuantumComputation qc(nqubits); - qc.x(0); - qc.h(0); // causes the creation of a CompoundOperation - qc.h(0); // cancels a gate in the compound operation - qc.x(0); // cancels the first gate, making the CompoundOperation empty - std::cout << "-----------------------------\n"; - qc.print(std::cout); - CircuitOptimizer::singleQubitGateFusion(qc); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - EXPECT_EQ(qc.getNops(), 0U); -} - -TEST_F(QFRFunctionality, removeDiagonalSingleQubitBeforeMeasure) { - const std::size_t nqubits = 1; - QuantumComputation qc(nqubits, nqubits); - qc.z(0); - qc.measure(0, 0); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - CircuitOptimizer::removeDiagonalGatesBeforeMeasure(qc); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - EXPECT_EQ(qc.getNops(), 1); - EXPECT_EQ(qc.begin()->get()->getType(), qc::Measure); -} - -TEST_F(QFRFunctionality, removeDiagonalCompoundOpBeforeMeasure) { - const std::size_t nqubits = 1; - QuantumComputation qc(nqubits, nqubits); - qc.z(0); - qc.t(0); - qc.measure(0, 0); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - CircuitOptimizer::singleQubitGateFusion(qc); - CircuitOptimizer::removeDiagonalGatesBeforeMeasure(qc); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - EXPECT_EQ(qc.getNops(), 1); - EXPECT_EQ(qc.begin()->get()->getType(), qc::Measure); -} - -TEST_F(QFRFunctionality, removeDiagonalTwoQubitGateBeforeMeasure) { - const std::size_t nqubits = 2; - QuantumComputation qc(nqubits, nqubits); - qc.cz(0, 1); - qc.measure({0, 1}, {0, 1}); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - CircuitOptimizer::removeDiagonalGatesBeforeMeasure(qc); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - EXPECT_EQ(qc.getNops(), 1); - EXPECT_EQ(qc.begin()->get()->getType(), qc::Measure); -} - -TEST_F(QFRFunctionality, leaveGateBeforeMeasure) { - const std::size_t nqubits = 2; - QuantumComputation qc(nqubits, nqubits); - qc.cz(0, 1); - qc.x(0); - qc.measure({0, 1}, {0, 1}); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - CircuitOptimizer::removeDiagonalGatesBeforeMeasure(qc); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - EXPECT_EQ(qc.getNops(), 3); -} - -TEST_F(QFRFunctionality, removeComplexGateBeforeMeasure) { - const std::size_t nqubits = 4; - QuantumComputation qc(nqubits, nqubits); - qc.cz(0, 1); - qc.x(0); - qc.cz(1, 2); - qc.cz(0, 1); - qc.z(0); - qc.cz(1, 2); - qc.x(3); - qc.t(3); - qc.mcz({0, 1, 2}, 3); - qc.measure({0, 1, 2, 3}, {0, 1, 2, 3}); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - CircuitOptimizer::removeDiagonalGatesBeforeMeasure(qc); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - EXPECT_EQ(qc.getNops(), 4); -} - -TEST_F(QFRFunctionality, removeSimpleCompoundOpBeforeMeasure) { - const std::size_t nqubits = 1; - QuantumComputation qc(nqubits, nqubits); - qc.x(0); - qc.t(0); - qc.measure(0, 0); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - CircuitOptimizer::singleQubitGateFusion(qc); - CircuitOptimizer::removeDiagonalGatesBeforeMeasure(qc); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - EXPECT_EQ(qc.getNops(), 2); -} - -TEST_F(QFRFunctionality, removePartOfCompoundOpBeforeMeasure) { - const std::size_t nqubits = 1; - QuantumComputation qc(nqubits, nqubits); - qc.t(0); - qc.x(0); - qc.t(0); - qc.measure(0, 0); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - CircuitOptimizer::singleQubitGateFusion(qc); - CircuitOptimizer::removeDiagonalGatesBeforeMeasure(qc); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - EXPECT_EQ(qc.getNops(), 2); -} - -TEST_F(QFRFunctionality, decomposeSWAPsUndirectedArchitecture) { - const std::size_t nqubits = 2; - QuantumComputation qc(nqubits, nqubits); - qc.swap(0, 1); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - CircuitOptimizer::decomposeSWAP(qc, false); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - auto it = qc.begin(); - const auto& op = *it; - EXPECT_TRUE(op->isStandardOperation()); - EXPECT_EQ(op->getType(), qc::X); - EXPECT_EQ(op->getControls().begin()->qubit, 0); - EXPECT_EQ(op->getTargets().at(0), 1); - ++it; - const auto& op2 = *it; - EXPECT_TRUE(op2->isStandardOperation()); - EXPECT_EQ(op2->getType(), qc::X); - EXPECT_EQ(op2->getControls().begin()->qubit, 1); - EXPECT_EQ(op2->getTargets().at(0), 0); - ++it; - const auto& op3 = *it; - EXPECT_TRUE(op3->isStandardOperation()); - EXPECT_EQ(op3->getType(), qc::X); - EXPECT_EQ(op3->getControls().begin()->qubit, 0); - EXPECT_EQ(op3->getTargets().at(0), 1); -} -TEST_F(QFRFunctionality, decomposeSWAPsDirectedArchitecture) { - const std::size_t nqubits = 2; - QuantumComputation qc(nqubits); - qc.swap(0, 1); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - CircuitOptimizer::decomposeSWAP(qc, true); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - auto it = qc.begin(); - const auto& op = *it; - EXPECT_TRUE(op->isStandardOperation()); - EXPECT_EQ(op->getType(), qc::X); - EXPECT_EQ(op->getControls().begin()->qubit, 0); - EXPECT_EQ(op->getTargets().at(0), 1); - - ++it; - const auto& op2 = *it; - EXPECT_TRUE(op2->isStandardOperation()); - EXPECT_EQ(op2->getType(), qc::H); - EXPECT_EQ(op2->getTargets().at(0), 1); - - ++it; - const auto& op3 = *it; - EXPECT_TRUE(op3->isStandardOperation()); - EXPECT_EQ(op3->getType(), qc::H); - EXPECT_EQ(op3->getTargets().at(0), 0); - - ++it; - const auto& op4 = *it; - EXPECT_TRUE(op4->isStandardOperation()); - EXPECT_EQ(op4->getType(), qc::X); - EXPECT_EQ(op4->getControls().begin()->qubit, 0); - EXPECT_EQ(op4->getTargets().at(0), 1); - - ++it; - const auto& op5 = *it; - EXPECT_TRUE(op5->isStandardOperation()); - EXPECT_EQ(op5->getType(), qc::H); - EXPECT_EQ(op5->getTargets().at(0), 1); - - ++it; - const auto& op6 = *it; - EXPECT_TRUE(op6->isStandardOperation()); - EXPECT_EQ(op6->getType(), qc::H); - EXPECT_EQ(op6->getTargets().at(0), 0); - - ++it; - const auto& op7 = *it; - EXPECT_TRUE(op7->isStandardOperation()); - EXPECT_EQ(op7->getType(), qc::X); - EXPECT_EQ(op7->getControls().begin()->qubit, 0); - EXPECT_EQ(op7->getTargets().at(0), 1); -} - -TEST_F(QFRFunctionality, decomposeSWAPsCompound) { - const std::size_t nqubits = 2; - QuantumComputation qc(nqubits); - QuantumComputation comp(nqubits); - comp.swap(0, 1); - comp.swap(0, 1); - comp.swap(0, 1); - qc.emplace_back(comp.asOperation()); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - qc::CircuitOptimizer::decomposeSWAP(qc, false); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - auto it = qc.begin(); - const auto& op = *it; - EXPECT_TRUE(op->isCompoundOperation()); - - const auto* cop = dynamic_cast(op.get()); - ASSERT_NE(cop, nullptr); - EXPECT_EQ(cop->size(), 9); -} - -TEST_F(QFRFunctionality, decomposeSWAPsCompoundDirected) { - const std::size_t nqubits = 2; - QuantumComputation qc(nqubits); - QuantumComputation comp(nqubits); - comp.swap(0, 1); - comp.swap(0, 1); - comp.swap(0, 1); - qc.emplace_back(comp.asOperation()); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - qc::CircuitOptimizer::decomposeSWAP(qc, true); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - auto it = qc.begin(); - const auto& op = *it; - EXPECT_TRUE(op->isCompoundOperation()); - - const auto* cop = dynamic_cast(op.get()); - ASSERT_NE(cop, nullptr); - EXPECT_EQ(cop->size(), 21); -} - -TEST_F(QFRFunctionality, removeFinalMeasurements) { - const std::size_t nqubits = 2; - QuantumComputation qc(nqubits, nqubits); - qc.h(0); - qc.h(1); - qc.measure(0, 0); - qc.measure(1, 1); - qc.h(1); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - CircuitOptimizer::removeFinalMeasurements(qc); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - auto it = qc.begin(); - ++it; - ++it; // skip first two H - const auto& op = *it; - EXPECT_TRUE(op->isNonUnitaryOperation()); - EXPECT_EQ(op->getType(), qc::Measure); - ++it; - const auto& op2 = *it; - EXPECT_TRUE(op2->isStandardOperation()); - EXPECT_EQ(op2->getType(), qc::H); - EXPECT_EQ(op2->getTargets().at(0), 1); -} - -TEST_F(QFRFunctionality, removeFinalMeasurementsTwoQubitMeasurement) { - const std::size_t nqubits = 2; - QuantumComputation qc(nqubits, nqubits); - qc.h(0); - qc.h(1); - qc.measure({0, 1}, {0, 1}); - qc.h(1); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - CircuitOptimizer::removeFinalMeasurements(qc); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - auto it = qc.begin(); - ++it; - ++it; // skip first two H - const auto& op = *it; - EXPECT_TRUE(op->isNonUnitaryOperation()); - EXPECT_EQ(op->getType(), qc::Measure); - ++it; - const auto& op2 = *it; - EXPECT_TRUE(op2->isStandardOperation()); - EXPECT_EQ(op2->getType(), qc::H); - EXPECT_EQ(op2->getTargets().at(0), 1); -} - -TEST_F(QFRFunctionality, removeFinalMeasurementsCompound) { - const std::size_t nqubits = 2; - QuantumComputation qc(nqubits, nqubits); - QuantumComputation comp(nqubits, nqubits); - comp.measure(0, 0); - comp.measure(1, 1); - comp.h(1); - qc.emplace_back(comp.asOperation()); - qc.h(1); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - CircuitOptimizer::removeFinalMeasurements(qc); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - auto it = qc.begin(); - const auto& op = *it; - EXPECT_TRUE(op->isCompoundOperation()); - - const auto* cop = dynamic_cast(op.get()); - ASSERT_NE(cop, nullptr); - EXPECT_EQ(cop->size(), 2); - ++it; - const auto& op2 = *it; - EXPECT_TRUE(op2->isStandardOperation()); - EXPECT_EQ(op2->getType(), qc::H); - EXPECT_EQ(op2->getTargets().at(0), 1); -} - -TEST_F(QFRFunctionality, removeFinalMeasurementsCompoundDegraded) { - const std::size_t nqubits = 2; - QuantumComputation qc(nqubits, nqubits); - QuantumComputation comp(nqubits, nqubits); - comp.measure(0, 0); - comp.h(1); - qc.emplace_back(comp.asOperation()); - qc.h(1); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - CircuitOptimizer::removeFinalMeasurements(qc); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - auto it = qc.begin(); - const auto& op = *it; - EXPECT_TRUE(op->isStandardOperation()); - EXPECT_EQ(op->getType(), qc::H); - EXPECT_EQ(op->getTargets().at(0), 1); - ++it; - const auto& op2 = *it; - EXPECT_TRUE(op2->isStandardOperation()); - EXPECT_EQ(op2->getType(), qc::H); - EXPECT_EQ(op2->getTargets().at(0), 1); -} - -TEST_F(QFRFunctionality, removeFinalMeasurementsCompoundEmpty) { - const std::size_t nqubits = 2; - QuantumComputation qc(nqubits, nqubits); - QuantumComputation comp(nqubits, nqubits); - comp.measure(0, 0); - qc.emplace_back(comp.asCompoundOperation()); - qc.h(1); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - CircuitOptimizer::removeFinalMeasurements(qc); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - auto it = qc.begin(); - const auto& op = *it; - EXPECT_TRUE(op->isStandardOperation()); - EXPECT_EQ(op->getType(), qc::H); - EXPECT_EQ(op->getTargets().at(0), 1); -} - -TEST_F(QFRFunctionality, removeFinalMeasurementsWithOperationsInFront) { - const std::string circ = - "OPENQASM 2.0;include \"qelib1.inc\";qreg q[3];qreg r[3];h q;cx q, " - "r;creg c[3];creg d[3];barrier q;measure q->c;measure r->d;\n"; - std::stringstream ss{}; - ss << circ; - QuantumComputation qc{}; - qc.import(ss, qc::Format::OpenQASM2); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - CircuitOptimizer::removeFinalMeasurements(qc); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - ASSERT_EQ(qc.getNops(), 2); - ASSERT_EQ(qc.getNindividualOps(), 6); -} - -TEST_F(QFRFunctionality, removeFinalMeasurementsWithBarrier) { - const std::size_t nqubits = 2; - QuantumComputation qc(nqubits, nqubits); - qc.barrier({0, 1}); - qc.measure(0, 0); - qc.measure(1, 1); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - CircuitOptimizer::removeFinalMeasurements(qc); - std::cout << "-----------------------------\n"; - qc.print(std::cout); - EXPECT_TRUE(qc.empty()); -} - TEST_F(QFRFunctionality, gateShortCutsAndCloning) { // This test checks if the gate shortcuts are working correctly // and if the cloning of gates is working correctly. @@ -933,311 +322,6 @@ TEST_F(QFRFunctionality, wrongRegisterSizes) { ASSERT_THROW(qc.measure({0}, {1, 2}), std::invalid_argument); } -TEST_F(QFRFunctionality, eliminateResetsBasicTest) { - QuantumComputation qc{}; - qc.addQubitRegister(1); - qc.addClassicalRegister(2); - qc.h(0); - qc.measure(0, 0U); - qc.reset(0); - qc.h(0); - qc.measure(0, 1U); - - std::cout << qc << "\n"; - - EXPECT_TRUE(CircuitOptimizer::isDynamicCircuit(qc)); - - EXPECT_NO_THROW(CircuitOptimizer::eliminateResets(qc);); - - std::cout << qc << "\n"; - - ASSERT_EQ(qc.getNqubits(), 2); - ASSERT_EQ(qc.getNindividualOps(), 4); - const auto& op0 = qc.at(0); - const auto& op1 = qc.at(1); - const auto& op2 = qc.at(2); - const auto& op3 = qc.at(3); - - EXPECT_TRUE(op0->getType() == qc::H); - const auto& targets0 = op0->getTargets(); - EXPECT_EQ(targets0.size(), 1); - EXPECT_EQ(targets0.at(0), static_cast(0)); - EXPECT_TRUE(op0->getControls().empty()); - - EXPECT_TRUE(op1->getType() == qc::Measure); - const auto& targets1 = op1->getTargets(); - EXPECT_EQ(targets1.size(), 1); - EXPECT_EQ(targets1.at(0), static_cast(0)); - const auto* measure0 = dynamic_cast(op1.get()); - ASSERT_NE(measure0, nullptr); - const auto& classics0 = measure0->getClassics(); - EXPECT_EQ(classics0.size(), 1); - EXPECT_EQ(classics0.at(0), 0); - - EXPECT_TRUE(op2->getType() == qc::H); - const auto& targets2 = op2->getTargets(); - EXPECT_EQ(targets2.size(), 1); - EXPECT_EQ(targets2.at(0), static_cast(1)); - EXPECT_TRUE(op2->getControls().empty()); - - EXPECT_TRUE(op3->getType() == qc::Measure); - const auto& targets3 = op3->getTargets(); - EXPECT_EQ(targets3.size(), 1); - EXPECT_EQ(targets3.at(0), static_cast(1)); - auto* measure1 = dynamic_cast(op3.get()); - ASSERT_NE(measure1, nullptr); - const auto& classics1 = measure1->getClassics(); - EXPECT_EQ(classics1.size(), 1); - EXPECT_EQ(classics1.at(0), 1); -} - -TEST_F(QFRFunctionality, eliminateResetsClassicControlled) { - QuantumComputation qc{}; - qc.addQubitRegister(1); - qc.addClassicalRegister(2); - qc.h(0); - qc.measure(0, 0U); - qc.reset(0); - qc.classicControlled(qc::X, 0, {0, 1U}, 1U); - std::cout << qc << "\n"; - - EXPECT_TRUE(CircuitOptimizer::isDynamicCircuit(qc)); - - EXPECT_NO_THROW(CircuitOptimizer::eliminateResets(qc);); - - std::cout << qc << "\n"; - - ASSERT_EQ(qc.getNqubits(), 2); - ASSERT_EQ(qc.getNindividualOps(), 3); - const auto& op0 = qc.at(0); - const auto& op1 = qc.at(1); - const auto& op2 = qc.at(2); - - EXPECT_TRUE(op0->getType() == qc::H); - const auto& targets0 = op0->getTargets(); - EXPECT_EQ(targets0.size(), 1); - EXPECT_EQ(targets0.at(0), static_cast(0)); - EXPECT_TRUE(op0->getControls().empty()); - - EXPECT_TRUE(op1->getType() == qc::Measure); - const auto& targets1 = op1->getTargets(); - EXPECT_EQ(targets1.size(), 1); - EXPECT_EQ(targets1.at(0), static_cast(0)); - auto* measure0 = dynamic_cast(op1.get()); - ASSERT_NE(measure0, nullptr); - const auto& classics0 = measure0->getClassics(); - EXPECT_EQ(classics0.size(), 1); - EXPECT_EQ(classics0.at(0), 0); - - EXPECT_TRUE(op2->isClassicControlledOperation()); - auto* classicControlled = - dynamic_cast(op2.get()); - ASSERT_NE(classicControlled, nullptr); - const auto& operation = classicControlled->getOperation(); - EXPECT_TRUE(operation->getType() == qc::X); - EXPECT_EQ(classicControlled->getNtargets(), 1); - const auto& targets = classicControlled->getTargets(); - EXPECT_EQ(targets.at(0), 1); - EXPECT_EQ(classicControlled->getNcontrols(), 0); -} - -TEST_F(QFRFunctionality, eliminateResetsMultipleTargetReset) { - QuantumComputation qc{}; - qc.addQubitRegister(2); - qc.reset({0, 1}); - qc.x(0); - qc.z(1); - qc.cx(1, 0); - - std::cout << qc << "\n"; - - EXPECT_TRUE(CircuitOptimizer::isDynamicCircuit(qc)); - - EXPECT_NO_THROW(CircuitOptimizer::eliminateResets(qc);); - - std::cout << qc << "\n"; - - ASSERT_EQ(qc.getNqubits(), 4); - ASSERT_EQ(qc.getNindividualOps(), 3); - const auto& op0 = qc.at(0); - const auto& op1 = qc.at(1); - const auto& op2 = qc.at(2); - - EXPECT_TRUE(op0->getType() == qc::X); - const auto& targets0 = op0->getTargets(); - EXPECT_EQ(targets0.size(), 1); - EXPECT_EQ(targets0.at(0), static_cast(2)); - EXPECT_TRUE(op0->getControls().empty()); - - EXPECT_TRUE(op1->getType() == qc::Z); - const auto& targets1 = op1->getTargets(); - EXPECT_EQ(targets1.size(), 1); - EXPECT_EQ(targets1.at(0), static_cast(3)); - EXPECT_TRUE(op1->getControls().empty()); - - EXPECT_TRUE(op2->getType() == qc::X); - const auto& targets2 = op2->getTargets(); - EXPECT_EQ(targets2.size(), 1); - EXPECT_EQ(targets2.at(0), static_cast(2)); - const auto& controls2 = op2->getControls(); - EXPECT_EQ(controls2.size(), 1); - EXPECT_EQ(controls2.count(3), 1); -} - -TEST_F(QFRFunctionality, eliminateResetsCompoundOperation) { - QuantumComputation qc(2U, 2U); - - qc.reset(0); - qc.reset(1); - - QuantumComputation comp(2U, 2U); - comp.cx(1, 0); - comp.reset(0); - comp.measure(0, 0); - comp.classicControlled(qc::X, 0, {0, 1U}, 1U); - qc.emplace_back(comp.asOperation()); - - std::cout << qc << "\n"; - - EXPECT_TRUE(CircuitOptimizer::isDynamicCircuit(qc)); - - EXPECT_NO_THROW(CircuitOptimizer::eliminateResets(qc);); - - std::cout << qc << "\n"; - - ASSERT_EQ(qc.getNqubits(), 5); - ASSERT_EQ(qc.getNindividualOps(), 3); - - const auto& op = qc.at(0); - EXPECT_TRUE(op->isCompoundOperation()); - auto* compOp0 = dynamic_cast(op.get()); - ASSERT_NE(compOp0, nullptr); - EXPECT_EQ(compOp0->size(), 3); - - const auto& op0 = compOp0->at(0); - const auto& op1 = compOp0->at(1); - const auto& op2 = compOp0->at(2); - - EXPECT_TRUE(op0->getType() == qc::X); - const auto& targets0 = op0->getTargets(); - EXPECT_EQ(targets0.size(), 1); - EXPECT_EQ(targets0.at(0), static_cast(2)); - const auto& controls0 = op0->getControls(); - EXPECT_EQ(controls0.size(), 1); - EXPECT_EQ(controls0.count(3), 1); - - EXPECT_TRUE(op1->getType() == qc::Measure); - const auto& targets1 = op1->getTargets(); - EXPECT_EQ(targets1.size(), 1); - EXPECT_EQ(targets1.at(0), static_cast(4)); - auto* measure0 = dynamic_cast(op1.get()); - ASSERT_NE(measure0, nullptr); - const auto& classics0 = measure0->getClassics(); - EXPECT_EQ(classics0.size(), 1); - EXPECT_EQ(classics0.at(0), 0); - - EXPECT_TRUE(op2->isClassicControlledOperation()); - auto* classicControlled = - dynamic_cast(op2.get()); - ASSERT_NE(classicControlled, nullptr); - const auto& operation = classicControlled->getOperation(); - EXPECT_TRUE(operation->getType() == qc::X); - EXPECT_EQ(classicControlled->getNtargets(), 1); - const auto& targets = classicControlled->getTargets(); - EXPECT_EQ(targets.at(0), 4); - EXPECT_EQ(classicControlled->getNcontrols(), 0); -} - -TEST_F(QFRFunctionality, FlattenRandomClifford) { - qc::RandomCliffordCircuit rcs(2U, 3U, 0U); - std::cout << rcs << "\n"; - const auto nops = rcs.getNindividualOps(); - - qc::CircuitOptimizer::flattenOperations(rcs); - std::cout << rcs << "\n"; - - for (const auto& op : rcs) { - EXPECT_FALSE(op->isCompoundOperation()); - } - EXPECT_EQ(nops, rcs.getNindividualOps()); -} - -TEST_F(QFRFunctionality, FlattenRecursive) { - const std::size_t nqubits = 1U; - - // create a nested compound operation - QuantumComputation op(nqubits); - op.x(0); - op.z(0); - QuantumComputation op2(nqubits); - op2.emplace_back(op.asCompoundOperation()); - QuantumComputation qc(nqubits); - qc.emplace_back(op2.asCompoundOperation()); - std::cout << qc << "\n"; - - qc::CircuitOptimizer::flattenOperations(qc); - std::cout << qc << "\n"; - - for (const auto& g : qc) { - EXPECT_FALSE(g->isCompoundOperation()); - } - - ASSERT_EQ(qc.getNops(), 2U); - auto& gate = qc.at(0); - EXPECT_EQ(gate->getType(), qc::X); - EXPECT_EQ(gate->getTargets().at(0), 0U); - EXPECT_TRUE(gate->getControls().empty()); - auto& gate2 = qc.at(1); - EXPECT_EQ(gate2->getType(), qc::Z); - EXPECT_EQ(gate2->getTargets().at(0), 0U); - EXPECT_TRUE(gate2->getControls().empty()); -} - -TEST_F(QFRFunctionality, FlattenCustomOnly) { - const std::size_t nqubits = 1U; - - // create a nested compound operation - QuantumComputation op(nqubits); - op.x(0); - op.z(0); - QuantumComputation op2(nqubits); - op2.emplace_back(op.asCompoundOperation()); - QuantumComputation qc(nqubits); - qc.emplace_back(op2.asCompoundOperation()); - std::cout << qc << "\n"; - - qc::CircuitOptimizer::flattenOperations(qc, true); - std::cout << qc << "\n"; - - ASSERT_EQ(qc.getNops(), 1U); - auto& gate = qc.at(0); - EXPECT_EQ(gate->getType(), qc::Compound); - - std::vector> opsCompound; - opsCompound.push_back(std::make_unique(0, qc::X)); - opsCompound.push_back(std::make_unique(0, qc::Z)); - QuantumComputation qc2(nqubits); - qc2.emplace_back(std::move(opsCompound), true); - std::cout << qc2 << "\n"; - - qc::CircuitOptimizer::flattenOperations(qc2, true); - std::cout << qc2 << "\n"; - - for (const auto& g : qc2) { - EXPECT_FALSE(g->isCompoundOperation()); - } - - ASSERT_EQ(qc2.getNops(), 2U); - auto& gate3 = qc2.at(0); - EXPECT_EQ(gate3->getType(), qc::X); - EXPECT_EQ(gate3->getTargets().at(0), 0U); - EXPECT_TRUE(gate3->getControls().empty()); - auto& gate4 = qc2.at(1); - EXPECT_EQ(gate4->getType(), qc::Z); - EXPECT_EQ(gate4->getTargets().at(0), 0U); - EXPECT_TRUE(gate4->getControls().empty()); -} - TEST_F(QFRFunctionality, OperationEquality) { const auto x = StandardOperation(0, qc::X); const auto z = StandardOperation(0, qc::Z); @@ -1333,74 +417,6 @@ TEST_F(QFRFunctionality, OperationEquality) { EXPECT_NE(compound0, compound2); } -TEST_F(QFRFunctionality, CNOTCancellation1) { - QuantumComputation qc(2); - qc.cx(1, 0); - qc.cx(1, 0); - - CircuitOptimizer::cancelCNOTs(qc); - EXPECT_TRUE(qc.empty()); -} - -TEST_F(QFRFunctionality, CNOTCancellation2) { - QuantumComputation qc(2); - qc.swap(0, 1); - qc.swap(1, 0); - - CircuitOptimizer::cancelCNOTs(qc); - EXPECT_TRUE(qc.empty()); -} - -TEST_F(QFRFunctionality, CNOTCancellation3) { - QuantumComputation qc(2); - qc.swap(0, 1); - qc.cx(1, 0); - - CircuitOptimizer::cancelCNOTs(qc); - EXPECT_TRUE(qc.size() == 2U); - const auto& firstOperation = qc.front(); - EXPECT_EQ(firstOperation->getType(), qc::X); - EXPECT_EQ(firstOperation->getTargets().front(), 0U); - EXPECT_EQ(firstOperation->getControls().begin()->qubit, 1U); - - const auto& secondOperation = qc.back(); - EXPECT_EQ(secondOperation->getType(), qc::X); - EXPECT_EQ(secondOperation->getTargets().front(), 1U); - EXPECT_EQ(secondOperation->getControls().begin()->qubit, 0U); -} - -TEST_F(QFRFunctionality, CNOTCancellation4) { - QuantumComputation qc(2); - qc.cx(1, 0); - qc.swap(0, 1); - - CircuitOptimizer::cancelCNOTs(qc); - EXPECT_TRUE(qc.size() == 2U); - const auto& firstOperation = qc.front(); - EXPECT_EQ(firstOperation->getType(), qc::X); - EXPECT_EQ(firstOperation->getTargets().front(), 1U); - EXPECT_EQ(firstOperation->getControls().begin()->qubit, 0U); - - const auto& secondOperation = qc.back(); - EXPECT_EQ(secondOperation->getType(), qc::X); - EXPECT_EQ(secondOperation->getTargets().front(), 0U); - EXPECT_EQ(secondOperation->getControls().begin()->qubit, 1U); -} - -TEST_F(QFRFunctionality, CNOTCancellation5) { - QuantumComputation qc(2); - qc.cx(1, 0); - qc.cx(0, 1); - qc.cx(1, 0); - - CircuitOptimizer::cancelCNOTs(qc); - EXPECT_TRUE(qc.size() == 1U); - const auto& firstOperation = qc.front(); - EXPECT_EQ(firstOperation->getType(), qc::SWAP); - EXPECT_EQ(firstOperation->getTargets().front(), 0U); - EXPECT_EQ(firstOperation->getTargets().back(), 1U); -} - TEST_F(QFRFunctionality, IndexOutOfRange) { QuantumComputation qc(2); qc::Permutation layout{}; @@ -1451,25 +467,6 @@ TEST_F(QFRFunctionality, AddAncillaryQubits) { EXPECT_TRUE(qc.garbage[1]); } -TEST_F(QFRFunctionality, SingleQubitGateCount) { - QuantumComputation qc(2U, 2U); - qc.x(0); - qc.h(0); - qc.cx(1, 0); - qc.z(0); - qc.measure(0, 0); - - EXPECT_EQ(qc.getNops(), 5U); - EXPECT_EQ(qc.getNindividualOps(), 5U); - EXPECT_EQ(qc.getNsingleQubitOps(), 3U); - - CircuitOptimizer::singleQubitGateFusion(qc); - - EXPECT_EQ(qc.getNops(), 4U); - EXPECT_EQ(qc.getNindividualOps(), 5U); - EXPECT_EQ(qc.getNsingleQubitOps(), 3U); -} - TEST_F(QFRFunctionality, CircuitDepthEmptyCircuit) { const QuantumComputation qc(2); EXPECT_EQ(qc.getDepth(), 0U); @@ -2001,87 +998,6 @@ TEST_F(QFRFunctionality, MeasurementSanityCheck) { EXPECT_THROW(qc.measure(0, {"d", 0U}), QFRException); } -TEST_F(QFRFunctionality, replaceCXwithCZ) { - qc::QuantumComputation qc(2U); - qc.cx(0, 1); - CircuitOptimizer::replaceMCXWithMCZ(qc); - std::cout << qc << "\n"; - EXPECT_EQ(qc.getNops(), 3U); - EXPECT_EQ(qc.at(0)->getType(), qc::H); - EXPECT_EQ(qc.at(0)->getTargets()[0], 1U); - EXPECT_EQ(qc.at(1)->getType(), qc::Z); - EXPECT_EQ(qc.at(1)->getTargets()[0], 1U); - EXPECT_EQ(*qc.at(1)->getControls().begin(), 0U); - EXPECT_EQ(qc.at(2)->getType(), qc::H); - EXPECT_EQ(qc.at(2)->getTargets()[0], 1U); -} - -TEST_F(QFRFunctionality, replaceCCXwithCCZ) { - std::size_t const nqubits = 3U; - qc::QuantumComputation qc(nqubits); - Controls const controls = {0, 1}; - Qubit const target = 2U; - qc.mcx(controls, target); - CircuitOptimizer::replaceMCXWithMCZ(qc); - std::cout << qc << "\n"; - EXPECT_EQ(qc.getNops(), 3U); - EXPECT_EQ(qc.at(0)->getType(), qc::H); - EXPECT_EQ(qc.at(0)->getTargets()[0], target); - EXPECT_EQ(qc.at(1)->getType(), qc::Z); - EXPECT_EQ(qc.at(1)->getTargets()[0], target); - EXPECT_EQ(qc.at(1)->getControls(), controls); - EXPECT_EQ(qc.at(2)->getType(), qc::H); - EXPECT_EQ(qc.at(2)->getTargets()[0], target); -} - -TEST_F(QFRFunctionality, replaceCXwithCZinCompoundOperation) { - std::size_t const nqubits = 2U; - qc::QuantumComputation op(nqubits); - op.cx(0, 1); - - qc::QuantumComputation qc(nqubits); - qc.emplace_back(op.asCompoundOperation()); - - CircuitOptimizer::replaceMCXWithMCZ(qc); - std::cout << qc << "\n"; - - CircuitOptimizer::flattenOperations(qc); - std::cout << qc << "\n"; - EXPECT_EQ(qc.getNops(), 3U); - EXPECT_EQ(qc.at(0)->getType(), qc::H); - EXPECT_EQ(qc.at(0)->getTargets()[0], 1U); - EXPECT_EQ(qc.at(1)->getType(), qc::Z); - EXPECT_EQ(qc.at(1)->getTargets()[0], 1U); - EXPECT_EQ(*qc.at(1)->getControls().begin(), 0U); - EXPECT_EQ(qc.at(2)->getType(), qc::H); - EXPECT_EQ(qc.at(2)->getTargets()[0], 1U); -} - -TEST_F(QFRFunctionality, testToffoliSequenceSimplification) { - std::size_t const nqubits = 3U; - qc::QuantumComputation qc(nqubits); - Controls const controls = {0, 1}; - Qubit const target = 2U; - qc.cx(0, target); - qc.mcx(controls, target); - CircuitOptimizer::replaceMCXWithMCZ(qc); - CircuitOptimizer::singleQubitGateFusion(qc); - CircuitOptimizer::flattenOperations(qc); - std::cout << qc << "\n"; - - qc::QuantumComputation reference(nqubits); - reference.h(target); - reference.cz(0, target); - reference.mcz(controls, target); - reference.h(target); - - for (std::size_t i = 0; i < reference.getNops(); ++i) { - EXPECT_EQ(qc.at(i)->getType(), reference.at(i)->getType()); - EXPECT_EQ(qc.at(i)->getTargets(), reference.at(i)->getTargets()); - EXPECT_EQ(qc.at(i)->getControls(), reference.at(i)->getControls()); - } -} - TEST_F(QFRFunctionality, testSettingAncillariesProperlyCreatesRegisters) { // create an empty circuit and assert some properties about its registers qc::QuantumComputation qc(3U); @@ -2185,3 +1101,35 @@ TEST_F(QFRFunctionality, StripIdleQubitsInMiddleOfCircuit) { ASSERT_EQ(qc.getNqubitsWithoutAncillae(), 3U); ASSERT_EQ(qc.getNancillae(), 0U); } + +TEST_F(QFRFunctionality, trivialOperationReordering) { + QuantumComputation qc(2); + qc.h(0); + qc.h(1); + std::cout << qc << "\n"; + qc.reorderOperations(); + std::cout << qc << "\n"; + auto it = qc.begin(); + const auto target = (*it)->getTargets().at(0); + EXPECT_EQ(target, 1); + ++it; + const auto target2 = (*it)->getTargets().at(0); + EXPECT_EQ(target2, 0); +} + +TEST_F(QFRFunctionality, OperationReorderingBarrier) { + QuantumComputation qc(2); + qc.h(0); + qc.barrier({0, 1}); + qc.h(1); + std::cout << qc << "\n"; + qc.reorderOperations(); + std::cout << qc << "\n"; + auto it = qc.begin(); + const auto target = (*it)->getTargets().at(0); + EXPECT_EQ(target, 0); + ++it; + ++it; + const auto target2 = (*it)->getTargets().at(0); + EXPECT_EQ(target2, 1); +} diff --git a/test/unittests/test_symbolic.cpp b/test/ir/test_symbolic.cpp similarity index 97% rename from test/unittests/test_symbolic.cpp rename to test/ir/test_symbolic.cpp index 54b2e03d1..b52a2ecca 100644 --- a/test/unittests/test_symbolic.cpp +++ b/test/ir/test_symbolic.cpp @@ -1,8 +1,8 @@ #include "Definitions.hpp" -#include "QuantumComputation.hpp" -#include "operations/Control.hpp" -#include "operations/Expression.hpp" -#include "operations/OpType.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/Control.hpp" +#include "ir/operations/Expression.hpp" +#include "ir/operations/OpType.hpp" #include #include diff --git a/test/na/test_nacomputation.cpp b/test/na/test_nacomputation.cpp index c146c601e..b866a1cab 100644 --- a/test/na/test_nacomputation.cpp +++ b/test/na/test_nacomputation.cpp @@ -1,10 +1,10 @@ #include "Definitions.hpp" +#include "ir/operations/OpType.hpp" #include "na/NAComputation.hpp" #include "na/NADefinitions.hpp" #include "na/operations/NAGlobalOperation.hpp" #include "na/operations/NALocalOperation.hpp" #include "na/operations/NAShuttlingOperation.hpp" -#include "operations/OpType.hpp" #include #include diff --git a/test/na/test_nadefinitions.cpp b/test/na/test_nadefinitions.cpp index d8a86ab84..867f756d1 100644 --- a/test/na/test_nadefinitions.cpp +++ b/test/na/test_nadefinitions.cpp @@ -1,6 +1,6 @@ -#include "QuantumComputation.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/OpType.hpp" #include "na/NADefinitions.hpp" -#include "operations/OpType.hpp" #include #include diff --git a/test/na/test_naoperation.cpp b/test/na/test_naoperation.cpp index 2b78f097d..f29b55520 100644 --- a/test/na/test_naoperation.cpp +++ b/test/na/test_naoperation.cpp @@ -1,9 +1,9 @@ #include "Definitions.hpp" +#include "ir/operations/OpType.hpp" #include "na/NADefinitions.hpp" #include "na/operations/NAGlobalOperation.hpp" #include "na/operations/NALocalOperation.hpp" #include "na/operations/NAShuttlingOperation.hpp" -#include "operations/OpType.hpp" #include #include diff --git a/test/unittests/circuit_optimizer/test_reorder_operations.cpp b/test/unittests/circuit_optimizer/test_reorder_operations.cpp deleted file mode 100644 index 94140c55a..000000000 --- a/test/unittests/circuit_optimizer/test_reorder_operations.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "CircuitOptimizer.hpp" -#include "QuantumComputation.hpp" - -#include -#include - -namespace qc { -TEST(ReorderOperations, trivialOperationReordering) { - QuantumComputation qc(2); - qc.h(0); - qc.h(1); - std::cout << qc << "\n"; - qc::CircuitOptimizer::reorderOperations(qc); - std::cout << qc << "\n"; - auto it = qc.begin(); - const auto target = (*it)->getTargets().at(0); - EXPECT_EQ(target, 1); - ++it; - const auto target2 = (*it)->getTargets().at(0); - EXPECT_EQ(target2, 0); -} - -TEST(ReorderOperations, OperationReorderingBarrier) { - QuantumComputation qc(2); - qc.h(0); - qc.barrier({0, 1}); - qc.h(1); - std::cout << qc << "\n"; - qc::CircuitOptimizer::reorderOperations(qc); - std::cout << qc << "\n"; - auto it = qc.begin(); - const auto target = (*it)->getTargets().at(0); - EXPECT_EQ(target, 0); - ++it; - ++it; - const auto target2 = (*it)->getTargets().at(0); - EXPECT_EQ(target2, 1); -} - -} // namespace qc diff --git a/test/zx/CMakeLists.txt b/test/zx/CMakeLists.txt new file mode 100644 index 000000000..3527121a2 --- /dev/null +++ b/test/zx/CMakeLists.txt @@ -0,0 +1,4 @@ +if(TARGET MQT::CoreZX) + file(GLOB_RECURSE ZX_TEST_SOURCES *.cpp) + package_add_test(mqt-core-zx-test MQT::CoreZX ${ZX_TEST_SOURCES}) +endif() diff --git a/test/zx/test_expression.cpp b/test/zx/test_expression.cpp index c78382743..900cdcdf7 100644 --- a/test/zx/test_expression.cpp +++ b/test/zx/test_expression.cpp @@ -1,4 +1,4 @@ -#include "operations/Expression.hpp" +#include "ir/operations/Expression.hpp" #include "zx/Rational.hpp" #include "zx/Utils.hpp" #include "zx/ZXDefinitions.hpp" diff --git a/test/zx/test_simplify.cpp b/test/zx/test_simplify.cpp index f094bf30f..a4a7effcb 100644 --- a/test/zx/test_simplify.cpp +++ b/test/zx/test_simplify.cpp @@ -1,4 +1,4 @@ -#include "operations/Expression.hpp" +#include "ir/operations/Expression.hpp" #include "zx/Simplify.hpp" #include "zx/ZXDefinitions.hpp" #include "zx/ZXDiagram.hpp" diff --git a/test/zx/test_zx_functionality.cpp b/test/zx/test_zx_functionality.cpp index 11cd39084..b34133789 100644 --- a/test/zx/test_zx_functionality.cpp +++ b/test/zx/test_zx_functionality.cpp @@ -1,10 +1,10 @@ #include "Definitions.hpp" -#include "Permutation.hpp" -#include "QuantumComputation.hpp" -#include "operations/CompoundOperation.hpp" -#include "operations/Expression.hpp" -#include "operations/OpType.hpp" -#include "operations/StandardOperation.hpp" +#include "ir/Permutation.hpp" +#include "ir/QuantumComputation.hpp" +#include "ir/operations/CompoundOperation.hpp" +#include "ir/operations/Expression.hpp" +#include "ir/operations/OpType.hpp" +#include "ir/operations/StandardOperation.hpp" #include "zx/FunctionalityConstruction.hpp" #include "zx/Simplify.hpp" #include "zx/ZXDefinitions.hpp" From 9308060157b19e9fdd9538f06e4a31a45bdfa8e1 Mon Sep 17 00:00:00 2001 From: burgholzer Date: Mon, 12 Aug 2024 20:56:10 +0200 Subject: [PATCH 02/13] =?UTF-8?q?=F0=9F=9A=A8=20fix=20linter=20warnings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: burgholzer --- include/mqt-core/dd/Simulation.hpp | 1 - src/circuit_optimizer/CircuitOptimizer.cpp | 1 - src/ir/operations/CompoundOperation.cpp | 1 + test/circuit_optimizer/test_flatten_operations.cpp | 3 +++ test/circuit_optimizer/test_remove_final_measurements.cpp | 4 ++++ test/circuit_optimizer/test_remove_operation.cpp | 1 + test/ir/test_qfr_functionality.cpp | 2 -- 7 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/mqt-core/dd/Simulation.hpp b/include/mqt-core/dd/Simulation.hpp index 066e6c689..197616956 100644 --- a/include/mqt-core/dd/Simulation.hpp +++ b/include/mqt-core/dd/Simulation.hpp @@ -7,7 +7,6 @@ #include #include -#include #include namespace dd { diff --git a/src/circuit_optimizer/CircuitOptimizer.cpp b/src/circuit_optimizer/CircuitOptimizer.cpp index c14a65f3b..ee2518f9e 100644 --- a/src/circuit_optimizer/CircuitOptimizer.cpp +++ b/src/circuit_optimizer/CircuitOptimizer.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include diff --git a/src/ir/operations/CompoundOperation.cpp b/src/ir/operations/CompoundOperation.cpp index 7fa67eeaa..e95878e79 100644 --- a/src/ir/operations/CompoundOperation.cpp +++ b/src/ir/operations/CompoundOperation.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include diff --git a/test/circuit_optimizer/test_flatten_operations.cpp b/test/circuit_optimizer/test_flatten_operations.cpp index b022d2bc4..331068af2 100644 --- a/test/circuit_optimizer/test_flatten_operations.cpp +++ b/test/circuit_optimizer/test_flatten_operations.cpp @@ -1,12 +1,15 @@ #include "algorithms/RandomCliffordCircuit.hpp" #include "circuit_optimizer/CircuitOptimizer.hpp" #include "ir/QuantumComputation.hpp" +#include "ir/operations/CompoundOperation.hpp" #include "ir/operations/OpType.hpp" +#include "ir/operations/StandardOperation.hpp" #include #include #include #include +#include #include namespace qc { diff --git a/test/circuit_optimizer/test_remove_final_measurements.cpp b/test/circuit_optimizer/test_remove_final_measurements.cpp index b1591c176..3a7234d1b 100644 --- a/test/circuit_optimizer/test_remove_final_measurements.cpp +++ b/test/circuit_optimizer/test_remove_final_measurements.cpp @@ -1,10 +1,14 @@ +#include "Definitions.hpp" #include "circuit_optimizer/CircuitOptimizer.hpp" #include "ir/QuantumComputation.hpp" +#include "ir/operations/CompoundOperation.hpp" #include "ir/operations/OpType.hpp" #include #include #include +#include +#include namespace qc { TEST(RemoveFinalMeasurements, removeFinalMeasurements) { diff --git a/test/circuit_optimizer/test_remove_operation.cpp b/test/circuit_optimizer/test_remove_operation.cpp index dc3c053c8..a8c1ac897 100644 --- a/test/circuit_optimizer/test_remove_operation.cpp +++ b/test/circuit_optimizer/test_remove_operation.cpp @@ -1,5 +1,6 @@ #include "circuit_optimizer/CircuitOptimizer.hpp" #include "ir/QuantumComputation.hpp" +#include "ir/operations/CompoundOperation.hpp" #include "ir/operations/OpType.hpp" #include diff --git a/test/ir/test_qfr_functionality.cpp b/test/ir/test_qfr_functionality.cpp index bf073fa35..4a0c091cb 100644 --- a/test/ir/test_qfr_functionality.cpp +++ b/test/ir/test_qfr_functionality.cpp @@ -1,6 +1,4 @@ #include "Definitions.hpp" -#include "algorithms/RandomCliffordCircuit.hpp" -// #include "circuit_optimizer/CircuitOptimizer.hpp" #include "ir/QuantumComputation.hpp" #include "ir/operations/ClassicControlledOperation.hpp" #include "ir/operations/CompoundOperation.hpp" From 4feec9db7fcb56c3a2044fc2db46fa7b2c30de55 Mon Sep 17 00:00:00 2001 From: burgholzer Date: Tue, 13 Aug 2024 00:32:16 +0200 Subject: [PATCH 03/13] =?UTF-8?q?=F0=9F=9A=A8=20fix=20linter=20warnings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: burgholzer --- src/dd/Simulation.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/dd/Simulation.cpp b/src/dd/Simulation.cpp index bb298d917..2df8ae5c6 100644 --- a/src/dd/Simulation.cpp +++ b/src/dd/Simulation.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include From fcf3f6956d2ead33457958096e7375d3ec631854 Mon Sep 17 00:00:00 2001 From: burgholzer Date: Tue, 13 Aug 2024 07:57:41 +0200 Subject: [PATCH 04/13] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20make=20tests=20with?= =?UTF-8?q?=20files=20work=20out=20of=20the=20box?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: burgholzer --- test/CMakeLists.txt | 3 +++ test/ir/CMakeLists.txt | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2c6598590..413ba2831 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -6,3 +6,6 @@ add_subdirectory(dd) add_subdirectory(ir) add_subdirectory(na) add_subdirectory(zx) + +# copy test circuits to build directory +file(COPY ${PROJECT_SOURCE_DIR}/test/circuits DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/test/ir/CMakeLists.txt b/test/ir/CMakeLists.txt index b6102d1a7..098da6942 100644 --- a/test/ir/CMakeLists.txt +++ b/test/ir/CMakeLists.txt @@ -1,4 +1,5 @@ if(TARGET MQT::CoreIR) file(GLOB_RECURSE IR_TEST_SOURCES *.cpp) - package_add_test(mqt-core-ir-test MQT::CoreIR ${IR_TEST_SOURCES}) + package_add_test_with_working_dir(mqt-core-ir-test MQT::CoreIR ${CMAKE_CURRENT_BINARY_DIR} + ${IR_TEST_SOURCES}) endif() From 208e2c1065db7df4fb57bbbbe716aa23627161c2 Mon Sep 17 00:00:00 2001 From: burgholzer Date: Tue, 13 Aug 2024 07:57:59 +0200 Subject: [PATCH 05/13] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20simplify=20reorderin?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: burgholzer --- src/ir/QuantumComputation.cpp | 39 +++-------------------------------- 1 file changed, 3 insertions(+), 36 deletions(-) diff --git a/src/ir/QuantumComputation.cpp b/src/ir/QuantumComputation.cpp index 9277c431e..c91d8493e 100644 --- a/src/ir/QuantumComputation.cpp +++ b/src/ir/QuantumComputation.cpp @@ -1134,36 +1134,9 @@ void QuantumComputation::reorderOperations() { auto dag = DAG(highestPhysicalQubit + 1); for (auto& op : ops) { - if (!op->isStandardOperation()) { - // compound operations are added "as-is" - if (op->isCompoundOperation()) { - const auto usedQubits = op->getUsedQubits(); - for (const auto q : usedQubits) { - dag.at(q).push_back(&op); - } - } else if (op->isNonUnitaryOperation()) { - for (const auto& b : op->getTargets()) { - dag.at(b).push_back(&op); - } - } else if (op->isClassicControlledOperation()) { - auto* cop = - dynamic_cast(op.get())->getOperation(); - for (const auto& control : cop->getControls()) { - dag.at(control.qubit).push_back(&op); - } - for (const auto& target : cop->getTargets()) { - dag.at(target).push_back(&op); - } - } else { - throw QFRException("Unexpected operation encountered"); - } - } else { - for (const auto& control : op->getControls()) { - dag.at(control.qubit).push_back(&op); - } - for (const auto& target : op->getTargets()) { - dag.at(target).push_back(&op); - } + const auto usedQubits = op->getUsedQubits(); + for (const auto q : usedQubits) { + dag.at(q).push_back(&op); } } @@ -1201,12 +1174,6 @@ void QuantumComputation::reorderOperations() { auto& it = dagIterators.at(static_cast(q)); auto& op = **it; - // warning for classically controlled operations - if (op->getType() == ClassicControlled) { - std::cerr << "Caution! Reordering operations might not work if the " - "circuit contains classically controlled operations\n"; - } - // check whether the gate can be scheduled, i.e. whether all qubits it // acts on are at this operation bool executable = true; From efc9d214b542f405ed27335f4fd58cb70210df16 Mon Sep 17 00:00:00 2001 From: burgholzer Date: Tue, 13 Aug 2024 08:09:07 +0200 Subject: [PATCH 06/13] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20simplify=20DAG=20con?= =?UTF-8?q?struction=20in=20circuit=20optimizer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: burgholzer --- src/circuit_optimizer/CircuitOptimizer.cpp | 60 ++++------------------ 1 file changed, 11 insertions(+), 49 deletions(-) diff --git a/src/circuit_optimizer/CircuitOptimizer.cpp b/src/circuit_optimizer/CircuitOptimizer.cpp index ee2518f9e..0cde338aa 100644 --- a/src/circuit_optimizer/CircuitOptimizer.cpp +++ b/src/circuit_optimizer/CircuitOptimizer.cpp @@ -76,7 +76,7 @@ void CircuitOptimizer::swapReconstruction(QuantumComputation& qc) { for (auto& it : qc.ops) { if (!it->isStandardOperation()) { - addNonStandardOperationToDag(dag, &it); + addToDag(dag, &it); continue; } @@ -160,49 +160,16 @@ DAG CircuitOptimizer::constructDAG(QuantumComputation& qc) { auto dag = DAG(highestPhysicalQubit + 1); - for (auto& it : qc.ops) { - if (!it->isStandardOperation()) { - addNonStandardOperationToDag(dag, &it); - } else { - addToDag(dag, &it); - } + for (auto& op : qc) { + addToDag(dag, &op); } return dag; } void CircuitOptimizer::addToDag(DAG& dag, std::unique_ptr* op) { - for (const auto& control : (*op)->getControls()) { - dag.at(control.qubit).push_back(op); - } - for (const auto& target : (*op)->getTargets()) { - dag.at(target).push_back(op); - } -} - -void CircuitOptimizer::addNonStandardOperationToDag( - DAG& dag, std::unique_ptr* op) { - const auto& gate = *op; - // compound operations are added "as-is" - if (gate->isCompoundOperation()) { - const auto usedQubits = gate->getUsedQubits(); - for (const auto q : usedQubits) { - dag.at(q).push_back(op); - } - } else if (gate->isNonUnitaryOperation()) { - for (const auto& b : gate->getTargets()) { - dag.at(b).push_back(op); - } - } else if (gate->isClassicControlledOperation()) { - auto* cop = - dynamic_cast(gate.get())->getOperation(); - for (const auto& control : cop->getControls()) { - dag.at(control.qubit).push_back(op); - } - for (const auto& target : cop->getTargets()) { - dag.at(target).push_back(op); - } - } else { - throw QFRException("Unexpected operation encountered"); + const auto usedQubits = (*op)->getUsedQubits(); + for (const auto q : usedQubits) { + dag.at(q).push_back(op); } } @@ -220,15 +187,10 @@ void CircuitOptimizer::singleQubitGateFusion(QuantumComputation& qc) { auto dag = DAG(highestPhysicalQubit + 1); - for (auto& it : qc.ops) { - if (!it->isStandardOperation()) { - addNonStandardOperationToDag(dag, &it); - continue; - } - - // not a single qubit operation TODO: multiple targets could also be - // considered here - if (!it->getControls().empty() || it->getTargets().size() > 1) { + for (auto& it : qc) { + // not a single-qubit operation + if (!it->isStandardOperation() || !it->getControls().empty() || + it->getTargets().size() > 1) { addToDag(dag, &it); continue; } @@ -1131,7 +1093,7 @@ void CircuitOptimizer::cancelCNOTs(QuantumComputation& qc) { for (auto& it : qc.ops) { if (!it->isStandardOperation()) { - addNonStandardOperationToDag(dag, &it); + addToDag(dag, &it); continue; } From 84b5a4faaef28d398fad5b0c6d0ddeb8d7adad97 Mon Sep 17 00:00:00 2001 From: burgholzer Date: Tue, 13 Aug 2024 08:09:38 +0200 Subject: [PATCH 07/13] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20only=20rely=20on=20p?= =?UTF-8?q?ublic=20API=20of=20QuantumComputation=20in=20circuit=20optimize?= =?UTF-8?q?r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: burgholzer --- include/mqt-core/ir/QuantumComputation.hpp | 6 +- .../ir/operations/CompoundOperation.hpp | 25 ++-- src/circuit_optimizer/CircuitOptimizer.cpp | 129 ++++++++++-------- 3 files changed, 87 insertions(+), 73 deletions(-) diff --git a/include/mqt-core/ir/QuantumComputation.hpp b/include/mqt-core/ir/QuantumComputation.hpp index 9548dac0f..868e4b490 100644 --- a/include/mqt-core/ir/QuantumComputation.hpp +++ b/include/mqt-core/ir/QuantumComputation.hpp @@ -35,8 +35,10 @@ class QuantumComputation { using iterator = typename std::vector>::iterator; using const_iterator = typename std::vector>::const_iterator; - - friend class CircuitOptimizer; + using reverse_iterator = + typename std::vector>::reverse_iterator; + using const_reverse_iterator = + typename std::vector>::const_reverse_iterator; protected: std::vector> ops; diff --git a/include/mqt-core/ir/operations/CompoundOperation.hpp b/include/mqt-core/ir/operations/CompoundOperation.hpp index 336d0d02b..ff0d17bbe 100644 --- a/include/mqt-core/ir/operations/CompoundOperation.hpp +++ b/include/mqt-core/ir/operations/CompoundOperation.hpp @@ -15,6 +15,11 @@ namespace qc { class CompoundOperation final : public Operation { +public: + using iterator = typename std::vector>::iterator; + using const_iterator = + typename std::vector>::const_iterator; + private: std::vector> ops; bool customGate; @@ -140,13 +145,8 @@ class CompoundOperation final : public Operation { // NOLINTNEXTLINE(readability-identifier-naming) void pop_back() { ops.pop_back(); } void resize(std::size_t count) { ops.resize(count); } - std::vector>::iterator - erase(std::vector>::const_iterator pos) { - return ops.erase(pos); - } - std::vector>::iterator - erase(std::vector>::const_iterator first, - std::vector>::const_iterator last) { + iterator erase(const_iterator pos) { return ops.erase(pos); } + iterator erase(const_iterator first, const_iterator last) { return ops.erase(first, last); } @@ -166,18 +166,17 @@ class CompoundOperation final : public Operation { } template - std::vector>::iterator - insert(std::vector>::const_iterator iterator, - Args&&... args) { + iterator insert(const_iterator iterator, Args&&... args) { return ops.insert(iterator, std::make_unique(std::forward(args)...)); } template - std::vector>::iterator - insert(std::vector>::const_iterator iterator, - std::unique_ptr& op) { + iterator insert(const_iterator iterator, std::unique_ptr& op) { return ops.insert(iterator, std::move(op)); } + template iterator insert(const_iterator iterator, T&& op) { + return ops.insert(iterator, std::forward(op)); + } [[nodiscard]] const auto& at(std::size_t i) const { return ops.at(i); } }; diff --git a/src/circuit_optimizer/CircuitOptimizer.cpp b/src/circuit_optimizer/CircuitOptimizer.cpp index 0cde338aa..db4b8775c 100644 --- a/src/circuit_optimizer/CircuitOptimizer.cpp +++ b/src/circuit_optimizer/CircuitOptimizer.cpp @@ -34,11 +34,11 @@ void CircuitOptimizer::removeOperation( qc::QuantumComputation& qc, const std::unordered_set& opTypes, const size_t opSize) { // opSize = 0 means that the operation can have any number of qubits - auto it = qc.ops.begin(); - while (it != qc.ops.end()) { + auto it = qc.begin(); + while (it != qc.end()) { if (opTypes.find((*it)->getType()) != opTypes.end() && (opSize == 0 || it->get()->getNqubits() == opSize)) { - it = qc.ops.erase(it); + it = qc.erase(it); } else if ((*it)->isCompoundOperation()) { auto* compOp = dynamic_cast((*it).get()); auto cit = compOp->cbegin(); @@ -52,7 +52,7 @@ void CircuitOptimizer::removeOperation( } } if (compOp->empty()) { - it = qc.ops.erase(it); + it = qc.erase(it); } else { if (compOp->size() == 1) { // CompoundOperation has degraded to single Operation @@ -74,7 +74,7 @@ void CircuitOptimizer::swapReconstruction(QuantumComputation& qc) { auto dag = DAG(highestPhysicalQubit + 1); - for (auto& it : qc.ops) { + for (auto& it : qc) { if (!it->isStandardOperation()) { addToDag(dag, &it); continue; @@ -583,31 +583,31 @@ void CircuitOptimizer::removeFinalMeasurements(QuantumComputation& qc) { void CircuitOptimizer::decomposeSWAP(QuantumComputation& qc, bool isDirectedArchitecture) { // decompose SWAPS in three cnot and optionally in four H - auto it = qc.ops.begin(); - while (it != qc.ops.end()) { + auto it = qc.begin(); + while (it != qc.end()) { if ((*it)->isStandardOperation()) { if ((*it)->getType() == qc::SWAP) { const auto targets = (*it)->getTargets(); - it = qc.ops.erase(it); - it = qc.ops.insert(it, std::make_unique( - Control{targets[0]}, targets[1], qc::X)); + it = qc.erase(it); + it = qc.insert(it, std::make_unique( + Control{targets[0]}, targets[1], qc::X)); if (isDirectedArchitecture) { - it = qc.ops.insert( + it = qc.insert( it, std::make_unique(targets[0], qc::H)); - it = qc.ops.insert( + it = qc.insert( it, std::make_unique(targets[1], qc::H)); - it = qc.ops.insert(it, std::make_unique( - Control{targets[0]}, targets[1], qc::X)); - it = qc.ops.insert( + it = qc.insert(it, std::make_unique( + Control{targets[0]}, targets[1], qc::X)); + it = qc.insert( it, std::make_unique(targets[0], qc::H)); - it = qc.ops.insert( + it = qc.insert( it, std::make_unique(targets[1], qc::H)); } else { - it = qc.ops.insert(it, std::make_unique( - Control{targets[1]}, targets[0], qc::X)); + it = qc.insert(it, std::make_unique( + Control{targets[1]}, targets[0], qc::X)); } - it = qc.ops.insert(it, std::make_unique( - Control{targets[0]}, targets[1], qc::X)); + it = qc.insert(it, std::make_unique( + Control{targets[0]}, targets[1], qc::X)); } else { ++it; } @@ -683,8 +683,8 @@ void CircuitOptimizer::eliminateResets(QuantumComputation& qc) { // c: 2/══════╩══════════╩═ // 0 1 auto replacementMap = std::map(); - auto it = qc.ops.begin(); - while (it != qc.ops.end()) { + auto it = qc.begin(); + while (it != qc.end()) { if ((*it)->getType() == qc::Reset) { for (const auto& target : (*it)->getTargets()) { auto indexAddQubit = static_cast(qc.getNqubits()); @@ -771,7 +771,7 @@ void CircuitOptimizer::deferMeasurements(QuantumComputation& qc) { } // if this is the last operation, nothing has to be done - if (*it == qc.ops.back()) { + if (*it == qc.back()) { break; } @@ -846,7 +846,7 @@ void CircuitOptimizer::deferMeasurements(QuantumComputation& qc) { std::stringstream ss{}; ss << "Underlying operation of classic-controlled operation is " "not a StandardOperation.\n"; - classicOp->print(ss, qc.nqubits); + classicOp->print(ss, qc.getNqubits()); throw QFRException(ss.str()); } @@ -939,7 +939,7 @@ bool CircuitOptimizer::isDynamicCircuit(QuantumComputation& qc) { bool hasMeasurements = false; - for (auto& it : qc.ops) { + for (auto& it : qc) { if (!it->isStandardOperation()) { if (it->isNonUnitaryOperation()) { // whenever a reset operation is encountered the circuit has to be @@ -1038,8 +1038,7 @@ void CircuitOptimizer::printDAG(const DAG& dag, const DAGIterators& iterators) { } using Iterator = qc::QuantumComputation::iterator; -Iterator flattenCompoundOperation(std::vector>& ops, - Iterator it) { +void flattenCompoundOperation(QuantumComputation& qc, Iterator& it) { assert((*it)->isCompoundOperation()); auto& op = dynamic_cast(**it); auto opIt = op.begin(); @@ -1048,7 +1047,7 @@ Iterator flattenCompoundOperation(std::vector>& ops, // move the operation from the compound operation in front of the compound // operation in the flattened container. `it` then points to the newly // inserted element - it = ops.insert(it, std::move(*opIt)); + it = qc.insert(it, std::move(*opIt)); // advance the operation iterator to point past the now moved-from element // in the compound operation ++opIt; @@ -1060,10 +1059,9 @@ Iterator flattenCompoundOperation(std::vector>& ops, // whenever all the operations have been processed, `it` points to the // compound operation and `opIt` to `op.end()`. The compound operation can now // be deleted safely - it = ops.erase(it); + it = qc.erase(it); // move the general iterator back to the position of the last moved operation std::advance(it, -movedOperations); - return it; } void CircuitOptimizer::flattenOperations(QuantumComputation& qc, @@ -1073,7 +1071,7 @@ void CircuitOptimizer::flattenOperations(QuantumComputation& qc, if ((*it)->isCompoundOperation()) { auto& op = dynamic_cast(**it); if (!customGatesOnly || op.isCustomGate()) { - it = flattenCompoundOperation(qc.ops, it); + flattenCompoundOperation(qc, it); } else { ++it; } @@ -1091,7 +1089,7 @@ void CircuitOptimizer::cancelCNOTs(QuantumComputation& qc) { auto dag = DAG(highestPhysicalQubit + 1U); - for (auto& it : qc.ops) { + for (auto& it : qc) { if (!it->isStandardOperation()) { addToDag(dag, &it); continue; @@ -1249,8 +1247,12 @@ void CircuitOptimizer::cancelCNOTs(QuantumComputation& qc) { removeIdentities(qc); } -void replaceMCXWithMCZ(std::vector>& ops) { - for (auto it = ops.begin(); it != ops.end(); ++it) { +void replaceMCXWithMCZ( + Iterator begin, const std::function& end, + const std::function&&)>& + insert, + const std::function& erase) { + for (auto it = begin; it != end(); ++it) { auto& op = *it; if (op->getType() == qc::X && op->getNcontrols() > 0) { const auto& controls = op->getControls(); @@ -1260,36 +1262,42 @@ void replaceMCXWithMCZ(std::vector>& ops) { // -c- ---c--- // | = | // -X- -H-Z-H- - std::array, 3U> replacementOps{}; - replacementOps[0] = std::make_unique(target, H); - replacementOps[1] = - std::make_unique(controls, target, Z); - replacementOps[2] = std::make_unique(target, H); - - it = ops.insert(it, std::make_move_iterator(replacementOps.begin()), - std::make_move_iterator(replacementOps.end())); - + it = insert(it, std::make_unique(target, H)); + it = insert(it, std::make_unique(controls, target, Z)); + it = insert(it, std::make_unique(target, H)); // advance to the original operation and delete it std::advance(it, 3); - it = ops.erase(it); + it = erase(it); --it; } else if (op->isCompoundOperation()) { - replaceMCXWithMCZ(dynamic_cast(*op).getOps()); + auto* compOp = dynamic_cast(op.get()); + replaceMCXWithMCZ( + compOp->begin(), [&compOp] { return compOp->end(); }, + [&compOp](auto it, auto&& op) { + return compOp->insert(it, std::forward(op)); + }, + [&compOp](auto it) { return compOp->erase(it); }); } } } void CircuitOptimizer::replaceMCXWithMCZ(qc::QuantumComputation& qc) { - ::qc::replaceMCXWithMCZ(qc.ops); + ::qc::replaceMCXWithMCZ( + qc.begin(), [&qc] { return qc.end(); }, + [&qc](auto it, auto&& op) { + return qc.insert(it, std::forward(op)); + }, + [&qc](auto it) { return qc.erase(it); }); } +using ConstReverseIterator = QuantumComputation::const_reverse_iterator; void backpropagateOutputPermutation( - std::vector>& ops, Permutation& permutation, - std::unordered_set& missingLogicalQubits) { - for (auto it = ops.rbegin(); it != ops.rend(); ++it) { + ConstReverseIterator rbegin, ConstReverseIterator rend, + Permutation& permutation, std::unordered_set& missingLogicalQubits) { + for (auto it = rbegin; it != rend; ++it) { if ((*it)->isCompoundOperation()) { auto& op = dynamic_cast(**it); - backpropagateOutputPermutation(op.getOps(), permutation, + backpropagateOutputPermutation(op.crbegin(), op.crend(), permutation, missingLogicalQubits); continue; } @@ -1366,7 +1374,7 @@ void CircuitOptimizer::backpropagateOutputPermutation(QuantumComputation& qc) { } } - ::qc::backpropagateOutputPermutation(qc.ops, permutation, + ::qc::backpropagateOutputPermutation(qc.crbegin(), qc.crend(), permutation, missingLogicalQubits); // `permutation` now holds a potentially incomplete initial layout @@ -1500,7 +1508,7 @@ struct DSU { void CircuitOptimizer::collectBlocks(qc::QuantumComputation& qc, const std::size_t maxBlockSize) { - if (qc.ops.size() <= 1) { + if (qc.size() <= 1) { return; } @@ -1653,14 +1661,17 @@ void CircuitOptimizer::collectBlocks(qc::QuantumComputation& qc, removeIdentities(qc); } -void elidePermutations(std::vector>& ops, +void elidePermutations(Iterator begin, const std::function& end, + const std::function& erase, Permutation& permutation) { - for (auto it = ops.begin(); it != ops.end();) { + for (auto it = begin; it != end();) { auto& op = *it; if (auto* compOp = dynamic_cast(op.get())) { - elidePermutations(compOp->getOps(), permutation); + elidePermutations( + compOp->begin(), [&compOp]() { return compOp->end(); }, + [&compOp](auto it) { return compOp->erase(it); }, permutation); if (compOp->empty()) { - it = ops.erase(it); + it = erase(it); continue; } if (compOp->isConvertibleToSingleOperation()) { @@ -1681,7 +1692,7 @@ void elidePermutations(std::vector>& ops, auto& target0 = permutation[targets[0]]; auto& target1 = permutation[targets[1]]; std::swap(target0, target1); - it = ops.erase(it); + it = erase(it); continue; } @@ -1696,7 +1707,9 @@ void CircuitOptimizer::elidePermutations(QuantumComputation& qc) { } auto permutation = qc.initialLayout; - ::qc::elidePermutations(qc.ops, permutation); + ::qc::elidePermutations( + qc.begin(), [&qc]() { return qc.end(); }, + [&qc](auto it) { return qc.erase(it); }, permutation); // adjust the initial layout Permutation initialLayout{}; From 4eb8ae94b003f1eacd120bab0775b8c436e13ec4 Mon Sep 17 00:00:00 2001 From: burgholzer Date: Tue, 13 Aug 2024 08:14:19 +0200 Subject: [PATCH 08/13] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20fix=20typo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: burgholzer --- src/ir/QuantumComputation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ir/QuantumComputation.cpp b/src/ir/QuantumComputation.cpp index c91d8493e..ebccc1a8f 100644 --- a/src/ir/QuantumComputation.cpp +++ b/src/ir/QuantumComputation.cpp @@ -1144,7 +1144,7 @@ void QuantumComputation::reorderOperations() { DAGIterators dagIterators{dag.size()}; for (size_t q = 0; q < dag.size(); ++q) { if (dag.at(q).empty()) { - // qubit is isdle + // qubit is idle dagIterators.at(q) = dag.at(q).end(); } else { // point to first operation From c5bad7f5cb8d57c8c3dbff0ed8e7e676c9574d74 Mon Sep 17 00:00:00 2001 From: burgholzer Date: Tue, 13 Aug 2024 08:14:34 +0200 Subject: [PATCH 09/13] =?UTF-8?q?=E2=9C=85=20adjust=20test=20to=20cover=20?= =?UTF-8?q?additional=20scenario?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: burgholzer --- test/ir/test_qfr_functionality.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ir/test_qfr_functionality.cpp b/test/ir/test_qfr_functionality.cpp index 4a0c091cb..42a53873f 100644 --- a/test/ir/test_qfr_functionality.cpp +++ b/test/ir/test_qfr_functionality.cpp @@ -1116,7 +1116,7 @@ TEST_F(QFRFunctionality, trivialOperationReordering) { } TEST_F(QFRFunctionality, OperationReorderingBarrier) { - QuantumComputation qc(2); + QuantumComputation qc(3); qc.h(0); qc.barrier({0, 1}); qc.h(1); From 7504bd0ba8314ffada33577805a06ab70688a240 Mon Sep 17 00:00:00 2001 From: burgholzer Date: Tue, 13 Aug 2024 10:33:03 +0200 Subject: [PATCH 10/13] =?UTF-8?q?=F0=9F=9A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: burgholzer --- src/circuit_optimizer/CircuitOptimizer.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/circuit_optimizer/CircuitOptimizer.cpp b/src/circuit_optimizer/CircuitOptimizer.cpp index db4b8775c..9aa2f0c36 100644 --- a/src/circuit_optimizer/CircuitOptimizer.cpp +++ b/src/circuit_optimizer/CircuitOptimizer.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -930,9 +931,7 @@ void CircuitOptimizer::deferMeasurements(QuantumComputation& qc) { bool CircuitOptimizer::isDynamicCircuit(QuantumComputation& qc) { Qubit highestPhysicalQubit = 0; for (const auto& q : qc.initialLayout) { - if (q.first > highestPhysicalQubit) { - highestPhysicalQubit = q.first; - } + highestPhysicalQubit = std::max(q.first, highestPhysicalQubit); } auto dag = DAG(highestPhysicalQubit + 1); @@ -1292,7 +1291,7 @@ void CircuitOptimizer::replaceMCXWithMCZ(qc::QuantumComputation& qc) { using ConstReverseIterator = QuantumComputation::const_reverse_iterator; void backpropagateOutputPermutation( - ConstReverseIterator rbegin, ConstReverseIterator rend, + const ConstReverseIterator& rbegin, const ConstReverseIterator& rend, Permutation& permutation, std::unordered_set& missingLogicalQubits) { for (auto it = rbegin; it != rend; ++it) { if ((*it)->isCompoundOperation()) { From bf5246c2ddcdb93f2092cd370b049651b9844469 Mon Sep 17 00:00:00 2001 From: burgholzer Date: Tue, 13 Aug 2024 10:39:46 +0200 Subject: [PATCH 11/13] =?UTF-8?q?=F0=9F=9A=9A=20folder=20structure=20in=20?= =?UTF-8?q?bindings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: burgholzer --- src/python/CMakeLists.txt | 19 ++++--------------- .../register_classic_controlled_operation.cpp | 0 .../register_compound_operation.cpp | 0 .../{ => ir}/operations/register_control.cpp | 0 .../register_non_unitary_operation.cpp | 0 .../operations/register_operation.cpp | 0 .../{ => ir}/operations/register_optype.cpp | 0 .../register_standard_operation.cpp | 0 .../register_symbolic_operation.cpp | 0 src/python/{ => ir}/register_operations.cpp | 0 src/python/{ => ir}/register_permutation.cpp | 0 .../{ => ir}/register_quantum_computation.cpp | 0 src/python/{ => ir}/register_symbolic.cpp | 0 .../{ => ir}/symbolic/register_expression.cpp | 0 .../{ => ir}/symbolic/register_term.cpp | 0 .../{ => ir}/symbolic/register_variable.cpp | 0 16 files changed, 4 insertions(+), 15 deletions(-) rename src/python/{ => ir}/operations/register_classic_controlled_operation.cpp (100%) rename src/python/{ => ir}/operations/register_compound_operation.cpp (100%) rename src/python/{ => ir}/operations/register_control.cpp (100%) rename src/python/{ => ir}/operations/register_non_unitary_operation.cpp (100%) rename src/python/{ => ir}/operations/register_operation.cpp (100%) rename src/python/{ => ir}/operations/register_optype.cpp (100%) rename src/python/{ => ir}/operations/register_standard_operation.cpp (100%) rename src/python/{ => ir}/operations/register_symbolic_operation.cpp (100%) rename src/python/{ => ir}/register_operations.cpp (100%) rename src/python/{ => ir}/register_permutation.cpp (100%) rename src/python/{ => ir}/register_quantum_computation.cpp (100%) rename src/python/{ => ir}/register_symbolic.cpp (100%) rename src/python/{ => ir}/symbolic/register_expression.cpp (100%) rename src/python/{ => ir}/symbolic/register_term.cpp (100%) rename src/python/{ => ir}/symbolic/register_variable.cpp (100%) diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt index 091670a57..a75035b22 100644 --- a/src/python/CMakeLists.txt +++ b/src/python/CMakeLists.txt @@ -1,4 +1,7 @@ if(NOT TARGET _core) + # collect source files + file(GLOB_RECURSE IR_PYTHON_SOURCES ir/*.cpp) + pybind11_add_module( # Name of the extension _core @@ -9,21 +12,7 @@ if(NOT TARGET _core) # Source code goes here ${MQT_CORE_INCLUDE_BUILD_DIR}/python/pybind11.hpp module.cpp - register_operations.cpp - register_permutation.cpp - register_symbolic.cpp - register_quantum_computation.cpp - operations/register_optype.cpp - operations/register_control.cpp - operations/register_operation.cpp - operations/register_standard_operation.cpp - operations/register_classic_controlled_operation.cpp - operations/register_compound_operation.cpp - operations/register_non_unitary_operation.cpp - operations/register_symbolic_operation.cpp - symbolic/register_variable.cpp - symbolic/register_term.cpp - symbolic/register_expression.cpp) + ${IR_PYTHON_SOURCES}) target_link_libraries(_core PRIVATE MQT::CoreIR MQT::ProjectOptions MQT::ProjectWarnings) # Install directive for scikit-build-core diff --git a/src/python/operations/register_classic_controlled_operation.cpp b/src/python/ir/operations/register_classic_controlled_operation.cpp similarity index 100% rename from src/python/operations/register_classic_controlled_operation.cpp rename to src/python/ir/operations/register_classic_controlled_operation.cpp diff --git a/src/python/operations/register_compound_operation.cpp b/src/python/ir/operations/register_compound_operation.cpp similarity index 100% rename from src/python/operations/register_compound_operation.cpp rename to src/python/ir/operations/register_compound_operation.cpp diff --git a/src/python/operations/register_control.cpp b/src/python/ir/operations/register_control.cpp similarity index 100% rename from src/python/operations/register_control.cpp rename to src/python/ir/operations/register_control.cpp diff --git a/src/python/operations/register_non_unitary_operation.cpp b/src/python/ir/operations/register_non_unitary_operation.cpp similarity index 100% rename from src/python/operations/register_non_unitary_operation.cpp rename to src/python/ir/operations/register_non_unitary_operation.cpp diff --git a/src/python/operations/register_operation.cpp b/src/python/ir/operations/register_operation.cpp similarity index 100% rename from src/python/operations/register_operation.cpp rename to src/python/ir/operations/register_operation.cpp diff --git a/src/python/operations/register_optype.cpp b/src/python/ir/operations/register_optype.cpp similarity index 100% rename from src/python/operations/register_optype.cpp rename to src/python/ir/operations/register_optype.cpp diff --git a/src/python/operations/register_standard_operation.cpp b/src/python/ir/operations/register_standard_operation.cpp similarity index 100% rename from src/python/operations/register_standard_operation.cpp rename to src/python/ir/operations/register_standard_operation.cpp diff --git a/src/python/operations/register_symbolic_operation.cpp b/src/python/ir/operations/register_symbolic_operation.cpp similarity index 100% rename from src/python/operations/register_symbolic_operation.cpp rename to src/python/ir/operations/register_symbolic_operation.cpp diff --git a/src/python/register_operations.cpp b/src/python/ir/register_operations.cpp similarity index 100% rename from src/python/register_operations.cpp rename to src/python/ir/register_operations.cpp diff --git a/src/python/register_permutation.cpp b/src/python/ir/register_permutation.cpp similarity index 100% rename from src/python/register_permutation.cpp rename to src/python/ir/register_permutation.cpp diff --git a/src/python/register_quantum_computation.cpp b/src/python/ir/register_quantum_computation.cpp similarity index 100% rename from src/python/register_quantum_computation.cpp rename to src/python/ir/register_quantum_computation.cpp diff --git a/src/python/register_symbolic.cpp b/src/python/ir/register_symbolic.cpp similarity index 100% rename from src/python/register_symbolic.cpp rename to src/python/ir/register_symbolic.cpp diff --git a/src/python/symbolic/register_expression.cpp b/src/python/ir/symbolic/register_expression.cpp similarity index 100% rename from src/python/symbolic/register_expression.cpp rename to src/python/ir/symbolic/register_expression.cpp diff --git a/src/python/symbolic/register_term.cpp b/src/python/ir/symbolic/register_term.cpp similarity index 100% rename from src/python/symbolic/register_term.cpp rename to src/python/ir/symbolic/register_term.cpp diff --git a/src/python/symbolic/register_variable.cpp b/src/python/ir/symbolic/register_variable.cpp similarity index 100% rename from src/python/symbolic/register_variable.cpp rename to src/python/ir/symbolic/register_variable.cpp From 62d67046ec9247b14e867562df6d4cffb127027c Mon Sep 17 00:00:00 2001 From: burgholzer Date: Tue, 13 Aug 2024 22:55:24 +0200 Subject: [PATCH 12/13] =?UTF-8?q?=E2=99=BB=EF=B8=8F=F0=9F=93=A6=20refactor?= =?UTF-8?q?=20`mqt.core`=20python=20package?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: burgholzer --- docs/dd_package_evaluation.md | 14 ++-- docs/quickstart.md | 40 +++++----- pyproject.toml | 6 +- src/mqt/core/__init__.py | 57 ++++++++++++-- src/mqt/core/dd/__init__.py | 1 + src/mqt/core/{ => dd}/evaluation.py | 0 src/mqt/core/{_core => ir}/__init__.pyi | 8 +- src/mqt/core/{_core => ir}/operations.pyi | 78 +++++++++---------- src/mqt/core/{_core => ir}/symbolic.pyi | 0 src/mqt/core/load.py | 54 ------------- src/mqt/core/operations.py | 38 --------- src/mqt/core/plugins/qiskit.py | 8 +- src/mqt/core/symbolic.py | 11 --- src/python/CMakeLists.txt | 25 +----- src/python/ir/CMakeLists.txt | 23 ++++++ src/python/{module.cpp => ir/register_ir.cpp} | 2 +- test/python/test_evaluation.py | 20 ++--- test/python/test_load.py | 4 +- test/python/test_qiskit.py | 4 +- 19 files changed, 169 insertions(+), 224 deletions(-) create mode 100644 src/mqt/core/dd/__init__.py rename src/mqt/core/{ => dd}/evaluation.py (100%) rename src/mqt/core/{_core => ir}/__init__.pyi (99%) rename src/mqt/core/{_core => ir}/operations.pyi (92%) rename src/mqt/core/{_core => ir}/symbolic.pyi (100%) delete mode 100644 src/mqt/core/load.py delete mode 100644 src/mqt/core/operations.py delete mode 100644 src/mqt/core/symbolic.py create mode 100644 src/python/ir/CMakeLists.txt rename src/python/{module.cpp => ir/register_ir.cpp} (91%) diff --git a/docs/dd_package_evaluation.md b/docs/dd_package_evaluation.md index d1208d335..a51a53779 100644 --- a/docs/dd_package_evaluation.md +++ b/docs/dd_package_evaluation.md @@ -39,7 +39,7 @@ To compare the performance of your newly proposed changes to the existing implem ## Running the comparison -There are two ways to run the comparison. Either you can use the Python module {py:mod}`mqt.core.evaluation` or you can use the CLI. +There are two ways to run the comparison. Either you can use the Python module {py:mod}`mqt.core.dd.evaluation` or you can use the CLI. Both ways are shown below. In both cases, you need to have the `evaluation` extra of `mqt-core` (i.e., `mqt.core[evaluation]`) installed. @@ -47,19 +47,19 @@ In both cases, you need to have the `evaluation` extra of `mqt-core` (i.e., `mqt ### Using the Python package -The Python package provides a function {py:func}`~mqt.core.evaluation.compare` that can be used to compare two generate result files. +The Python package provides a function {py:func}`~mqt.core.dd.evaluation.compare` that can be used to compare two generate result files. The function takes two arguments, the file path of the baseline json and the file path of the json results from your changes. The function will then print a detailed comparison. An exemplary run is shown below. ```{code-cell} ipython3 -from mqt.core.evaluation import compare +from mqt.core.dd.evaluation import compare baseline_path = "../test/python/results_baseline.json" feature_path = "../test/python/results_feature.json" compare(baseline_path, feature_path) ``` -Note that the method offers several parameters to customize the comparison. See {py:func}`mqt.core.evaluation.compare`. +Note that the method offers several parameters to customize the comparison. See {py:func}`mqt.core.dd.evaluation.compare`. An exemplary run adjusting the parameters is shown below. ```{code-cell} ipython3 @@ -72,13 +72,13 @@ In an even simpler fashion, the comparison can be run from the command line via Examples of such runs are shown below. ```{code-cell} ipython3 -! mqt-core-compare ../test/python/results_baseline.json ../test/python/results_feature.json --factor=0.2 --only_changed +! mqt-core-dd-compare ../test/python/results_baseline.json ../test/python/results_feature.json --factor=0.2 --only_changed ``` ```{code-cell} ipython3 -! mqt-core-compare ../test/python/results_baseline.json ../test/python/results_feature.json --no_split --dd --task=functionality +! mqt-core-dd-compare ../test/python/results_baseline.json ../test/python/results_feature.json --no_split --dd --task=functionality ``` ```{code-cell} ipython3 -! mqt-core-compare ../test/python/results_baseline.json ../test/python/results_feature.json --dd --algorithm=bv --num_qubits=1024 +! mqt-core-dd-compare ../test/python/results_baseline.json ../test/python/results_feature.json --dd --algorithm=bv --num_qubits=1024 ``` diff --git a/docs/quickstart.md b/docs/quickstart.md index c0ff18b6d..d9691f5d6 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -13,9 +13,9 @@ mystnb: # Quickstart -The central interface for working with quantum circuits in the Munich Quantum Toolkit is the {py:class}`~mqt.core.QuantumComputation` class. +The central interface for working with quantum circuits in the Munich Quantum Toolkit is the {py:class}`~mqt.core.ir.QuantumComputation` class. It represents quantum circuits as a sequential list of operations. -Operations can be directly applied to the {py:class}`~mqt.core.QuantumComputation`: +Operations can be directly applied to the {py:class}`~mqt.core.ir.QuantumComputation`: ```{code-cell} ipython3 from mqt.core import QuantumComputation @@ -34,7 +34,7 @@ print(qc.qasm3_str()) The circuit class provides a lot of flexibility as every unitary gate can be declared as a controlled gate: ```{code-cell} ipython3 -from mqt.core.operations import Control +from mqt.core.ir.operations import Control nqubits = 2 qc = QuantumComputation(nqubits) @@ -65,10 +65,10 @@ print(qc.qasm3_str()) ## Layout Information -A {py:class}`~mqt.core.QuantumComputation` also contains information about the mapping of algorithmic (or logical/virtual/circuit) qubits to and from device (or physical) qubits. -These are contained in the {py:attr}`~mqt.core.QuantumComputation.initial_layout` and {py:attr}`~mqt.core.QuantumComputation.output_permutation` members which are instances of the {py:class}`~mqt.core.Permutation` class. If no layout is given the trivial layout is assumed. +A {py:class}`~mqt.core.ir.QuantumComputation` also contains information about the mapping of algorithmic (or logical/virtual/circuit) qubits to and from device (or physical) qubits. +These are contained in the {py:attr}`~mqt.core.ir.QuantumComputation.initial_layout` and {py:attr}`~mqt.core.ir.QuantumComputation.output_permutation` members which are instances of the {py:class}`~mqt.core.ir.Permutation` class. If no layout is given the trivial layout is assumed. -When printing the OpenQASM representation of the {py:class}`~mqt.core.QuantumComputation` the input and output permutations are given as comments in the first two lines of the QASM string. The format is: +When printing the OpenQASM representation of the {py:class}`~mqt.core.ir.QuantumComputation` the input and output permutations are given as comments in the first two lines of the QASM string. The format is: `// i Q_0, Q_1, ..., Q_n` ... algorithmic qubit $i$ is mapped to device qubit $Q_i$. @@ -90,7 +90,7 @@ print(qc.qasm3_str()) ``` The layout information can also be automatically determined from measurements -using the {py:meth}`~mqt.core.QuantumComputation.initialize_io_mapping` method: +using the {py:meth}`~mqt.core.ir.QuantumComputation.initialize_io_mapping` method: ```{code-cell} ipython3 nqubits = 3 @@ -126,19 +126,19 @@ print(qc) ## Operations -The operations in a {py:class}`~mqt.core.QuantumComputation` object are of type {py:class}`~mqt.core.operations.Operation`. +The operations in a {py:class}`~mqt.core.ir.QuantumComputation` object are of type {py:class}`~mqt.core.ir.operations.Operation`. Every type of operation in `mqt-core` is derived from this class. Operations can also be explicitly constructed. -Each {py:class}`~mqt.core.operations.Operation` has a type in the form of an {py:class}`~mqt.core.operations.OpType`. +Each {py:class}`~mqt.core.ir.operations.Operation` has a type in the form of an {py:class}`~mqt.core.ir.operations.OpType`. ### `StandardOperation` -A {py:class}`~mqt.core.operations.StandardOperation` is used to represent basic unitary gates. These can also be declared with arbitrary targets and controls. +A {py:class}`~mqt.core.ir.operations.StandardOperation` is used to represent basic unitary gates. These can also be declared with arbitrary targets and controls. ```{code-cell} ipython3 from math import pi -from mqt.core.operations import OpType, StandardOperation +from mqt.core.ir.operations import OpType, StandardOperation nqubits = 3 @@ -162,10 +162,10 @@ print(qc) ### `NonUnitaryOperation` -A {py:class}`~mqt.core.operations.NonUnitaryOperation` is used to represent operations involving measurements or resets. +A {py:class}`~mqt.core.ir.operations.NonUnitaryOperation` is used to represent operations involving measurements or resets. ```{code-cell} ipython3 -from mqt.core.operations import NonUnitaryOperation +from mqt.core.ir.operations import NonUnitaryOperation nqubits = 2 qc = QuantumComputation(nqubits, nqubits) @@ -185,12 +185,12 @@ print(qc.qasm3_str()) ### `SymbolicOperation` -A {py:class}`~mqt.core.operations.SymbolicOperation` can represent all gates of a {py:class}`~mqt.core.operations.StandardOperation` but the gate parameters can be symbolic. -Symbolic expressions are represented in MQT using the {py:class}`~mqt.core.symbolic.Expression` type, which represent linear combinations of symbolic {py:class}`~mqt.core.symbolic.Term` objects over some set of {py:class}`~mqt.core.symbolic.Variable` objects. +A {py:class}`~mqt.core.ir.operations.SymbolicOperation` can represent all gates of a {py:class}`~mqt.core.ir.operations.StandardOperation` but the gate parameters can be symbolic. +Symbolic expressions are represented in MQT using the {py:class}`~mqt.core.ir.symbolic.Expression` type, which represent linear combinations of symbolic {py:class}`~mqt.core.ir.symbolic.Term` objects over some set of {py:class}`~mqt.core.ir.symbolic.Variable` objects. ```{code-cell} ipython3 -from mqt.core.operations import SymbolicOperation -from mqt.core.symbolic import Expression, Term, Variable +from mqt.core.ir.operations import SymbolicOperation +from mqt.core.ir.symbolic import Expression, Term, Variable nqubits = 1 @@ -211,10 +211,10 @@ u2_symb = SymbolicOperation(target=0, params=[sym, 2.0], op_type=OpType.u2) ### `CompoundOperation` -A {py:class}`~mqt.core.operations.CompoundOperation` bundles multiple {py:class}`~mqt.core.operations.Operation` objects together. +A {py:class}`~mqt.core.ir.operations.CompoundOperation` bundles multiple {py:class}`~mqt.core.ir.operations.Operation` objects together. ```{code-cell} ipython3 -from mqt.core.operations import CompoundOperation +from mqt.core.ir.operations import CompoundOperation nqubits = 2 comp_op = CompoundOperation() @@ -247,7 +247,7 @@ print(qc) ## Interfacing with other SDKs -Since a {py:class}`~mqt.core.QuantumComputation` can be imported from and exported to an OpenQASM 3.0 (or OpenQASM 2.0) string, any library that can work with OpenQASM is easy to use in conjunction with the {py:class}`~mqt.core.QuantumComputation` class. +Since a {py:class}`~mqt.core.ir.QuantumComputation` can be imported from and exported to an OpenQASM 3.0 (or OpenQASM 2.0) string, any library that can work with OpenQASM is easy to use in conjunction with the {py:class}`~mqt.core.ir.QuantumComputation` class. In addition, `mqt-core` can import [Qiskit](https://qiskit.org/) {py:class}`~qiskit.circuit.QuantumCircuit` objects directly. diff --git a/pyproject.toml b/pyproject.toml index 791112924..091992e0d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,7 +65,7 @@ qiskit = [ dev = ["mqt.core[coverage, docs]",] [project.scripts] -mqt-core-compare = "mqt.core.evaluation:main" +mqt-core-dd-compare = "mqt.core.dd.evaluation:main" [project.urls] Homepage = "https://github.com/cda-tum/mqt-core" @@ -91,7 +91,7 @@ build-dir = "build/{build_type}" wheel.packages = ["src/mqt"] # Only build the Python bindings target -build.targets = ["_core"] +build.targets = ["ir"] # Only install the Python package component install.components = ["mqt-core_Python"] @@ -250,7 +250,7 @@ isort.required-imports = ["from __future__ import annotations"] "I002", # Allow missing `from __future__ import annotations` import ] "src/mqt/core/_compat/**.py" = ["TID251"] -"src/mqt/core/evaluation.py" = ["T201"] +"src/mqt/core/dd/evaluation.py" = ["T201"] "src/mqt/core/__main__.py" = ["T201"] [tool.ruff.lint.pydocstyle] diff --git a/src/mqt/core/__init__.py b/src/mqt/core/__init__.py index 0dba35ca0..896e8b881 100644 --- a/src/mqt/core/__init__.py +++ b/src/mqt/core/__init__.py @@ -2,17 +2,60 @@ from __future__ import annotations -from ._core import Permutation, QuantumComputation +from os import PathLike +from pathlib import Path +from typing import TYPE_CHECKING, Union + from ._version import version as __version__ from ._version import version_tuple as version_info +from .ir import QuantumComputation + +if TYPE_CHECKING: + from qiskit.circuit import QuantumCircuit + + """The type of input that can be used to load a quantum circuit.""" + CircuitInputType = Union[QuantumComputation, str, PathLike[str], QuantumCircuit] + + +def load(input_circuit: CircuitInputType) -> QuantumComputation: + """Load a quantum circuit from any supported format as a :class:`~mqt.core.ir.QuantumComputation`. + + Args: + input_circuit: The input circuit to translate to a :class:`~mqt.core.ir.QuantumComputation`. This can be a :class:`~mqt.core.ir.QuantumComputation` itself, a file name to any of the supported file formats, an OpenQASM (2.0 or 3.0) string, or a Qiskit :class:`~qiskit.circuit.QuantumCircuit`. + + Returns: + The :class:`~mqt.core.ir.QuantumComputation`. + + Raises: + ValueError: If the input circuit is a Qiskit :class:`~qiskit.circuit.QuantumCircuit` but the `qiskit` extra is not installed. + FileNotFoundError: If the input circuit is a file name and the file does not exist. + """ + if isinstance(input_circuit, QuantumComputation): + return input_circuit + + if isinstance(input_circuit, (str, PathLike)): + if not Path(input_circuit).is_file(): + if isinstance(input_circuit, PathLike) or "OPENQASM" not in input_circuit: + msg = f"File {input_circuit} does not exist." + raise FileNotFoundError(msg) + # otherwise, we assume that this is a QASM string + return QuantumComputation.from_qasm(input_circuit) + + return QuantumComputation(input_circuit) + + try: + from .plugins.qiskit import qiskit_to_mqt + except ImportError: + msg = "Qiskit is not installed. Please install `mqt.core[qiskit]` to use Qiskit circuits as input." + raise ValueError(msg) from None + + return qiskit_to_mqt(input_circuit) + __all__ = [ - "Permutation", - "QuantumComputation", "__version__", + "load", "version_info", ] - -for cls in (Permutation, QuantumComputation): - cls.__module__ = "mqt.core" -del cls +if TYPE_CHECKING: + __all__ += ["CircuitInputType"] diff --git a/src/mqt/core/dd/__init__.py b/src/mqt/core/dd/__init__.py new file mode 100644 index 000000000..34710aa8e --- /dev/null +++ b/src/mqt/core/dd/__init__.py @@ -0,0 +1 @@ +"""MQT Core DD - The MQT Decision Diagram Package.""" diff --git a/src/mqt/core/evaluation.py b/src/mqt/core/dd/evaluation.py similarity index 100% rename from src/mqt/core/evaluation.py rename to src/mqt/core/dd/evaluation.py diff --git a/src/mqt/core/_core/__init__.pyi b/src/mqt/core/ir/__init__.pyi similarity index 99% rename from src/mqt/core/_core/__init__.pyi rename to src/mqt/core/ir/__init__.pyi index 6ef5aba88..5a15016e4 100644 --- a/src/mqt/core/_core/__init__.pyi +++ b/src/mqt/core/ir/__init__.pyi @@ -1,3 +1,5 @@ +"""MQT Core IR - The MQT Core Intermediate Representation (IR) module.""" + from collections.abc import Iterable, Iterator, Mapping, MutableMapping, MutableSequence, Sequence from os import PathLike from typing import overload @@ -82,7 +84,7 @@ class Permutation(MutableMapping[int, int]): class QuantumComputation(MutableSequence[Operation]): """The main class for representing quantum computations within the MQT. - Acts as mutable sequence of :class:`~mqt.core.operations.Operation` objects, which represent the individual operations in the quantum computation. + Acts as mutable sequence of :class:`~mqt.core.ir.operations.Operation` objects, which represent the individual operations in the quantum computation. Args: nq: The number of qubits in the quantum computation. @@ -171,7 +173,7 @@ class QuantumComputation(MutableSequence[Operation]): def num_total_ops(self: Self) -> int: """Return the total number of operations in the quantum computation. - Recursively counts sub-operations (e.g., from :class:`~mqt.core.operations.CompoundOperation` objects). + Recursively counts sub-operations (e.g., from :class:`~mqt.core.ir.operations.CompoundOperation` objects). """ def depth(self: Self) -> int: @@ -185,7 +187,7 @@ class QuantumComputation(MutableSequence[Operation]): This gives ownership of the operations to the resulting operation, so the quantum computation will be empty after this operation. - When the quantum computation contains more than one operation, the resulting operation is a :class:`~mqt.core.operations.CompoundOperation`. + When the quantum computation contains more than one operation, the resulting operation is a :class:`~mqt.core.ir.operations.CompoundOperation`. Returns: The operation representing the quantum computation. diff --git a/src/mqt/core/_core/operations.pyi b/src/mqt/core/ir/operations.pyi similarity index 92% rename from src/mqt/core/_core/operations.pyi rename to src/mqt/core/ir/operations.pyi index bb9f164ba..70cbaafc4 100644 --- a/src/mqt/core/_core/operations.pyi +++ b/src/mqt/core/ir/operations.pyi @@ -3,7 +3,7 @@ from collections.abc import Mapping, Sequence from typing import ClassVar, overload from .._compat.typing import Self -from ..symbolic import Expression, Variable +from .symbolic import Expression, Variable class Control: """A control is a pair of a qubit and a type. The type can be either positive or negative. @@ -70,14 +70,14 @@ class OpType: A barrier operation. It is used to separate operations in the circuit. See Also: - :meth:`mqt.core.QuantumComputation.barrier` + :meth:`mqt.core.ir.QuantumComputation.barrier` """ classic_controlled: ClassVar[OpType] """ A classic controlled operation. It is used to control the execution of an operation based on the value of a classical register. See Also: - :meth:`mqt.core.QuantumComputation.classic_controlled` + :meth:`mqt.core.ir.QuantumComputation.classic_controlled` """ compound: ClassVar[OpType] """ @@ -91,56 +91,56 @@ class OpType: A DCX gate. See Also: - :meth:`mqt.core.QuantumComputation.dcx` + :meth:`mqt.core.ir.QuantumComputation.dcx` """ ecr: ClassVar[OpType] """ An ECR gate. See Also: - :meth:`mqt.core.QuantumComputation.ecr` + :meth:`mqt.core.ir.QuantumComputation.ecr` """ gphase: ClassVar[OpType] """ A global phase operation. See Also: - :meth:`mqt.core.QuantumComputation.gphase` + :meth:`mqt.core.ir.QuantumComputation.gphase` """ h: ClassVar[OpType] """ A Hadamard gate. See Also: - :meth:`mqt.core.QuantumComputation.h` + :meth:`mqt.core.ir.QuantumComputation.h` """ i: ClassVar[OpType] """ An identity operation. See Also: - :meth:`mqt.core.QuantumComputation.i` + :meth:`mqt.core.ir.QuantumComputation.i` """ iswap: ClassVar[OpType] """ An iSWAP gate. See Also: - :meth:`mqt.core.QuantumComputation.iswap` + :meth:`mqt.core.ir.QuantumComputation.iswap` """ iswapdg: ClassVar[OpType] r""" An :math:`i\text{SWAP}^\dagger` gate. See Also: - :meth:`mqt.core.QuantumComputation.iswapdg` + :meth:`mqt.core.ir.QuantumComputation.iswapdg` """ measure: ClassVar[OpType] """ A measurement operation. See Also: - :meth:`mqt.core.QuantumComputation.measure` + :meth:`mqt.core.ir.QuantumComputation.measure` """ none: ClassVar[OpType] """ @@ -151,126 +151,126 @@ class OpType: A Peres gate. See Also: - :meth:`mqt.core.QuantumComputation.peres` + :meth:`mqt.core.ir.QuantumComputation.peres` """ peresdg: ClassVar[OpType] """ A :math:`\text{Peres}^\dagger` gate. See Also: - :meth:`mqt.core.QuantumComputation.peresdg` + :meth:`mqt.core.ir.QuantumComputation.peresdg` """ p: ClassVar[OpType] """ A phase gate. See Also: - :meth:`mqt.core.QuantumComputation.p` + :meth:`mqt.core.ir.QuantumComputation.p` """ reset: ClassVar[OpType] """ A reset operation. See Also: - :meth:`mqt.core.QuantumComputation.reset` + :meth:`mqt.core.ir.QuantumComputation.reset` """ rx: ClassVar[OpType] r""" An :math:`R_x` gate. See Also: - :meth:`mqt.core.QuantumComputation.rx` + :meth:`mqt.core.ir.QuantumComputation.rx` """ rxx: ClassVar[OpType] r""" An :math:`R_{xx}` gate. See Also: - :meth:`mqt.core.QuantumComputation.rxx` + :meth:`mqt.core.ir.QuantumComputation.rxx` """ ry: ClassVar[OpType] r""" An :math:`R_y` gate. See Also: - :meth:`mqt.core.QuantumComputation.ry` + :meth:`mqt.core.ir.QuantumComputation.ry` """ ryy: ClassVar[OpType] r""" An :math:`R_{yy}` gate. See Also: - :meth:`mqt.core.QuantumComputation.ryy` + :meth:`mqt.core.ir.QuantumComputation.ryy` """ rz: ClassVar[OpType] r""" An :math:`R_z` gate. See Also: - :meth:`mqt.core.QuantumComputation.rz` + :meth:`mqt.core.ir.QuantumComputation.rz` """ rzx: ClassVar[OpType] r""" An :math:`R_{zx}` gate. See Also: - :meth:`mqt.core.QuantumComputation.rzx` + :meth:`mqt.core.ir.QuantumComputation.rzx` """ rzz: ClassVar[OpType] r""" An :math:`R_{zz}` gate. See Also: - :meth:`mqt.core.QuantumComputation.rzz` + :meth:`mqt.core.ir.QuantumComputation.rzz` """ s: ClassVar[OpType] """ An S gate. See Also: - :meth:`mqt.core.QuantumComputation.s` + :meth:`mqt.core.ir.QuantumComputation.s` """ sdg: ClassVar[OpType] r""" An :math:`S^\dagger` gate. See Also: - :meth:`mqt.core.QuantumComputation.sdg` + :meth:`mqt.core.ir.QuantumComputation.sdg` """ swap: ClassVar[OpType] """ A SWAP gate. See Also: - :meth:`mqt.core.QuantumComputation.swap` + :meth:`mqt.core.ir.QuantumComputation.swap` """ sx: ClassVar[OpType] r""" A :math:`\sqrt{X}` gate. See Also: - :meth:`mqt.core.QuantumComputation.sx` + :meth:`mqt.core.ir.QuantumComputation.sx` """ sxdg: ClassVar[OpType] r""" A :math:`\sqrt{X}^\dagger` gate. See Also: - :meth:`mqt.core.QuantumComputation.sxdg` + :meth:`mqt.core.ir.QuantumComputation.sxdg` """ t: ClassVar[OpType] """ A T gate. See Also: - :meth:`mqt.core.QuantumComputation.t` + :meth:`mqt.core.ir.QuantumComputation.t` """ tdg: ClassVar[OpType] r""" A :math:`T^\dagger` gate. See Also: - :meth:`mqt.core.QuantumComputation.tdg` + :meth:`mqt.core.ir.QuantumComputation.tdg` """ teleportation: ClassVar[OpType] """ @@ -281,63 +281,63 @@ class OpType: A U2 gate. See Also: - :meth:`mqt.core.QuantumComputation.u2` + :meth:`mqt.core.ir.QuantumComputation.u2` """ u: ClassVar[OpType] """ A U gate. See Also: - :meth:`mqt.core.QuantumComputation.u` + :meth:`mqt.core.ir.QuantumComputation.u` """ v: ClassVar[OpType] """ A V gate. See Also: - :meth:`mqt.core.QuantumComputation.v` + :meth:`mqt.core.ir.QuantumComputation.v` """ vdg: ClassVar[OpType] r""" A :math:`V^\dagger` gate. See Also: - :meth:`mqt.core.QuantumComputation.vdg` + :meth:`mqt.core.ir.QuantumComputation.vdg` """ x: ClassVar[OpType] """ An X gate. See Also: - :meth:`mqt.core.QuantumComputation.x` + :meth:`mqt.core.ir.QuantumComputation.x` """ xx_minus_yy: ClassVar[OpType] r""" An :math:`R_{XX - YY}` gate. See Also: - :meth:`mqt.core.QuantumComputation.xx_minus_yy` + :meth:`mqt.core.ir.QuantumComputation.xx_minus_yy` """ xx_plus_yy: ClassVar[OpType] r""" An :math:`R_{XX + YY}` gate. See Also: - :meth:`mqt.core.QuantumComputation.xx_plus_yy` + :meth:`mqt.core.ir.QuantumComputation.xx_plus_yy` """ y: ClassVar[OpType] """ A Y gate. See Also: - :meth:`mqt.core.QuantumComputation.y` + :meth:`mqt.core.ir.QuantumComputation.y` """ z: ClassVar[OpType] """ A Z gate. See Also: - :meth:`mqt.core.QuantumComputation.z` + :meth:`mqt.core.ir.QuantumComputation.z` """ @property @@ -357,7 +357,7 @@ class OpType: def __setstate__(self: Self, state: int) -> None: ... class Operation(ABC): - """An abstract base class for operations that can be added to a :class:`~mqt.core.QuantumComputation`.""" + """An abstract base class for operations that can be added to a :class:`~mqt.core.ir.QuantumComputation`.""" type_: OpType """ diff --git a/src/mqt/core/_core/symbolic.pyi b/src/mqt/core/ir/symbolic.pyi similarity index 100% rename from src/mqt/core/_core/symbolic.pyi rename to src/mqt/core/ir/symbolic.pyi diff --git a/src/mqt/core/load.py b/src/mqt/core/load.py deleted file mode 100644 index 3098ce26b..000000000 --- a/src/mqt/core/load.py +++ /dev/null @@ -1,54 +0,0 @@ -"""IO handling within MQT Core.""" - -from __future__ import annotations - -from os import PathLike -from pathlib import Path -from typing import TYPE_CHECKING, Union - -from . import QuantumComputation - -if TYPE_CHECKING: - from qiskit.circuit import QuantumCircuit - - CircuitInputType = Union[QuantumComputation, str, PathLike[str], QuantumCircuit] - - -def load(input_circuit: CircuitInputType) -> QuantumComputation: - """Load a quantum circuit from any supported format as a :class:`~mqt.core.QuantumComputation`. - - Args: - input_circuit: The input circuit to translate to a :class:`~mqt.core.QuantumComputation`. This can be a :class:`~mqt.core.QuantumComputation` itself, a file name to any of the supported file formats, an OpenQASM (2.0 or 3.0) string, or a Qiskit :class:`~qiskit.circuit.QuantumCircuit`. - - Returns: - The :class:`~mqt.core.QuantumComputation`. - - Raises: - ValueError: If the input circuit is a Qiskit :class:`~qiskit.circuit.QuantumCircuit` but the `qiskit` extra is not installed. - FileNotFoundError: If the input circuit is a file name and the file does not exist. - """ - if isinstance(input_circuit, QuantumComputation): - return input_circuit - - if isinstance(input_circuit, (str, PathLike)): - if not Path(input_circuit).is_file(): - if isinstance(input_circuit, PathLike) or "OPENQASM" not in input_circuit: - msg = f"File {input_circuit} does not exist." - raise FileNotFoundError(msg) - # otherwise, we assume that this is a QASM string - return QuantumComputation.from_qasm(input_circuit) - - return QuantumComputation(input_circuit) - - try: - from .plugins.qiskit import qiskit_to_mqt - except ImportError: - msg = "Qiskit is not installed. Please install `mqt.core[qiskit]` to use Qiskit circuits as input." - raise ValueError(msg) from None - - return qiskit_to_mqt(input_circuit) - - -__all__ = ["load"] -if TYPE_CHECKING: - __all__ += ["CircuitInputType"] diff --git a/src/mqt/core/operations.py b/src/mqt/core/operations.py deleted file mode 100644 index 218ba9379..000000000 --- a/src/mqt/core/operations.py +++ /dev/null @@ -1,38 +0,0 @@ -"""Operations Module.""" - -from __future__ import annotations - -from ._core.operations import ( - ClassicControlledOperation, - CompoundOperation, - Control, - NonUnitaryOperation, - Operation, - OpType, - StandardOperation, - SymbolicOperation, -) - -__all__ = ( - "ClassicControlledOperation", - "CompoundOperation", - "Control", - "NonUnitaryOperation", - "OpType", - "Operation", - "StandardOperation", - "SymbolicOperation", -) - -for cls in ( - ClassicControlledOperation, - CompoundOperation, - Control, - NonUnitaryOperation, - Operation, - OpType, - StandardOperation, - SymbolicOperation, -): - cls.__module__ = "mqt.core.operations" -del cls diff --git a/src/mqt/core/plugins/qiskit.py b/src/mqt/core/plugins/qiskit.py index 2ed821701..afbddfc8b 100644 --- a/src/mqt/core/plugins/qiskit.py +++ b/src/mqt/core/plugins/qiskit.py @@ -8,8 +8,8 @@ from qiskit.circuit import AncillaQubit, AncillaRegister, Clbit, Instruction, ParameterExpression, Qubit -from .. import QuantumComputation -from ..operations import ( +from ..ir import QuantumComputation +from ..ir.operations import ( CompoundOperation, Control, NonUnitaryOperation, @@ -17,7 +17,7 @@ StandardOperation, SymbolicOperation, ) -from ..symbolic import Expression, Term, Variable +from ..ir.symbolic import Expression, Term, Variable if TYPE_CHECKING: from collections.abc import Mapping, Sequence @@ -26,7 +26,7 @@ def qiskit_to_mqt(circ: QuantumCircuit) -> QuantumComputation: - """Convert a Qiskit :class:`~qiskit.circuit.QuantumCircuit` to a :class:`~mqt.core.QuantumComputation` object. + """Convert a Qiskit :class:`~qiskit.circuit.QuantumCircuit` to a :class:`~mqt.core.ir.QuantumComputation` object. Args: circ: The Qiskit circuit to convert. diff --git a/src/mqt/core/symbolic.py b/src/mqt/core/symbolic.py deleted file mode 100644 index 8f590a3ea..000000000 --- a/src/mqt/core/symbolic.py +++ /dev/null @@ -1,11 +0,0 @@ -"""Symbolic expressions and terms.""" - -from __future__ import annotations - -from ._core.symbolic import Expression, Term, Variable - -__all__ = ("Expression", "Term", "Variable") - -for cls in (Variable, Term, Expression): - cls.__module__ = "mqt.core.symbolic" -del cls diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt index a75035b22..07d753def 100644 --- a/src/python/CMakeLists.txt +++ b/src/python/CMakeLists.txt @@ -1,23 +1,2 @@ -if(NOT TARGET _core) - # collect source files - file(GLOB_RECURSE IR_PYTHON_SOURCES ir/*.cpp) - - pybind11_add_module( - # Name of the extension - _core - # Prefer thin LTO if available - THIN_LTO - # Optimize the bindings for size - OPT_SIZE - # Source code goes here - ${MQT_CORE_INCLUDE_BUILD_DIR}/python/pybind11.hpp - module.cpp - ${IR_PYTHON_SOURCES}) - target_link_libraries(_core PRIVATE MQT::CoreIR MQT::ProjectOptions MQT::ProjectWarnings) - - # Install directive for scikit-build-core - install( - TARGETS _core - DESTINATION . - COMPONENT ${MQT_CORE_TARGET_NAME}_Python) -endif() +# add the IR bindings package +add_subdirectory(ir) diff --git a/src/python/ir/CMakeLists.txt b/src/python/ir/CMakeLists.txt new file mode 100644 index 000000000..bfc8a6d1e --- /dev/null +++ b/src/python/ir/CMakeLists.txt @@ -0,0 +1,23 @@ +if(NOT TARGET ir) + # collect source files + file(GLOB_RECURSE IR_SOURCES **.cpp) + + # declare the Python module + pybind11_add_module( + # Name of the extension + ir + # Prefer thin LTO if available + THIN_LTO + # Optimize the bindings for size + OPT_SIZE + # Source code goes here + ${MQT_CORE_INCLUDE_BUILD_DIR}/python/pybind11.hpp + ${IR_SOURCES}) + target_link_libraries(ir PRIVATE MQT::CoreIR MQT::ProjectOptions MQT::ProjectWarnings) + + # Install directive for scikit-build-core + install( + TARGETS ir + DESTINATION . + COMPONENT ${MQT_CORE_TARGET_NAME}_Python) +endif() diff --git a/src/python/module.cpp b/src/python/ir/register_ir.cpp similarity index 91% rename from src/python/module.cpp rename to src/python/ir/register_ir.cpp index b9d11c56e..6cc22fc86 100644 --- a/src/python/module.cpp +++ b/src/python/ir/register_ir.cpp @@ -11,7 +11,7 @@ void registerOperations(py::module& m); void registerSymbolic(py::module& m); void registerQuantumComputation(py::module& m); -PYBIND11_MODULE(_core, m, py::mod_gil_not_used()) { +PYBIND11_MODULE(ir, m, py::mod_gil_not_used()) { registerPermutation(m); py::module symbolic = m.def_submodule("symbolic"); diff --git a/test/python/test_evaluation.py b/test/python/test_evaluation.py index 7ea9d18ae..89ea9a17a 100644 --- a/test/python/test_evaluation.py +++ b/test/python/test_evaluation.py @@ -8,7 +8,7 @@ import pytest -from mqt.core.evaluation import __aggregate, __flatten_dict, __post_processing +from mqt.core.dd.evaluation import __aggregate, __flatten_dict, __post_processing if TYPE_CHECKING: from pytest_console_scripts import ScriptRunner @@ -100,7 +100,7 @@ def test_aggregate() -> None: def test_compare_with_negative_factor(script_runner: ScriptRunner) -> None: """Testing factor -0.1.""" ret = script_runner.run([ - "mqt-core-compare", + "mqt-core-dd-compare", "./test/python/results_baseline.json", "./test/python/results_feature.json", "--factor=-0.1", @@ -113,7 +113,7 @@ def test_compare_with_negative_factor(script_runner: ScriptRunner) -> None: def test_compare_with_invalid_sort_option(script_runner: ScriptRunner) -> None: """Testing an invalid sort option.""" ret = script_runner.run([ - "mqt-core-compare", + "mqt-core-dd-compare", "./test/python/results_baseline.json", "./test/python/results_feature.json", "--sort=after", @@ -126,7 +126,7 @@ def test_compare_with_invalid_sort_option(script_runner: ScriptRunner) -> None: def test_cli_with_num_qubits_specified_without_algorithm(script_runner: ScriptRunner) -> None: """Testing the error case when num_qubits is specified without algorithm.""" ret = script_runner.run([ - "mqt-core-compare", + "mqt-core-dd-compare", "./test/python/results_baseline.json", "./test/python/results_feature.json", "--factor=0.2", @@ -140,7 +140,7 @@ def test_cli_with_num_qubits_specified_without_algorithm(script_runner: ScriptRu def test_cli_with_default_parameters(script_runner: ScriptRunner) -> None: """Testing the command line functionality with default parameters.""" ret = script_runner.run([ - "mqt-core-compare", + "mqt-core-dd-compare", "./test/python/results_baseline.json", "./test/python/results_feature.json", ]) @@ -156,7 +156,7 @@ def test_cli_with_default_parameters(script_runner: ScriptRunner) -> None: def test_cli_with_factor_point_three(script_runner: ScriptRunner) -> None: """Testing the command line functionality with default parameters, except that factor is set to 0.3 and dd details should be shown.""" ret = script_runner.run([ - "mqt-core-compare", + "mqt-core-dd-compare", "./test/python/results_baseline.json", "./test/python/results_feature.json", "--factor=0.3", @@ -174,7 +174,7 @@ def test_cli_with_factor_point_three(script_runner: ScriptRunner) -> None: def test_cli_with_only_changed(script_runner: ScriptRunner) -> None: """Testing the command line functionality with default parameters, except that factor is set to 0.2 and only_changed is set to true.""" ret = script_runner.run([ - "mqt-core-compare", + "mqt-core-dd-compare", "./test/python/results_baseline.json", "./test/python/results_feature.json", "--factor=0.2", @@ -190,7 +190,7 @@ def test_cli_with_only_changed(script_runner: ScriptRunner) -> None: def test_cli_with_only_changed_and_no_split(script_runner: ScriptRunner) -> None: """Testing the command line functionality with factor=0.1 per default, but both only_changed and no_split are set to true, and dd details should be shown.""" ret = script_runner.run([ - "mqt-core-compare", + "mqt-core-dd-compare", "./test/python/results_baseline.json", "./test/python/results_feature.json", "--dd", @@ -209,7 +209,7 @@ def test_cli_with_only_changed_and_no_split(script_runner: ScriptRunner) -> None def test_cli_with_no_split(script_runner: ScriptRunner) -> None: """Testing the command line functionality with default parameters, except for no_split set to true, dd details should be shown and the output tables should only show benchmarks from the Functionality task.""" ret = script_runner.run([ - "mqt-core-compare", + "mqt-core-dd-compare", "./test/python/results_baseline.json", "./test/python/results_feature.json", "--no_split", @@ -228,7 +228,7 @@ def test_cli_with_no_split(script_runner: ScriptRunner) -> None: def test_cli_with_sort_by_algorithm(script_runner: ScriptRunner) -> None: """Testing the command line functionality with sort set with "algorithm" and no_split set to true. DD details should be shown and the output tables should only show benchmarks from the BV algorithm with 1024 qubits.""" ret = script_runner.run([ - "mqt-core-compare", + "mqt-core-dd-compare", "./test/python/results_baseline.json", "./test/python/results_feature.json", "--sort=algorithm", diff --git a/test/python/test_load.py b/test/python/test_load.py index be1d84455..93480f108 100644 --- a/test/python/test_load.py +++ b/test/python/test_load.py @@ -9,8 +9,8 @@ import pytest from qiskit import QuantumCircuit, qasm2 -from mqt.core import QuantumComputation -from mqt.core.load import load +from mqt.core import load +from mqt.core.ir import QuantumComputation def test_loading_quantum_computation() -> None: diff --git a/test/python/test_qiskit.py b/test/python/test_qiskit.py index 79d8a35df..aec9639dd 100644 --- a/test/python/test_qiskit.py +++ b/test/python/test_qiskit.py @@ -10,9 +10,9 @@ from qiskit.circuit.library import U2Gate, XXMinusYYGate, XXPlusYYGate from qiskit.providers.fake_provider import Fake5QV1 -from mqt.core.operations import CompoundOperation, SymbolicOperation +from mqt.core.ir.operations import CompoundOperation, SymbolicOperation +from mqt.core.ir.symbolic import Expression from mqt.core.plugins.qiskit import qiskit_to_mqt -from mqt.core.symbolic import Expression def test_empty_circuit() -> None: From f490b00c05efd9329156f6557925c5ae013364f1 Mon Sep 17 00:00:00 2001 From: burgholzer Date: Tue, 13 Aug 2024 22:55:44 +0200 Subject: [PATCH 13/13] =?UTF-8?q?=F0=9F=A9=B9=20fix=20intersphinx=20links?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: burgholzer --- docs/conf.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 725c4c39f..13b538118 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -78,13 +78,13 @@ intersphinx_mapping = { "python": ("https://docs.python.org/3", None), - "qiskit": ("https://docs.quantum.ibm.com/api/qiskit/", None), - "mqt": ("https://mqt.readthedocs.io/en/latest/", None), - "ddsim": ("https://mqt.readthedocs.io/projects/ddsim/en/latest/", None), - "qmap": ("https://mqt.readthedocs.io/projects/qmap/en/latest/", None), - "qcec": ("https://mqt.readthedocs.io/projects/qcec/en/latest/", None), - "qecc": ("https://mqt.readthedocs.io/projects/qecc/en/latest/", None), - "syrec": ("https://mqt.readthedocs.io/projects/syrec/en/latest/", None), + "qiskit": ("https://docs.quantum.ibm.com/api/qiskit", None), + "mqt": ("https://mqt.readthedocs.io/en/latest", None), + "ddsim": ("https://mqt.readthedocs.io/projects/ddsim/en/latest", None), + "qmap": ("https://mqt.readthedocs.io/projects/qmap/en/latest", None), + "qcec": ("https://mqt.readthedocs.io/projects/qcec/en/latest", None), + "qecc": ("https://mqt.readthedocs.io/projects/qecc/en/latest", None), + "syrec": ("https://mqt.readthedocs.io/projects/syrec/en/latest", None), } myst_enable_extensions = [