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

Add test for 6350 #6369

Merged
merged 3 commits into from
May 6, 2021
Merged
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
39 changes: 39 additions & 0 deletions test/python/transpiler/test_basis_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from qiskit.quantum_info import Operator
from qiskit.transpiler.exceptions import TranspilerError
from qiskit.transpiler.passes.basis import BasisTranslator, UnrollCustomDefinitions
from qiskit.test.mock import FakeAthens


from qiskit.circuit.library.standard_gates.equivalence_library import (
Expand Down Expand Up @@ -816,3 +817,41 @@ def test_condition_set_substitute_node(self):
expected.measure(1, 1)
expected.u2(0, pi, 0).c_if(cr, 1)
self.assertEqual(circ_transpiled, expected)

def test_skip_target_basis_equivalences_1(self):
"""Test that BasisTranslator skips gates in the target_basis - #6085"""

qstr = 'OPENQASM 2.0; \
include "qelib1.inc"; \
qreg q[5]; \
cu1(4.1564508) q[2],q[3]; \
ccx q[0],q[1],q[4]; \
rzz(0.48622471) q[0],q[2]; \
ccx q[3],q[4],q[1]; \
ch q[2],q[0]; \
y q[3]; \
cu3(2.5787688,1.3265772,3.1398664) q[1],q[4]; \
id q[0]; \
y q[1]; \
t q[2]; \
t q[3]; \
tdg q[4]; \
cz q[0],q[1]; \
ccx q[2],q[4],q[3]; \
rx(5.976651) q[1]; \
u3(4.8520889,3.6025647,5.7475542) q[2]; \
cswap q[0],q[3],q[4]; \
rz(2.1885681) q[2]; \
cu3(2.7675189,4.5725211,2.9940136) q[0],q[3]; \
cx q[1],q[4];'
circ = QuantumCircuit()
circ = circ.from_qasm_str(qstr)

circ_transpiled = transpile(
circ,
backend=FakeAthens(),
basis_gates=["id", "rz", "sx", "x", "cx"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is a bit redundant because FakeAthens already has this basis set, but it doesn't hurt anything.

routing_method="sabre",
seed_transpiler=42,
)
self.assertEqual(circ_transpiled.count_ops(), {"cx": 91, "rz": 66, "sx": 22})