diff --git a/tket/src/Utils/Expression.cpp b/tket/src/Utils/Expression.cpp index e24263b098..d81ca4617c 100644 --- a/tket/src/Utils/Expression.cpp +++ b/tket/src/Utils/Expression.cpp @@ -14,8 +14,11 @@ #include "Expression.hpp" +#include + #include "Constants.hpp" #include "Symbols.hpp" +#include "symengine/symengine_exception.h" namespace tket { @@ -57,7 +60,11 @@ std::optional eval_expr(const Expr& e) { if (!SymEngine::free_symbols(e).empty()) { return std::nullopt; } else { - return SymEngine::eval_double(e); + try { + return SymEngine::eval_double(e); + } catch (SymEngine::NotImplementedError&) { + return std::nullopt; + } } } diff --git a/tket/tests/Circuit/test_Boxes.cpp b/tket/tests/Circuit/test_Boxes.cpp index 54903436c8..9d75f9efeb 100644 --- a/tket/tests/Circuit/test_Boxes.cpp +++ b/tket/tests/Circuit/test_Boxes.cpp @@ -380,6 +380,12 @@ SCENARIO("Pauli gadgets", "[boxes]") { Eigen::MatrixXcd u = tket_sim::get_unitary(c); REQUIRE((u - Eigen::Matrix4cd::Identity()).cwiseAbs().sum() < ERR_EPS); } + GIVEN("complex coefficient") { + Expr ei{SymEngine::I}; + PauliExpBox pebox({Pauli::Z}, ei); + Expr p = pebox.get_phase(); + REQUIRE(p == ei); + } } SCENARIO("box daggers", "[boxes]") {