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

Address RuntimeError in qiskit_to_tk conversion. #201

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ dist
obj
docs/extensions
.ipynb_checkpoints
*.ipynb
pytket/extensions/qiskit/_metadata.py
11 changes: 10 additions & 1 deletion pytket/extensions/qiskit/qiskit_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,16 @@ def add_qiskit_data(self, data: "QuantumCircuitData") -> None:
gate_def = CustomGateDef.define(
instr.name, subc, list(subc.free_symbols())
)
self.tkc.add_custom_gate(gate_def, params, qubits + bits) # type: ignore
try:
self.tkc.add_custom_gate(gate_def, params, qubits + bits) # type: ignore
except RuntimeError:
raise NotImplementedError(
f"Conversion of qiskit's {instr.name} instruction is "
+ "currently unsupported by qiskit_to_tk. Consider "
+ "using QuantumCircuit.decompose() before attempting "
+ "conversion."
)

elif optype == OpType.CU3 and type(instr) == qiskit_gates.CUGate:
if instr.params[-1] == 0:
self.tkc.add_gate(
Expand Down
17 changes: 16 additions & 1 deletion tests/qiskit_convert_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
)
from qiskit.quantum_info import Pauli, SparsePauliOp # type: ignore
from qiskit.transpiler import PassManager # type: ignore
from qiskit.circuit.library import RYGate, MCMT, XXPlusYYGate, PauliEvolutionGate, UnitaryGate # type: ignore
from qiskit.circuit.library import RYGate, MCMT, XXPlusYYGate, PauliEvolutionGate, UnitaryGate, RealAmplitudes # type: ignore
import qiskit.circuit.library.standard_gates as qiskit_gates # type: ignore
from qiskit.circuit import Parameter
from qiskit.synthesis import SuzukiTrotter # type: ignore
Expand Down Expand Up @@ -1013,3 +1013,18 @@ def test_failed_conversion_error() -> None:
NotImplementedError, match=r"Conversion of qiskit's xx_plus_yy instruction"
):
qiskit_to_tk(qc)


def test_custom_gate_error() -> None:
qc = QuantumCircuit(3)

params = [np.pi / 2] * 9
real_amps1 = RealAmplitudes(3, reps=2)

real_amps2 = real_amps1.assign_parameters(params)
qc.compose(real_amps2, qubits=[0, 1, 2], inplace=True)

with pytest.raises(
NotImplementedError, match=r"Conversion of qiskit's RealAmplitudes instruction"
):
qiskit_to_tk(qc)