Skip to content

Commit

Permalink
fix: Fixing again issues with ecr_.* names (#74)
Browse files Browse the repository at this point in the history
* Fixing again issues with ecr_.* names

* [skip ci] Adding release note

* Rename unreleased rst file

* Add test for ECR gates with ibm_strasbourg

---------

Co-authored-by: Yaiza <[email protected]>
Co-authored-by: Jesus Talavera <[email protected]>
  • Loading branch information
3 people committed Sep 17, 2024
1 parent 52ea07b commit c5974cb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
13 changes: 8 additions & 5 deletions qiskit_ibm_transpiler/wrappers/transpile.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,19 @@ def _create_transpile_layout(initial, final, circuit, orig_circuit):

class FixECR(TransformationPass):
def run(self, dag):
for node in dag.named_nodes("ecr"):
dag.substitute_node(node, library.ECRGate())
for node in dag.op_nodes():
if node.name.startswith("ecr"):
dag.substitute_node(node, library.ECRGate())
return dag


def _get_circuit_from_qasm(qasm_string: str):
try:
return qasm2.loads(
qasm_string,
custom_instructions=_get_circuit_from_qasm.QISKIT_INSTRUCTIONS,
return _get_circuit_from_qasm.fix_ecr(
qasm2.loads(
qasm_string,
custom_instructions=_get_circuit_from_qasm.QISKIT_INSTRUCTIONS,
)
)
except QASM2ParseError:
return _get_circuit_from_qasm.fix_ecr(qasm3.loads(qasm_string))
Expand Down
1 change: 1 addition & 0 deletions release-notes/unreleased/74.bug.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes a bug with ECR gates coming from Qiskit when parsing using OpenQASM2
15 changes: 15 additions & 0 deletions tests/test_transpiler_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,18 @@ def test_fix_ecr_qasm3():

circuit_from_qasm = _get_circuit_from_qasm(qasm3.dumps(qc))
assert isinstance(list(circuit_from_qasm)[0].operation, ECRGate)


def test_fix_ecr_ibm_strasbourg():
num_qubits = 16
circuit = QuantumCircuit(num_qubits)
for i in range(num_qubits - 1):
circuit.ecr(i, i + 1)

cloud_transpiler_service = TranspilerService(
backend_name="ibm_strasbourg",
ai="false",
optimization_level=3,
)
transpiled_circuit = cloud_transpiler_service.run(circuit)
assert any(isinstance(gate.operation, ECRGate) for gate in list(transpiled_circuit))

0 comments on commit c5974cb

Please sign in to comment.