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

Fix converting Rxx and similar Qiskit gates #2579

Merged
merged 11 commits into from
Nov 25, 2024
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ Vladimir Kozhukalov
Francesc Sabater
Emiliano Godinez
Tommy Nguyen
Duong H. D. Tran
5 changes: 4 additions & 1 deletion mitiq/interface/mitiq_qiskit/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,17 @@ def from_qiskit(circuit: qiskit.QuantumCircuit) -> cirq.Circuit:
Returns:
Mitiq circuit representation equivalent to the input Qiskit circuit.
"""

try:
mitiq_circuit = from_qasm(qasm2.dumps(circuit))
except QasmException:
# Try to decompose circuit before running
# This is necessary for converting qiskit circuits with
# custom packaged gates, e.g., QFT gates
circuit = circuit.decompose()
GATES_TO_DECOMPOSE = ["rxx", "rzz", "rzx", "ryy", "QFT"]
circuit = circuit.decompose(gates_to_decompose=GATES_TO_DECOMPOSE)
mitiq_circuit = from_qasm(qasm2.dumps(circuit))

return mitiq_circuit


Expand Down
8 changes: 8 additions & 0 deletions mitiq/interface/mitiq_qiskit/tests/test_conversions_qiskit.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,3 +476,11 @@ def test_remove_identity_from_idle_with_multiple_registers():
input_multi, input_single = _multi_reg_circuits()
assert circuit_multi_reg == input_multi
assert circuit_single_reg == input_single


def test_convert_to_mitiq_with_rx_and_rzz():
"""Tests that convert_to_mitiq works with RX and RZZ gates."""
test_qc = qiskit.QuantumCircuit(2)
test_qc.rx(0.1, 0)
test_qc.rzz(0.1, 0, 1)
assert convert_to_mitiq(test_qc)