Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/pybind is_clifford #968

Merged
merged 3 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Loading