fedimser / quantum_decomp

Converts unitary matrix to Qiskit/Cirq/Q# cirquit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

decompose_4x4_optimal is broken.

DevelopDaily opened this issue · comments

This will crash.

import sys
import platform
import numpy as np
import quantum_decomp as gd

print(sys.version_info)
print(sys.platform)
print(platform.release())

Id = np.array([[1, 0], [0, 1]])
H = np.array([[1, 1], [1, -1]]) / np.sqrt(2)
A = np.kron(Id, H)
gd.decompose_4x4_optimal(A)

Hi, it works for me:
image

From you snippet it looks like you didn't import the library.
If you are still getting error, can you please provide an error message?

I was using the "imports" and I re-posted my full test case above. In fact, I can run it with one of these successfully:

A = np.kron(Id, Id)
A = np.kron(H, H)
A = np.kron(H, Id)

It just fails when this one is used:

A = np.kron(Id, H)

This is my system info:

sys.version_info(major=3, minor=7, micro=3, releaselevel='final', serial=0)
linux
5.3.0-64-generic

The error message:

Traceback (most recent call last):

  File "/media/sf_u19_04_100GB_test/quantum_decomp/test_bug.py", line 13, in <module>
    gd.decompose_4x4_optimal(A)

  File "/media/sf_u19_04_100GB_test/quantum_decomp/src/decompose_4x4.py", line 401, in decompose_4x4_optimal
    magic_decomp = decompose_to_magic_diagonal(U)

  File "/media/sf_u19_04_100GB_test/quantum_decomp/src/decompose_4x4.py", line 313, in decompose_to_magic_diagonal
    UA_dag, UB_dag, lxe = decompose_4x4_partial(Psi_tilde)

  File "/media/sf_u19_04_100GB_test/quantum_decomp/src/decompose_4x4.py", line 200, in decompose_4x4_partial
    e, f = decompose_product_state(e_f)

  File "/media/sf_u19_04_100GB_test/quantum_decomp/src/decompose_4x4.py", line 144, in decompose_product_state
    assert np.allclose(np.kron(a, b), state)

AssertionError

This bug was fixed by febfb09
Code in first comment now works.