Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
ElePT committed Jan 15, 2025
1 parent c8f1730 commit 81b4465
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions test/python/transpiler/test_unitary_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import scipy
from ddt import ddt, data

from qiskit import transpile
from qiskit import transpile, generate_preset_pass_manager
from qiskit.providers.fake_provider import Fake5QV1, GenericBackendV2
from qiskit.circuit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit.circuit.library import quantum_volume
Expand Down Expand Up @@ -921,7 +921,6 @@ def test_3q_measure_all(self):

def test_target_with_global_gates(self):
"""Test that 2q decomposition can handle a target with global gates."""

basis_gates = ["h", "p", "cp", "rz", "cx", "ccx", "swap"]
target = Target.from_configuration(basis_gates=basis_gates)

Expand All @@ -931,9 +930,28 @@ def test_target_with_global_gates(self):
bell_op = Operator(bell)
qc = QuantumCircuit(2)
qc.unitary(bell_op, [0, 1])

tqc = transpile(qc, target=target)
self.assertTrue(set(tqc.count_ops()).issubset(basis_gates))

def test_determinism(self):
"""Test that the decomposition is deterministic."""
gate_counts = {"rx": 6, "rz": 12, "iswap": 2}
basis_gates = ["rx", "rz", "iswap"]
target = Target.from_configuration(basis_gates=basis_gates)
pm = generate_preset_pass_manager(target=target, optimization_level=2, seed_transpiler=42)

qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)

for _ in range(10):
out = pm.run(qc)
self.assertTrue(Operator(out).equiv(qc))
self.assertTrue(set(out.count_ops()).issubset(basis_gates))
for basis_gate in basis_gates:
self.assertLessEqual(out.count_ops()[basis_gate], gate_counts[basis_gate])


if __name__ == "__main__":
unittest.main()

0 comments on commit 81b4465

Please sign in to comment.