Skip to content

Commit

Permalink
modified from_qiskit function, added test for convert_to_mitiq
Browse files Browse the repository at this point in the history
  • Loading branch information
gluonhiggs committed Nov 17, 2024
1 parent 1fdd877 commit cfecd99
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 5 additions & 5 deletions mitiq/interface/mitiq_qiskit/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import qiskit
from cirq.contrib.qasm_import import circuit_from_qasm
from cirq.contrib.qasm_import.exception import QasmException
from qiskit import qasm2
from qiskit import qasm2, transpile
from qiskit.transpiler import PassManager
from qiskit.transpiler.layout import Layout
from qiskit.transpiler.passes import SetLayout
Expand Down Expand Up @@ -52,9 +52,7 @@ def _remove_qasm_barriers(qasm: QASMType) -> QASMType:
return "".join(lines)


def _map_bit_index(
bit_index: int, new_register_sizes: List[int]
) -> Tuple[int, int]:
def _map_bit_index(bit_index: int, new_register_sizes: List[int]) -> Tuple[int, int]:
"""Returns the register index and (qu)bit index in this register for the
mapped bit_index.
Expand Down Expand Up @@ -255,7 +253,9 @@ def from_qiskit(circuit: qiskit.QuantumCircuit) -> cirq.Circuit:
# 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=["qft"])
circuit = circuit.decompose(
gates_to_decompose=["u1", "u2", "u3", "cx", "rx", "ry"]
)
circuit = circuit.decompose()
mitiq_circuit = from_qasm(qasm2.dumps(circuit))
return mitiq_circuit
Expand Down
7 changes: 7 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,10 @@ 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 cfecd99

Please sign in to comment.