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 in LexiRoute.cpp when using RoutingPass #724

Closed
nquetschlich opened this issue Jan 17, 2023 · 3 comments
Closed

Critical Assertion in LexiRoute.cpp when using RoutingPass #724

nquetschlich opened this issue Jan 17, 2023 · 3 comments

Comments

@nquetschlich
Copy link

Hi,

I am combining qiskit and TKET compilation passes together in a single compilation flow and for some quantum circuits, I sometimes get the following critical assertion leading to an abort of the python script.

[2023-01-17 09:14:13] [tket] [critical] Assertion 'jt != architecture_nodes.end()' (/Users/alec/.conan/data/tket/1.0.36/tket/stable/build/59ebf0620228eb658575009636eae68dcd1b80d6/Mapping/LexiRoute.cpp : reassign_node : 58) failed. Aborting.

The behavior can be reproduced by the (rather lengthy) code example:

from qiskit.circuit.equivalence_library import StandardEquivalenceLibrary
from qiskit.transpiler.passes import (
    ApplyLayout,
    BasisTranslator,
    EnlargeWithAncilla,
    FullAncillaAllocation,
    SabreLayout,
)
from qiskit.transpiler import CouplingMap, PassManager
from qiskit.providers.fake_provider import FakeMontreal
from qiskit import QuantumCircuit

from pytket.passes import (
    RoutingPass,
)
from pytket import architecture
from pytket.extensions.qiskit import qiskit_to_tk, tk_to_qiskit


cmap = FakeMontreal().configuration().coupling_map


def MyBasisTranslator(qc):
    transpile_pass = BasisTranslator(StandardEquivalenceLibrary, target_basis=["rz", "sx", "x", "cx", "measure"])
    pm = PassManager(transpile_pass)
    qc = pm.run(qc)
    return qc


def MySabreLayout(qc):
    transpile_pass = [
        SabreLayout(coupling_map=CouplingMap(cmap)),
        FullAncillaAllocation(coupling_map=CouplingMap(cmap)),
        EnlargeWithAncilla(),
        ApplyLayout(),
    ]
    pm = PassManager(transpile_pass)
    qc = pm.run(qc)
    return qc


def MyRoutingPass(qc):
    tket_pass = RoutingPass(architecture.Architecture(cmap))
    tket_qc = qiskit_to_tk(qc)
    tket_pass.apply(tket_qc)
    return tk_to_qiskit(tket_qc)


for i in range (1000):
    print(i)
    qasm_str = 'OPENQASM 2.0; include "qelib1.inc";qreg q[20];creg meas[20];h q[0];h q[1];cz q[0],q[1];h q[2];h q[3];cz q[2],q[3];h q[4];h q[5];cz q[4],q[5];h q[6];h q[7];cz q[6],q[7];h q[8];h q[9];cz q[8],q[9];h q[10];cz q[3],q[10];cz q[9],q[10];h q[11];cz q[7],q[11];h q[12];cz q[2],q[12];h q[13];cz q[5],q[13];h q[14];cz q[12],q[14];cz q[13],q[14];h q[15];cz q[6],q[15];cz q[11],q[15];h q[16];cz q[0],q[16];cz q[8],q[16];h q[17];h q[18];cz q[1],q[18];cz q[17],q[18];h q[19];cz q[4],q[19];cz q[17],q[19];'
    qc = QuantumCircuit.from_qasm_str(qasm_str)

    qc = MyBasisTranslator(qc)
    qc = MySabreLayout(qc)
    qc = MyRoutingPass(qc)

The error occurs not always, when executing the script it usually happens before iteration 30.
Also, it happens for different target devices and corresponding cmaps. Interestingly, the error says node 58 although IBM Montreal is a 27 qubit device and the printed path obviously does not correspond to a valid path on my computer, even the mentioned TKET version within the printed path is outdated.

I use pytket v1.10.0, qiskit v0.39.4, python 3.10.8 and Mac OS 13.1.

@sjdilkes
Copy link
Contributor

Good morning @nquetschlich, thank you very much for bringing this issue to our attention.

This is actually a known bug with an open pull request for its fix at #715. If you're interested, hopefully the description of the issue in that pull request will explain what was going wrong.

I have run your example locally using a build of TKET from this linked branch and the script passes (multiple times).

I will leave this issue open until that pull request is merged. Once the pull request is merged we will put out a release so the fix is available through the pytket version available from pip. I'll let you know here once this is done.

@nquetschlich
Copy link
Author

Hi @sjdilkes, thank you very much for your fast response. I am looking forward to that release and will check out the details of the PR.

@sjdilkes
Copy link
Contributor

sjdilkes commented Jan 17, 2023

Hi @nquetschlich, #715 is now merged and pytket 1.11.0 is now available through pip with a fix for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants