mirror of https://github.com/Qiskit/qiskit.git
Keeping randn in TwoQubitWeylDecomposition but seeded (#3653)
* seeding randn * use np.random.RandomState * i * cleaning up * test case * Update test/python/quantum_info/test_synthesis.py Co-Authored-By: Ali Javadi-Abhari <ajavadia@users.noreply.github.com> * Update qiskit/quantum_info/synthesis/two_qubit_decompose.py Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>
This commit is contained in:
parent
5dd98aac56
commit
2d75ea7b46
|
@ -161,8 +161,9 @@ class TwoQubitWeylDecomposition:
|
|||
# M2 is a symmetric complex matrix. We need to decompose it as M2 = P D P^T where
|
||||
# P ∈ SO(4), D is diagonal with unit-magnitude elements.
|
||||
# D, P = la.eig(M2) # this can fail for certain kinds of degeneracy
|
||||
for _ in range(100): # FIXME: this randomized algorithm is horrendous
|
||||
M2real = np.random.randn()*M2.real + np.random.randn()*M2.imag
|
||||
for i in range(100): # FIXME: this randomized algorithm is horrendous
|
||||
state = np.random.RandomState(i)
|
||||
M2real = state.randn()*M2.real + state.randn()*M2.imag
|
||||
_, P = la.eigh(M2real)
|
||||
D = P.T.dot(M2).dot(P).diagonal()
|
||||
if np.allclose(P.dot(np.diag(D)).dot(P.T), M2, rtol=1.0e-13, atol=1.0e-13):
|
||||
|
|
|
@ -542,6 +542,12 @@ class TestTwoQubitDecomposeExact(QiskitTestCase):
|
|||
U = execute(qc, sim).result().get_unitary()
|
||||
self.assertEqual(two_qubit_cnot_decompose.num_basis_gates(U), 3)
|
||||
|
||||
def test_seed_289(self):
|
||||
"""This specific case failed when PR #3585 was applied
|
||||
See https://github.com/Qiskit/qiskit-terra/pull/3652"""
|
||||
unitary = random_unitary(4, seed=289)
|
||||
self.check_exact_decomposition(unitary.data, two_qubit_cnot_decompose)
|
||||
|
||||
# FIXME: need to write tests for the approximate decompositions
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue