import math
from pytket import Bit, Circuit, Qubit
from pytket.architecture import Architecture
from pytket.circuit import if_not_bit
from pytket.passes import DecomposeBoxes, DecomposeMultiQubitsCX, DefaultMappingPass
sub_0 = Circuit()
sing_29 = Qubit("sing_29", 0)
sub_0.add_qubit(sing_29)
reg_42 = sub_0.add_q_register("reg_42", 1)
sing_54 = Qubit("sing_54", 0)
sub_0.add_qubit(sing_54)
sing_67 = Qubit("sing_67", 0)
sub_0.add_qubit(sing_67)
sing_81 = Bit("sing_81", 0)
sub_0.add_bit(sing_81)
sing_94 = Bit("sing_94", 0)
sub_0.add_bit(sing_94)
reg_107 = sub_0.add_c_register("reg_107", 1)
sub_0.CX(sing_29, reg_42[0])
sub_0.CRz(math.pi, sing_54, reg_42[0])
sub_0.Tdg(sing_54, condition=if_not_bit(reg_107[0]))
sub_0.add_clexpr_from_logicexp(sing_94 | reg_107[0], [sing_81])
sub_0.add_clexpr_from_logicexp(sing_94 & sing_81, [reg_107[0]])
sub_0.CRx(math.pi, sing_29, sing_54)
def _make_line_topology(n_qubits: int):
return [(i, i + 1) for i in range(n_qubits)]
def _route_circuit(circuit: Circuit) -> None:
arch = Architecture(_make_line_topology(circuit.n_qubits))
DecomposeMultiQubitsCX().apply(circuit)
DefaultMappingPass(arch).apply(circuit)
circuit_copy = sub_0.copy()
# routing block
DecomposeBoxes().apply(circuit_copy)
_route_circuit(circuit_copy)
##########
This causes a segfault. The stack trace shown by gdb is
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff709ec1c in tket::MappingFrontier::advance_next_2qb_slice(unsigned int) () from /home/ilan/programming/QFpp/.venv/lib/python3.12/site-packages/pytket/_tket/libtket.so
(gdb) bt
#0 0x00007ffff709ec1c in tket::MappingFrontier::advance_next_2qb_slice(unsigned int) () from /home/ilan/programming/QFpp/.venv/lib/python3.12/site-packages/pytket/_tket/libtket.so
#1 0x00007ffff7093859 in tket::LexiRoute::solve(unsigned int) () from /home/ilan/programming/QFpp/.venv/lib/python3.12/site-packages/pytket/_tket/libtket.so
#2 0x00007ffff709683e in tket::LexiRouteRoutingMethod::routing_method(std::shared_ptr<tket::MappingFrontier>&, std::shared_ptr<tket::Architecture> const&) const ()
from /home/ilan/programming/QFpp/.venv/lib/python3.12/site-packages/pytket/_tket/libtket.so
#3 0x00007ffff70af54e in tket::MappingManager::route_circuit_with_maps(tket::Circuit&, std::vector<std::shared_ptr<tket::RoutingMethod const>, std::allocator<std::shared_ptr<tket::RoutingMethod const> > > const&, std::shared_ptr<tket::unit_bimaps_t>) const () from /home/ilan/programming/QFpp/.venv/lib/python3.12/site-packages/pytket/_tket/libtket.so
#4 0x00007ffff7181851 in std::_Function_handler<bool (tket::Circuit&, std::shared_ptr<tket::unit_bimaps_t>), tket::gen_routing_pass(tket::Architecture const&, std::vector<std::shared_ptr<tket::RoutingMethod const>, std::allocator<std::shared_ptr<tket::RoutingMethod const> > > const&)::{lambda(tket::Circuit&, std::shared_ptr<tket::unit_bimaps_t>)#1}>::_M_invoke(std::_Any_data const&, tket::Circuit&, std::shared_ptr<tket::unit_bimaps_t>&&) ()
from /home/ilan/programming/QFpp/.venv/lib/python3.12/site-packages/pytket/_tket/libtket.so
#5 0x00007ffff715fc34 in tket::StandardPass::apply(tket::CompilationUnit&, tket::SafetyMode, std::function<void (tket::CompilationUnit const&, nlohmann::json_abi_v3_12_0::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_12_0::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void> const&)> const&, std::function<void (tket::CompilationUnit const&, nlohmann::json_abi_v3_12_0::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_12_0::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void> const&)> const&) const ()
from /home/ilan/programming/QFpp/.venv/lib/python3.12/site-packages/pytket/_tket/libtket.so
#6 0x00007ffff71662d9 in tket::SequencePass::apply(tket::CompilationUnit&, tket::SafetyMode, std::function<void (tket::CompilationUnit const&, nlohmann::json_abi_v3_12_0::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_12_0::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void> const&)> const&, std::function<void (tket::CompilationUnit const&, nlohmann::json_abi_v3_12_0::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_12_0::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void> const&)> const&) const ()
from /home/ilan/programming/QFpp/.venv/lib/python3.12/site-packages/pytket/_tket/libtket.so
#7 0x00007ffff71662d9 in tket::SequencePass::apply(tket::CompilationUnit&, tket::SafetyMode, std::function<void (tket::CompilationUnit const&, nlohmann::json_abi_v3_12_0::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_12_0::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void> const&)> const&, std::function<void (tket::CompilationUnit const&, nlohmann::json_abi_v3_12_0::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::json_abi_v3_12_0::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> >, void> const&)> const&) const ()
from /home/ilan/programming/QFpp/.venv/lib/python3.12/site-packages/pytket/_tket/libtket.so
#8 0x00007ffff59e3161 in ?? () from /home/ilan/programming/QFpp/.venv/lib/python3.12/site-packages/pytket/_tket/passes.abi3.so
#9 0x00007ffff59e323e in ?? () from /home/ilan/programming/QFpp/.venv/lib/python3.12/site-packages/pytket/_tket/passes.abi3.so
#10 0x00007ffff59f3842 in ?? () from /home/ilan/programming/QFpp/.venv/lib/python3.12/site-packages/pytket/_tket/passes.abi3.so
#11 0x0000000000549975 in PyObject_Vectorcall ()
#12 0x00000000005d6f09 in _PyEval_EvalFrameDefault ()
#13 0x00000000005d543b in PyEval_EvalCode ()
#14 0x00000000005d322c in ?? ()
#15 0x0000000000581d1d in ?? ()
#16 0x0000000000549975 in PyObject_Vectorcall ()
#17 0x00000000005d6f09 in _PyEval_EvalFrameDefault ()
#18 0x00000000006bcb52 in ?? ()
#19 0x00000000006bc782 in Py_RunMain ()
#20 0x00000000006bc3ed in Py_BytesMain ()
#21 0x00007ffff7c2a1ca in __libc_start_call_main (main=main@entry=0x518930, argc=argc@entry=3, argv=argv@entry=0x7fffffffd128) at ../sysdeps/nptl/libc_start_call_main.h:58
I tried to reduce the test case even further but found that I couldn't, for example, removing the CX gate works, removing any one of the classical exprs works, and so does removing the CRx gate.
When I run the circuit below, create a line topology and call
DefaultMappingPassusing that topology, I get a segfault.Run this circuit
This causes a segfault. The stack trace shown by
gdbisI tried to reduce the test case even further but found that I couldn't, for example, removing the
CXgate works, removing any one of the classical exprs works, and so does removing theCRxgate.Info
tket version: 0.12.16
OS: Ubuntu 24.04
Python version: 3.12.3