From cb0daf3c5f34586801dac08e39f7f4f3380510ea Mon Sep 17 00:00:00 2001 From: burgholzer Date: Mon, 8 Jan 2024 09:48:24 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20missing=20`mcx`=20gate=20s?= =?UTF-8?q?upport=20in=20OpenQASM3=20parser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/parsers/QASM3Parser.cpp | 5 +++-- test/unittests/test_qasm3_parser.cpp | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/parsers/QASM3Parser.cpp b/src/parsers/QASM3Parser.cpp index 802db8238..b446c32cd 100644 --- a/src/parsers/QASM3Parser.cpp +++ b/src/parsers/QASM3Parser.cpp @@ -359,8 +359,9 @@ class OpenQasm3Parser final : public InstVisitor { size_t implicitControls{0}; if (iter == gates.end()) { - if (identifier == "mcx_gray" || identifier == "mcx_vchain" || - identifier == "mcx_recursive" || identifier == "mcphase") { + if (identifier == "mcx" || identifier == "mcx_gray" || + identifier == "mcx_vchain" || identifier == "mcx_recursive" || + identifier == "mcphase") { // we create a temp gate definition for these gates gate = getMcGateDefinition(identifier, gateCallStatement->operands.size(), diff --git a/test/unittests/test_qasm3_parser.cpp b/test/unittests/test_qasm3_parser.cpp index b4a210d8a..79093d083 100644 --- a/test/unittests/test_qasm3_parser.cpp +++ b/test/unittests/test_qasm3_parser.cpp @@ -692,6 +692,22 @@ TEST_F(Qasm3ParserTest, ImportQasm2CPrefix) { EXPECT_EQ(out, expected); } +TEST_F(Qasm3ParserTest, ImportMCXGate) { + const std::string testfile = "OPENQASM 3.0;\n" + "qubit[4] q;\n" + "mcx q[0], q[1], q[2], q[3];\n"; + auto qc = QuantumComputation::fromQASM(testfile); + + const std::string out = qc.toQASM(); + const std::string expected = "// i 0 1 2 3\n" + "// o 0 1 2 3\n" + "OPENQASM 3.0;\n" + "include \"stdgates.inc\";\n" + "qubit[4] q;\n" + "ctrl(3) @ x q[0], q[1], q[2], q[3];\n"; + EXPECT_EQ(out, expected); +} + TEST_F(Qasm3ParserTest, ImportQasm2CPrefixInvalidGate) { const std::string testfile = "OPENQASM 2.0;\n" "qubit[5] q;\n"