Skip to content

Commit

Permalink
Feature/pybind is_clifford (#968)
Browse files Browse the repository at this point in the history
* Add Op.is_clifford to binder

* Add changelog entry
  • Loading branch information
yao-cqc authored Aug 15, 2023
1 parent 0520933 commit 5523f6f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pytket/binders/circuit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pytket/docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
--------------------
Expand Down
12 changes: 12 additions & 0 deletions pytket/tests/circuit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

0 comments on commit 5523f6f

Please sign in to comment.