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

Update basis equivalence test to be more specific #6532

Merged
merged 3 commits into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
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
99 changes: 99 additions & 0 deletions test/python/qasm/TestBasisTranslator_skip_target.qasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
OPENQASM 2.0;
include "qelib1.inc";
qreg q[5];
h q[0];
cu1(4.1564508) q[2],q[1];
swap q[0],q[1];
swap q[1],q[2];
cx q[3],q[2];
tdg q[2];
swap q[3],q[4];
cx q[3],q[2];
t q[2];
swap q[4],q[3];
cx q[3],q[2];
tdg q[2];
t q[3];
swap q[3],q[4];
cx q[3],q[2];
t q[2];
h q[2];
cx q[3],q[4];
t q[3];
tdg q[4];
cx q[3],q[4];
swap q[2],q[3];
rzz(0.48622471) q[2],q[1];
ch q[1],q[2];
t q[1];
swap q[0],q[1];
id q[2];
swap q[1],q[2];
h q[4];
cx q[3],q[4];
swap q[3],q[2];
tdg q[4];
cx q[3],q[4];
swap q[2],q[3];
t q[4];
cx q[3],q[4];
t q[3];
swap q[3],q[2];
tdg q[4];
cx q[3],q[4];
cx q[3],q[2];
tdg q[2];
t q[3];
cx q[3],q[2];
y q[3];
t q[3];
h q[3];
swap q[2],q[3];
t q[4];
h q[4];
cu3(2.5787688,1.3265772,3.1398664) q[4],q[3];
tdg q[3];
cx q[3],q[2];
tdg q[2];
swap q[2],q[1];
cx q[0],q[1];
t q[1];
swap q[3],q[2];
cx q[2],q[1];
tdg q[1];
cx q[0],q[1];
t q[1];
h q[1];
t q[2];
swap q[2],q[1];
cx q[0],q[1];
t q[0];
tdg q[1];
cx q[0],q[1];
u3(4.8520889,3.6025647,5.7475542) q[0];
rz(2.1885681) q[0];
cx q[1],q[2];
h q[1];
cx q[2],q[1];
tdg q[1];
swap q[1],q[2];
y q[4];
cz q[3],q[4];
cx q[3],q[2];
t q[2];
cx q[1],q[2];
t q[1];
tdg q[2];
cx q[3],q[2];
t q[2];
h q[2];
swap q[2],q[3];
cx q[2],q[1];
tdg q[1];
t q[2];
cx q[2],q[1];
swap q[1],q[2];
cx q[3],q[2];
cu3(2.7675189,4.5725211,2.9940136) q[1],q[2];
rx(5.976651) q[4];
cx q[4],q[3];
37 changes: 7 additions & 30 deletions test/python/transpiler/test_basis_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


"""Test the BasisTranslator pass"""

import os

from numpy import pi

Expand All @@ -26,7 +26,6 @@
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 @@ -820,38 +819,16 @@ def test_condition_set_substitute_node(self):

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)

qasm_file = os.path.join(
os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
"qasm",
"TestBasisTranslator_skip_target.qasm",
)
circ = circ.from_qasm_file(qasm_file)
circ_transpiled = transpile(
circ,
backend=FakeAthens(),
basis_gates=["id", "rz", "sx", "x", "cx"],
routing_method="sabre",
seed_transpiler=42,
)
self.assertEqual(circ_transpiled.count_ops(), {"cx": 91, "rz": 66, "sx": 22})