From 7d0e93044c2e9b93c7f54c1b5b1842e0aa93d7ac Mon Sep 17 00:00:00 2001 From: Tom Peham Date: Fri, 23 Jun 2023 14:53:02 +0200 Subject: [PATCH 01/17] Remove redundant gates after depth-optimal synthesis. --- .../cliffordsynthesis/CliffordSynthesizer.hpp | 1 + src/cliffordsynthesis/CliffordSynthesizer.cpp | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/cliffordsynthesis/CliffordSynthesizer.hpp b/include/cliffordsynthesis/CliffordSynthesizer.hpp index b3ff07bb5..faa03d8f1 100644 --- a/include/cliffordsynthesis/CliffordSynthesizer.hpp +++ b/include/cliffordsynthesis/CliffordSynthesizer.hpp @@ -152,6 +152,7 @@ class CliffordSynthesizer { const Configuration& config); static void updateResults(const Configuration& config, const Results& newResults, Results& currentResults); + void removeRedundantGates(); }; } // namespace cs diff --git a/src/cliffordsynthesis/CliffordSynthesizer.cpp b/src/cliffordsynthesis/CliffordSynthesizer.cpp index 7e5c4ab2a..e8f3a6880 100644 --- a/src/cliffordsynthesis/CliffordSynthesizer.cpp +++ b/src/cliffordsynthesis/CliffordSynthesizer.cpp @@ -6,11 +6,14 @@ #include "cliffordsynthesis/CliffordSynthesizer.hpp" #include "LogicTerm/Logic.hpp" +#include "QuantumComputation.hpp" +#include "cliffordsynthesis/Tableau.hpp" #include "utils/logging.hpp" #include #include #include +#include #include namespace cs { @@ -226,6 +229,12 @@ void CliffordSynthesizer::depthOptimalSynthesis( // fixed depth limit and the goal to minimize the number of gates. minimizeGatesFixedDepth(config); } + + if (!initialTableau.hasDestabilizers()) { + // If destabilizers aren't considered, the synthesis might include gates + // that have no impact on the final tableau, so we can remove them + removeRedundantGates(); + } } void CliffordSynthesizer::minimizeGatesFixedDepth(EncoderConfig config) { @@ -518,4 +527,22 @@ CliffordSynthesizer::synthesizeSubcircuit( synth.initResultCircuitFromResults(); return synth.resultCircuit; } + +void CliffordSynthesizer::removeRedundantGates() { + Tableau prev = initialTableau; + Tableau curr = initialTableau; + initResultCircuitFromResults(); + qc::QuantumComputation reducedResult(resultCircuit->getNqubits()); + + for (auto& gate : *resultCircuit) { + curr.applyGate(gate.get()); + if (prev != curr) { + prev.applyGate(gate.get()); + reducedResult.emplace_back(std::move(gate)); + } + } + + results.setResultCircuit(reducedResult); + results.setSingleQubitGates(reducedResult.getNsingleQubitOps()); +} } // namespace cs From 6d1b5aaacccd8a6ee795d11df35ddb798aad8e5a Mon Sep 17 00:00:00 2001 From: Tom Peham Date: Mon, 26 Jun 2023 10:17:35 +0200 Subject: [PATCH 02/17] Retrigger CI runs. From be3b9dff3f2699fac34f88068e38037a2e98c34c Mon Sep 17 00:00:00 2001 From: Tom Peham Date: Mon, 26 Jun 2023 13:18:54 +0200 Subject: [PATCH 03/17] Try fixing deprecationwarning in constructor of Paulilist. --- test/python/test_cliffordsynthesis.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/python/test_cliffordsynthesis.py b/test/python/test_cliffordsynthesis.py index fbb1a15cb..b30656689 100644 --- a/test/python/test_cliffordsynthesis.py +++ b/test/python/test_cliffordsynthesis.py @@ -8,7 +8,7 @@ import pytest from qiskit import QuantumCircuit -from qiskit.quantum_info import Clifford, PauliList +from qiskit.quantum_info import Clifford, Pauli, PauliList from mqt import qcec, qmap @@ -270,7 +270,7 @@ def test_synthesize_from_qiskit_clifford(bell_circuit: QuantumCircuit) -> None: def test_synthesize_from_qiskit_pauli_list(bell_circuit: QuantumCircuit) -> None: """Test that we can synthesize a circuit from a Qiskit PauliList.""" - pauli_list = PauliList(["XX", "ZZ"]) + pauli_list = PauliList([Pauli("XX"), Pauli("ZZ")]) circ, results = qmap.synthesize_clifford(target_tableau=pauli_list) assert qcec.verify(circ, bell_circuit).considered_equivalent() From 5286abe21ddaba6b15ec44e584bce4dbd3c0871f Mon Sep 17 00:00:00 2001 From: Tom Peham Date: Mon, 26 Jun 2023 13:31:17 +0200 Subject: [PATCH 04/17] Revert changes to clifford test --- test/python/test_cliffordsynthesis.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/python/test_cliffordsynthesis.py b/test/python/test_cliffordsynthesis.py index b30656689..fbb1a15cb 100644 --- a/test/python/test_cliffordsynthesis.py +++ b/test/python/test_cliffordsynthesis.py @@ -8,7 +8,7 @@ import pytest from qiskit import QuantumCircuit -from qiskit.quantum_info import Clifford, Pauli, PauliList +from qiskit.quantum_info import Clifford, PauliList from mqt import qcec, qmap @@ -270,7 +270,7 @@ def test_synthesize_from_qiskit_clifford(bell_circuit: QuantumCircuit) -> None: def test_synthesize_from_qiskit_pauli_list(bell_circuit: QuantumCircuit) -> None: """Test that we can synthesize a circuit from a Qiskit PauliList.""" - pauli_list = PauliList([Pauli("XX"), Pauli("ZZ")]) + pauli_list = PauliList(["XX", "ZZ"]) circ, results = qmap.synthesize_clifford(target_tableau=pauli_list) assert qcec.verify(circ, bell_circuit).considered_equivalent() From 62b36856512ba74fca362ec7a9f8b82140141c86 Mon Sep 17 00:00:00 2001 From: Tom Peham Date: Mon, 26 Jun 2023 13:31:31 +0200 Subject: [PATCH 05/17] Ignore Deprecationwarnings from numpy. Since numpy 1.25, qiskit throws a `DeprecationWarning` when constructing a `PauliList`. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 499dbe864..39fd47091 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -106,7 +106,7 @@ testpaths = ["test/python"] addopts = ["-ra", "--strict-markers", "--strict-config", "--showlocals"] log_cli_level = "INFO" xfail_strict = true -filterwarnings = ["error"] +filterwarnings = ["error", "ignore::DeprecationWarning:numpy:.*"] [tool.coverage.run] source = ["mqt.qmap"] From 59e2bccc2f6424572bfb74ffe219fe1d17c6a78c Mon Sep 17 00:00:00 2001 From: Tom Peham Date: Mon, 26 Jun 2023 13:31:31 +0200 Subject: [PATCH 06/17] Ignore Deprecationwarnings from numpy. Since numpy 1.25, qiskit throws a `DeprecationWarning` when constructing a `PauliList`. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 499dbe864..39fd47091 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -106,7 +106,7 @@ testpaths = ["test/python"] addopts = ["-ra", "--strict-markers", "--strict-config", "--showlocals"] log_cli_level = "INFO" xfail_strict = true -filterwarnings = ["error"] +filterwarnings = ["error", "ignore::DeprecationWarning:numpy:.*"] [tool.coverage.run] source = ["mqt.qmap"] From 76e23e062e05b06a5f18a6081b7e6e1ab99ef743 Mon Sep 17 00:00:00 2001 From: Tom Peham Date: Mon, 26 Jun 2023 13:34:59 +0200 Subject: [PATCH 07/17] Fix typo --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 39fd47091..b2dba016d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -106,7 +106,7 @@ testpaths = ["test/python"] addopts = ["-ra", "--strict-markers", "--strict-config", "--showlocals"] log_cli_level = "INFO" xfail_strict = true -filterwarnings = ["error", "ignore::DeprecationWarning:numpy:.*"] +filterwarnings = ["error", "ignore::DeprecationWarning:numpy.*:"] [tool.coverage.run] source = ["mqt.qmap"] From 0f2cb56f7271c6d34e35e87b422571678598de02 Mon Sep 17 00:00:00 2001 From: Tom Peham Date: Mon, 26 Jun 2023 14:00:14 +0200 Subject: [PATCH 08/17] Change Capitalization in pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b2dba016d..43d559e3d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -106,7 +106,7 @@ testpaths = ["test/python"] addopts = ["-ra", "--strict-markers", "--strict-config", "--showlocals"] log_cli_level = "INFO" xfail_strict = true -filterwarnings = ["error", "ignore::DeprecationWarning:numpy.*:"] +filterwarnings = ["error", "ignore::DeprecationWarning:NumPy.*:"] [tool.coverage.run] source = ["mqt.qmap"] From a5bedb57b4d80c0678795c3a48008ae6fcfc5374 Mon Sep 17 00:00:00 2001 From: Tom Peham Date: Mon, 26 Jun 2023 14:13:14 +0200 Subject: [PATCH 09/17] Very specific warning matching. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 43d559e3d..c95114160 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -106,7 +106,7 @@ testpaths = ["test/python"] addopts = ["-ra", "--strict-markers", "--strict-config", "--showlocals"] log_cli_level = "INFO" xfail_strict = true -filterwarnings = ["error", "ignore::DeprecationWarning:NumPy.*:"] +filterwarnings = ["error", "ignore::DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)"] [tool.coverage.run] source = ["mqt.qmap"] From 48865e8cbd7411978866b0af02b3b5df15384521 Mon Sep 17 00:00:00 2001 From: Tom Peham Date: Mon, 26 Jun 2023 15:11:23 +0200 Subject: [PATCH 10/17] Try to fix ignoring deprecationwarning --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c95114160..6b5e82fc8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -106,7 +106,7 @@ testpaths = ["test/python"] addopts = ["-ra", "--strict-markers", "--strict-config", "--showlocals"] log_cli_level = "INFO" xfail_strict = true -filterwarnings = ["error", "ignore::DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)"] +filterwarnings = ["error", "ignore:DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)"] [tool.coverage.run] source = ["mqt.qmap"] From 076b89d9fb026da84c742a49d65a2c213c2f8d70 Mon Sep 17 00:00:00 2001 From: Tom Peham Date: Mon, 26 Jun 2023 15:22:19 +0200 Subject: [PATCH 11/17] Ignore all Deprecationwarnings --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 6b5e82fc8..e12db891c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -106,7 +106,7 @@ testpaths = ["test/python"] addopts = ["-ra", "--strict-markers", "--strict-config", "--showlocals"] log_cli_level = "INFO" xfail_strict = true -filterwarnings = ["error", "ignore:DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)"] +filterwarnings = ["error", "ignore::DeprecationWarning"] [tool.coverage.run] source = ["mqt.qmap"] From 340329c6e41c659b56f2a592ba8d79d876c0ad02 Mon Sep 17 00:00:00 2001 From: Tom Peham Date: Mon, 26 Jun 2023 15:31:30 +0200 Subject: [PATCH 12/17] Specifiy DeprecationWarning. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index e12db891c..c236df4f3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -106,7 +106,7 @@ testpaths = ["test/python"] addopts = ["-ra", "--strict-markers", "--strict-config", "--showlocals"] log_cli_level = "INFO" xfail_strict = true -filterwarnings = ["error", "ignore::DeprecationWarning"] +filterwarnings = ["error", "ignore:Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.):DeprecationWarning"] [tool.coverage.run] source = ["mqt.qmap"] From fce3fd9388496ca9876da00cfb50cb88191ba4cd Mon Sep 17 00:00:00 2001 From: Tom Peham Date: Mon, 26 Jun 2023 15:40:54 +0200 Subject: [PATCH 13/17] Convert string in pytproject.toml to raw string. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c236df4f3..3439fd949 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -106,7 +106,7 @@ testpaths = ["test/python"] addopts = ["-ra", "--strict-markers", "--strict-config", "--showlocals"] log_cli_level = "INFO" xfail_strict = true -filterwarnings = ["error", "ignore:Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.):DeprecationWarning"] +filterwarnings = ["error", 'ignore:Conversion of an array with ndim > 0 to a scalar is deprecated\\(\\) and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.):DeprecationWarning'] [tool.coverage.run] source = ["mqt.qmap"] From 5268792a6f1f450349bd79298955e69f0ebf1275 Mon Sep 17 00:00:00 2001 From: Tom Peham Date: Mon, 26 Jun 2023 15:49:30 +0200 Subject: [PATCH 14/17] Remove escape character from string. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 3439fd949..b1433a2d1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -106,7 +106,7 @@ testpaths = ["test/python"] addopts = ["-ra", "--strict-markers", "--strict-config", "--showlocals"] log_cli_level = "INFO" xfail_strict = true -filterwarnings = ["error", 'ignore:Conversion of an array with ndim > 0 to a scalar is deprecated\\(\\) and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.):DeprecationWarning'] +filterwarnings = ["error", 'ignore:Conversion of an array with ndim > 0 to a scalar is deprecated and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.):DeprecationWarning'] [tool.coverage.run] source = ["mqt.qmap"] From e9f94e9f07d6918acbdde7f362a79cff46b22c10 Mon Sep 17 00:00:00 2001 From: Tom Peham Date: Mon, 26 Jun 2023 15:56:21 +0200 Subject: [PATCH 15/17] Try if space at beginning of message is an issue --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b1433a2d1..7eba744a4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -106,7 +106,7 @@ testpaths = ["test/python"] addopts = ["-ra", "--strict-markers", "--strict-config", "--showlocals"] log_cli_level = "INFO" xfail_strict = true -filterwarnings = ["error", 'ignore:Conversion of an array with ndim > 0 to a scalar is deprecated and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.):DeprecationWarning'] +filterwarnings = ["error", 'ignore: Conversion of an array with ndim > 0 to a scalar is deprecated and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.):DeprecationWarning'] [tool.coverage.run] source = ["mqt.qmap"] From 810f163351ddbc6de27f24462f139abddb063300 Mon Sep 17 00:00:00 2001 From: Tom Peham Date: Mon, 26 Jun 2023 16:21:24 +0200 Subject: [PATCH 16/17] Fix deprecationwarning string. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 7eba744a4..cb4f01ee5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -106,7 +106,7 @@ testpaths = ["test/python"] addopts = ["-ra", "--strict-markers", "--strict-config", "--showlocals"] log_cli_level = "INFO" xfail_strict = true -filterwarnings = ["error", 'ignore: Conversion of an array with ndim > 0 to a scalar is deprecated and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.):DeprecationWarning'] +filterwarnings = ["error", 'ignore:Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.):DeprecationWarning'] [tool.coverage.run] source = ["mqt.qmap"] From 6d2a17952686c19bc5607f9916065f8901b05ec4 Mon Sep 17 00:00:00 2001 From: Tom Peham Date: Mon, 26 Jun 2023 17:18:41 +0200 Subject: [PATCH 17/17] Fix filtering of specific deprecationwarning. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index cb4f01ee5..dd134e181 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -106,7 +106,7 @@ testpaths = ["test/python"] addopts = ["-ra", "--strict-markers", "--strict-config", "--showlocals"] log_cli_level = "INFO" xfail_strict = true -filterwarnings = ["error", 'ignore:Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.):DeprecationWarning'] +filterwarnings = ["error", 'ignore:Conversion.*to a scalar is deprecated.*:DeprecationWarning:qiskit:'] [tool.coverage.run] source = ["mqt.qmap"]