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

qiskit_to_tk: KeyError for certain gates #138

Open
nquetschlich opened this issue Jun 30, 2023 · 1 comment
Open

qiskit_to_tk: KeyError for certain gates #138

nquetschlich opened this issue Jun 30, 2023 · 1 comment
Labels
circuit_conversion Issues and pull requests related to coverting qiskit circuits to pytket and vice versa

Comments

@nquetschlich
Copy link

nquetschlich commented Jun 30, 2023

The qiskit_to_tk transformation fails when certain gates are present in the original Qiskit.QuantumCircuit and throws a respective KeyError.

One example can be seen here:

from qiskit import QuantumCircuit
from qiskit.circuit.random import random_circuit
from pytket.extensions.qiskit import qiskit_to_tk

qc = random_circuit(8, depth=10, measure=False, seed=10)
qc_tket = qiskit_to_tk(qc)

Resulting in: KeyError: <class 'qiskit.circuit.library.standard_gates.xx_plus_yy.XXPlusYYGate'>

I could imagine that the problem occurs for gates which are not part of the openQASM2.0 gates. But there are even gates from that gateset which lead to the same error, for example here:

from qiskit import QuantumCircuit
from pytket.extensions.qiskit import qiskit_to_tk

qc = QuantumCircuit(3)
qc.rccx(0,1,2)
qc_tket = qiskit_to_tk(qc)

Resulting in: KeyError: <class 'qiskit.circuit.library.standard_gates.x.RCCXGate'>

(based on pytket v1.16.0 and qiskit v0.43.1)

@CalMacCQ
Copy link
Contributor

CalMacCQ commented Jun 30, 2023

Thanks for reporting this.

The KeyError is happening here as a dict is used to map qiskit Instruction s to pytket OpTypes. Admittedly the error message could be more informative (should be better imo).

In pytket we don't currently have OpTypes for XXPlusYYGate or RCCX.

A few unsupported gates were discussed here
#88

In the next release we will support CSX, CCZ and most qiskit ControlledGates for which the base gate is supported by the converter (CS, CSdg, C3sx etc). I don't believe RCCX will work though.

I'm not sure how to support these gates (nicely) in the converter without adding new OpTypes to pytket. Maybe we could consider adding the RCCX.

Edit: I guess we could use CnRx(pi) for this? Although the decomposition may be worse than RCCX. We do have a definition for this in C++ but its not currently exposed to pytket.

@CalMacCQ CalMacCQ added the circuit_conversion Issues and pull requests related to coverting qiskit circuits to pytket and vice versa label Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
circuit_conversion Issues and pull requests related to coverting qiskit circuits to pytket and vice versa
Projects
None yet
Development

No branches or pull requests

2 participants