Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Critical assertion failure from circuit containing multiple ClassicalExpBoxes #1590

Open
CalMacCQ opened this issue Sep 18, 2024 · 1 comment
Assignees
Labels
bug Something isn't working classical-logic issues related to classical logical expressions

Comments

@CalMacCQ
Copy link
Contributor

CalMacCQ commented Sep 18, 2024

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})
@CalMacCQ CalMacCQ added bug Something isn't working classical-logic issues related to classical logical expressions labels Sep 18, 2024
@CalMacCQ
Copy link
Contributor Author

CalMacCQ commented Sep 18, 2024

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 -> #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working classical-logic issues related to classical logical expressions
Projects
None yet
Development

No branches or pull requests

2 participants