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

test/transpiler: add regression tests for #9701 #9739

Merged
merged 1 commit into from
Mar 6, 2023
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
35 changes: 35 additions & 0 deletions test/python/transpiler/test_optimize_1q_decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,41 @@ def test_euler_decomposition_zsx_2(self):
result = passmanager.run(circuit)
self.assertEqual(circuit, result, f"Circuit:\n{circuit}\nResult:\n{result}")

def test_optimize_run_of_u_to_single_u_on_target_no_error(self):
"""U(pi/3, 0, 0) * U(pi/3, 0, 0) * U(pi/3, 0, 0) -> U(pi, 0, 0). See #9701."""
qr = QuantumRegister(1, "qr")
circuit = QuantumCircuit(qr)
for _ in range(3):
circuit.append(UGate(np.pi / 3, 0.0, 0.0), [qr[0]])

expected = QuantumCircuit(qr)
expected.append(UGate(np.pi, 0.0, 0.0), [qr[0]])

passmanager = PassManager()
passmanager.append(Optimize1qGatesDecomposition(target=target_rz_ry_u_noerror))
result = passmanager.run(circuit)

msg = f"expected:\n{expected}\nresult:\n{result}"
self.assertEqual(expected, result, msg=msg)

def test_optimize_run_of_u_to_single_u_no_target(self):
"""U(pi/3, 0, 0) * U(pi/3, 0, 0) * U(pi/3, 0, 0) -> U(pi, 0, 0). See #9701."""
qr = QuantumRegister(1, "qr")
circuit = QuantumCircuit(qr)
for _ in range(3):
circuit.append(UGate(np.pi / 3, 0.0, 0.0), [qr[0]])

expected = QuantumCircuit(qr)
expected.append(UGate(np.pi, 0.0, 0.0), [qr[0]])

basis = ["u"]
passmanager = PassManager()
passmanager.append(Optimize1qGatesDecomposition(basis))
result = passmanager.run(circuit)

msg = f"expected:\n{expected}\nresult:\n{result}"
self.assertEqual(expected, result, msg=msg)

def test_optimize_u_to_phase_gate(self):
"""U(0, 0, pi/4) -> p(pi/4). Basis [p, sx]."""
qr = QuantumRegister(2, "qr")
Expand Down