From 5523f6f830f4dce020fdc94fa1af467c29badd92 Mon Sep 17 00:00:00 2001 From: yao-cqc <75305462+yao-cqc@users.noreply.github.com> Date: Tue, 15 Aug 2023 11:37:50 +0100 Subject: [PATCH] Feature/pybind is_clifford (#968) * Add Op.is_clifford to binder * Add changelog entry --- pytket/binders/circuit/main.cpp | 9 ++++++++- pytket/docs/changelog.rst | 1 + pytket/tests/circuit_test.py | 12 ++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/pytket/binders/circuit/main.cpp b/pytket/binders/circuit/main.cpp index 14c84ac90a..5796fb0a8b 100644 --- a/pytket/binders/circuit/main.cpp +++ b/pytket/binders/circuit/main.cpp @@ -105,7 +105,14 @@ PYBIND11_MODULE(circuit, m) { }) .def( "is_clifford_type", - [](const Op &op) { return op.get_desc().is_clifford_gate(); }) + [](const Op &op) { return op.get_desc().is_clifford_gate(); }, + "Check if the operation is one of the Clifford `OpType`s.") + .def( + "is_clifford", [](const Op &op) { return op.is_clifford(); }, + "Test whether the operation is in the Clifford group. A return value " + "of true guarantees that the operation is Clifford. However, the " + "converse is not the case as some Clifford operations may not be " + "detected as such.") .def("is_gate", [](const Op &op) { return op.get_desc().is_gate(); }); // NOTE: Sphinx does not automatically pick up the docstring for OpType diff --git a/pytket/docs/changelog.rst b/pytket/docs/changelog.rst index bd9740ed9d..2aca63b563 100644 --- a/pytket/docs/changelog.rst +++ b/pytket/docs/changelog.rst @@ -7,6 +7,7 @@ Unreleased Minor new features: * Implement equality checking for all boxes. +* Add ``Op.is_clifford`` to python binding. 1.18.0 (August 2023) -------------------- diff --git a/pytket/tests/circuit_test.py b/pytket/tests/circuit_test.py index 7bfeb54f5a..27460d3b04 100644 --- a/pytket/tests/circuit_test.py +++ b/pytket/tests/circuit_test.py @@ -1051,6 +1051,17 @@ def test_clifford_checking() -> None: assert m.is_clifford_type() == False +def test_clifford_evaluation() -> None: + c = Circuit(2, 1) + c.Rx(0, 0).ISWAP(1, 0, 1).Rz(0.3, 0) + rx = c.get_commands()[0].op + assert rx.is_clifford() + iswap = c.get_commands()[1].op + assert iswap.is_clifford() + rz = c.get_commands()[2].op + assert rz.is_clifford() == False + + def test_getting_registers() -> None: c = Circuit(2, 1) c_regs = c.c_registers @@ -1160,6 +1171,7 @@ def test_error_wrong_parameters() -> None: test_str() test_phase() test_clifford_checking() + test_clifford_evaluation() test_measuring_registers() test_multi_controlled_gates() test_counting_n_qubit_gates()