tket
tket copied to clipboard
Critical assertion failure from circuit containing multiple `ClassicalExpBox`es
I've found that I get an assertion failure when I try to obtain a list of all of the ClassicalExpBoxes contained in this Circuit.
Unfortunately I haven't found a smaller circuit to reprodce the issue yet.
Circuit json file -> classicalexp_issue_circ.json
To reproduce, first load in the circuit
import json
from pytket import Circuit
with open("classicalexp_issue_circ.json", "r") as fp:
circuit = Circuit.from_dict(json.load(fp))
If I then try to obtain a list of all of the ClassicalExpBox commands...
from pytket import OpType
print(circuit.commands_of_type(optype=OpType.ClassicalExpBox)
I get a crash when runnning the above from the terminal
[2024-09-18 22:32:11] [tket] [critical] Assertion 'found' (/Users/runner/.conan2/p/b/tket386a3833d4772/b/src/Circuit/macro_circ_info.cpp : args_from_frontier : 979) failed. Aborting.
zsh: abort python issue_script.py
However if I run
print(circuit.ops_of_type(optype=OpType.ClassicalExpBox))
this executes without issue.
Note that this is a large circuit containing 20 ClassicalExpBoxes
from pytket.utils.stats import gate_counts
gate_counts(circuit)
gives
Counter({<OpType.Conditional: 110>: 45, <OpType.PhasedX: 71>: 22, <OpType.SetBits: 15>: 21, <OpType.ClassicalExpBox: 109>: 20, <OpType.Reset: 68>: 18, <OpType.Measure: 66>: 18, <OpType.Barrier: 8>: 2, <OpType.ZZPhase: 76>: 2, <OpType.Rz: 36>: 2})
As pointed out by @daniel-mills-cqc this circuit causes a RuntimeError when we attempt to run the DecomposeClassicalExp pass on it.
import json
from pytket.passes import DecomposeClassicalExp
from pytket import Circuit
with open("classicalexp_issue.json", 'r') as fp:
circuit = Circuit.from_dict(json.load(fp))
DecomposeClassicalExp().apply(circuit)
Gives the not so enlightening error message...
_decompose_expressions(circ)
358 newcirc.add_barrier(args)
359 else:
--> 360 newcirc.add_gate(op, args, **kwargs)
361 return newcirc, modified
RuntimeError: Unable to cast Python instance of type <class 'list'> to C++ type 'std::__1::vector<unsigned int, std::__1::allocator<unsigned int>>'
I recognise this error message from when we try to mix and match integers and unitids when adding conditional ops to a circuit. Made an issue to make this clearer -> https://github.com/CQCL/tket/issues/1580
It seems likely to me that the same sort of mismatch is occuring when the Circuit.add_gate method is called in the circuit construction part of the pass. See this line of code.