Skip to content

Commit

Permalink
Introduce new op types GPI, GPI2 and AAMS (#1329)
Browse files Browse the repository at this point in the history
  • Loading branch information
cqc-alec authored Apr 10, 2024
1 parent ecac301 commit c2a9014
Show file tree
Hide file tree
Showing 17 changed files with 424 additions and 73 deletions.
72 changes: 72 additions & 0 deletions pytket/binders/circuit/Circuit/add_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,42 @@ void init_circuit_add_op(py::class_<Circuit, std::shared_ptr<Circuit>> &c) {
"\n\n:return: the new :py:class:`Circuit`",
py::arg("angle0"), py::arg("angle1"), py::arg("angle2"),
py::arg("qubit"))
.def(
"GPI",
[](Circuit *circ, const Expr &angle, unsigned qb,
const py::kwargs &kwargs) {
return add_gate_method_oneparam<unsigned>(
circ, OpType::GPI, angle, {qb}, kwargs);
},
"Appends a GPI gate with a possibly symbolic angle "
"(specified in half-turns)."
"\n\n:return: the new :py:class:`Circuit`",
py::arg("angle"), py::arg("qubit"))
.def(
"GPI2",
[](Circuit *circ, const Expr &angle, unsigned qb,
const py::kwargs &kwargs) {
return add_gate_method_oneparam<unsigned>(
circ, OpType::GPI, angle, {qb}, kwargs);
},
"Appends a GPI2 gate with a possibly symbolic angle "
"(specified in half-turns)."
"\n\n:return: the new :py:class:`Circuit`",
py::arg("angle"), py::arg("qubit"))
.def(
"AAMS",
[](Circuit *circ, const Expr &angle0, const Expr &angle1,
const Expr &angle2, const unsigned &qb0, const unsigned &qb1,
const py::kwargs &kwargs) {
return add_gate_method_manyparams<unsigned>(
circ, OpType::AAMS, {angle0, angle1, angle2}, {qb0, qb1},
kwargs);
},
"Appends an AAMS gate with possibly symbolic angles "
"(specified in half-turns)."
"\n\n:return: the new :py:class:`Circuit`",
py::arg("angle0"), py::arg("angle1"), py::arg("angle2"),
py::arg("qubit0"), py::arg("qubit1"))
.def(
"TK1",
[](Circuit *circ, const Expr &angle0, const Expr &angle1,
Expand Down Expand Up @@ -1940,6 +1976,42 @@ void init_circuit_add_op(py::class_<Circuit, std::shared_ptr<Circuit>> &c) {
"\n\n:return: the new :py:class:`Circuit`",
py::arg("angle0"), py::arg("angle1"), py::arg("angle2"),
py::arg("qubit"))
.def(
"GPI",
[](Circuit *circ, const Expr &angle, const Qubit &qb,
const py::kwargs &kwargs) {
return add_gate_method_oneparam<UnitID>(
circ, OpType::GPI, angle, {qb}, kwargs);
},
"Appends a GPI gate with a possibly symbolic angle "
"(specified in half-turns)."
"\n\n:return: the new :py:class:`Circuit`",
py::arg("angle"), py::arg("qubit"))
.def(
"GPI2",
[](Circuit *circ, const Expr &angle, const Qubit &qb,
const py::kwargs &kwargs) {
return add_gate_method_oneparam<UnitID>(
circ, OpType::GPI2, angle, {qb}, kwargs);
},
"Appends a GPI2 gate with a possibly symbolic angle "
"(specified in half-turns)."
"\n\n:return: the new :py:class:`Circuit`",
py::arg("angle"), py::arg("qubit"))
.def(
"AAMS",
[](Circuit *circ, const Expr &angle0, const Expr &angle1,
const Expr &angle2, const Qubit &qb0, const Qubit &qb1,
const py::kwargs &kwargs) {
return add_gate_method_manyparams<UnitID>(
circ, OpType::AAMS, {angle0, angle1, angle2}, {qb0, qb1},
kwargs);
},
"Appends an AAMS gate with possibly symbolic angles "
"(specified in half-turns)."
"\n\n:return: the new :py:class:`Circuit`",
py::arg("angle0"), py::arg("angle1"), py::arg("angle2"),
py::arg("qubit0"), py::arg("qubit1"))
.def(
"TK1",
[](Circuit *circ, const Expr &angle0, const Expr &angle1,
Expand Down
22 changes: 22 additions & 0 deletions pytket/binders/circuit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,28 @@ PYBIND11_MODULE(circuit, m) {
"\\end{array} \\right] = e^{\\frac12 i\\pi(\\lambda+\\phi)} "
"\\mathrm{Rz}(\\phi) \\mathrm{Ry}(\\theta) "
"\\mathrm{Rz}(\\lambda)`")
.value(
"GPI", OpType::GPI,
":math:`(\\phi) \\mapsto \\left[ \\begin{array}{cc} 0 & "
"e^{-i\\pi\\phi} \\\\ e^{i\\pi\\phi} & 0 \\end{array} \\right]`")
.value(
"GPI2", OpType::GPI2,
":math:`(\\phi) \\mapsto \\frac{1}{\\sqrt 2} \\left[ "
"\\begin{array}{cc} 1 & -ie^{-i\\pi\\phi} \\\\ -ie^{i\\pi\\phi} & "
"1 \\end{array} \\right]`")
.value(
"AAMS", OpType::AAMS,
":math:`(\\theta, \\phi_0, \\phi_1) \\mapsto \\left[ "
"\\begin{array}{cccc} \\cos\\frac{\\pi\\theta}{2} & 0 & 0 & "
"-ie^{-i\\pi(\\phi_0+\\phi_1)}\\sin\\frac{\\pi\\theta}{2} \\\\ "
"0 & "
"\\cos\\frac{\\pi\\theta}{2} & "
"-ie^{i\\pi(\\phi_1-\\phi_0)}\\sin\\frac{\\pi\\theta}{2} & 0 \\\\ 0 "
"& "
"-ie^{i\\pi(\\phi_0-\\phi_1)}\\sin\\frac{\\pi\\theta}{2} & "
"\\cos\\frac{\\pi\\theta}{2} & 0 \\\\ "
"-ie^{i\\pi(\\phi_0+\\phi_1)}\\sin\\frac{\\pi\\theta}{2} & 0 & 0 & "
"\\cos\\frac{\\pi\\theta}{2} \\end{array} \\right]`")
.value(
"TK1", OpType::TK1,
":math:`(\\alpha, \\beta, \\gamma) \\mapsto "
Expand Down
2 changes: 1 addition & 1 deletion pytket/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def package(self):
cmake.install()

def requirements(self):
self.requires("tket/1.2.110@tket/stable")
self.requires("tket/1.2.111@tket/stable")
self.requires("tklog/0.3.3@tket/stable")
self.requires("tkrng/0.3.3@tket/stable")
self.requires("tkassert/0.3.4@tket/stable")
Expand Down
1 change: 1 addition & 0 deletions pytket/docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Features:
* New optimisation ``Transform.PushCliffordsThroughMeasures()`` and pass
``CliffordPushThroughMeasures`` that optimises Clifford subcircuits
before end of circuit measurement gates.
* Add ``OpType.GPI``, ``OpType.GPI2`` and ``OpType.AAMS``.

Fixes:

Expand Down
Loading

0 comments on commit c2a9014

Please sign in to comment.