Skip to content

Commit

Permalink
Fix converting Rxx and similar Qiskit gates (#2579)
Browse files Browse the repository at this point in the history
  • Loading branch information
gluonhiggs authored Nov 25, 2024
1 parent 97702bf commit be6a76c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
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)

0 comments on commit be6a76c

Please sign in to comment.