Skip to content

Commit

Permalink
remove unnecessary and faulty cast to Gate in op.get_unitary (#1030)
Browse files Browse the repository at this point in the history
* remove unnecessary and faulty cast to Gate in op.get_unitary

* add test, and changlog entry

* clang + black
  • Loading branch information
trvto authored Sep 18, 2023
1 parent 61f8194 commit 5d09663
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
7 changes: 1 addition & 6 deletions pytket/binders/circuit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,12 +542,7 @@ PYBIND11_MODULE(circuit, m) {
.def("__hash__", &deletedHash<Op>, deletedHashDocstring)
.def("__repr__", [](const Op &op) { return op.get_name(); })
.def("free_symbols", [](const Op &op) { return op.free_symbols(); })
.def(
"get_unitary",
[](const Op *op) {
const auto &gate = dynamic_cast<const Gate &>(*op);
return gate.get_unitary();
})
.def("get_unitary", [](const Op *op) { return op->get_unitary(); })
.def(
"is_clifford_type",
[](const Op &op) { return op.get_desc().is_clifford_gate(); },
Expand Down
1 change: 1 addition & 0 deletions pytket/docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Unreleased

Fixes:

* Fix ``Op.get_unitary()`` runtime error for non gate ``Op``s.
* Fix ``CliffordSimp`` slow runtime issue.
* Correct implementation of ``free_symbols()`` and ``symbol_substitution()`` for
``ConjugationBox``.
Expand Down
4 changes: 4 additions & 0 deletions pytket/tests/circuit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,10 @@ def test_boxes() -> None:
d.add_conjugation_box(conj_box2, [Qubit(0), Qubit(1), Qubit(2)])
assert d.n_gates == 25
assert json_validate(d)
# test op.get_unitary doesn't throw
for command in d.get_commands():
if len(command.op.free_symbols()) == 0:
command.op.get_unitary()


def test_tofollibox_strats() -> None:
Expand Down

0 comments on commit 5d09663

Please sign in to comment.