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

Add apply_clifford_basis_change_tensor #1005

Merged
merged 10 commits into from
Sep 6, 2023
19 changes: 16 additions & 3 deletions pytket/binders/tailoring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ namespace py = pybind11;

namespace tket {

QubitPauliString apply_clifford_basis_change(
QubitPauliTensor apply_clifford_basis_change(
const QubitPauliString &in_pauli, const Circuit &circ) {
UnitaryRevTableau tab = circuit_to_unitary_rev_tableau(circ);
QubitPauliTensor new_operator =
tab.get_row_product(QubitPauliTensor(in_pauli));
return new_operator.string;
return new_operator;
}

QubitPauliString apply_clifford_basis_change_string(const QubitPauliString &in_pauli, const Circuit &circ) {
return apply_clifford_basis_change(in_pauli, circ).string;
}

PYBIND11_MODULE(tailoring, m) {
Expand Down Expand Up @@ -163,13 +167,22 @@ PYBIND11_MODULE(tailoring, m) {
py::arg("circuit"), py::arg("samples"))
.def("__repr__", &UniversalFrameRandomisation::to_string);
m.def(
"apply_clifford_basis_change", &apply_clifford_basis_change,
"apply_clifford_basis_change", &apply_clifford_basis_change_string,
"Given Pauli operator P and Clifford circuit C, "
"returns C_dagger.P.C in multiplication order. This ignores any -1 "
"phase that could be introduced.\n\n:param pauli: Pauli "
"operator being transformed. \n:param circuit: "
"Clifford circuit acting on Pauli operator.\n"
":return: :py:class:`QubitPauliString` for new operator",
py::arg("pauli"), py::arg("circuit"));
m.def(
"apply_clifford_basis_change_tensor", &apply_clifford_basis_change,
"Given Pauli operator P and Clifford circuit C, "
"returns C_dagger.P.C in multiplication order"
"\n\n:param pauli: Pauli "
"operator being transformed. \n:param circuit: "
"Clifford circuit acting on Pauli operator.\n"
":return: :py:class:`QubitPauliTensor` for new operator",
py::arg("pauli"), py::arg("circuit"));
}
} // namespace tket
1 change: 1 addition & 0 deletions pytket/pytket/_tket/tailoring.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ class UniversalFrameRandomisation:
def sample_circuits(self, circuit: pytket._tket.circuit.Circuit, samples: int) -> List[pytket._tket.circuit.Circuit]: ...

def apply_clifford_basis_change(pauli: pytket._tket.pauli.QubitPauliString, circuit: pytket._tket.circuit.Circuit) -> pytket._tket.pauli.QubitPauliString: ...
def apply_clifford_basis_change_tensor(pauli: pytket._tket.pauli.QubitPauliString, circuit: pytket._tket.circuit.Circuit) -> pytket._tket.pauli.QubitPauliTensor: ...
14 changes: 14 additions & 0 deletions pytket/tests/characterisation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
PauliFrameRandomisation,
UniversalFrameRandomisation,
apply_clifford_basis_change,
apply_clifford_basis_change_tensor,
)
from pytket.pauli import Pauli, QubitPauliString

Expand Down Expand Up @@ -116,15 +117,24 @@ def test_apply_clifford_basis_change() -> None:
z_op = QubitPauliString(Qubit(0), Pauli.Z)
x_op = QubitPauliString(Qubit(0), Pauli.X)
assert apply_clifford_basis_change(z_op, circ_0) == x_op
t = apply_clifford_basis_change_tensor(z_op, circ_0)
assert t.string == x_op
assert t.coeff == 1

circ_1 = Circuit(2).CX(0, 1)
zz_op = QubitPauliString([Qubit(0), Qubit(1)], [Pauli.Z, Pauli.Z])
iz_op = QubitPauliString([Qubit(0), Qubit(1)], [Pauli.I, Pauli.Z])
assert apply_clifford_basis_change(zz_op, circ_1) == iz_op
t = apply_clifford_basis_change_tensor(zz_op, circ_1)
assert t.string == iz_op
assert t.coeff == 1

circ_2 = Circuit(2).H(0).CX(0, 1).S(1).X(0)
zz_op = QubitPauliString([Qubit(0), Qubit(1)], [Pauli.Z, Pauli.Z])
assert apply_clifford_basis_change(zz_op, circ_2) == iz_op
t = apply_clifford_basis_change_tensor(zz_op, circ_2)
assert t.string == iz_op
assert t.coeff == -1

circ_3 = (
Circuit(4).H(0).H(1).H(2).H(3).CX(0, 1).CX(1, 2).CX(2, 3).S(0).Y(1).Z(2).X(3)
Expand All @@ -136,6 +146,10 @@ def test_apply_clifford_basis_change() -> None:
[Qubit(0), Qubit(1), Qubit(2), Qubit(3)], [Pauli.Y, Pauli.X, Pauli.Y, Pauli.I]
)
assert apply_clifford_basis_change(yxzi_op, circ_3) == yxyi_op
t = apply_clifford_basis_change_tensor(yxzi_op, circ_3)

assert t.string == yxyi_op
assert t.coeff == 1


if __name__ == "__main__":
Expand Down
Loading